• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2021-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 /**
17  * @addtogroup DriverHdi
18  * @{
19  *
20  * @brief Provides APIs for a system ability to obtain hardware device interface (HDI) services,
21  * load or unload a device, and listen for service status, and capabilities for the hdi-gen tool to
22  * automatically generate code in the interface description language (IDL).
23  *
24  * The HDF and the IDL code generated allow system abilities to access the HDI driver service.
25  *
26  * @since 1.0
27  */
28 
29 /**
30  * @file iservmgr_hdi.h
31  *
32  * @brief Defines the data structs and interface types related to service management based on the C++ language.
33  *
34  * @since 1.0
35  */
36 
37 #ifndef HDI_ISERVICE_MANAGER_INF_H
38 #define HDI_ISERVICE_MANAGER_INF_H
39 
40 #include <vector>
41 #include <hdi_base.h>
42 #include <iremote_broker.h>
43 #include <refbase.h>
44 
45 #include "iservstat_listener_hdi.h"
46 
47 namespace OHOS {
48 namespace HDI {
49 namespace ServiceManager {
50 namespace V1_0 {
51 /**
52  * @brief Defines the HDI service information struct.
53  */
54 
55 struct HdiServiceInfo {
56     /** HDI service name */
57     std::string serviceName;
58     /** Device type */
59     uint16_t devClass;
60     /** Device ID */
61     uint32_t devId;
62 };
63 
64 /**
65  * @brief Defines the HDI APIs for service management. Developers using C++ can use the APIs to obtain
66  * a service or service set and register a service status listener.
67  */
68 class IServiceManager : public HdiBase {
69 public:
70     /** HDI interface descriptor, which is used to verify the permission for accessing the HDI interface. */
71     DECLARE_HDI_DESCRIPTOR(u"HDI.IServiceManager.V1_0");
72 
73     /**
74      * @brief Obtains a service manager object.
75      *
76      * @return Returns the service manager object obtained.
77      */
78     static ::OHOS::sptr<IServiceManager> Get();
79 
80     /**
81      * @brief Obtain an HDI service.
82      *
83      * @param serviceName Indicates the pointer to the HDI service name to obtain.
84      * @return Returns the HDI service obtained.
85      */
86     virtual ::OHOS::sptr<IRemoteObject> GetService(const char *serviceName) = 0;
87 
88     /**
89      * @brief Obtains information about all loaded HDI services.
90      *
91      * @param serviceInfos Indicates information about all loaded services.
92      * @return Returns <b>HDF_SUCCESS</b> if the operation is successful; otherwise, the operation fails.
93      */
94     virtual int32_t ListAllService(std::vector<HdiServiceInfo> &serviceInfos) = 0;
95 
96     /**
97      * @brief Registers a listener for observing the service status.
98      *
99      * @param listener Indicates the listener object to register.
100      * @param deviceClass Indicates the service type of the device to be observed.
101      * @return Returns <b>HDF_SUCCESS</b> if the operation is successful; otherwise, the operation fails.
102      */
103 
104     virtual int32_t RegisterServiceStatusListener(::OHOS::sptr<IServStatListener> listener, uint16_t deviceClass) = 0;
105     /**
106      * @brief Unregisters a service status listener.
107      *
108      * @param listener Indicates the listener object to unregister.
109      * @return Returns <b>HDF_SUCCESS</b> if the operation is successful; otherwise, the operation fails.
110      */
111     virtual int32_t UnregisterServiceStatusListener(::OHOS::sptr<IServStatListener> listener) = 0;
112 
113     /**
114      * @brief Queries HDI services based on the specified interface descriptor.
115      *
116      * @param serviceNames Indicates the service names obtained.
117      * @param interfaceDesc Indicates the interface descriptor.
118      * @return Returns <b>HDF_SUCCESS</b> if the operation is successful; otherwise, the operation fails.
119      */
120     virtual int32_t ListServiceByInterfaceDesc(std::vector<std::string> &serviceNames, const char *interfaceDesc) = 0;
121 };
122 } // namespace V1_0
123 } // namespace ServiceManager
124 } // namespace HDI
125 } // namespace OHOS
126 
127 #endif /* HDI_ISERVICE_MANAGER_INF_H */
128