1 /*
2  * Copyright (c) 2021-2022 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 FOUNDATION_EVENT_CESFWK_INNERKITS_INCLUDE_COMMON_EVENT_DEATH_RECIPIENT_H
17 #define FOUNDATION_EVENT_CESFWK_INNERKITS_INCLUDE_COMMON_EVENT_DEATH_RECIPIENT_H
18 
19 #include "cpp/queue.h"
20 #include "ffrt.h"
21 #include <memory>
22 #include <mutex>
23 #include <singleton.h>
24 
25 #include "system_ability_status_change_stub.h"
26 
27 namespace OHOS {
28 namespace EventFwk {
29 class CommonEventDeathRecipient : public DelayedSingleton<CommonEventDeathRecipient> {
30 public:
31     CommonEventDeathRecipient() = default;
32     ~CommonEventDeathRecipient();
33 
34     void SubscribeSAManager();
35 private:
36     class SystemAbilityStatusChangeListener : public SystemAbilityStatusChangeStub {
37     public:
38         SystemAbilityStatusChangeListener();
39         ~SystemAbilityStatusChangeListener() = default;
40         void OnAddSystemAbility(int32_t systemAbilityId, const std::string& deviceId) override;
41         void OnRemoveSystemAbility(int32_t systemAbilityId, const std::string& deviceId) override;
42     private:
43         bool isSAOffline_ = false;
44         std::mutex mutex_;
45         std::shared_ptr<ffrt::queue> queue_ = nullptr;
46     };
47 
48     std::mutex listenerMutex_;
49     sptr<ISystemAbilityStatusChange> statusChangeListener_ = nullptr;
50 };
51 }  // namespace EventFwk
52 }  // namespace OHOS
53 
54 #endif  // FOUNDATION_EVENT_CESFWK_INNERKITS_INCLUDE_COMMON_EVENT_DEATH_RECIPIENT_H
55