• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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      * Retrieve an existing service, blocking for a few seconds
30      * if it doesn't yet exist.
31      */
32     virtual sptr<IRemoteObject> GetService(const std::u16string& name) = 0;
33 
34     /**
35      * Retrieve an existing service, non-blocking.
36      */
37     virtual sptr<IRemoteObject> CheckService(const std::u16string& name) = 0;
38 
39     /**
40      * Register a service.
41      */
42     virtual int AddService(const std::u16string& name, const sptr<IRemoteObject> &service,
43         bool allowIsolated = false, int dumpsysFlags = 0) = 0;
44 
45     enum {
46         GET_SERVICE_TRANSACTION = FIRST_CALL_TRANSACTION,
47         CHECK_SERVICE_TRANSACTION,
48         ADD_SERVICE_TRANSACTION,
49     };
50 public:
51     DECLARE_INTERFACE_DESCRIPTOR(u"");
52 };
53 
54 class ServiceRegistry {
55 public:
56     /**
57      * get Service registry instance.
58      */
59     static sptr<IServiceRegistry> GetInstance();
60 
61 private:
62     static std::mutex serviceRegistryLock_;
63 };
64 
65 class SystemAbilityManagerClient {
66 public:
67     static SystemAbilityManagerClient& GetInstance();
68 
69     /**
70      * get system ability manager.
71      */
72     sptr<ISystemAbilityManager> GetSystemAbilityManager();
73 
74     /**
75      * destroy remote object of samgr.
76      */
77     void DestroySystemAbilityManagerObject();
78 
79 private:
80     SystemAbilityManagerClient() = default;
81     ~SystemAbilityManagerClient() = default;
82 
83     sptr<ISystemAbilityManager> systemAbilityManager_;
84     std::mutex systemAbilityManagerLock_;
85 };
86 } // namespace OHOS
87 
88 #endif // ZIPC_SERVICE_REGISTRY_INCLUDE_H