Skip to content

Commit

Permalink
[charging] Expose charging suspendable on D-Bus. JB#59152
Browse files Browse the repository at this point in the history
In devices where it is not possible to suspend charging, it makes
little sense to have charging hysteresis controls visible in
settings application.

Add dbus method for querying whether charging is suspendable as
an enabler for settings application side changes.

Required D-Bus constants are in mce-dev >= 1.32.0

Signed-off-by: Simo Piiroinen <simo.piiroinen@jolla.com>
  • Loading branch information
spiiroin committed Nov 22, 2022
1 parent 68b61d1 commit 7b6058f
Show file tree
Hide file tree
Showing 3 changed files with 50 additions and 1 deletion.
3 changes: 3 additions & 0 deletions mce.conf
Original file line number Diff line number Diff line change
Expand Up @@ -237,6 +237,9 @@
<allow send_destination="com.nokia.mce"
send_interface="com.nokia.mce.request"
send_member="get_charging_state"/>
<allow send_destination="com.nokia.mce"
send_interface="com.nokia.mce.request"
send_member="get_charging_suspendable"/>

<allow send_destination="com.nokia.mce"
send_interface="com.nokia.mce.request"
Expand Down
46 changes: 46 additions & 0 deletions modules/charging.c
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,7 @@ static gboolean mch_dbus_get_charging_state_cb (DBusMessage *const req);
static void mch_dbus_send_forced_charging_state (DBusMessage *const req);
static gboolean mch_dbus_get_forced_charging_state_cb(DBusMessage *const req);
static gboolean mch_dbus_set_forced_charging_state_cb(DBusMessage *const req);
static gboolean mch_dbus_get_charging_suspendable_cb (DBusMessage *const req);
static gboolean mch_dbus_initial_cb (gpointer aptr);
static void mch_dbus_init (void);
static void mch_dbus_quit (void);
Expand Down Expand Up @@ -1113,6 +1114,43 @@ mch_dbus_set_forced_charging_state_cb(DBusMessage *const req)
return TRUE;
}

/** Callback for handling charging suspendable D-Bus queries
*
* @param req method call message to reply
*/
static gboolean
mch_dbus_get_charging_suspendable_cb(DBusMessage *const req)
{
DBusMessage *rsp = NULL;
dbus_bool_t val = (mch_control_path != NULL);

mce_log(LL_DEBUG, "%s query from: %s",
dbus_message_get_member(req),
mce_dbus_get_message_sender_ident(req));

if( !(rsp = dbus_new_method_reply(req)) )
goto EXIT;

if( !dbus_message_append_args(rsp,
DBUS_TYPE_BOOLEAN, &val,
DBUS_TYPE_INVALID) )
goto EXIT;

mce_log(LL_DEBUG, "%s reply: %s",
dbus_message_get_member(req),
val ? "true" : "false");

if( !dbus_message_get_no_reply(req) )
dbus_send_message(rsp), rsp = 0;

EXIT:

if( rsp )
dbus_message_unref(rsp);

return TRUE;
}

/** Array of dbus message handlers */
static mce_dbus_handler_t mch_dbus_handlers[] =
{
Expand Down Expand Up @@ -1156,6 +1194,14 @@ static mce_dbus_handler_t mch_dbus_handlers[] =
.args =
" <arg direction=\"in\" name=\"forced_charging_state\" type=\"s\"/>\n"
},
{
.interface = MCE_REQUEST_IF,
.name = MCE_CHARGING_SUSPENDABLE_GET,
.type = DBUS_MESSAGE_TYPE_METHOD_CALL,
.callback = mch_dbus_get_charging_suspendable_cb,
.args =
" <arg direction=\"out\" name=\"charging_suspendable\" type=\"b\"/>\n"
},
/* sentinel */
{
.interface = 0
Expand Down
2 changes: 1 addition & 1 deletion rpm/mce.spec
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ BuildRequires: pkgconfig(dsme) >= 0.65.0
BuildRequires: pkgconfig(thermalmanager_dbus_if)
BuildRequires: pkgconfig(libiphb)
BuildRequires: pkgconfig(glib-2.0) >= 2.36.0
BuildRequires: pkgconfig(mce) >= 1.31.0
BuildRequires: pkgconfig(mce) >= 1.32.0
BuildRequires: pkgconfig(libngf0) >= 0.24
BuildRequires: pkgconfig(libsystemd)
BuildRequires: kernel-headers >= 2.6.32
Expand Down

0 comments on commit 7b6058f

Please sign in to comment.