summaryrefslogtreecommitdiff
path: root/bus/stats.c
diff options
context:
space:
mode:
authorSimon McVittie <smcv@collabora.com>2017-06-09 16:24:13 +0100
committerSimon McVittie <smcv@collabora.com>2017-06-29 15:42:20 +0100
commit64dfab578c99d3b58324b0fc6b1da0d95f6ab9b5 (patch)
tree8531e7a60eecf552fbf4a8b9c8e98873147c4131 /bus/stats.c
parent38e9bc323bb011224b973f3a277443dee6c5f8d5 (diff)
downloaddbus-64dfab578c99d3b58324b0fc6b1da0d95f6ab9b5.tar.gz
dbus-64dfab578c99d3b58324b0fc6b1da0d95f6ab9b5.tar.bz2
dbus-64dfab578c99d3b58324b0fc6b1da0d95f6ab9b5.zip
driver: Share bus_driver_get_conn_helper with other modules
Now that we're starting to implement methods in more places, it makes sense to share this code. The Stats interface can already benefit. Signed-off-by: Simon McVittie <smcv@collabora.com> Reviewed-by: Philip Withnall <withnall@endlessm.com> Bug: https://bugs.freedesktop.org/show_bug.cgi?id=101567
Diffstat (limited to 'bus/stats.c')
-rw-r--r--bus/stats.c40
1 files changed, 21 insertions, 19 deletions
diff --git a/bus/stats.c b/bus/stats.c
index 065a09d5..15822556 100644
--- a/bus/stats.c
+++ b/bus/stats.c
@@ -120,37 +120,37 @@ bus_stats_handle_get_connection_stats (DBusConnection *caller_connection,
DBusMessage *message,
DBusError *error)
{
- const char *bus_name = NULL;
- DBusString bus_name_str;
+ BusDriverFound found;
DBusMessage *reply = NULL;
DBusMessageIter iter, arr_iter;
static dbus_uint32_t stats_serial = 0;
dbus_uint32_t in_messages, in_bytes, in_fds, in_peak_bytes, in_peak_fds;
dbus_uint32_t out_messages, out_bytes, out_fds, out_peak_bytes, out_peak_fds;
- BusRegistry *registry;
- BusService *service;
DBusConnection *stats_connection;
_DBUS_ASSERT_ERROR_IS_CLEAR (error);
- registry = bus_connection_get_registry (caller_connection);
-
- if (! dbus_message_get_args (message, error,
- DBUS_TYPE_STRING, &bus_name,
- DBUS_TYPE_INVALID))
- return FALSE;
+ found = bus_driver_get_conn_helper (caller_connection, message,
+ "statistics", NULL, &stats_connection,
+ error);
- _dbus_string_init_const (&bus_name_str, bus_name);
- service = bus_registry_lookup (registry, &bus_name_str);
-
- if (service == NULL)
+ switch (found)
{
- dbus_set_error (error, DBUS_ERROR_NAME_HAS_NO_OWNER,
- "Bus name '%s' has no owner", bus_name);
- return FALSE;
+ case BUS_DRIVER_FOUND_SELF:
+ dbus_set_error (error, DBUS_ERROR_INVALID_ARGS,
+ "GetConnectionStats is not meaningful for the "
+ "message bus \"%s\" itself", DBUS_SERVICE_DBUS);
+ goto failed;
+
+ case BUS_DRIVER_FOUND_PEER:
+ break;
+
+ case BUS_DRIVER_FOUND_ERROR:
+ /* fall through */
+ default:
+ goto failed;
}
- stats_connection = bus_service_get_primary_owners_connection (service);
_dbus_assert (stats_connection != NULL);
reply = _dbus_asv_new_method_return (message, &iter, &arr_iter);
@@ -212,10 +212,12 @@ bus_stats_handle_get_connection_stats (DBusConnection *caller_connection,
return TRUE;
oom:
+ BUS_SET_OOM (error);
+ /* fall through */
+failed:
if (reply != NULL)
dbus_message_unref (reply);
- BUS_SET_OOM (error);
return FALSE;
}