1 /*
2  * Copyright (c) 2022-2024 Huawei Device Co., Ltd.
3  * Licensed under the Apache License, Version 2.0 (the "License");
4  * you may not use this file except in compliance with the License.
5  * You may obtain a copy of the License at
6  *
7  *     http://www.apache.org/licenses/LICENSE-2.0
8  *
9  * Unless required by applicable law or agreed to in writing, software
10  * distributed under the License is distributed on an "AS IS" BASIS,
11  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12  * See the License for the specific language governing permissions and
13  * limitations under the License.
14  */
15 
16 #include "publisher.h"
17 
18 namespace OHOS {
19 namespace DistributedHardware {
20 IMPLEMENT_SINGLE_INSTANCE(Publisher);
Publisher()21 Publisher::Publisher() : publisherItems_({
22         { DHTopic::TOPIC_START_DSCREEN, std::make_shared<PublisherItem>(DHTopic::TOPIC_START_DSCREEN) },
23         { DHTopic::TOPIC_SINK_PROJECT_WINDOW_INFO,
24             std::make_shared<PublisherItem>(DHTopic::TOPIC_SINK_PROJECT_WINDOW_INFO) },
25         { DHTopic::TOPIC_STOP_DSCREEN, std::make_shared<PublisherItem>(DHTopic::TOPIC_STOP_DSCREEN) },
26         { DHTopic::TOPIC_DEV_OFFLINE, std::make_shared<PublisherItem>(DHTopic::TOPIC_DEV_OFFLINE) },
27         { DHTopic::TOPIC_LOW_LATENCY, std::make_shared<PublisherItem>(DHTopic::TOPIC_LOW_LATENCY) },
28         { DHTopic::TOPIC_INIT_DHMS_READY, std::make_shared<PublisherItem>(DHTopic::TOPIC_INIT_DHMS_READY) },
29         { DHTopic::TOPIC_PHY_DEV_PLUGIN, std::make_shared<PublisherItem>(DHTopic::TOPIC_PHY_DEV_PLUGIN) },
30         { DHTopic::TOPIC_ISOMERISM, std::make_shared<PublisherItem>(DHTopic::TOPIC_ISOMERISM) }
31     })
32 {
33 }
34 
~Publisher()35 Publisher::~Publisher()
36 {
37 }
38 
RegisterListener(const DHTopic topic,const sptr<IPublisherListener> listener)39 void Publisher::RegisterListener(const DHTopic topic, const sptr<IPublisherListener> listener)
40 {
41     publisherItems_[topic]->AddListener(listener);
42 }
43 
UnregisterListener(const DHTopic topic,const sptr<IPublisherListener> listener)44 void Publisher::UnregisterListener(const DHTopic topic, const sptr<IPublisherListener> listener)
45 {
46     publisherItems_[topic]->RemoveListener(listener);
47 }
48 
PublishMessage(const DHTopic topic,const std::string & message)49 void Publisher::PublishMessage(const DHTopic topic, const std::string &message)
50 {
51     publisherItems_[topic]->PublishMessage(message);
52 }
53 } // namespace DistributedHardware
54 } // namespace OHOS