Skip to content

Commit

Permalink
[bluetooth] Block suspend on bluez start/stop. JB#18661
Browse files Browse the repository at this point in the history
While the idea of bluez tracking is to block suspend when it is expected
that either bluetooth daemon itself or other related parts in the sw stack
are processing something, bluez startup / restarts etc are not protected
against suspending.

Block suspend when org.bluez appears to / disappears from D-Bus SystemBus.

Signed-off-by: Simo Piiroinen <simo.piiroinen@jollamobile.com>
  • Loading branch information
spiiroin committed Nov 24, 2016
1 parent 3934a09 commit 6c793b5
Show file tree
Hide file tree
Showing 2 changed files with 79 additions and 0 deletions.
4 changes: 4 additions & 0 deletions .depend
Expand Up @@ -531,16 +531,20 @@ modules/battery-upower.pic.o:\
modules/bluetooth.o:\
modules/bluetooth.c\
builtin-gconf.h\
datapipe.h\
libwakelock.h\
mce-dbus.h\
mce-log.h\
mce.h\

modules/bluetooth.pic.o:\
modules/bluetooth.c\
builtin-gconf.h\
datapipe.h\
libwakelock.h\
mce-dbus.h\
mce-log.h\
mce.h\

modules/callstate.o:\
modules/callstate.c\
Expand Down
75 changes: 75 additions & 0 deletions modules/bluetooth.c
Expand Up @@ -19,6 +19,7 @@
* License along with mce. If not, see <http://www.gnu.org/licenses/>.
*/

#include "../mce.h"
#include "../mce-log.h"
#include "../mce-dbus.h"
#include "../libwakelock.h"
Expand Down Expand Up @@ -184,6 +185,76 @@ static void bluetooth_dbus_quit(void)
{
mce_dbus_handler_unregister_array(bluetooth_dbus_handlers);
}
/* ========================================================================= *
* DATAPIPE_TRACKING
* ========================================================================= */

/** Availability of bluez; from bluez_available_pipe */
static service_state_t bluez_available = SERVICE_STATE_UNDEF;

/** Datapipe trigger for bluez availability
*
* @param data bluez D-Bus service availability (as a void pointer)
*/
static void bluetooth_datapipe_bluez_available_cb(gconstpointer const data)
{
service_state_t prev = bluez_available;
bluez_available = GPOINTER_TO_INT(data);

if( bluez_available == prev )
goto EXIT;

mce_log(LL_DEVEL, "bluez dbus service: %s -> %s",
service_state_repr(prev),
service_state_repr(bluez_available));

switch( bluez_available ) {
case SERVICE_STATE_RUNNING:
case SERVICE_STATE_STOPPED:
bluetooth_suspend_block_start();
break;

default:
break;
}

EXIT:
return;
}

/** Array of datapipe handlers */
static datapipe_handler_t bluetooth_datapipe_handlers[] =
{
// output triggers
{
.datapipe = &bluez_available_pipe,
.output_cb = bluetooth_datapipe_bluez_available_cb,
},
// sentinel
{
.datapipe = 0,
}
};

static datapipe_bindings_t bluetooth_datapipe_bindings =
{
.module = "bluetooth",
.handlers = bluetooth_datapipe_handlers,
};

/** Append triggers/filters to datapipes
*/
static void bluetooth_datapipe_init(void)
{
datapipe_bindings_init(&bluetooth_datapipe_bindings);
}

/** Remove triggers/filters from datapipes
*/
static void bluetooth_datapipe_quit(void)
{
datapipe_bindings_quit(&bluetooth_datapipe_bindings);
}

/* ========================================================================= *
* MODULE_LOAD_UNLOAD
Expand All @@ -199,6 +270,8 @@ const gchar *g_module_check_init(GModule *module)
{
(void)module;

bluetooth_datapipe_init();

bluetooth_dbus_init();

return 0;
Expand All @@ -212,6 +285,8 @@ void g_module_unload(GModule *module)
{
(void)module;

bluetooth_datapipe_quit();

bluetooth_dbus_quit();

bluetooth_suspend_block_stop();
Expand Down

0 comments on commit 6c793b5

Please sign in to comment.