1 /* 2 * Copyright (c) 2021-2023 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 #ifndef OHOS_DCAMERA_SOURCE_CALLBACK_H 17 #define OHOS_DCAMERA_SOURCE_CALLBACK_H 18 19 #include <map> 20 #include <mutex> 21 22 #include "dcamera_source_callback_stub.h" 23 #include "idistributed_hardware_source.h" 24 25 namespace OHOS { 26 namespace DistributedHardware { 27 class DCameraSourceCallback : public DCameraSourceCallbackStub { 28 public: 29 DCameraSourceCallback() = default; 30 ~DCameraSourceCallback() override; 31 32 int32_t OnNotifyRegResult(const std::string& devId, const std::string& dhId, const std::string& reqId, 33 int32_t status, std::string& data) override; 34 int32_t OnNotifyUnregResult(const std::string& devId, const std::string& dhId, const std::string& reqId, 35 int32_t status, std::string& data) override; 36 int32_t OnHardwareStateChanged(const std::string &devId, const std::string &dhId, int32_t status) override; 37 int32_t OnDataSyncTrigger(const std::string &devId) override; 38 39 void PushRegCallback(std::string& reqId, std::shared_ptr<RegisterCallback>& callback); 40 void PopRegCallback(std::string& reqId); 41 void PushUnregCallback(std::string& reqId, std::shared_ptr<UnregisterCallback>& callback); 42 void PopUnregCallback(std::string& reqId); 43 void RegisterStateListener(const std::shared_ptr<DistributedHardwareStateListener> listener); 44 void UnRegisterStateListener(); 45 void RegisterTriggerListener(const std::shared_ptr<DataSyncTriggerListener> listener); 46 void UnRegisterTriggerListener(); 47 private: 48 std::map<std::string, std::shared_ptr<RegisterCallback>> regCallbacks_; 49 std::map<std::string, std::shared_ptr<UnregisterCallback>> unregCallbacks_; 50 std::mutex mapMutex_; 51 std::mutex stateListenerMtx_; 52 std::shared_ptr<DistributedHardwareStateListener> stateListener_ = nullptr; 53 std::mutex triggerListenerMtx_; 54 std::shared_ptr<DataSyncTriggerListener> triggerListener_ = nullptr; 55 const size_t DID_MAX_SIZE = 256; 56 }; 57 } // namespace DistributedHardware 58 } // namespace OHOS 59 #endif // OHOS_DCAMERA_SOURCE_CALLBACK_H 60