1 /* 2 * Copyright (c) 2023 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 OHOS_DMS_SA_CLIENT_H 17 #define OHOS_DMS_SA_CLIENT_H 18 19 #include <mutex> 20 21 #include "distributed_event_listener.h" 22 #include "dms_client.h" 23 #include "dms_handler.h" 24 #include "if_system_ability_manager.h" 25 #include "iservice_registry.h" 26 #include "sam_log.h" 27 #include "system_ability_status_change_stub.h" 28 #include "system_ability_definition.h" 29 30 namespace OHOS { 31 namespace DistributedSchedule { 32 class DmsSaClient : public SystemAbilityStatusChangeStub { 33 public: 34 static DmsSaClient &GetInstance(); 35 bool SubscribeDmsSA(); 36 int32_t AddDSchedEventListener(const std::string& type, const sptr<IDSchedEventListener>& listener); 37 int32_t DelDSchedEventListener(const std::string& type, const sptr<IDSchedEventListener>& listener); 38 void OnAddSystemAbility(int32_t systemAbilityId, const std::string& deviceId) override; 39 void OnRemoveSystemAbility(int32_t systemAbilityId, const std::string& deviceId) override; 40 private: DmsSaClient()41 DmsSaClient() {}; ~DmsSaClient()42 ~DmsSaClient() {}; 43 bool hasSubscribeDmsSA_ = false; 44 OHOS::sptr<ISystemAbilityManager> saMgrProxy_; 45 std::map<std::string, sptr<IDSchedEventListener>> listeners_; 46 std::mutex eventMutex_; 47 }; 48 49 class DmsSystemAbilityStatusChange : public SystemAbilityStatusChangeStub { 50 public: 51 DmsSystemAbilityStatusChange(); 52 ~DmsSystemAbilityStatusChange(); 53 void OnAddSystemAbility(int32_t systemAbilityId, const std::string& deviceId) override; 54 void OnRemoveSystemAbility(int32_t systemAbilityId, const std::string& deviceId) override; 55 }; 56 } // namespace DistributedSchedule 57 } // namespace OHOS 58 #endif