• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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     })
28 {
29 }
30 
~Publisher()31 Publisher::~Publisher()
32 {
33 }
34 
RegisterListener(const DHTopic topic,const sptr<IPublisherListener> & listener)35 void Publisher::RegisterListener(const DHTopic topic, const sptr<IPublisherListener> &listener)
36 {
37     publisherItems_[topic]->AddListener(listener);
38 }
39 
UnregisterListener(const DHTopic topic,const sptr<IPublisherListener> & listener)40 void Publisher::UnregisterListener(const DHTopic topic, const sptr<IPublisherListener> &listener)
41 {
42     publisherItems_[topic]->RemoveListener(listener);
43 }
44 
PublishMessage(const DHTopic topic,const std::string & message)45 void Publisher::PublishMessage(const DHTopic topic, const std::string &message)
46 {
47     publisherItems_[topic]->PublishMessage(message);
48 }
49 } // namespace DistributedHardware
50 } // namespace OHOS