summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDima Zavin <dima@android.com>2011-04-18 10:55:37 -0700
committerDima Zavin <dima@android.com>2011-04-18 15:59:13 -0700
commit54921de415cd91af21801115baa40e78fc4ea4be (patch)
treed3a86f4aca35796029f60b253540dbf407c98d48
parentc9881d8c5631faa85ff24668df9cb82921528d69 (diff)
downloadhardware_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>
-rw-r--r--hardware.c22
-rw-r--r--include/hardware/hardware.h17
2 files changed, 33 insertions, 6 deletions
diff --git a/hardware.c b/hardware.c
index d2e3b4c..2559237 100644
--- a/hardware.c
+++ b/hardware.c
@@ -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