Linux-Bluetooth Archive on lore.kernel.org
 help / color / Atom feed
* [PATCH BlueZ 0/1] ELL based mainloop
@ 2019-08-08  4:46 Inga Stotland
  2019-08-08  4:46 ` [PATCH BlueZ 1/1] shared/mainloop: Add ell-based mainloop implementation Inga Stotland
  0 siblings, 1 reply; 2+ messages in thread
From: Inga Stotland @ 2019-08-08  4:46 UTC (permalink / raw)
  To: linux-bluetooth; +Cc: luiz.dentz, Inga Stotland

This patch addresses a need to be able to use common mainloop for the
ell-based apps that desire to use common bluetooth fuctionality
(e.g., bt_shell).

A bit awkward callback handling there is due to the discrepancy in the
arg type for signo (signal number) in:

typedef void (*mainloop_signal_func) (int signum, void *user_data)
and
typedef void (*l_main_signal_cb_t) (uint32_t signo, void *user_data)

My guess is that ell derives the unsigned int type from <sys/signalfd.h>,
where ssi_signo is defined as uint32_t. Bluez is probably following the
standard Linux signal handling, where signal is represented as an int. 


Inga Stotland (1):
  shared/mainloop: Add ell-based mainloop implementation

 Makefile.am               |  13 +++-
 src/shared/mainloop-ell.c | 129 ++++++++++++++++++++++++++++++++++++++
 2 files changed, 139 insertions(+), 3 deletions(-)
 create mode 100644 src/shared/mainloop-ell.c

-- 
2.21.0


^ permalink raw reply	[flat|nested] 2+ messages in thread

* [PATCH BlueZ 1/1] shared/mainloop: Add ell-based mainloop implementation
  2019-08-08  4:46 [PATCH BlueZ 0/1] ELL based mainloop Inga Stotland
@ 2019-08-08  4:46 ` Inga Stotland
  0 siblings, 0 replies; 2+ messages in thread
From: Inga Stotland @ 2019-08-08  4:46 UTC (permalink / raw)
  To: linux-bluetooth; +Cc: luiz.dentz, Inga Stotland

This adds implementation of wrapper mainloop functions to interact with
ell main APIs, enabling support for the applications that link with ell
library and use mainloop functionality.
---
 Makefile.am               |  13 +++-
 src/shared/mainloop-ell.c | 129 ++++++++++++++++++++++++++++++++++++++
 2 files changed, 139 insertions(+), 3 deletions(-)
 create mode 100644 src/shared/mainloop-ell.c

diff --git a/Makefile.am b/Makefile.am
index 9d25a815b..d175d3572 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -162,6 +162,10 @@ CLEANFILES += $(ell_built_sources)
 
 noinst_LTLIBRARIES += src/libshared-glib.la src/libshared-mainloop.la
 
+if LIBSHARED_ELL
+noinst_LTLIBRARIES += src/libshared-ell.la
+endif
+
 shared_sources = src/shared/io.h src/shared/timeout.h \
 			src/shared/queue.h src/shared/queue.c \
 			src/shared/util.h src/shared/util.c \
@@ -206,10 +210,13 @@ src_libshared_mainloop_la_SOURCES = $(shared_sources) \
 				src/shared/mainloop-notify.c
 
 if LIBSHARED_ELL
-noinst_LTLIBRARIES += src/libshared-ell.la
-
 src_libshared_ell_la_SOURCES = $(shared_sources) \
-				src/shared/io-ell.c
+				src/shared/io-ell.c \
+				src/shared/timeout-mainloop.c \
+				src/shared/mainloop.h \
+				src/shared/mainloop-ell.c \
+				src/shared/mainloop-notify.h \
+				src/shared/mainloop-notify.c
 endif
 
 attrib_sources = attrib/att.h attrib/att-database.h attrib/att.c \
diff --git a/src/shared/mainloop-ell.c b/src/shared/mainloop-ell.c
new file mode 100644
index 000000000..027c8a0ef
--- /dev/null
+++ b/src/shared/mainloop-ell.c
@@ -0,1 +1,125 @@
+/*
+ *
+ *  BlueZ - Bluetooth protocol stack for Linux
+ *
+ *  Copyright (C) 2019  Intel Corporation
+ *
+ *
+ *  This library is free software; you can redistribute it and/or
+ *  modify it under the terms of the GNU Lesser General Public
+ *  License as published by the Free Software Foundation; either
+ *  version 2.1 of the License, or (at your option) any later version.
+ *
+ *  This library is distributed in the hope that it will be useful,
+ *  but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ *  Lesser General Public License for more details.
+ *
+ */
+
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#endif
+
+#define _GNU_SOURCE
+#include <errno.h>
+#include <unistd.h>
+#include <stdlib.h>
+
+#include <ell/ell.h>
+
+#include "mainloop.h"
+
+static bool is_initialized;
+static int exit_status;
+static mainloop_signal_func sig_func;
+
+static void l_sig_func(uint32_t signo, void *user_data)
+{
+	if (sig_func)
+		sig_func(signo, user_data);
+}
+
+void mainloop_init(void)
+{
+	is_initialized = l_main_init();
+}
+
+void mainloop_quit(void)
+{
+	l_main_quit();
+}
+
+void mainloop_exit_success(void)
+{
+	exit_status = EXIT_SUCCESS;
+	l_main_quit();
+}
+
+void mainloop_exit_failure(void)
+{
+	exit_status = EXIT_FAILURE;
+	l_main_quit();
+}
+
+int mainloop_run(void)
+{
+	if (!is_initialized)
+		return -EINVAL;
+
+	l_main_run();
+
+	is_initialized = false;
+	sig_func = NULL;
+
+	return exit_status;
+}
+
+int mainloop_run_with_signal(mainloop_signal_func func, void *user_data)
+{
+	if (!is_initialized || !func)
+		return -EINVAL;
+
+	/* Workaround for sign discrepancy in ell and bluez */
+	sig_func = func;
+
+	return l_main_run_with_signal(l_sig_func, user_data);
+}
+
+int mainloop_add_fd(int fd, uint32_t events, mainloop_event_func callback,
+				void *user_data, mainloop_destroy_func destroy)
+{
+	return -ENOSYS;
+}
+
+int mainloop_modify_fd(int fd, uint32_t events)
+{
+	return -ENOSYS;
+}
+
+int mainloop_remove_fd(int fd)
+{
+	return -ENOSYS;
+}
+
+int mainloop_add_timeout(unsigned int msec, mainloop_timeout_func callback,
+				void *user_data, mainloop_destroy_func destroy)
+{
+	return -ENOSYS;
+}
+
+int mainloop_modify_timeout(int fd, unsigned int msec)
+{
+	return -ENOSYS;
+}
+
+int mainloop_remove_timeout(int id)
+{
+	return -ENOSYS;
+}
+
+int mainloop_set_signal(sigset_t *mask, mainloop_signal_func callback,
+				void *user_data, mainloop_destroy_func destroy)
+{
+	return -ENOSYS;
+}
-- 
2.21.0


^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, back to index

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-08-08  4:46 [PATCH BlueZ 0/1] ELL based mainloop Inga Stotland
2019-08-08  4:46 ` [PATCH BlueZ 1/1] shared/mainloop: Add ell-based mainloop implementation Inga Stotland

Linux-Bluetooth Archive on lore.kernel.org

Archives are clonable:
	git clone --mirror https://lore.kernel.org/linux-bluetooth/0 linux-bluetooth/git/0.git

	# If you have public-inbox 1.1+ installed, you may
	# initialize and index your mirror using the following commands:
	public-inbox-init -V2 linux-bluetooth linux-bluetooth/ https://lore.kernel.org/linux-bluetooth \
		linux-bluetooth@vger.kernel.org linux-bluetooth@archiver.kernel.org
	public-inbox-index linux-bluetooth


Newsgroup available over NNTP:
	nntp://nntp.lore.kernel.org/org.kernel.vger.linux-bluetooth


AGPL code for this site: git clone https://public-inbox.org/ public-inbox