• 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_DEVICE_OBSERVER_H
17 #define TELEPHONY_DISTRIBUTED_COMMUNICATION_DEVICE_OBSERVER_H
18 
19 #include "ffrt.h"
20 #include "call_manager_base.h"
21 #include "system_ability_status_change_stub.h"
22 #include "i_distributed_device_callback.h"
23 #include "i_distributed_device_state_callback.h"
24 
25 namespace OHOS {
26 namespace Telephony {
27 class DistributedDeviceCallback : public IDistributedDeviceCallback {
28 public:
29     DistributedDeviceCallback() = default;
30     ~DistributedDeviceCallback() override = default;
31     int32_t OnDistributedDeviceOnline(const std::string &devId, const std::string &devName,
32         int32_t devType, int32_t devRole) override;
33     int32_t OnDistributedDeviceOffline(const std::string &devId, const std::string &devName,
34         int32_t devType, int32_t devRole) override;
35     int32_t OnDistributedAudioDeviceChange(const std::string &devId, const std::string &devName,
36         int32_t devType, int32_t devRole) override;
37 
38 private:
39     AudioDeviceType ConvertDeviceType(int32_t devType);
40 };
41 
42 class DistributedSystemAbilityListener : public SystemAbilityStatusChangeStub {
43 public:
44     DistributedSystemAbilityListener() = default;
45     ~DistributedSystemAbilityListener() = default;
46     void OnAddSystemAbility(int32_t systemAbilityId, const std::string &deviceId) override;
47     void OnRemoveSystemAbility(int32_t systemAbilityId, const std::string &deviceId) override;
48 };
49 
50 class DistributedDeviceObserver {
51 public:
52     DistributedDeviceObserver() = default;
53     ~DistributedDeviceObserver() = default;
54     void Init();
55     void RegisterDevCallback();
56     int32_t UnRegisterDevCallback();
57     void RegisterDevStatusCallback(const std::shared_ptr<IDistributedDeviceStateCallback> &callback);
58     void UnRegisterDevStatusCallback(const std::shared_ptr<IDistributedDeviceStateCallback> &callback);
59     void OnDeviceOnline(const std::string &devId, const std::string &devName, AudioDeviceType devType);
60     void OnDeviceOffline(const std::string &devId, const std::string &devName, AudioDeviceType devType);
61     void OnDistributedAudioDeviceChange(const std::string &devId, const std::string &devName,
62         AudioDeviceType devType, int32_t devRole);
63     void OnRemoveSystemAbility();
64 
65 private:
66     sptr<DistributedSystemAbilityListener> saListener_{nullptr};
67     ffrt::mutex mutex_{};
68     std::list<std::shared_ptr<IDistributedDeviceStateCallback>> callbacks_{};
69     std::shared_ptr<IDistributedDeviceCallback> deviceListener_{nullptr};
70 };
71 
72 } // namespace Telephony
73 } // namespace OHOS
74 
75 #endif // TELEPHONY_DISTRIBUTED_COMMUNICATION_DEVICE_OBSERVER_H
76