Skip to content

Commit

Permalink
[mce] Expose battery/charging data on D-Bus. Fixes JB#37422
Browse files Browse the repository at this point in the history
Tracking battery data via statefs requires dealing with fuse and kernel
related quirks. Since mce already deals with that, it would be preferable
to reuse already functioning code instead of duplicating it elsewhere.

Add handlers D-Bus method calls that can be used to query current values
and send signals when state changes are detected.

The following information is made available:
- usb_cable_state: unknown | connected | disconnected
- charging_state:  unknown | on | off
- battery_status:  unknown | full | ok | low | empty
- battery_level:   -1 | 0...100

Related D-Bus constants are defined in mce-headers >= 1.21.0.

Signed-off-by: Simo Piiroinen <simo.piiroinen@jollamobile.com>

REVIEW separate internal & dbus state processing more clearly
  • Loading branch information
spiiroin committed Jan 23, 2017
1 parent 06cb7ae commit afe100c
Show file tree
Hide file tree
Showing 8 changed files with 820 additions and 5 deletions.
20 changes: 20 additions & 0 deletions .depend
Expand Up @@ -132,6 +132,24 @@ mce-command-line.pic.o:\
mce-command-line.c\
mce-command-line.h\

mce-common.o:\
mce-common.c\
builtin-gconf.h\
datapipe.h\
mce-common.h\
mce-dbus.h\
mce-log.h\
mce.h\

mce-common.pic.o:\
mce-common.c\
builtin-gconf.h\
datapipe.h\
mce-common.h\
mce-dbus.h\
mce-log.h\
mce.h\

mce-conf.o:\
mce-conf.c\
datapipe.h\
Expand Down Expand Up @@ -390,6 +408,7 @@ mce.o:\
event-switches.h\
libwakelock.h\
mce-command-line.h\
mce-common.h\
mce-conf.h\
mce-dbus.h\
mce-dsme.h\
Expand All @@ -415,6 +434,7 @@ mce.pic.o:\
event-switches.h\
libwakelock.h\
mce-command-line.h\
mce-common.h\
mce-conf.h\
mce-dbus.h\
mce-dsme.h\
Expand Down
21 changes: 18 additions & 3 deletions Makefile
@@ -1,8 +1,20 @@
# Makefile for MCE
# Copyright © 2004-2011 Nokia Corporation.
# Written by David Weinehall
# Modified by Tuomo Tanskanen
# Modified by Simo Piiroinen
# Copyright (C) 2012-2017 Jolla Ltd.
#
# @author David Weinehall <david.weinehall@nokia.com>
# @author Tuomo Tanskanen
# @author Irina Bezruk <ext-irina.bezruk@nokia.com>
# @author Victor Portnov <ext-victor.portnov@nokia.com>
# @author Jukka Turunen <ext-jukka.t.turunen@nokia.com>
# @author Santtu Lakkala <ext-santtu.1.lakkala@nokia.com>
# @author Tapio Rantala <ext-tapio.rantala@nokia.com>
# @author Dmitry Rozhkov <dmitry.rozhkov@jollamobile.com>
# @author Kalle Jokiniemi <kalle.jokiniemi@jolla.com>
# @author Philippe De Swert <philippe.deswert@jollamobile.com>
# @author Pekka Lundstrom <pekka.lundstrom@jollamobile.com>
# @author Martin Kampas <martin.kampas@tieto.com>
# @author Simo Piiroinen <simo.piiroinen@jollamobile.com>
#
# mce is free software; you can redistribute it and/or modify
# it under the terms of the GNU Lesser General Public License
Expand Down Expand Up @@ -275,6 +287,7 @@ MCE_LDLIBS += $(MCE_PKG_LDLIBS)
MCE_CORE += tklock.c
MCE_CORE += modetransition.c
MCE_CORE += powerkey.c
MCE_CORE += mce-common.c
MCE_CORE += mce-fbdev.c
MCE_CORE += mce-dbus.c
MCE_CORE += mce-dsme.c
Expand Down Expand Up @@ -533,6 +546,8 @@ NORMALIZE_USES_SPC =\
filewatcher.h\
homekey.dot\
libwakelock.h\
mce-common.c\
mce-common.h\
mce-dsme.c\
mce-dsme.h\
mce-fbdev.c\
Expand Down
82 changes: 81 additions & 1 deletion datapipe.c
Expand Up @@ -4,8 +4,10 @@
* this can be used to filter data and to setup data triggers
* <p>
* Copyright © 2007-2008 Nokia Corporation and/or its subsidiary(-ies).
* Copyright (C) 2014-2017 Jolla Ltd.
* <p>
* @author David Weinehall <david.weinehall@nokia.com>
* @author Simo Piiroinen <simo.piiroinen@jollamobile.com>
*
* mce is free software; you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License
Expand Down Expand Up @@ -785,7 +787,7 @@ void mce_datapipe_init(void)
setup_datapipe(&battery_status_pipe, READ_ONLY, DONT_FREE_CACHE,
0, GINT_TO_POINTER(BATTERY_STATUS_UNDEF));
setup_datapipe(&battery_level_pipe, READ_ONLY, DONT_FREE_CACHE,
0, GINT_TO_POINTER(100));
0, GINT_TO_POINTER(BATTERY_LEVEL_INITIAL));
setup_datapipe(&camera_button_pipe, READ_ONLY, DONT_FREE_CACHE,
0, GINT_TO_POINTER(CAMERA_BUTTON_UNDEF));
setup_datapipe(&inactivity_timeout_pipe, READ_ONLY, DONT_FREE_CACHE,
Expand Down Expand Up @@ -1060,6 +1062,32 @@ const char *usb_cable_state_repr(usb_cable_state_t state)
return res;
}

/** Convert usb_cable_state_t enum to dbus argument string
*
* @param state usb_cable_state_t enumeration value
*
* @return representation of state for use over dbus
*/
const char *usb_cable_state_to_dbus(usb_cable_state_t state)
{
const char *res = MCE_USB_CABLE_STATE_UNKNOWN;

switch( state ) {
case USB_CABLE_DISCONNECTED:
res = MCE_USB_CABLE_STATE_DISCONNECTED;
break;

case USB_CABLE_ASK_USER:
case USB_CABLE_CONNECTED:
res = MCE_USB_CABLE_STATE_CONNECTED;
break;
default:
break;
}

return res;
}

/** Convert charger_state_t enum to human readable string
*
* @param state charger_state_t enumeration value
Expand All @@ -1080,6 +1108,30 @@ const char *charger_state_repr(charger_state_t state)
return res;
}

/** Convert charger_state_t enum to dbus argument string
*
* @param state charger_state_t enumeration value
*
* @return representation of state for use over dbus
*/
const char *charger_state_to_dbus(charger_state_t state)
{
const char *res = MCE_CHARGER_STATE_UNKNOWN;

switch( state ) {
case CHARGER_STATE_OFF:
res = MCE_CHARGER_STATE_OFF;
break;
case CHARGER_STATE_ON:
res = MCE_CHARGER_STATE_ON;
break;
default:
break;
}

return res;
}

/** Convert lock_state_t enum to human readable string
*
* @param state lock_state_t enumeration value
Expand Down Expand Up @@ -1124,6 +1176,34 @@ const char *battery_status_repr(battery_status_t state)
return res;
}

/** Convert battery_status_t enum to dbus argument string
*
* @param state battery_status_t enumeration value
*
* @return representation of state for use over dbus
*/
const char *battery_status_to_dbus(battery_status_t state)
{
const char *res = MCE_BATTERY_STATUS_UNKNOWN;
switch( state ) {
case BATTERY_STATUS_FULL:
res = MCE_BATTERY_STATUS_FULL;
break;
case BATTERY_STATUS_OK:
res = MCE_BATTERY_STATUS_OK;
break;
case BATTERY_STATUS_LOW:
res = MCE_BATTERY_STATUS_LOW;
break;
case BATTERY_STATUS_EMPTY:
res = MCE_BATTERY_STATUS_EMPTY;
break;
default:
break;
}
return res;
}

/** Convert alarm_ui_state_t enum to human readable string
*
* @param state alarm_ui_state_t enumeration value
Expand Down

0 comments on commit afe100c

Please sign in to comment.