#ifndef __HW_USB_GADGET_H__
#define __HW_USB_GADGET_H__
-/**************************************
- * Those symbols must be initialized first in deviced
- *
- * The usb-gadget source code have been scattered throughout the deviced and device-common.
- * Because of this, it might have been implemented that totally same data structure on the
- * both side. To avoid this inefficiency, define/initialize the data structure on the
- * deviced first, and device-common refer it through extern keyword. The deviced must have
- * cflag -rdynamic or ldflag --export-dynamic so that the dlopen-ed device-common can refer
- * those variables with extern keyword.
- *
- * Accessing symbol in this way would be removed when the usb-gadget of the device-common
- * is integrated into the deviced.
- */
-#include <glib.h>
-#include <hal/device/hal-usb_gadget-interface.h>
-
-struct _usb_mode_mapping_table {
- int mode_v; /* Integer defined by vconf */
- unsigned int mode; /* Bitmap of usb function combination */
- struct usb_gadget_attrs attrs;
-};
-extern GList *usb_mode_mapping_table_custom;
-
-struct service_config {
- char name[128];
- int remain_after_disable;
-};
-extern GList *service_config_list;
-/**************************************/
struct usb_function *find_usb_function_by_id(int id);
struct usb_function *find_usb_function_by_name(const char *name);
#include <stdlib.h>
#include <unistd.h>
+#include <dlfcn.h>
+
#include <libsyscommon/libsystemd.h>
#include <libsyscommon/list.h>
#include <hal/device/hal-usb_gadget-interface.h>
static struct usb_function *_available_funcs[];
+/**************************************
+ * Those symbols must be initialized first in deviced
+ *
+ * The usb-gadget source code have been scattered throughout the deviced and device-common.
+ * Because of this, it might have been implemented that totally same data structure on the
+ * both side. To avoid this inefficiency, define/initialize the data structure on the
+ * deviced first, and device-common refer it through dlsym(). The deviced must have
+ * cflag -rdynamic or ldflag --export-dynamic so that the dlopen-ed device-common can refer
+ * those variables with dlsym().
+ *
+ * Accessing symbol in this way would be removed when the usb-gadget of the device-common
+ * is integrated into the deviced.
+ */
+#include <glib.h>
+#include <hal/device/hal-usb_gadget-interface.h>
+
+struct _usb_mode_mapping_table {
+ int mode_v; /* Integer defined by vconf */
+ unsigned int mode; /* Bitmap of usb function combination */
+ struct usb_gadget_attrs attrs;
+};
+static GList *usb_mode_mapping_table_custom;
+
+struct service_config {
+ char name[128];
+ int remain_after_disable;
+};
+static GList *service_config_list;
+/**************************************/
+
struct usb_function *find_usb_function_by_id(int id);
static void simple_cleanup_config(struct usb_configuration *config)
EXPORT
int simple_translator_open(hal_backend_usb_gadget_funcs *usb_gadget_funcs)
{
+ char *dlerr;
+
if (!usb_gadget_funcs)
return -EINVAL;
+ dlerror(); // clear any existing dl error
+
+ usb_mode_mapping_table_custom = *(GList **) dlsym(RTLD_DEFAULT, "usb_mode_mapping_table_custom");
+ dlerr = dlerror();
+ if (dlerr) {
+ _E("%s", dlerr);
+ return -ENOTSUP;
+ }
+
+ service_config_list = *(GList **) dlsym(RTLD_DEFAULT, "service_config_list");
+ dlerr = dlerror();
+ if (dlerr) {
+ _E("%s", dlerror());
+ return -ENOTSUP;
+ }
+
/* e.g.
* /hal/etc/deviced/usb_gadget.conf
*