• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2024 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 TELEPHONY_DISTRIBUTED_DATA_SOURCE_CONTROLLER_H
17 #define TELEPHONY_DISTRIBUTED_DATA_SOURCE_CONTROLLER_H
18 
19 #include <map>
20 #include "ffrt.h"
21 #include "distributed_data_controller.h"
22 
23 namespace OHOS {
24 namespace Telephony {
25 class DistributedDataSourceController : public DistributedDataController,
26                                         public std::enable_shared_from_this<DistributedDataSourceController> {
27 public:
28     DistributedDataSourceController() = default;
29     ~DistributedDataSourceController() override = default;
30     void OnDeviceOnline(const std::string &devId, const std::string &devName, AudioDeviceType devType) override;
31     void OnDeviceOffline(const std::string &devId, const std::string &devName, AudioDeviceType devType) override;
32     void OnCallCreated(const sptr<CallBase> &call, const std::string &devId) override;
33     void OnCallDestroyed() override;
34     void ProcessCallInfo(const sptr<CallBase> &call, DistributedDataType type) override;
35     void OnConnected() override;
36 
37 protected:
38     void HandleRecvMsg(int32_t msgType, const cJSON *msg) override;
39 
40 private:
41     void SaveLocalData(const std::string &num, DistributedDataType type, const std::string &data);
42     void SaveLocalData(const sptr<CallBase> &call, DistributedDataType type);
43     void HandleDataQueryMsg(const cJSON *msg);
44     std::string CreateDataRspMsg(DistributedMsgType msgType, uint32_t itemType, const std::string &num,
45         const std::string &name, const std::string &value);
46     void SendLocalDataRsp();
47     std::string CreateCurrentDataRspMsg(const std::string &num, bool isMuted, int32_t direction);
48     void HandleCurrentDataQueryMsg(const cJSON *msg);
49 
50 private:
51     ffrt::mutex mutex_{};
52     std::map<std::string, std::map<uint32_t, std::string>> localInfo_{};
53     std::map<std::string, uint32_t> queryInfo_{};
54 };
55 
56 } // namespace Telephony
57 } // namespace OHOS
58 
59 #endif // TELEPHONY_DISTRIBUTED_DATA_SOURCE_CONTROLLER_H
60