diff options
author | Dima Zavin <dima@android.com> | 2011-04-18 10:55:37 -0700 |
---|---|---|
committer | Dima Zavin <dima@android.com> | 2011-04-18 15:59:13 -0700 |
commit | 54921de415cd91af21801115baa40e78fc4ea4be (patch) | |
tree | d3a86f4aca35796029f60b253540dbf407c98d48 /hardware.c | |
parent | c9881d8c5631faa85ff24668df9cb82921528d69 (diff) | |
download | hardware_libhardware-54921de415cd91af21801115baa40e78fc4ea4be.zip hardware_libhardware-54921de415cd91af21801115baa40e78fc4ea4be.tar.gz hardware_libhardware-54921de415cd91af21801115baa40e78fc4ea4be.tar.bz2 |
libhardware: add concept of module classes
Needed for things like audio and audio effects. Provides a
new interface to loading modules named 'hw_get_module_by_class'.
This takes two parameters: 'class_id' and 'instance' which are
used to construct the filename for the module to be loaded. If
instance is NULL, then this function acts identically to
hw_get_module where 'class_id' == 'id' (and in fact the latter
implemented exactly this way).
For audio, this new mechanism allows us to load multiple audio
interfaces by doing:
hw_get_module_by_class("audio", "primary", &module);
hw_get_module_by_class("audio", "a2dp", &module);
hw_get_module_by_class("audio", "usb", &module);
...
In the future we will likely want to add the ability to load a set of
module instances based on a config file, which will have a standard
syntax and the mechanism will be provided by libhardware.
Change-Id: I9976cc6d59a85a414b18e7b398a36edfbce4abd8
Signed-off-by: Dima Zavin <dima@android.com>
Diffstat (limited to 'hardware.c')
-rw-r--r-- | hardware.c | 22 |
1 files changed, 17 insertions, 5 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); +} |