Skip to content

Commit

Permalink
Make MCE introspectable over D-Bus
Browse files Browse the repository at this point in the history
Previously mce did not support org.freedesktop.DBus.Introspectable
D-Bus interface which required use of workarounds for making method
calls or listening to signals from qt and qml applications.

Augment mce dbus handler structures to hold XML introspection data too.

Allow registering of dummy signal handlers for the purposes of holding
introspection data for outbound signals.

Unify all dbus handler registration to happen via array-of-handers
functionality and provide introspection data for all method calls
supported by mce and (non-configurable) signals sent by mce.

Do diagnostic logging if mce still sends non-introspectable signals.

Implement org.freedesktop.DBus.Introspectable D-Bus interface for mce.

Allow use of org.freedesktop.DBus.Peer D-Bus interface with mce.

[mce] Make MCE introspectable over D-Bus. Fixes JB#21034
  • Loading branch information
spiiroin committed Aug 18, 2014
1 parent 5dba0aa commit 4139106
Show file tree
Hide file tree
Showing 19 changed files with 1,284 additions and 472 deletions.
495 changes: 404 additions & 91 deletions mce-dbus.c

Large diffs are not rendered by default.

9 changes: 9 additions & 0 deletions mce-dbus.h
Expand Up @@ -60,11 +60,19 @@ DBusMessage *dbus_send_with_block(const gchar *const service,
gint timeout, int first_arg_type, ...);
pid_t dbus_get_pid_from_bus_name(const gchar *const bus_name);

gconstpointer mce_dbus_handler_add_ex(const gchar *const interface,
const gchar *const name,
const gchar *const args,
const gchar *const rules,
const guint type,
gboolean (*callback)(DBusMessage *const msg));

gconstpointer mce_dbus_handler_add(const gchar *const interface,
const gchar *const name,
const gchar *const rules,
const guint type,
gboolean (*callback)(DBusMessage *const msg));

void mce_dbus_handler_remove(gconstpointer cookie);
gboolean mce_dbus_is_owner_monitored(const gchar *service,
GSList *monitor_list);
Expand All @@ -90,6 +98,7 @@ typedef struct
const char *interface;
const char *name;
const char *rules;
const char *args;
int type;
gboolean (*callback)(DBusMessage *const msg);

Expand Down
5 changes: 5 additions & 0 deletions mce.conf
Expand Up @@ -10,6 +10,11 @@
</policy>

<policy context="default">
<allow send_destination="com.nokia.mce"
send_interface="org.freedesktop.DBus.Introspectable"/>
<allow send_destination="com.nokia.mce"
send_interface="org.freedesktop.DBus.Peer"/>

<allow send_destination="com.nokia.mce"
send_interface="com.nokia.mce.request"
send_member="get_radio_states"/>
Expand Down
43 changes: 35 additions & 8 deletions modules/alarm.c
Expand Up @@ -223,6 +223,36 @@ static gboolean alarm_dialog_status_dbus_cb(DBusMessage *const msg)
return status;
}

/** Array of dbus message handlers */
static mce_dbus_handler_t alarm_dbus_handlers[] =
{
/* signals */
{
.interface = VISUAL_REMINDERS_SIGNAL_IF,
.name = VISUAL_REMINDER_STATUS_SIG,
.type = DBUS_MESSAGE_TYPE_SIGNAL,
.callback = alarm_dialog_status_dbus_cb,
},
/* sentinel */
{
.interface = 0
}
};

/** Add dbus handlers
*/
static void mce_alarm_init_dbus(void)
{
mce_dbus_handler_register_array(alarm_dbus_handlers);
}

/** Remove dbus handlers
*/
static void mce_alarm_quit_dbus(void)
{
mce_dbus_handler_unregister_array(alarm_dbus_handlers);
}

/**
* Init function for the alarm interface module
*
Expand All @@ -236,15 +266,9 @@ const gchar *g_module_check_init(GModule *module)
{
(void)module;

/* visual_reminders_status */
if (mce_dbus_handler_add(VISUAL_REMINDERS_SIGNAL_IF,
VISUAL_REMINDER_STATUS_SIG,
NULL,
DBUS_MESSAGE_TYPE_SIGNAL,
alarm_dialog_status_dbus_cb) == NULL)
goto EXIT;
/* Add dbus handlers */
mce_alarm_init_dbus();

EXIT:
return NULL;
}

Expand All @@ -260,5 +284,8 @@ void g_module_unload(GModule *module)
{
(void)module;

/* Remove dbus handlers */
mce_alarm_quit_dbus();

return;
}
169 changes: 89 additions & 80 deletions modules/battery-bme.c
Expand Up @@ -420,6 +420,90 @@ static gboolean request_charger_status(void)
BME_STATUS_INFO_REQ, NULL, DBUS_TYPE_INVALID);
}

/** Array of dbus message handlers */
static mce_dbus_handler_t battery_bme_dbus_handlers[] =
{
/* signals */
{
.interface = BME_SIGNAL_IF,
.name = BME_BATTERY_FULL,
.type = DBUS_MESSAGE_TYPE_SIGNAL,
.callback = battery_full_dbus_cb,
},
{
.interface = BME_SIGNAL_IF,
.name = BME_BATTERY_OK,
.type = DBUS_MESSAGE_TYPE_SIGNAL,
.callback = battery_ok_dbus_cb,
},
{
.interface = BME_SIGNAL_IF,
.name = BME_BATTERY_LOW,
.type = DBUS_MESSAGE_TYPE_SIGNAL,
.callback = battery_low_dbus_cb,
},
{
.interface = BME_SIGNAL_IF,
.name = BME_BATTERY_EMPTY,
.type = DBUS_MESSAGE_TYPE_SIGNAL,
.callback = battery_empty_dbus_cb,
},
{
.interface = BME_SIGNAL_IF,
.name = BME_BATTERY_STATE_UPDATE,
.type = DBUS_MESSAGE_TYPE_SIGNAL,
.callback = battery_state_changed_dbus_cb,
},
{
.interface = BME_SIGNAL_IF,
.name = BME_CHARGER_CHARGING_ON,
.type = DBUS_MESSAGE_TYPE_SIGNAL,
.callback = charger_charging_on_dbus_cb,
},
{
.interface = BME_SIGNAL_IF,
.name = BME_CHARGER_CHARGING_OFF,
.type = DBUS_MESSAGE_TYPE_SIGNAL,
.callback = charger_charging_off_dbus_cb,
},
{
.interface = BME_SIGNAL_IF,
.name = BME_CHARGER_CHARGING_FAILED,
.type = DBUS_MESSAGE_TYPE_SIGNAL,
.callback = charger_charging_failed_dbus_cb,
},
{
.interface = BME_SIGNAL_IF,
.name = BME_CHARGER_CONNECTED,
.type = DBUS_MESSAGE_TYPE_SIGNAL,
.callback = charger_connected_dbus_cb,
},
{
.interface = BME_SIGNAL_IF,
.name = BME_CHARGER_DISCONNECTED,
.type = DBUS_MESSAGE_TYPE_SIGNAL,
.callback = charger_disconnected_dbus_cb,
},
/* sentinel */
{
.interface = 0
}
};

/** Add dbus handlers
*/
static void battery_bme_init_dbus(void)
{
mce_dbus_handler_register_array(battery_bme_dbus_handlers);
}

/** Remove dbus handlers
*/
static void battery_bme_quit_dbus(void)
{
mce_dbus_handler_unregister_array(battery_bme_dbus_handlers);
}

/**
* Init function for the battery and charger module
*
Expand All @@ -433,90 +517,12 @@ const gchar *g_module_check_init(GModule *module)
{
(void)module;

/* battery_full */
if (mce_dbus_handler_add(BME_SIGNAL_IF,
BME_BATTERY_FULL,
NULL,
DBUS_MESSAGE_TYPE_SIGNAL,
battery_full_dbus_cb) == NULL)
goto EXIT;

/* battery_ok */
if (mce_dbus_handler_add(BME_SIGNAL_IF,
BME_BATTERY_OK,
NULL,
DBUS_MESSAGE_TYPE_SIGNAL,
battery_ok_dbus_cb) == NULL)
goto EXIT;

/* battery_low */
if (mce_dbus_handler_add(BME_SIGNAL_IF,
BME_BATTERY_LOW,
NULL,
DBUS_MESSAGE_TYPE_SIGNAL,
battery_low_dbus_cb) == NULL)
goto EXIT;

/* battery_empty */
if (mce_dbus_handler_add(BME_SIGNAL_IF,
BME_BATTERY_EMPTY,
NULL,
DBUS_MESSAGE_TYPE_SIGNAL,
battery_empty_dbus_cb) == NULL)
goto EXIT;

/* battery_state_changed */
if (mce_dbus_handler_add(BME_SIGNAL_IF,
BME_BATTERY_STATE_UPDATE,
NULL,
DBUS_MESSAGE_TYPE_SIGNAL,
battery_state_changed_dbus_cb) == NULL)
goto EXIT;

/* charger_charging_on */
if (mce_dbus_handler_add(BME_SIGNAL_IF,
BME_CHARGER_CHARGING_ON,
NULL,
DBUS_MESSAGE_TYPE_SIGNAL,
charger_charging_on_dbus_cb) == NULL)
goto EXIT;

/* charger_charging_off */
if (mce_dbus_handler_add(BME_SIGNAL_IF,
BME_CHARGER_CHARGING_OFF,
NULL,
DBUS_MESSAGE_TYPE_SIGNAL,
charger_charging_off_dbus_cb) == NULL)
goto EXIT;

/* charger_charging_failed */
if (mce_dbus_handler_add(BME_SIGNAL_IF,
BME_CHARGER_CHARGING_FAILED,
NULL,
DBUS_MESSAGE_TYPE_SIGNAL,
charger_charging_failed_dbus_cb) == NULL)
goto EXIT;

/* charger_connected */
if (mce_dbus_handler_add(BME_SIGNAL_IF,
BME_CHARGER_CONNECTED,
NULL,
DBUS_MESSAGE_TYPE_SIGNAL,
charger_connected_dbus_cb) == NULL)
goto EXIT;

/* charger_disconnected */
if (mce_dbus_handler_add(BME_SIGNAL_IF,
BME_CHARGER_DISCONNECTED,
NULL,
DBUS_MESSAGE_TYPE_SIGNAL,
charger_disconnected_dbus_cb) == NULL)
goto EXIT;
/* Add dbus handlers */
battery_bme_init_dbus();

/* Update charger status */
request_charger_status();

EXIT:
return NULL;
}

Expand All @@ -532,5 +538,8 @@ void g_module_unload(GModule *module)
{
(void)module;

/* Remove dbus handlers */
battery_bme_quit_dbus();

return;
}
67 changes: 55 additions & 12 deletions modules/battery-upower.c
Expand Up @@ -1072,6 +1072,56 @@ G_MODULE_EXPORT module_info_struct module_info =
.priority = 100
};

/** Array of dbus message handlers */
static mce_dbus_handler_t battery_upower_dbus_handlers[] =
{
/* signals */
{
.interface = UPOWER_INTERFACE,
.name = "DeviceAdded",
.type = DBUS_MESSAGE_TYPE_SIGNAL,
.callback = xup_device_added_cb,
},
{
.interface = UPOWER_INTERFACE,
.name = "DeviceChanged",
.type = DBUS_MESSAGE_TYPE_SIGNAL,
.callback = xup_device_changed_cb,
},
{
.interface = UPOWER_INTERFACE,
.name = "DeviceRemoved",
.type = DBUS_MESSAGE_TYPE_SIGNAL,
.callback = xup_device_removed_cb,
},

{
.interface = DBUS_INTERFACE_DBUS,
.name = "NameOwnerChanged",
.rules = "arg0='"UPOWER_SERVICE"'",
.type = DBUS_MESSAGE_TYPE_SIGNAL,
.callback = xup_name_owner_cb,
},
/* sentinel */
{
.interface = 0
}
};

/** Add dbus handlers
*/
static void mce_battery_init_dbus(void)
{
mce_dbus_handler_register_array(battery_upower_dbus_handlers);
}

/** Remove dbus handlers
*/
static void mce_battery_quit_dbus(void)
{
mce_dbus_handler_unregister_array(battery_upower_dbus_handlers);
}

/** Init function for the battery and charger module
*
* @todo XXX status needs to be set on error!
Expand All @@ -1089,18 +1139,8 @@ const gchar *g_module_check_init(GModule *module)
mcebat_init();
upowbat_init();

/* Track device signals from upowerd */
mce_dbus_handler_add(UPOWER_INTERFACE, "DeviceAdded", 0,
DBUS_MESSAGE_TYPE_SIGNAL, xup_device_added_cb);
mce_dbus_handler_add(UPOWER_INTERFACE, "DeviceChanged", 0,
DBUS_MESSAGE_TYPE_SIGNAL, xup_device_changed_cb);
mce_dbus_handler_add(UPOWER_INTERFACE, "DeviceRemoved", 0,
DBUS_MESSAGE_TYPE_SIGNAL, xup_device_removed_cb);

/* Track availablity of upowerd */
mce_dbus_handler_add(DBUS_INTERFACE_DBUS, "NameOwnerChanged",
"arg0='"UPOWER_SERVICE"'",
DBUS_MESSAGE_TYPE_SIGNAL, xup_name_owner_cb);
/* Add dbus handlers */
mce_battery_init_dbus();

/* Initiate available device objects query.
* Properties will be probed when reply arrives.
Expand All @@ -1120,6 +1160,9 @@ void g_module_unload(GModule *module)
{
(void)module;

/* Remove dbus handlers */
mce_battery_quit_dbus();

devlist_rem_dev_all();
mcebat_update_cancel();
}

0 comments on commit 4139106

Please sign in to comment.