1 /*
2 * Copyright (c) 2022 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 })
31 {
32 }
33
~Publisher()34 Publisher::~Publisher()
35 {
36 }
37
RegisterListener(const DHTopic topic,const sptr<IPublisherListener> & listener)38 void Publisher::RegisterListener(const DHTopic topic, const sptr<IPublisherListener> &listener)
39 {
40 publisherItems_[topic]->AddListener(listener);
41 }
42
UnregisterListener(const DHTopic topic,const sptr<IPublisherListener> & listener)43 void Publisher::UnregisterListener(const DHTopic topic, const sptr<IPublisherListener> &listener)
44 {
45 publisherItems_[topic]->RemoveListener(listener);
46 }
47
PublishMessage(const DHTopic topic,const std::string & message)48 void Publisher::PublishMessage(const DHTopic topic, const std::string &message)
49 {
50 publisherItems_[topic]->PublishMessage(message);
51 }
52 } // namespace DistributedHardware
53 } // namespace OHOS