summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/hsd-headset.c57
-rw-r--r--src/hsd-headset.h2
-rw-r--r--src/hsd-manager.c38
-rw-r--r--src/hsd-manager.h2
4 files changed, 69 insertions, 30 deletions
diff --git a/src/hsd-headset.c b/src/hsd-headset.c
index 3011272..1b81d19 100644
--- a/src/hsd-headset.c
+++ b/src/hsd-headset.c
@@ -37,7 +37,7 @@ static GDBusNodeInfo *introspection_data = NULL;
/* Introspection data for the service we are exporting */
static const gchar introspection_xml[] =
"<node>"
- " <interface name='org.freedesktop.Headset'>"
+ " <interface name='" HSD_HEADSET_INTERFACE "'>"
" <method name='Connect'>"
" <arg type='a{sv}' name='properties' direction='in'/>"
" <arg type='a{sv}' name='results' direction='out'/>"
@@ -79,10 +79,35 @@ static void
headset_set_state (HsdHeadset *h,
HsdHeadsetState state)
{
+ GVariantBuilder * builder, *invalidated_builder;
+ GError *error;
+
if (h->state == state)
return;
h->state = state;
+
+ error = NULL;
+ builder = g_variant_builder_new (G_VARIANT_TYPE_ARRAY);
+ invalidated_builder = g_variant_builder_new (G_VARIANT_TYPE ("as"));
+ g_variant_builder_add (builder,
+ "{sv}",
+ "State",
+ g_variant_new_string (headset_state_to_string (state)));
+ g_dbus_connection_emit_signal (hsd_dbus_connection_get (),
+ NULL,
+ h->device,
+ "org.freedesktop.DBus.Properties",
+ "PropertiesChanged",
+ g_variant_new ("(sa{sv}as)",
+ HSD_HEADSET_INTERFACE,
+ builder,
+ invalidated_builder),
+ &error);
+ if (error) {
+ g_warning ("failed to emit PropertiesChanged: %s", error->message);
+ g_clear_error (&error);
+ }
}
static gboolean
@@ -123,7 +148,7 @@ connect_failed:
h->owner = NULL;
headset_set_state (h, HSD_HEADSET_STATE_IDLE);
g_dbus_method_invocation_return_dbus_error (invocation,
- "org.freedesktop.Headset.Error.Failed", "failed to connect");
+ HSD_HEADSET_INTERFACE ".Error.Failed", "failed to connect");
return FALSE;
}
}
@@ -210,31 +235,31 @@ headset_connect (HsdHeadset *h,
not_idle:
{
g_dbus_method_invocation_return_dbus_error (invocation,
- "org.freedesktop.Headset.Error.Failed", "headset not idle");
+ HSD_HEADSET_INTERFACE ".Error.Failed", "headset not idle");
return;
}
socket_failed:
{
g_dbus_method_invocation_return_dbus_error (invocation,
- "org.freedesktop.Headset.Error.Failed", "failed to create socket");
+ HSD_HEADSET_INTERFACE ".Error.Failed", "failed to create socket");
goto close_fd;
}
bind_failed:
{
g_dbus_method_invocation_return_dbus_error (invocation,
- "org.freedesktop.Headset.Error.Failed", "failed to bind socket");
+ HSD_HEADSET_INTERFACE ".Error.Failed", "failed to bind socket");
goto close_fd;
}
sockopt_failed:
{
g_dbus_method_invocation_return_dbus_error (invocation,
- "org.freedesktop.Headset.Error.Failed", "failed to setsockopt");
+ HSD_HEADSET_INTERFACE ".Error.Failed", "failed to setsockopt");
goto close_fd;
}
connect_failed:
{
g_dbus_method_invocation_return_dbus_error (invocation,
- "org.freedesktop.Headset.Error.Failed", "failed to connect");
+ HSD_HEADSET_INTERFACE ".Error.Failed", "failed to connect");
goto close_fd;
}
close_fd:
@@ -273,7 +298,7 @@ headset_disconnect (HsdHeadset *h,
not_owner:
{
g_dbus_method_invocation_return_dbus_error (invocation,
- "org.freedesktop.Headset.Error.NotAuthorized", "not the connection owner");
+ HSD_HEADSET_INTERFACE ".Error.NotAuthorized", "not the connection owner");
return;
}
}
@@ -293,20 +318,24 @@ headset_method_call (GDBusConnection *connection,
if (h->invocation)
goto busy;
- if (g_strcmp0 (method_name, "Connect") == 0) {
- headset_connect (h, connection, sender, parameters, invocation);
- } else if (g_strcmp0 (method_name, "Disconnect") == 0) {
- headset_disconnect (h, connection, sender, parameters, invocation);
+ if (g_strcmp0 (interface_name, HSD_HEADSET_INTERFACE) == 0) {
+ if (g_strcmp0 (method_name, "Connect") == 0) {
+ headset_connect (h, connection, sender, parameters, invocation);
+ } else if (g_strcmp0 (method_name, "Disconnect") == 0) {
+ headset_disconnect (h, connection, sender, parameters, invocation);
+ } else
+ g_dbus_method_invocation_return_dbus_error (invocation,
+ HSD_HEADSET_INTERFACE ".Error.NotImplemented", "no such method");
} else
g_dbus_method_invocation_return_dbus_error (invocation,
- "org.freedesktop.Headset.Error.NotImplemented", "no such method");
+ HSD_HEADSET_INTERFACE ".Error.NotImplemented", "no such method");
return;
busy:
{
g_dbus_method_invocation_return_dbus_error (invocation,
- "org.freedesktop.Headset.Error.Busy", "We have a pending operation");
+ HSD_HEADSET_INTERFACE ".Error.Busy", "We have a pending operation");
return;
}
}
diff --git a/src/hsd-headset.h b/src/hsd-headset.h
index b30c01b..cecc12d 100644
--- a/src/hsd-headset.h
+++ b/src/hsd-headset.h
@@ -17,6 +17,8 @@
* Boston, MA 02110-1301, USA.
*/
+#define HSD_HEADSET_INTERFACE "org.freedesktop.Headset"
+
typedef enum {
HSD_HEADSET_STATE_IDLE,
HSD_HEADSET_STATE_PENDING,
diff --git a/src/hsd-manager.c b/src/hsd-manager.c
index 7a10264..2ef38ca 100644
--- a/src/hsd-manager.c
+++ b/src/hsd-manager.c
@@ -28,7 +28,7 @@ static GDBusNodeInfo *introspection_data = NULL;
/* Introspection data for the service we are exporting */
static const gchar introspection_xml[] =
"<node>"
- " <interface name='org.freedesktop.HeadsetManager'>"
+ " <interface name='" HSD_MANAGER_INTERFACE "'>"
" <method name='GetDevices'>"
" <arg type='a(oa{sv})' name='devices' direction='out'/>"
" </method>"
@@ -66,9 +66,13 @@ manager_get_devices (HsdManager *m,
GVariant *parameters,
GDBusMethodInvocation *invocation)
{
+ GVariant *var;
+
g_debug ("manager GetDevices");
- g_dbus_method_invocation_return_dbus_error (invocation,
- "org.freedesktop.Headset.Error.NotImplemented", "no such method");
+
+ var = g_variant_new_array (G_VARIANT_TYPE ("(oa{sv})"), NULL, 0);
+ g_dbus_method_invocation_return_value (
+ invocation, g_variant_new_tuple (&var, 1));
}
static void
@@ -79,7 +83,7 @@ manager_register (HsdManager *m,
{
g_debug ("manager Register");
g_dbus_method_invocation_return_dbus_error (invocation,
- "org.freedesktop.Headset.Error.NotImplemented", "no such method");
+ HSD_MANAGER_INTERFACE ".Error.NotImplemented", "no such method");
}
static void
@@ -90,7 +94,7 @@ manager_unregister (HsdManager *m,
{
g_debug ("manager Unregister");
g_dbus_method_invocation_return_dbus_error (invocation,
- "org.freedesktop.Headset.Error.NotImplemented", "no such method");
+ HSD_MANAGER_INTERFACE ".Error.NotImplemented", "no such method");
}
static void
@@ -105,15 +109,19 @@ manager_method_call (GDBusConnection *connection,
{
HsdManager *m = user_data;
- if (g_strcmp0 (method_name, "GetDevices") == 0) {
- manager_get_devices (m, connection, parameters, invocation);
- } else if (g_strcmp0 (method_name, "Register") == 0) {
- manager_register (m, connection, parameters, invocation);
- } else if (g_strcmp0 (method_name, "Unregister") == 0) {
- manager_unregister (m, connection, parameters, invocation);
+ if (g_strcmp0 (interface_name, HSD_MANAGER_INTERFACE) == 0) {
+ if (g_strcmp0 (method_name, "GetDevices") == 0) {
+ manager_get_devices (m, connection, parameters, invocation);
+ } else if (g_strcmp0 (method_name, "Register") == 0) {
+ manager_register (m, connection, parameters, invocation);
+ } else if (g_strcmp0 (method_name, "Unregister") == 0) {
+ manager_unregister (m, connection, parameters, invocation);
+ } else
+ g_dbus_method_invocation_return_dbus_error (invocation,
+ HSD_MANAGER_INTERFACE ".Error.NotImplemented", "no such method");
} else
- g_dbus_method_invocation_return_dbus_error (invocation,
- "org.freedesktop.Headset.Error.NotImplemented", "no such method");
+ g_dbus_method_invocation_return_dbus_error (invocation,
+ HSD_SERVICE ".Error.NotImplemented", "no such interface");
}
static const GDBusInterfaceVTable manager_interface_vtable =
@@ -172,7 +180,7 @@ hsd_manager_add_headset (HsdManager *manager, HsdHeadset *headset, GError **erro
g_dbus_connection_emit_signal (conn,
NULL,
"/",
- HSD_MANAGER_INTERFACE_SERVICE,
+ HSD_MANAGER_INTERFACE,
"DeviceAdded",
g_variant_new ("(oa{sv})",
headset->device,
@@ -196,7 +204,7 @@ hsd_manager_remove_headset (HsdManager *manager, HsdHeadset *headset, GError **e
g_dbus_connection_emit_signal (conn,
NULL,
"/",
- HSD_MANAGER_INTERFACE_SERVICE,
+ HSD_MANAGER_INTERFACE,
"DeviceRemoved",
g_variant_new ("(o)",
headset->device),
diff --git a/src/hsd-manager.h b/src/hsd-manager.h
index f4f607c..058f171 100644
--- a/src/hsd-manager.h
+++ b/src/hsd-manager.h
@@ -17,7 +17,7 @@
* Boston, MA 02110-1301, USA.
*/
-#define HSD_MANAGER_INTERFACE_SERVICE HSD_SERVICE ".HeadsetManager"
+#define HSD_MANAGER_INTERFACE "org.freedesktop.HeadsetManager"
struct _HsdManager {
guint id;