diff options
-rw-r--r-- | hardware.c | 22 | ||||
-rw-r--r-- | include/hardware/hardware.h | 17 |
2 files changed, 33 insertions, 6 deletions
@@ -117,13 +117,20 @@ static int load(const char *id, return status; } -int hw_get_module(const char *id, const struct hw_module_t **module) +int hw_get_module_by_class(const char *class_id, const char *inst, + 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]; + char name[PATH_MAX]; + + if (inst) + snprintf(name, PATH_MAX, "%s.%s", class_id, inst); + else + strlcpy(name, class_id, PATH_MAX); /* * Here we rely on the fact that calling dlopen multiple times on @@ -139,15 +146,15 @@ int hw_get_module(const char *id, const struct hw_module_t **module) continue; } snprintf(path, sizeof(path), "%s/%s.%s.so", - HAL_LIBRARY_PATH1, id, prop); + HAL_LIBRARY_PATH1, name, prop); if (access(path, R_OK) == 0) break; snprintf(path, sizeof(path), "%s/%s.%s.so", - HAL_LIBRARY_PATH2, id, prop); + HAL_LIBRARY_PATH2, name, prop); if (access(path, R_OK) == 0) break; } else { snprintf(path, sizeof(path), "%s/%s.default.so", - HAL_LIBRARY_PATH1, id); + HAL_LIBRARY_PATH1, name); if (access(path, R_OK) == 0) break; } } @@ -156,8 +163,13 @@ int hw_get_module(const char *id, const struct hw_module_t **module) 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); + status = load(class_id, path, module); } return status; } + +int hw_get_module(const char *id, const struct hw_module_t **module) +{ + return hw_get_module_by_class(id, NULL, module); +} diff --git a/include/hardware/hardware.h b/include/hardware/hardware.h index d9cc0dc..2251593 100644 --- a/include/hardware/hardware.h +++ b/include/hardware/hardware.h @@ -113,10 +113,25 @@ typedef struct hw_device_t { /** * Get the module info associated with a module by id. - * @return: 0 == success, <0 == error and *pHmi == NULL + * + * @return: 0 == success, <0 == error and *module == NULL */ int hw_get_module(const char *id, const struct hw_module_t **module); +/** + * Get the module info associated with a module instance by class 'class_id' + * and instance 'inst'. + * + * Some modules types necessitate multiple instances. For example audio supports + * multiple concurrent interfaces and thus 'audio' is the module class + * and 'primary' or 'a2dp' are module interfaces. This implies that the files + * providing these modules would be named audio.primary.<variant>.so and + * audio.a2dp.<variant>.so + * + * @return: 0 == success, <0 == error and *module == NULL + */ +int hw_get_module_by_class(const char *class_id, const char *inst, + const struct hw_module_t **module); /** * pixel format definitions |