Skip to content

Commit

Permalink
Merge branch 'jb38667_charger_type' into 'master'
Browse files Browse the repository at this point in the history
Make charger type available on D-Bus

See merge request mer-core/mce!125
  • Loading branch information
spiiroin committed Aug 28, 2019
2 parents def606b + a80fd7e commit 5903c02
Show file tree
Hide file tree
Showing 10 changed files with 518 additions and 19 deletions.
20 changes: 10 additions & 10 deletions .depend
Expand Up @@ -1344,6 +1344,16 @@ tklock.pic.o:\
systemui/tklock-dbus-names.h\
tklock.h\

tools/dummy_compositor.o:\
tools/dummy_compositor.c\
builtin-gconf.h\
mce-dbus.h\

tools/dummy_compositor.pic.o:\
tools/dummy_compositor.c\
builtin-gconf.h\
mce-dbus.h\

tools/evdev_trace.o:\
tools/evdev_trace.c\
evdev.h\
Expand All @@ -1356,16 +1366,6 @@ tools/evdev_trace.pic.o:\
mce-log.h\
tools/fileusers.h\

tools/dummy_compositor.o:\
tools/dummy_compositor.c\
builtin-gconf.h\
mce-dbus.h\

tools/dummy_compositor.pic.o:\
tools/dummy_compositor.c\
builtin-gconf.h\
mce-dbus.h\

tools/fileusers.o:\
tools/fileusers.c\
mce-log.h\
Expand Down
66 changes: 66 additions & 0 deletions datapipe.c
Expand Up @@ -5,6 +5,7 @@
* <p>
* Copyright © 2007-2008 Nokia Corporation and/or its subsidiary(-ies).
* Copyright (C) 2014-2019 Jolla Ltd.
* Copyright (c) 2019 Open Mobile Platform LLC.
* <p>
* @author David Weinehall <david.weinehall@nokia.com>
* @author Simo Piiroinen <simo.piiroinen@jollamobile.com>
Expand Down Expand Up @@ -113,6 +114,7 @@ static const char *datapipe_hook_call_state_value (gconstpointer data);
static const char *datapipe_hook_call_type_value (gconstpointer data);
static const char *datapipe_hook_tklock_request_value (gconstpointer data);
static const char *datapipe_hook_charger_state_value (gconstpointer data);
static const char *datapipe_hook_charger_type_value (gconstpointer data);
static const char *datapipe_hook_battery_status_value (gconstpointer data);
static const char *datapipe_hook_camera_button_state_value(gconstpointer data);
static const char *datapipe_hook_audio_route_value (gconstpointer data);
Expand Down Expand Up @@ -202,6 +204,13 @@ const char *service_state_repr(service_state_t state);
const char *usb_cable_state_repr (usb_cable_state_t state);
const char *usb_cable_state_to_dbus(usb_cable_state_t state);

/* ------------------------------------------------------------------------- *
* CHARGER_TYPE
* ------------------------------------------------------------------------- */

const char *charger_type_repr (charger_type_t type);
const char *charger_type_to_dbus(charger_type_t type);

/* ------------------------------------------------------------------------- *
* CHARGER_STATE
* ------------------------------------------------------------------------- */
Expand Down Expand Up @@ -473,6 +482,14 @@ datapipe_hook_tklock_request_value(gconstpointer data)
}
#define datapipe_hook_tklock_request_change 0

static const char *
datapipe_hook_charger_type_value(gconstpointer data)
{
charger_type_t value = GPOINTER_TO_INT(data);
return charger_type_repr(value);
}
#define datapipe_hook_charger_type_change 0

static const char *
datapipe_hook_charger_state_value(gconstpointer data)
{
Expand Down Expand Up @@ -698,6 +715,9 @@ datapipe_t tklock_request_pipe = DATAPIPE_INIT(tklock_request,
/** UI side is in a state where user interaction is expected */
datapipe_t interaction_expected_pipe = DATAPIPE_INIT(interaction_expected, boolean, false, 0, DATAPIPE_FILTERING_DENIED, DATAPIPE_CACHE_DEFAULT);

/** Charger type; read only */
datapipe_t charger_type_pipe = DATAPIPE_INIT(charger_type, charger_type, CHARGER_TYPE_NONE, 0, DATAPIPE_FILTERING_DENIED, DATAPIPE_CACHE_DEFAULT);

/** Charger state; read only */
datapipe_t charger_state_pipe = DATAPIPE_INIT(charger_state, charger_state, CHARGER_STATE_UNDEF, 0, DATAPIPE_FILTERING_DENIED, DATAPIPE_CACHE_DEFAULT);

Expand Down Expand Up @@ -1283,6 +1303,7 @@ void mce_datapipe_quit(void)
datapipe_free(&topmost_window_pid_pipe);
datapipe_free(&camera_button_state_pipe);
datapipe_free(&battery_status_pipe);
datapipe_free(&charger_type_pipe);
datapipe_free(&charger_state_pipe);
datapipe_free(&interaction_expected_pipe);
datapipe_free(&tklock_request_pipe);
Expand Down Expand Up @@ -1614,6 +1635,51 @@ const char *usb_cable_state_to_dbus(usb_cable_state_t state)
return res;
}

/** Convert charger_type_t enum to human readable string
*
* @param type charger_type_t enumeration value
*
* @return human readable representation of type
*/
const char *
charger_type_repr(charger_type_t type)
{
const char *repr = "unknown";
switch( type ) {
case CHARGER_TYPE_NONE: repr = "none"; break;
case CHARGER_TYPE_USB: repr = "usb"; break;
case CHARGER_TYPE_DCP: repr = "dcp"; break;
case CHARGER_TYPE_HVDCP: repr = "hwdcp"; break;
case CHARGER_TYPE_CDP: repr = "cdp"; break;
case CHARGER_TYPE_WIRELESS: repr = "wireless"; break;
case CHARGER_TYPE_OTHER: repr = "other"; break;
default: break;
}
return repr;
}

/** Convert charger_type_t enum to dbus argument string
*
* @param type charger_type_t enumeration value
*
* @return representation of type for use over dbus
*/
const char *
charger_type_to_dbus(charger_type_t type)
{
const char *repr = MCE_CHARGER_TYPE_OTHER;
switch( type ) {
case CHARGER_TYPE_NONE: repr = MCE_CHARGER_TYPE_NONE; break;
case CHARGER_TYPE_USB: repr = MCE_CHARGER_TYPE_USB; break;
case CHARGER_TYPE_DCP: repr = MCE_CHARGER_TYPE_DCP; break;
case CHARGER_TYPE_HVDCP: repr = MCE_CHARGER_TYPE_HVDCP; break;
case CHARGER_TYPE_CDP: repr = MCE_CHARGER_TYPE_CDP; break;
case CHARGER_TYPE_WIRELESS: repr = MCE_CHARGER_TYPE_WIRELESS; break;
default: break;
}
return repr;
}

/** Convert charger_state_t enum to human readable string
*
* @param state charger_state_t enumeration value
Expand Down
2 changes: 2 additions & 0 deletions datapipe.h
Expand Up @@ -4,6 +4,7 @@
* <p>
* Copyright © 2007 Nokia Corporation and/or its subsidiary(-ies).
* Copyright (C) 2014-2019 Jolla Ltd.
* Copyright (c) 2019 Open Mobile Platform LLC.
* <p>
* @author David Weinehall <david.weinehall@nokia.com>
* @author: Simo Piiroinen <simo.piiroinen@jollamobile.com>
Expand Down Expand Up @@ -253,6 +254,7 @@ extern datapipe_t ignore_incoming_call_event_pipe;
extern datapipe_t call_type_pipe;
extern datapipe_t tklock_request_pipe;
extern datapipe_t interaction_expected_pipe;
extern datapipe_t charger_type_pipe;
extern datapipe_t charger_state_pipe;
extern datapipe_t battery_status_pipe;
extern datapipe_t battery_level_pipe;
Expand Down
118 changes: 117 additions & 1 deletion mce-common.c
Expand Up @@ -3,6 +3,7 @@
* Common state logic for Mode Control Entity
* <p>
* Copyright (C) 2017-2019 Jolla Ltd.
* Copyright (c) 2019 Open Mobile Platform LLC.
* <p>
* @author Simo Piiroinen <simo.piiroinen@jollamobile.com>
*
Expand Down Expand Up @@ -78,6 +79,8 @@ static void common_on_proximity_quit (void);

static void common_dbus_send_usb_cable_state (DBusMessage *const req);
static gboolean common_dbus_get_usb_cable_state_cb(DBusMessage *const req);
static void common_dbus_send_charger_type (DBusMessage *const req);
static gboolean common_dbus_get_charger_type_cb (DBusMessage *const req);
static void common_dbus_send_charger_state (DBusMessage *const req);
static gboolean common_dbus_get_charger_state_cb (DBusMessage *const req);
static void common_dbus_send_battery_status (DBusMessage *const req);
Expand All @@ -93,6 +96,7 @@ static void common_dbus_quit (void);
* ------------------------------------------------------------------------- */

static void common_datapipe_usb_cable_state_cb (gconstpointer data);
static void common_datapipe_charger_type_cb (gconstpointer data);
static void common_datapipe_charger_state_cb (gconstpointer data);
static void common_datapipe_battery_status_cb (gconstpointer data);
static void common_datapipe_battery_level_cb (gconstpointer data);
Expand All @@ -114,6 +118,9 @@ void mce_common_quit(void);
/** USB cable status; assume undefined */
static usb_cable_state_t usb_cable_state = USB_CABLE_UNDEF;

/** Charger type; assume none */
static charger_type_t charger_type = CHARGER_TYPE_NONE;

/** Charger state; assume undefined */
static charger_state_t charger_state = CHARGER_STATE_UNDEF;

Expand Down Expand Up @@ -393,6 +400,69 @@ common_dbus_get_usb_cable_state_cb(DBusMessage *const req)
return TRUE;
}

/* ------------------------------------------------------------------------- *
* charger_type
* ------------------------------------------------------------------------- */

/** Send charger_type D-Bus signal / method call reply
*
* @param req method call message to reply, or NULL to send signal
*/
static void
common_dbus_send_charger_type(DBusMessage *const req)
{
static const char *last = 0;

DBusMessage *msg = NULL;

const char *value = charger_type_to_dbus(charger_type);

if( req ) {
msg = dbus_new_method_reply(req);
}
else if( last == value ) {
goto EXIT;
}
else {
last = value;
msg = dbus_new_signal(MCE_SIGNAL_PATH,
MCE_SIGNAL_IF,
MCE_CHARGER_TYPE_SIG);
}

if( !dbus_message_append_args(msg,
DBUS_TYPE_STRING, &value,
DBUS_TYPE_INVALID) )
goto EXIT;

mce_log(LL_DEBUG, "%s: %s = %s",
req ? "reply" : "broadcast",
"charger_type", value);

dbus_send_message(msg), msg = 0;

EXIT:

if( msg )
dbus_message_unref(msg);
}

/** Callback for handling charger_type D-Bus queries
*
* @param req method call message to reply
*/
static gboolean
common_dbus_get_charger_type_cb(DBusMessage *const req)
{
mce_log(LL_DEBUG, "charger_type query from: %s",
mce_dbus_get_message_sender_ident(req));

if( !dbus_message_get_no_reply(req) )
common_dbus_send_charger_type(req);

return TRUE;
}

/* ------------------------------------------------------------------------- *
* charger_state
* ------------------------------------------------------------------------- */
Expand Down Expand Up @@ -562,7 +632,7 @@ common_dbus_send_battery_level(DBusMessage *const req)

mce_log(LL_DEBUG, "%s: %s = %d",
req ? "reply" : "broadcast",
"charger_state", value);
"battery_level", value);

dbus_send_message(msg), msg = 0;

Expand Down Expand Up @@ -603,6 +673,13 @@ static mce_dbus_handler_t common_dbus_handlers[] =
.args =
" <arg name=\"usb_cable_state\" type=\"s\"/>\n"
},
{
.interface = MCE_SIGNAL_IF,
.name = MCE_CHARGER_TYPE_SIG,
.type = DBUS_MESSAGE_TYPE_SIGNAL,
.args =
" <arg name=\"charger_type\" type=\"s\"/>\n"
},
{
.interface = MCE_SIGNAL_IF,
.name = MCE_CHARGER_STATE_SIG,
Expand Down Expand Up @@ -633,6 +710,14 @@ static mce_dbus_handler_t common_dbus_handlers[] =
.args =
" <arg direction=\"out\" name=\"usb_cable_state\" type=\"s\"/>\n"
},
{
.interface = MCE_REQUEST_IF,
.name = MCE_CHARGER_TYPE_GET,
.type = DBUS_MESSAGE_TYPE_METHOD_CALL,
.callback = common_dbus_get_charger_type_cb,
.args =
" <arg direction=\"out\" name=\"charger_type\" type=\"s\"/>\n"
},
{
.interface = MCE_REQUEST_IF,
.name = MCE_CHARGER_STATE_GET,
Expand Down Expand Up @@ -683,6 +768,7 @@ static gboolean common_dbus_initial_cb(gpointer aptr)
* some values to undefined state.
*/
common_dbus_send_usb_cable_state(0);
common_dbus_send_charger_type(0);
common_dbus_send_charger_state(0);
common_dbus_send_battery_status(0);
common_dbus_send_battery_level(0);
Expand Down Expand Up @@ -754,6 +840,32 @@ static void common_datapipe_usb_cable_state_cb(gconstpointer data)
return;
}

/* ------------------------------------------------------------------------- *
* charger_type
* ------------------------------------------------------------------------- */

/** Callback for handling charger_type_pipe state changes
*
* @param data charger_type (as void pointer)
*/
static void common_datapipe_charger_type_cb(gconstpointer data)
{
charger_type_t prev = charger_type;
charger_type = GPOINTER_TO_INT(data);

if( charger_type == prev )
goto EXIT;

mce_log(LL_DEBUG, "charger_type = %s -> %s",
charger_type_repr(prev),
charger_type_repr(charger_type));

common_dbus_send_charger_type(0);

EXIT:
return;
}

/* ------------------------------------------------------------------------- *
* charger_state
* ------------------------------------------------------------------------- */
Expand Down Expand Up @@ -868,6 +980,10 @@ static datapipe_handler_t common_datapipe_handlers[] =
.datapipe = &usb_cable_state_pipe,
.output_cb = common_datapipe_usb_cable_state_cb,
},
{
.datapipe = &charger_type_pipe,
.output_cb = common_datapipe_charger_type_cb,
},
{
.datapipe = &charger_state_pipe,
.output_cb = common_datapipe_charger_state_cb,
Expand Down
20 changes: 20 additions & 0 deletions mce-dbus.h
Expand Up @@ -4,6 +4,7 @@
* <p>
* Copyright © 2004-2010 Nokia Corporation and/or its subsidiary(-ies).
* Copyright (C) 2013-2019 Jolla Ltd.
* Copyright (c) 2019 Open Mobile Platform LLC.
* <p>
* @author David Weinehall <david.weinehall@nokia.com>
* @author Simo Piiroinen <simo.piiroinen@jollamobile.com>
Expand Down Expand Up @@ -49,6 +50,25 @@
*/
# define MCE_CHARGER_STATE_REQ "req_charger_state"

/** Override current charger type
*
* Available in devel flavor mce only, and only to privileged applications.
*
* @since mce 1.102.0
*
* @param string: current charger type, one of:
* - #MCE_CHARGER_TYPE_NONE
* - #MCE_CHARGER_TYPE_USB
* - #MCE_CHARGER_TYPE_DCP
* - #MCE_CHARGER_TYPE_HVDCP
* - #MCE_CHARGER_TYPE_CDP
* - #MCE_CHARGER_TYPE_WIRELESS
* - #MCE_CHARGER_TYPE_OTHER
*
* @return boolean true if accepted, false / error reply otherwise
*/
# define MCE_CHARGER_TYPE_REQ "req_charger_type"

/** Override current battery level
*
* Available in devel flavor mce only, and only to privileged applications.
Expand Down

0 comments on commit 5903c02

Please sign in to comment.