1 /* 2 * Copyright (c) 2022-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 hdi_base.h 31 * 32 * @brief Defines the HDI base class for managing HDI objects. 33 * 34 * @since 1.0 35 */ 36 37 #ifndef HDI_BASE_INTERFACE_H 38 #define HDI_BASE_INTERFACE_H 39 40 #include <string> 41 #ifdef __LITEOS__ 42 #include <memory> 43 #else 44 #include <refbase.h> 45 #endif 46 47 namespace OHOS { 48 namespace HDI { 49 /** 50 * @brief Defines the HDI base class for managing HDI objects. 51 */ 52 #ifdef __LITEOS__ 53 class HdiBase : public std::enable_shared_from_this<HdiBase> { 54 #else 55 class HdiBase : virtual public OHOS::RefBase { 56 #endif 57 public: 58 HdiBase() = default; 59 virtual ~HdiBase() = default; 60 }; 61 62 /** 63 * @brief Defines an HDI interface descriptor macro. 64 * 65 * @param DESCRIPTOR Indicates the interface descriptor. 66 */ 67 #define DECLARE_HDI_DESCRIPTOR(DESCRIPTOR) \ 68 __attribute__((visibility("hidden"))) \ 69 const static inline std::u16string metaDescriptor_ = {DESCRIPTOR}; \ 70 const static inline std::u16string &GetDescriptor() \ 71 { \ 72 return metaDescriptor_; \ 73 } 74 } // namespace HDI 75 } // namespace OHOS 76 77 #endif // HDI_BASE_INTERFACE_H 78