• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2024-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_COMMUNICATION_DATA_CONTROLLER_H
17 #define TELEPHONY_DISTRIBUTED_COMMUNICATION_DATA_CONTROLLER_H
18 
19 #include "cJSON.h"
20 #include "call_base.h"
21 #include "i_distributed_device_state_callback.h"
22 #include "session_adapter.h"
23 
24 namespace OHOS {
25 namespace Telephony {
26 constexpr const char* DISTRIBUTED_MSG_TYPE = "dataType";
27 constexpr const char* DISTRIBUTED_ITEM_TYPE = "itemType";
28 
29 constexpr const char* DISTRIBUTED_ITEM_NUM = "num";
30 constexpr const char* DISTRIBUTED_ITEM_NAME = "name";
31 constexpr const char* DISTRIBUTED_ITEM_LOCATION = "location";
32 constexpr const char* DISTRIBUTED_ITEM_MUTE = "mute";
33 constexpr const char* DISTRIBUTED_ITEM_DIRECTION = "direction";
34 
35 constexpr uint32_t DISTRIBUTED_DATA_TYPE_OFFSET_BASE = 1;
36 constexpr uint32_t DISTRIBUTED_MAX_RECV_DATA_LEN = 2048;
37 
38 enum class DistributedDataType : int32_t {
39     NAME = 0,
40     LOCATION = 1,
41     MAX = 2
42 };
43 
44 enum class DistributedMsgType : int32_t {
45     UNKNOWN = -1,
46     DATA_REQ = 100,
47     DATA_RSP = 101,
48     MUTE_RINGER = 102,
49     MUTE = 104,
50     CURRENT_DATA_REQ = 105,
51     CURRENT_DATA_RSP = 106,
52 };
53 
54 class DistributedDataController : public IDistributedDeviceStateCallback, public ISessionCallback {
55 public:
56     DistributedDataController() = default;
57     ~DistributedDataController() override = default;
OnDistributedAudioDeviceChange(const std::string & devId,const std::string & devName,AudioDeviceType devType,int32_t devRole)58     void OnDistributedAudioDeviceChange(const std::string &devId, const std::string &devName,
59         AudioDeviceType devType, int32_t devRole) override {}
OnRemoveSystemAbility()60     void OnRemoveSystemAbility() override {}
61     void OnReceiveMsg(const char* data, uint32_t dataLen) override;
62 
63     virtual void OnCallCreated(const sptr<CallBase> &call, const std::string &devId) = 0;
64     virtual void OnCallDestroyed() = 0;
65     virtual void ProcessCallInfo(const sptr<CallBase> &call, DistributedDataType type) = 0;
66 
67     void SetMuted(bool isMute);
68     void MuteRinger();
69 
70 protected:
71     virtual void HandleRecvMsg(int32_t msgType, const cJSON *msg) = 0;
72     bool GetInt32Value(const cJSON *msg, const std::string &name, int32_t &value);
73     bool GetStringValue(const cJSON *msg, const std::string &name, std::string &value);
74     bool GetBoolValue(const cJSON *msg, const std::string &name, bool &value);
75     void HandleMuted(const cJSON *msg);
76 
77 protected:
78     std::shared_ptr<SessionAdapter> session_{nullptr};
79 
80 private:
81     std::string CreateMuteMsg(DistributedMsgType msgType, bool isMute);
82     std::string CreateMuteRingerMsg(DistributedMsgType msgType);
83     void HandleMuteRinger();
84 };
85 
86 } // namespace Telephony
87 } // namespace OHOS
88 
89 #endif // TELEPHONY_DISTRIBUTED_COMMUNICATION_DATA_CONTROLLER_H
90