3,通用硬體模組(libhardware.so) (1)標頭檔案為:/hardware/libhardware/include/hardware/hardware.h 標頭檔案中主要定義了通用硬體模組結構體hw_module_t,聲明瞭JNI呼叫的介面函式hw_get_module hw_module_t定義如下: typedef struct hw_module_t { /** tag must be initialized to HARDWARE_MODULE_TAG */ uint32_t tag;
/** major version number for the module */ uint16_t version_major;
/** minor version number of the module */ uint16_t version_minor;
/** Identifier of module */ const char *id;
/** Name of this module */ const char *name;
/** Author/owner/implementor of the module */ const char *author;
/** padding to 128 bytes, reserved for future use */ uint32_t reserved[32-7];
} hw_module_t; 硬體模組方法結構體hw_module_methods_t定義如下: 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; 只定義了一個open方法,其中呼叫的裝置結構體引數hw_device_t定義如下: typedef struct hw_device_t { /** tag must be initialized to HARDWARE_DEVICE_TAG */ uint32_t tag;
/** version number for hw_device_t */ uint32_t version;
/** reference to the module this device belongs to */ struct hw_module_t* module;
/** padding reserved for future use */ uint32_t reserved[12];
/** Close this device */ int (*close)(struct hw_device_t* device);
int hw_get_module(const char *id, const struct hw_module_t **module) { int status; int i; const struct hw_module_t *hmi = NULL; char prop[PATH_MAX]; char path[PATH_MAX]; for (i=0 ; i<HAL_VARIANT_KEYS_COUNT+1 ; i++) { if (i < HAL_VARIANT_KEYS_COUNT) { if (property_get(variant_keys[i], prop, NULL) == 0) { continue; } snprintf(path, sizeof(path), "%s/%s.%s.so", HAL_LIBRARY_PATH, id, prop); } else { snprintf(path, sizeof(path), "%s/%s.default.so", HAL_LIBRARY_PATH, id); } if (access(path, R_OK)) { continue; } /* we found a library matching this id/variant */ break; }
status = -ENOENT; if (i < HAL_VARIANT_KEYS_COUNT+1) { /* load the module, if this fails, we're doomed, and we should not try * to load a different variant. */ status = load(id, path, module); }