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 servmgr_hdi.h 31 * 32 * @brief Defines the data structs and interface types related to service management based on C. 33 * 34 * @since 1.0 35 */ 36 37 #ifndef HDI_SERVICE_MANAGER_INF_H 38 #define HDI_SERVICE_MANAGER_INF_H 39 40 #include "hdf_remote_service.h" 41 #include "servstat_listener_hdi.h" 42 #ifdef __cplusplus 43 extern "C" { 44 #endif /* __cplusplus */ 45 46 /** 47 * @brief Defines a set of HDI services for system abilities. 48 */ 49 struct HdiServiceSet { 50 /** HDI service names */ 51 const char **serviceNames; 52 /** Number of HDI services. */ 53 uint32_t count; 54 }; 55 56 /** 57 * @brief Defines the HDI APIs for service management. Developers using C can use the APIs to obtain a service or 58 * service set and register a service status listener. 59 */ 60 struct HDIServiceManager { 61 /** 62 * @brief Obtain an HDI service. 63 * 64 * @param self Indicates the pointer to the service manager object. 65 * @param serviceName Indicates the pointer to the HDI service name to obtain. 66 * @return Returns the HDI service name obtained. 67 */ 68 struct HdfRemoteService *(*GetService)(struct HDIServiceManager *self, const char *serviceName); 69 70 /** 71 * @brief Registers a listener for observing the service status. 72 * 73 * @param self Indicates the pointer to the service manager object. 74 * @param listener Indicates the listener object to register. 75 * @param deviceClass Indicates the service type of the device to be observed. 76 * @return Returns <b>HDF_SUCCESS</b> if the operation is successful; otherwise, the operation fails. 77 */ 78 int32_t (*RegisterServiceStatusListener)( 79 struct HDIServiceManager *self, struct ServiceStatusListener *listener, uint16_t deviceClass); 80 81 /** 82 * @brief Unregisters a service status listener. 83 * 84 * @param self Indicates the pointer to the service manager object. 85 * @param listener Indicates the pointer to the listener object to unregister. 86 * @return Returns <b>HDF_SUCCESS</b> if the operation is successful; otherwise, the operation fails. 87 */ 88 int32_t (*UnregisterServiceStatusListener)(struct HDIServiceManager *self, struct ServiceStatusListener *listener); 89 90 /** 91 * @brief Obtains the HDI service set based on the interface descriptor. 92 * 93 * @param interfaceName Indicates the pointer to the interface descriptor. 94 * @return Returns the service names obtained. 95 */ 96 struct HdiServiceSet *(*ListServiceByInterfaceDesc)(struct HDIServiceManager *self, const char *interfaceName); 97 }; 98 99 /** 100 * @brief Obtain the <b>HDIServiceManager</b> object. 101 * 102 * @return Returns the <b>HDIServiceManager</b> object obtained. 103 */ 104 struct HDIServiceManager *HDIServiceManagerGet(void); 105 106 /** 107 * @brief Releases an <b>HDIServiceManager</b> object. 108 * @param servmgr Indicates the <b>HDIServiceManager</b> object to release. 109 */ 110 void HDIServiceManagerRelease(struct HDIServiceManager *servmgr); 111 112 /** 113 * @brief Releases an <b>HdiServiceSet</b> object. 114 * @return Returns <b>0</b> if the operation is successful; returns a negative number otherwise. 115 */ 116 int32_t HdiServiceSetRelease(struct HdiServiceSet *serviceSet); 117 118 #ifdef __cplusplus 119 } 120 #endif /* __cplusplus */ 121 122 #endif /* HDI_SERVICE_MANAGER_INF_H */ 123