* [PATCH BlueZ 1/3] android: Convert libaudio-internal to a plugin
@ 2014-01-10 12:14 Luiz Augusto von Dentz
2014-01-10 12:14 ` [PATCH BlueZ 2/3] android: Convert libhal-internal " Luiz Augusto von Dentz
` (2 more replies)
0 siblings, 3 replies; 4+ messages in thread
From: Luiz Augusto von Dentz @ 2014-01-10 12:14 UTC (permalink / raw)
To: linux-bluetooth
From: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
This convert the static library libaudio-internal.la to
audio.a2dp.default.so when building with autotools.
---
android/Makefile.am | 9 +++++----
1 file changed, 5 insertions(+), 4 deletions(-)
diff --git a/android/Makefile.am b/android/Makefile.am
index 0a32a95..97173db 100644
--- a/android/Makefile.am
+++ b/android/Makefile.am
@@ -114,18 +114,19 @@ android_android_tester_LDADD = lib/libbluetooth-internal.la \
android_android_tester_LDFLAGS = -pthread
-noinst_LTLIBRARIES += android/libaudio-internal.la
+plugin_LTLIBRARIES += android/audio.a2dp.default.la
-android_libaudio_internal_la_SOURCES = android/audio-msg.h \
+android_audio_a2dp_default_la_SOURCES = android/audio-msg.h \
android/hal-audio.c \
android/hardware/audio.h \
android/hardware/audio_effect.h \
android/hardware/hardware.h \
android/system/audio.h
-android_libaudio_internal_la_CFLAGS = -I$(srcdir)/android
+android_audio_a2dp_default_la_CFLAGS = -I$(srcdir)/android
-android_libaudio_internal_la_LDFLAGS = -pthread
+android_audio_a2dp_default_la_LDFLAGS = $(AM_LDFLAGS) -module -avoid-version \
+ -no-undefined -pthread
endif
--
1.8.4.2
^ permalink raw reply related [flat|nested] 4+ messages in thread* [PATCH BlueZ 2/3] android: Convert libhal-internal to a plugin 2014-01-10 12:14 [PATCH BlueZ 1/3] android: Convert libaudio-internal to a plugin Luiz Augusto von Dentz @ 2014-01-10 12:14 ` Luiz Augusto von Dentz 2014-01-10 12:14 ` [PATCH BlueZ 3/3] android: Load bluetooth.default.so as a module Luiz Augusto von Dentz 2014-01-10 13:39 ` [PATCH BlueZ 1/3] android: Convert libaudio-internal to a plugin Luiz Augusto von Dentz 2 siblings, 0 replies; 4+ messages in thread From: Luiz Augusto von Dentz @ 2014-01-10 12:14 UTC (permalink / raw) To: linux-bluetooth From: Luiz Augusto von Dentz <luiz.von.dentz@intel.com> This convert the static library libhal-internal.la to bluetooth.default.la when building with autotools. --- android/Makefile.am | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/android/Makefile.am b/android/Makefile.am index 97173db..4b843b2 100644 --- a/android/Makefile.am +++ b/android/Makefile.am @@ -39,9 +39,9 @@ android_bluetoothd_SOURCES = android/main.c \ android_bluetoothd_LDADD = lib/libbluetooth-internal.la @GLIB_LIBS@ -noinst_LTLIBRARIES += android/libhal-internal.la +plugin_LTLIBRARIES += android/bluetooth.default.la -android_libhal_internal_la_SOURCES = android/hal.h android/hal-bluetooth.c \ +android_bluetooth_default_la_SOURCES = android/hal.h android/hal-bluetooth.c \ android/hal-sock.c \ android/hal-hidhost.c \ android/hal-pan.c \ @@ -63,8 +63,10 @@ android_libhal_internal_la_SOURCES = android/hal.h android/hal-bluetooth.c \ android/hal-log.h \ android/hal-ipc.h android/hal-ipc.c -android_libhal_internal_la_CPPFLAGS = -I$(srcdir)/android \ +android_bluetooth_default_la_CPPFLAGS = -I$(srcdir)/android \ -DPLATFORM_SDK_VERSION=19 +android_bluetooth_default_la_LDFLAGS = $(AM_LDFLAGS) -module -avoid-version \ + -no-undefined noinst_PROGRAMS += android/haltest @@ -87,7 +89,7 @@ android_haltest_SOURCES = android/client/haltest.c \ android/client/hwmodule.c \ android/hal-utils.h android/hal-utils.c -android_haltest_LDADD = android/libhal-internal.la +android_haltest_LDADD = android/bluetooth.default.la android_haltest_CFLAGS = $(AM_CFLAGS) -I$(srcdir)/android \ -DPLATFORM_SDK_VERSION=19 @@ -110,7 +112,7 @@ android_android_tester_SOURCES = emulator/btdev.h emulator/btdev.c \ android_android_tester_CFLAGS = $(AM_CFLAGS) -I$(srcdir)/android android_android_tester_LDADD = lib/libbluetooth-internal.la \ - android/libhal-internal.la @GLIB_LIBS@ + android/bluetooth.default.la @GLIB_LIBS@ android_android_tester_LDFLAGS = -pthread -- 1.8.4.2 ^ permalink raw reply related [flat|nested] 4+ messages in thread
* [PATCH BlueZ 3/3] android: Load bluetooth.default.so as a module 2014-01-10 12:14 [PATCH BlueZ 1/3] android: Convert libaudio-internal to a plugin Luiz Augusto von Dentz 2014-01-10 12:14 ` [PATCH BlueZ 2/3] android: Convert libhal-internal " Luiz Augusto von Dentz @ 2014-01-10 12:14 ` Luiz Augusto von Dentz 2014-01-10 13:39 ` [PATCH BlueZ 1/3] android: Convert libaudio-internal to a plugin Luiz Augusto von Dentz 2 siblings, 0 replies; 4+ messages in thread From: Luiz Augusto von Dentz @ 2014-01-10 12:14 UTC (permalink / raw) To: linux-bluetooth From: Luiz Augusto von Dentz <luiz.von.dentz@intel.com> This makes haltest and android-tester to load bluetooth.default.so instead of linking directly to it. --- android/Makefile.am | 26 +++++----- android/hardware/hardware.c | 124 ++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 138 insertions(+), 12 deletions(-) create mode 100644 android/hardware/hardware.c diff --git a/android/Makefile.am b/android/Makefile.am index 4b843b2..f5e8c99 100644 --- a/android/Makefile.am +++ b/android/Makefile.am @@ -1,4 +1,6 @@ if ANDROID +android_plugindir = $(abs_top_srcdir)/android/.libs + noinst_PROGRAMS += android/system-emulator android_system_emulator_SOURCES = android/system-emulator.c \ @@ -61,7 +63,8 @@ android_bluetooth_default_la_SOURCES = android/hal.h android/hal-bluetooth.c \ android/hardware/hardware.h \ android/cutils/properties.h \ android/hal-log.h \ - android/hal-ipc.h android/hal-ipc.c + android/hal-ipc.h android/hal-ipc.c \ + android/hal-utils.h android/hal-utils.c android_bluetooth_default_la_CPPFLAGS = -I$(srcdir)/android \ -DPLATFORM_SDK_VERSION=19 @@ -86,15 +89,14 @@ android_haltest_SOURCES = android/client/haltest.c \ android/client/if-hh.c \ android/client/if-pan.c \ android/client/if-sock.c \ - android/client/hwmodule.c \ + android/hardware/hardware.c \ android/hal-utils.h android/hal-utils.c -android_haltest_LDADD = android/bluetooth.default.la - android_haltest_CFLAGS = $(AM_CFLAGS) -I$(srcdir)/android \ - -DPLATFORM_SDK_VERSION=19 + -DPLATFORM_SDK_VERSION=19 \ + -DPLUGINDIR=\""$(android_plugindir)"\" -android_haltest_LDFLAGS = -pthread +android_haltest_LDFLAGS = -pthread -ldl noinst_PROGRAMS += android/android-tester @@ -106,15 +108,15 @@ android_android_tester_SOURCES = emulator/btdev.h emulator/btdev.c \ src/shared/mgmt.h src/shared/mgmt.c \ src/shared/hciemu.h src/shared/hciemu.c \ src/shared/tester.h src/shared/tester.c \ - android/hal-utils.h android/hal-utils.c \ - android/client/hwmodule.c android/android-tester.c + android/hardware/hardware.c \ + android/android-tester.c -android_android_tester_CFLAGS = $(AM_CFLAGS) -I$(srcdir)/android +android_android_tester_CFLAGS = $(AM_CFLAGS) -I$(srcdir)/android \ + -DPLUGINDIR=\""$(android_plugindir)"\" -android_android_tester_LDADD = lib/libbluetooth-internal.la \ - android/bluetooth.default.la @GLIB_LIBS@ +android_android_tester_LDADD = lib/libbluetooth-internal.la @GLIB_LIBS@ -android_android_tester_LDFLAGS = -pthread +android_android_tester_LDFLAGS = -pthread -ldl plugin_LTLIBRARIES += android/audio.a2dp.default.la diff --git a/android/hardware/hardware.c b/android/hardware/hardware.c new file mode 100644 index 0000000..4bd5eba --- /dev/null +++ b/android/hardware/hardware.c @@ -0,0 +1,124 @@ +/* + * Copyright (C) 2008 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include <hardware/hardware.h> + +#include <dlfcn.h> +#include <string.h> +#include <pthread.h> +#include <errno.h> +#include <limits.h> +#include <stdio.h> + +#define LOG_TAG "HAL" + +#define LOG_INFO " I" +#define LOG_WARN " W" +#define LOG_ERROR " E" +#define LOG_DEBUG " D" +#define ALOG(pri, tag, fmt, arg...) fprintf(stderr, tag pri": " fmt"\n", ##arg) + +#define info(fmt, arg...) ALOG(LOG_INFO, LOG_TAG, fmt, ##arg) +#define warn(fmt, arg...) ALOG(LOG_WARN, LOG_TAG, fmt, ##arg) +#define error(fmt, arg...) ALOG(LOG_ERROR, LOG_TAG, fmt, ##arg) + +/** + * Load the file defined by the variant and if successful + * return the dlopen handle and the hmi. + * @return 0 = success, !0 = failure. + */ +static int load(const char *id, + const char *path, + const struct hw_module_t **pHmi) +{ + int status; + void *handle; + struct hw_module_t *hmi; + const char *sym = HAL_MODULE_INFO_SYM_AS_STR; + + /* + * load the symbols resolving undefined symbols before + * dlopen returns. Since RTLD_GLOBAL is not or'd in with + * RTLD_NOW the external symbols will not be global + */ + handle = dlopen(path, RTLD_NOW); + if (handle == NULL) { + char const *err_str = dlerror(); + error("load: module=%s\n%s", path, err_str?err_str:"unknown"); + status = -EINVAL; + goto done; + } + + /* Get the address of the struct hal_module_info. */ + hmi = (struct hw_module_t *)dlsym(handle, sym); + if (hmi == NULL) { + error("load: couldn't find symbol %s", sym); + status = -EINVAL; + goto done; + } + + /* Check that the id matches */ + if (strcmp(id, hmi->id) != 0) { + error("load: id=%s != hmi->id=%s", id, hmi->id); + status = -EINVAL; + goto done; + } + + hmi->dso = handle; + + *pHmi = hmi; + + info("loaded HAL id=%s path=%s hmi=%p handle=%p", + id, path, *pHmi, handle); + + return 0; + +done: + hmi = NULL; + if (handle != NULL) { + dlclose(handle); + handle = NULL; + } + + return status; +} + +int hw_get_module_by_class(const char *class_id, const char *inst, + const struct hw_module_t **module) +{ + char path[PATH_MAX]; + char name[PATH_MAX]; + + if (inst) + snprintf(name, PATH_MAX, "%s.%s", class_id, inst); + else + snprintf(name, PATH_MAX, "%s", class_id); + + /* + * Here we rely on the fact that calling dlopen multiple times on + * the same .so will simply increment a refcount (and not load + * a new copy of the library). + * We also assume that dlopen() is thread-safe. + */ + snprintf(path, sizeof(path), "%s/%s.default.so", PLUGINDIR, name); + + return load(class_id, path, module); +} + +int hw_get_module(const char *id, const struct hw_module_t **module) +{ + return hw_get_module_by_class(id, NULL, module); +} -- 1.8.4.2 ^ permalink raw reply related [flat|nested] 4+ messages in thread
* Re: [PATCH BlueZ 1/3] android: Convert libaudio-internal to a plugin 2014-01-10 12:14 [PATCH BlueZ 1/3] android: Convert libaudio-internal to a plugin Luiz Augusto von Dentz 2014-01-10 12:14 ` [PATCH BlueZ 2/3] android: Convert libhal-internal " Luiz Augusto von Dentz 2014-01-10 12:14 ` [PATCH BlueZ 3/3] android: Load bluetooth.default.so as a module Luiz Augusto von Dentz @ 2014-01-10 13:39 ` Luiz Augusto von Dentz 2 siblings, 0 replies; 4+ messages in thread From: Luiz Augusto von Dentz @ 2014-01-10 13:39 UTC (permalink / raw) To: linux-bluetooth@vger.kernel.org Hi, On Fri, Jan 10, 2014 at 2:14 PM, Luiz Augusto von Dentz <luiz.dentz@gmail.com> wrote: > From: Luiz Augusto von Dentz <luiz.von.dentz@intel.com> > > This convert the static library libaudio-internal.la to > audio.a2dp.default.so when building with autotools. > --- > android/Makefile.am | 9 +++++---- > 1 file changed, 5 insertions(+), 4 deletions(-) > > diff --git a/android/Makefile.am b/android/Makefile.am > index 0a32a95..97173db 100644 > --- a/android/Makefile.am > +++ b/android/Makefile.am > @@ -114,18 +114,19 @@ android_android_tester_LDADD = lib/libbluetooth-internal.la \ > > android_android_tester_LDFLAGS = -pthread > > -noinst_LTLIBRARIES += android/libaudio-internal.la > +plugin_LTLIBRARIES += android/audio.a2dp.default.la > > -android_libaudio_internal_la_SOURCES = android/audio-msg.h \ > +android_audio_a2dp_default_la_SOURCES = android/audio-msg.h \ > android/hal-audio.c \ > android/hardware/audio.h \ > android/hardware/audio_effect.h \ > android/hardware/hardware.h \ > android/system/audio.h > > -android_libaudio_internal_la_CFLAGS = -I$(srcdir)/android > +android_audio_a2dp_default_la_CFLAGS = -I$(srcdir)/android > > -android_libaudio_internal_la_LDFLAGS = -pthread > +android_audio_a2dp_default_la_LDFLAGS = $(AM_LDFLAGS) -module -avoid-version \ > + -no-undefined -pthread > > endif > > -- > 1.8.4.2 This now pushed. -- Luiz Augusto von Dentz ^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2014-01-10 13:39 UTC | newest] Thread overview: 4+ messages (download: mbox.gz follow: Atom feed -- links below jump to the message on this page -- 2014-01-10 12:14 [PATCH BlueZ 1/3] android: Convert libaudio-internal to a plugin Luiz Augusto von Dentz 2014-01-10 12:14 ` [PATCH BlueZ 2/3] android: Convert libhal-internal " Luiz Augusto von Dentz 2014-01-10 12:14 ` [PATCH BlueZ 3/3] android: Load bluetooth.default.so as a module Luiz Augusto von Dentz 2014-01-10 13:39 ` [PATCH BlueZ 1/3] android: Convert libaudio-internal to a plugin Luiz Augusto von Dentz
This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox