Fix args in XML interface spec, add example code to handle Register()
authorJannis Pohlmann <jannis.pohlmann@codethink.co.uk>
Tue, 12 Jun 2012 08:36:41 +0000 (09:36 +0100)
committerJannis Pohlmann <jannis.pohlmann@codethink.co.uk>
Tue, 12 Jun 2012 08:36:41 +0000 (09:36 +0100)
The XML element name for D-Bus method parameters is "arg", not "param".

luc_handler_service_handle_register() now has a "GVariant *apps"
parameter and reads/prints the foreground apps that are passed to it.
This is just example code to demonstrate how this can be done. It
will later be replaced with the real implementation.

luc-handler/luc-handler-dbus.xml
luc-handler/luc-handler-service.c

index db05691..0578caa 100644 (file)
@@ -7,11 +7,11 @@
   <interface name="org.genivi.LUCHandler1">
     <method name="Register">
       <annotation name="org.freedesktop.DBus.GLib.Async" value="true"/>
-      <param name="apps" type="a{sas}" direction="in"/>
+      <arg name="apps" type="a{sas}" direction="in"/>
     </method>
     <method name="Deregister">
       <annotation name="org.freedesktop.DBus.GLib.Async" value="true"/>
-      <param name="apps" type="a{sas}" direction="in"/>
+      <arg name="apps" type="a{sas}" direction="in"/>
     </method>
     <property name="Content" type="a{sas}" access="read"/>
   </interface>
index 230ee83..61303ab 100644 (file)
@@ -39,9 +39,11 @@ static void     luc_handler_service_set_property      (GObject               *ob
                                                        GParamSpec            *pspec);
 static gboolean luc_handler_service_handle_register   (LUCHandler            *interface,
                                                        GDBusMethodInvocation *invocation,
+                                                       GVariant              *apps,
                                                        LUCHandlerService     *service);
 static gboolean luc_handler_service_handle_deregister (LUCHandler            *interface,
                                                        GDBusMethodInvocation *invocation,
+                                                       GVariant              *apps,
                                                        LUCHandlerService     *service);
 
 
@@ -170,17 +172,33 @@ static void luc_handler_service_set_property (GObject      *object,
 static gboolean
 luc_handler_service_handle_register (LUCHandler            *object,
                                      GDBusMethodInvocation *invocation,
+                                     GVariant              *apps,
                                      LUCHandlerService     *service)
 {
+  GVariant *foreground_apps;
+  gchar    *app_name;
+  guint     n;
+
   g_return_val_if_fail (IS_LUC_HANDLER (object), FALSE);
   g_return_val_if_fail (G_IS_DBUS_METHOD_INVOCATION (invocation), FALSE);
   g_return_val_if_fail (LUC_HANDLER_IS_SERVICE (service), FALSE);
 
-  g_debug ("Register called");
+  g_debug ("Register called:");
 
   /* TODO read the apps parameter and update the "content" property of
    * the skeleton */
 
+  foreground_apps = g_variant_lookup_value (apps, "foreground",
+                                            G_VARIANT_TYPE_STRING_ARRAY);
+  if (foreground_apps != NULL)
+    {
+      for (n = 0; n < g_variant_n_children (foreground_apps); n++)
+        {
+          g_variant_get_child (foreground_apps, n, "&s", &app_name);
+          g_debug ("  foreground: %s", app_name);
+        }
+    }
+
   g_dbus_method_invocation_return_value (invocation, NULL);
 
   return TRUE;
@@ -191,6 +209,7 @@ luc_handler_service_handle_register (LUCHandler            *object,
 static gboolean
 luc_handler_service_handle_deregister (LUCHandler            *object,
                                        GDBusMethodInvocation *invocation,
+                                       GVariant              *apps,
                                        LUCHandlerService     *service)
 {
   g_return_val_if_fail (IS_LUC_HANDLER (object), FALSE);