Encoding Summary of the android HAL Interface
Define a modulestruct xxx_module_t {hw_module_t common; xxx. Here we mainly use ops interfaces that can be operated on the module when it is not open. Sometimes we can leave it empty}
Struct xxx_mdoule HAL_MODULE_INFO_SYM = {fill the struct with hw_module_t
} // All hal modules have the same name. This structure is converted into an hmi descriptor during compilation for use when loading the corresponding so. At the same time, the load id must be consistent with hw_module_t.
The methods of hw_module_t generally needs to specify and implement an open interface, as shown below: typedef struct hw_module_methods_t {/** Open a specific device */
Int (* open) (const struct hw_module_t * module, const char * id, struct hw_device_t ** device);} hw_module_methods_t;
Generally, the xxx_device_t interface of the device to be used by a module is returned after open. The general structure is as follows. Note that when multiple encapsulation is performed, make sure that the hw_device_t is at the first address of the returned address: typedef struct xxx_device_t {hw_device_t common; xxx various ops functions that can operate on devices. } Or class xxx_xxxx_t: public struct xxx_device_t {xxx_xxx_t ();}
In the constructor, xxx_xxxx_t () {initialization of xxx_device_t is completed, including the ops required by the common and various framework layers}
Struct definition of hw_device_t: typedef struct hw_device_t {uint32_t tag; uint32_t version; struct completion * module; uint32_t reserved [12]; int (* close) (struct hw_device_t * device );
} Hw_device_t;
In conclusion, HAL provides interfaces to the upper layer through the struct xxx_device_t structure.
That is, the interface is contained in the struct xxx_device_t structure.
The specific execution is to return the open function under the function List member of the struct variable struct xxx_module_t HAL_MODULE_INFO_SYM to the upper layer.
Additional: the reason for naming all HAL modules HAL_MODULE_INFO_SYM is that this name will be replaced with a macro name HMI, that is, when the compiler combines the CPP of each module to produce the so library, an HMI symbol table exists internally. When this symbol table loads the module again, it will first perform the dlsym operation, specifically specifying that the symbol entry to be searched is "HMI", which requires that the current module must contain this symbol name. Therefore, each HAL library must ensure that its name is HAL_MODULE_INFO_SYM, because only this name will be replaced with HMI and then compiled into the SO file, SO that it will be loaded into the HMI portal, that is, hw_module_t.