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 #ifndef OHOS_DAUDIO_IPC_CALLBACK_H
17 #define OHOS_DAUDIO_IPC_CALLBACK_H
18 
19 #include <map>
20 #include <mutex>
21 
22 #include "daudio_ipc_callback_stub.h"
23 #include "idistributed_hardware_source.h"
24 
25 namespace OHOS {
26 namespace DistributedHardware {
27 class DAudioIpcCallback : public DAudioIpcCallbackStub {
28 public:
29     DAudioIpcCallback() = default;
30     ~DAudioIpcCallback() override = default;
31 
32     int32_t OnNotifyRegResult(const std::string &devId, const std::string &dhId, const std::string &reqId,
33         int32_t status, const std::string &resultData) override;
34     int32_t OnNotifyUnregResult(const std::string &devId, const std::string &dhId, const std::string &reqId,
35         int32_t status, const std::string &resultData) 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 PushRegisterCallback(const std::string &reqId, const std::shared_ptr<RegisterCallback> &callback);
40     void PopRegisterCallback(const std::string &reqId);
41     void PushUnregisterCallback(const std::string &reqId, const std::shared_ptr<UnregisterCallback> &callback);
42     void PopUnregisterCallback(const 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 
48 private:
49     std::mutex registerMapMtx_;
50     std::map<std::string, std::shared_ptr<RegisterCallback>> registerCallbackMap_;
51     std::mutex unregisterMapMtx_;
52     std::map<std::string, std::shared_ptr<UnregisterCallback>> unregisterCallbackMap_;
53     std::mutex stateListenerMtx_;
54     std::shared_ptr<DistributedHardwareStateListener> stateListener_ = nullptr;
55     std::mutex triggerListenerMtx_;
56     std::shared_ptr<DataSyncTriggerListener> triggerListener_ = nullptr;
57 };
58 } // DistributedHardware
59 } // OHOS
60 #endif // OHOS_DAUDIO_IPC_CALLBACK_H