• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2021 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 "dcamera_source_callback.h"
17 
18 #include "anonymous_string.h"
19 #include "distributed_camera_errno.h"
20 #include "distributed_hardware_log.h"
21 
22 namespace OHOS {
23 namespace DistributedHardware {
~DCameraSourceCallback()24 DCameraSourceCallback::~DCameraSourceCallback()
25 {
26     regCallbacks_.clear();
27     unregCallbacks_.clear();
28 }
29 
OnNotifyRegResult(const std::string & devId,const std::string & dhId,const std::string & reqId,int32_t status,std::string & data)30 int32_t DCameraSourceCallback::OnNotifyRegResult(const std::string& devId, const std::string& dhId,
31     const std::string& reqId, int32_t status, std::string& data)
32 {
33     DHLOGI("DCameraSourceCallback OnNotifyRegResult devId: %s dhId: %s",
34         GetAnonyString(devId).c_str(), GetAnonyString(dhId).c_str());
35     auto iter = regCallbacks_.find(reqId);
36     if (iter == regCallbacks_.end()) {
37         DHLOGE("DCameraSourceCallback OnNotifyRegResult not found devId: %s dhId: %s",
38             GetAnonyString(devId).c_str(), GetAnonyString(dhId).c_str());
39         return DCAMERA_NOT_FOUND;
40     }
41     int32_t ret = iter->second->OnRegisterResult(devId, dhId, status, data);
42     if (ret != DCAMERA_OK) {
43         DHLOGE("DCameraSourceCallback OnNotifyRegResult failed, devId: %s dhId: %s ret: %d",
44             GetAnonyString(devId).c_str(), GetAnonyString(dhId).c_str(), ret);
45     }
46     regCallbacks_.erase(iter);
47     return ret;
48 }
49 
OnNotifyUnregResult(const std::string & devId,const std::string & dhId,const std::string & reqId,int32_t status,std::string & data)50 int32_t DCameraSourceCallback::OnNotifyUnregResult(const std::string& devId, const std::string& dhId,
51     const std::string& reqId, int32_t status, std::string& data)
52 {
53     DHLOGI("DCameraSourceCallback OnNotifyUnregResult devId: %s dhId: %s",
54         GetAnonyString(devId).c_str(), GetAnonyString(dhId).c_str());
55     auto iter = unregCallbacks_.find(reqId);
56     if (iter == unregCallbacks_.end()) {
57         DHLOGE("DCameraSourceCallback OnNotifyUnregResult not found devId: %s dhId: %s",
58             GetAnonyString(devId).c_str(), GetAnonyString(dhId).c_str());
59         return DCAMERA_NOT_FOUND;
60     }
61     int32_t ret = iter->second->OnUnregisterResult(devId, dhId, status, data);
62     if (ret != DCAMERA_OK) {
63         DHLOGE("DCameraSourceCallback OnNotifyUnregResult failed, devId: %s dhId: %s ret: %d",
64             GetAnonyString(devId).c_str(), GetAnonyString(dhId).c_str(), ret);
65     }
66     unregCallbacks_.erase(iter);
67     return ret;
68 }
69 
PushRegCallback(std::string & reqId,std::shared_ptr<RegisterCallback> & callback)70 void DCameraSourceCallback::PushRegCallback(std::string& reqId, std::shared_ptr<RegisterCallback>& callback)
71 {
72     regCallbacks_.emplace(reqId, callback);
73 }
74 
PopRegCallback(std::string & reqId)75 void DCameraSourceCallback::PopRegCallback(std::string& reqId)
76 {
77     regCallbacks_.erase(reqId);
78 }
79 
PushUnregCallback(std::string & reqId,std::shared_ptr<UnregisterCallback> & callback)80 void DCameraSourceCallback::PushUnregCallback(std::string& reqId, std::shared_ptr<UnregisterCallback>& callback)
81 {
82     unregCallbacks_.emplace(reqId, callback);
83 }
84 
PopUnregCallback(std::string & reqId)85 void DCameraSourceCallback::PopUnregCallback(std::string& reqId)
86 {
87     unregCallbacks_.erase(reqId);
88 }
89 } // namespace DistributedHardware
90 } // namespace OHOS
91