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 constexpr int32_t QOS_MIN_BW = 4 * 1024 * 1024; 38 39 enum class DistributedDataType : int32_t { 40 NAME = 0, 41 LOCATION = 1, 42 MAX = 2 43 }; 44 45 enum class DistributedMsgType : int32_t { 46 UNKNOWN = -1, 47 DATA_REQ = 100, 48 DATA_RSP = 101, 49 MUTE_RINGER = 102, 50 MUTE = 104, 51 CURRENT_DATA_REQ = 105, 52 CURRENT_DATA_RSP = 106, 53 }; 54 55 class DistributedDataController : public IDistributedDeviceStateCallback, public ISessionCallback { 56 public: 57 DistributedDataController() = default; 58 ~DistributedDataController() override = default; OnDistributedAudioDeviceChange(const std::string & devId,const std::string & devName,AudioDeviceType devType,int32_t devRole)59 void OnDistributedAudioDeviceChange(const std::string &devId, const std::string &devName, 60 AudioDeviceType devType, int32_t devRole) override {} OnRemoveSystemAbility()61 void OnRemoveSystemAbility() override {} 62 void OnReceiveMsg(const char* data, uint32_t dataLen) override; 63 64 virtual void OnCallCreated(const sptr<CallBase> &call, const std::string &devId) = 0; 65 virtual void OnCallDestroyed() = 0; 66 virtual void ProcessCallInfo(const sptr<CallBase> &call, DistributedDataType type) = 0; 67 68 void SetMuted(bool isMute); 69 void MuteRinger(); 70 71 protected: 72 virtual void HandleRecvMsg(int32_t msgType, const cJSON *msg) = 0; 73 bool GetInt32Value(const cJSON *msg, const std::string &name, int32_t &value); 74 bool GetStringValue(const cJSON *msg, const std::string &name, std::string &value); 75 bool GetBoolValue(const cJSON *msg, const std::string &name, bool &value); 76 void HandleMuted(const cJSON *msg); 77 78 protected: 79 std::shared_ptr<SessionAdapter> session_{nullptr}; 80 81 private: 82 std::string CreateMuteMsg(DistributedMsgType msgType, bool isMute); 83 std::string CreateMuteRingerMsg(DistributedMsgType msgType); 84 void HandleMuteRinger(); 85 }; 86 87 } // namespace Telephony 88 } // namespace OHOS 89 90 #endif // TELEPHONY_DISTRIBUTED_COMMUNICATION_DATA_CONTROLLER_H 91