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 idevmgr_hdi.h 31 * 32 * @brief Defines the data structs and interface types related to device management based on the C++ language. 33 * 34 * @since 1.0 35 */ 36 #ifndef HDI_DEVICE_MANAGER_HDI_INF_H 37 #define HDI_DEVICE_MANAGER_HDI_INF_H 38 39 #include <vector> 40 #include <hdi_base.h> 41 42 namespace OHOS { 43 namespace HDI { 44 namespace DeviceManager { 45 namespace V1_0 { 46 /** 47 * @brief Defines the device information struct. 48 */ 49 struct DevInfo { 50 /** Device ID */ 51 uint32_t devId; 52 /** Service name */ 53 std::string servName; 54 /** Device name */ 55 std::string deviceName; 56 }; 57 58 /** 59 * @brief Defines the device linked list struct. 60 */ 61 struct HdiDevHostInfo { 62 /** Host name */ 63 std::string hostName; 64 /** Host ID */ 65 uint32_t hostId; 66 /** List of devices managed by the host */ 67 std::vector<DevInfo> devInfo; 68 }; 69 70 /** 71 * @brief Defines the HDI APIs for device management. Developers using C++ can use these APIs to 72 * obtain device information and load or unload a device. 73 */ 74 class IDeviceManager : public HdiBase { 75 public: 76 /** HDI interface descriptor, which is used to verify the permission for accessing the HDI interface. */ 77 DECLARE_HDI_DESCRIPTOR(u"HDI.IDeviceManager.V1_0"); 78 IDeviceManager() = default; 79 virtual ~IDeviceManager() = default; 80 81 /** 82 * @brief Obtains a device manager object. 83 * 84 * @return Returns the device manager object obtained. 85 */ 86 static ::OHOS::sptr<IDeviceManager> Get(); 87 88 /** 89 * @brief Loads a device driver. 90 * 91 * @param serviceName Indicates the service name of the device to load. 92 * @return Returns <b>HDF_SUCCESS</b> if the operation is successful; otherwise, the operation fails. 93 */ 94 virtual int32_t LoadDevice(const std::string &serviceName) = 0; 95 96 /** 97 * @brief Unloads a device driver. 98 * 99 * @param serviceName Indicates the service name of the device to unload. 100 * @return Returns <b>HDF_SUCCESS</b> if the operation is successful; otherwise, the operation fails. 101 */ 102 virtual int32_t UnloadDevice(const std::string &serviceName) = 0; 103 104 /** 105 * @brief Obtains information about all loaded devices. 106 * 107 * @param deviceInfos Indicates information about all loaded devices. 108 * @return Returns <b>HDF_SUCCESS</b> if the operation is successful; otherwise, the operation fails. 109 */ 110 virtual int32_t ListAllDevice(std::vector<HdiDevHostInfo> &deviceInfos) = 0; 111 }; 112 } // namespace V1_0 113 } // namespace DeviceManager 114 } // namespace HDI 115 } // namespace OHOS 116 117 #endif /* HDI_DEVICE_MANAGER_HDI_INF_H */ 118