1 /*
2  * Copyright (C) 2023-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 #ifndef OHOS_WIFI_SYSTEM_ABILITY_LISTENER_H
16 #define OHOS_WIFI_SYSTEM_ABILITY_LISTENER_H
17 
18 #ifndef OHOS_ARCH_LITE
19 #include <unordered_set>
20 #include "system_ability_status_change_stub.h"
21 #include <mutex>
22 #endif // OHOS_ARCH_LITE
23 
24 namespace OHOS {
25 namespace Wifi {
26 
27 class WifiSystemAbilityListener {
28 public:
29     WifiSystemAbilityListener();
30     virtual ~WifiSystemAbilityListener();
31     void SubscribeSystemAbility(int systemAbilityId);
32     void UnSubscribeSystemAbility(int systemAbilityId);
33     virtual void OnSystemAbilityChanged(int systemAbilityId, bool add) = 0;
34 
35 #ifndef OHOS_ARCH_LITE
36 private:
37     class SystemAbilityStatusChangeListener : public OHOS::SystemAbilityStatusChangeStub {
38     public:
SystemAbilityStatusChangeListener(WifiSystemAbilityListener * listener)39         explicit SystemAbilityStatusChangeListener(WifiSystemAbilityListener *listener)
40         {
41             abilityListener = listener;
42         }
~SystemAbilityStatusChangeListener()43         ~SystemAbilityStatusChangeListener()
44         {
45             abilityListener = nullptr;
46         }
47         void OnAddSystemAbility(int32_t systemAbilityId, const std::string &deviceId) override;
48         void OnRemoveSystemAbility(int32_t systemAbilityId, const std::string &deviceId) override;
49 
50     private:
51         WifiSystemAbilityListener* abilityListener;
52     };
53 #endif // OHOS_ARCH_LITE
54 
55 private:
56 #ifndef OHOS_ARCH_LITE
57     sptr<ISystemAbilityStatusChange> statusChangeListener;
58     std::unordered_set<int32_t> allListenerIds;
59     std::mutex listenerMutex;
60 #endif
61 };
62 }  // namespace Wifi
63 }  // namespace OHOS
64 #endif
65