Use new ::g-properties-changed-emitted signal in gdbus-codegen(1)
authorDavid Zeuthen <davidz@redhat.com>
Thu, 26 Aug 2010 19:09:11 +0000 (15:09 -0400)
committerDavid Zeuthen <davidz@redhat.com>
Thu, 26 Aug 2010 19:15:29 +0000 (15:15 -0400)
This allows us to also emit changes on the manager object.

Signed-off-by: David Zeuthen <davidz@redhat.com>
data/org.freedesktop.UDisks.xml
src/linuxdaemon.c

index 6b72892..5f1e0e3 100644 (file)
         <doc:doc><doc:summary>Object path of device that was added.</doc:summary></doc:doc>
       </arg>
 
+      <arg name="properties" type="a{sa{sv}}">
+        <doc:doc><doc:summary>Properties for the interfaces for the device that was added.</doc:summary></doc:doc>
+      </arg>
+
       <doc:doc>
         <doc:description>
           <doc:para>
         <doc:doc><doc:summary>Object path of device that was changed.</doc:summary></doc:doc>
       </arg>
 
+      <arg name="changed_properties" type="a{sa{sv}}">
+        <doc:doc><doc:summary>The properties that changed.</doc:summary></doc:doc>
+      </arg>
+
       <doc:doc>
         <doc:description>
           <doc:para>
index 7c720ee..ffa4db8 100644 (file)
@@ -231,7 +231,15 @@ static void
 emit_added (LinuxDaemon  *daemon,
             LinuxDevice  *device)
 {
-  daemon_emit_device_added (DAEMON (daemon), linux_device_get_object_path (device));
+  GVariantBuilder builder;
+  g_variant_builder_init (&builder, G_VARIANT_TYPE ("a{sa{sv}}"));
+  g_variant_builder_add (&builder,
+                         "{s@a{sv}}",
+                         device_interface_info ()->name,
+                         device_properties (DEVICE (device)));
+  daemon_emit_device_added (DAEMON (daemon),
+                            linux_device_get_object_path (device),
+                            g_variant_builder_end (&builder));
 }
 
 static void
@@ -241,6 +249,25 @@ emit_removed (LinuxDaemon  *daemon,
   daemon_emit_device_removed (DAEMON (daemon), linux_device_get_object_path (device));
 }
 
+static gboolean
+on_properties_changed_emitted (LinuxDevice         *exported_object,
+                               GVariant            *changed_properties,
+                               const gchar* const  *invalidated_properties,
+                               gpointer             user_data)
+{
+  LinuxDaemon *daemon = LINUX_DAEMON (user_data);
+  GVariantBuilder builder;
+  g_variant_builder_init (&builder, G_VARIANT_TYPE ("a{sa{sv}}"));
+  g_variant_builder_add (&builder,
+                         "{s@a{sv}}",
+                         device_interface_info ()->name,
+                         changed_properties);
+  daemon_emit_device_changed (DAEMON (daemon),
+                              linux_device_get_object_path (LINUX_DEVICE (exported_object)),
+                              g_variant_builder_end (&builder));
+  return FALSE; /* don't consume the signal */
+}
+
 static void
 handle_device_uevent (LinuxDaemon  *daemon,
                       const gchar  *action,
@@ -258,6 +285,10 @@ handle_device_uevent (LinuxDaemon  *daemon,
           if (maybe_export_unexport_object (daemon, device, FALSE))
             emit_removed (daemon, device);
 
+          g_warn_if_fail (g_signal_handlers_disconnect_by_func (device,
+                                                                G_CALLBACK (on_properties_changed_emitted),
+                                                                daemon) == 1);
+
           g_hash_table_remove (daemon->priv->map_sysfs_path_to_object, sysfs_path);
           g_print ("removed object with sysfs path `%s'\n", sysfs_path);
         }
@@ -290,6 +321,11 @@ handle_device_uevent (LinuxDaemon  *daemon,
           object_path = linux_device_get_object_path (device);
           visible = linux_device_get_visible (device);
 
+          g_signal_connect (device,
+                            "g-properties-changed-emitted",
+                            G_CALLBACK (on_properties_changed_emitted),
+                            daemon);
+
           g_hash_table_insert (daemon->priv->map_sysfs_path_to_object,
                                g_strdup (sysfs_path),
                                device);