1 /* 2 * Copyright (c) 2021 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 SERVICE_REGISTRY_INCLUDE_H 17 #define SERVICE_REGISTRY_INCLUDE_H 18 19 #include "ipc_types.h" 20 #include <iremote_broker.h> 21 #include "ipc_object_stub.h" 22 #include "iremote_proxy.h" 23 #include "if_system_ability_manager.h" 24 25 namespace OHOS { 26 class IServiceRegistry : public IRemoteBroker { 27 public: 28 /** 29 * GetService, Retrieve an existing service, blocking for a few seconds. 30 * 31 * @param name, name of service 32 * @return if it doesn't yet exist. return nulltpr. 33 */ 34 virtual sptr<IRemoteObject> GetService(const std::u16string& name) = 0; 35 36 /** 37 * CheckService, Retrieve an existing service, non-blocking. 38 * 39 * @param name, name of service. 40 * @return if it doesn't yet exist. return nulltpr. 41 */ 42 virtual sptr<IRemoteObject> CheckService(const std::u16string& name) = 0; 43 44 /** 45 * AddService, Register a service. 46 * 47 * @param name, name of service. 48 * @param service, remoteobject of service. 49 * @return ERR_OK indicates that the add was successful. 50 */ 51 virtual int AddService(const std::u16string& name, const sptr<IRemoteObject> &service, 52 bool allowIsolated = false, int dumpsysFlags = 0) = 0; 53 54 enum { 55 GET_SERVICE_TRANSACTION = FIRST_CALL_TRANSACTION, 56 CHECK_SERVICE_TRANSACTION, 57 ADD_SERVICE_TRANSACTION, 58 }; 59 public: 60 DECLARE_INTERFACE_DESCRIPTOR(u""); 61 }; 62 63 class ServiceRegistry { 64 public: 65 /** 66 * GetInstance, get Service registry instance. 67 * 68 * @return Get Single Instance Object. 69 */ 70 static sptr<IServiceRegistry> GetInstance(); 71 72 private: 73 static std::mutex serviceRegistryLock_; 74 }; 75 76 class SystemAbilityManagerClient { 77 public: 78 /** 79 * GetInstance, get SystemAbilityManagerClient instance. 80 * 81 * @return Get Single Instance Object. 82 */ 83 static SystemAbilityManagerClient& GetInstance(); 84 85 /** 86 * GetSystemAbilityManager, get system ability manager. 87 * 88 * @return Get systemAbilityManager_. 89 */ 90 sptr<ISystemAbilityManager> GetSystemAbilityManager(); 91 92 /** 93 * DestroySystemAbilityManagerObject, destroy remote object of samgr. 94 * 95 * @return destroy systemAbilityManager_. 96 */ 97 void DestroySystemAbilityManagerObject(); 98 99 private: 100 SystemAbilityManagerClient() = default; 101 ~SystemAbilityManagerClient() = default; 102 103 sptr<ISystemAbilityManager> systemAbilityManager_; 104 std::mutex systemAbilityManagerLock_; 105 }; 106 } // namespace OHOS 107 108 #endif // ZIPC_SERVICE_REGISTRY_INCLUDE_H