• 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 "dscreen_source_callback.h"
17 
18 #include "dscreen_errcode.h"
19 #include "dscreen_log.h"
20 #include "dscreen_util.h"
21 
22 namespace OHOS {
23 namespace DistributedHardware {
OnNotifyRegResult(const std::string & devId,const std::string & dhId,const std::string & reqId,int32_t status,const std::string & data)24 int32_t DScreenSourceCallback::OnNotifyRegResult(const std::string &devId, const std::string &dhId,
25     const std::string &reqId, int32_t status, const std::string &data)
26 {
27     DHLOGI("DScreenSourceCallback OnNotifyRegResult devId: %s dhId: %s status: %d",
28         GetAnonyString(devId).c_str(), GetAnonyString(dhId).c_str(), status);
29     auto iter = registerCallbackMap_.find(reqId);
30     if (iter != registerCallbackMap_.end()) {
31         if (iter->second == nullptr) {
32             DHLOGE("DScreenSourceCallback Regcallback is null.");
33             return ERR_DH_SCREEN_SA_REGISTERCALLBACK_NOT_FOUND;
34         }
35         iter->second->OnRegisterResult(devId, dhId, status, data);
36         registerCallbackMap_.erase(reqId);
37         return DH_SUCCESS;
38     }
39 
40     return ERR_DH_SCREEN_SA_REGISTERCALLBACK_NOT_FOUND;
41 }
42 
OnNotifyUnregResult(const std::string & devId,const std::string & dhId,const std::string & reqId,int32_t status,const std::string & data)43 int32_t DScreenSourceCallback::OnNotifyUnregResult(const std::string &devId, const std::string &dhId,
44     const std::string &reqId, int32_t status, const std::string &data)
45 {
46     DHLOGI("DScreenSourceCallback OnNotifyUnregResult devId: %s dhId: %s status: %d",
47         GetAnonyString(devId).c_str(), GetAnonyString(dhId).c_str(), status);
48     auto iter = unregisterCallbackMap_.find(reqId);
49     if (iter != unregisterCallbackMap_.end()) {
50         if (iter->second == nullptr) {
51             DHLOGE("DScreenSourceCallback Unregcallback is null.");
52             return ERR_DH_SCREEN_SA_UNREGISTERCALLBACK_NOT_FOUND;
53         }
54         iter->second->OnUnregisterResult(devId, dhId, status, data);
55         unregisterCallbackMap_.erase(reqId);
56         return DH_SUCCESS;
57     }
58 
59     return ERR_DH_SCREEN_SA_UNREGISTERCALLBACK_NOT_FOUND;
60 }
61 
PushRegRegisterCallback(const std::string & reqId,const std::shared_ptr<RegisterCallback> & callback)62 void DScreenSourceCallback::PushRegRegisterCallback(const std::string &reqId,
63     const std::shared_ptr<RegisterCallback> &callback)
64 {
65     DHLOGD("PushRegRegisterCallback");
66     registerCallbackMap_.emplace(reqId, callback);
67 }
68 
PopRegRegisterCallback(const std::string & reqId)69 void DScreenSourceCallback::PopRegRegisterCallback(const std::string &reqId)
70 {
71     DHLOGD("PopRegRegisterCallback");
72     registerCallbackMap_.erase(reqId);
73 }
74 
PushUnregisterCallback(const std::string & reqId,const std::shared_ptr<UnregisterCallback> & callback)75 void DScreenSourceCallback::PushUnregisterCallback(const std::string &reqId,
76     const std::shared_ptr<UnregisterCallback> &callback)
77 {
78     DHLOGD("PushUnregisterCallback");
79     unregisterCallbackMap_.emplace(reqId, callback);
80 }
81 
PopUnregisterCallback(const std::string & reqId)82 void DScreenSourceCallback::PopUnregisterCallback(const std::string &reqId)
83 {
84     DHLOGD("PopUnregisterCallback");
85     unregisterCallbackMap_.erase(reqId);
86 }
87 }
88 }