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_MANAGER_H 17 #define TELEPHONY_DISTRIBUTED_COMMUNICATION_MANAGER_H 18 19 #include "singleton.h" 20 #include "ffrt.h" 21 #include "call_manager_inner_type.h" 22 #include "call_state_listener_base.h" 23 #include "distributed_device_observer.h" 24 #include "distributed_data_controller.h" 25 #include "distributed_device_switch_controller.h" 26 27 namespace OHOS { 28 namespace Telephony { 29 enum class DistributedRole : int8_t { 30 UNKNOWN = -1, 31 SOURCE = 0, 32 SINK = 1 33 }; 34 35 enum class DistributedStatus : int8_t { 36 UNKNOWN = -1, 37 DISCONNECT = 0, 38 CONNECT = 1 39 }; 40 41 class DistributedCommunicationManager : public CallStateListenerBase { 42 DECLARE_DELAYED_SINGLETON(DistributedCommunicationManager) 43 public: 44 void Init(); 45 void InitExtWrapper(); 46 void DeInitExtWrapper(); 47 int32_t RegDevCallbackWrapper(const std::shared_ptr<IDistributedDeviceCallback> &callback); 48 int32_t UnRegDevCallbackWrapper(); 49 int32_t SwitchDevWrapper(const std::string &devId, int32_t direction); 50 void OnDeviceOnline(const std::string &devId, const std::string &devName, AudioDeviceType deviceType, 51 int32_t devRole); 52 void OnDeviceOffline(const std::string &devId, const std::string &devName, AudioDeviceType deviceType, 53 int32_t devRole); 54 void OnRemoveSystemAbility(); 55 bool IsSinkRole(); 56 bool IsConnected(); 57 bool IsDistributedDev(const AudioDevice& device); 58 const std::shared_ptr<DistributedDeviceObserver>& GetDistributedDeviceObserver(); 59 bool SwitchToSourceDevice(); 60 bool SwitchToSinkDevice(const AudioDevice& device); 61 bool IsAudioOnSink(); 62 void SetMuted(bool isMute); 63 void MuteRinger(); 64 void ProcessCallInfo(const sptr<CallBase> &call, DistributedDataType type); 65 66 void NewCallCreated(sptr<CallBase> &call) override; 67 void CallDestroyed(const DisconnectedDetails &details) override; 68 69 private: 70 bool IsDistributedDev(const std::string &devId); 71 std::string ParseDevIdFromAudioDevice(const AudioDevice& device); 72 73 private: 74 typedef int32_t (*REGISTER_DEVICE_CALLBACK)(const std::shared_ptr<OHOS::Telephony::IDistributedDeviceCallback>&); 75 typedef int32_t (*UN_REGISTER_DEVICE_CALLBACK)(void); 76 typedef int32_t (*SWITCH_DEVICE)(const std::string&, int32_t); 77 ffrt::mutex mutexFunc_{}; 78 void *extWrapperHandler_{nullptr}; 79 REGISTER_DEVICE_CALLBACK regDevCallbackFunc_{nullptr}; 80 UN_REGISTER_DEVICE_CALLBACK unRegDevCallbackFunc_{nullptr}; 81 SWITCH_DEVICE switchDevFunc_{nullptr}; 82 83 ffrt::mutex mutex_{}; 84 std::list<std::string> peerDevices_{}; 85 std::shared_ptr<DistributedDeviceObserver> devObserver_{nullptr}; 86 std::shared_ptr<DistributedDataController> dataController_{nullptr}; 87 std::shared_ptr<DistributedDeviceSwitchController> devSwitchController_{nullptr}; 88 DistributedStatus status_{DistributedStatus::UNKNOWN}; 89 DistributedRole role_{DistributedRole::UNKNOWN}; 90 }; 91 92 } // namespace Telephony 93 } // namespace OHOS 94 95 #endif // TELEPHONY_DISTRIBUTED_COMMUNICATION_MANAGER_H 96