summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSam Spilsbury <sam.spilsbury@canonical.com>2011-06-17 19:58:06 +0800
committerSam Spilsbury <sam.spilsbury@canonical.com>2011-06-17 19:58:06 +0800
commitfb2014fd063ccd73f492b2b378cbd6abfe3ec182 (patch)
tree90adf202adfff6c85fbe9b35e6ea896c98a81b07
parent8e2c48c5f45873ac250405da3f4478dd27780fe9 (diff)
downloadcompositionkit-fb2014fd063ccd73f492b2b378cbd6abfe3ec182.tar.gz
compositionkit-fb2014fd063ccd73f492b2b378cbd6abfe3ec182.tar.bz2
Switch to using gdbus-codegen
-rw-r--r--CMakeLists.txt20
-rw-r--r--ckservice/ckservice-main.c320
-rw-r--r--ckservice/ckservice.xml2
3 files changed, 121 insertions, 221 deletions
diff --git a/CMakeLists.txt b/CMakeLists.txt
index 86a0a89..802bb77 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -178,14 +178,28 @@ target_link_libraries (compositionkit ${COMPOSITIONKIT_LIBRARIES})
if (BUILD_COMPOSITIONKIT_SERVICE)
- pkg_check_modules (COMPOSITIONKIT_SERVICE gobject-2.0 gio-2.0 gtk+-2.0 gthread-2.0 x11)
+ pkg_check_modules (COMPOSITIONKIT_SERVICE glib-2.0 gobject-2.0 gio-2.0 gthread-2.0 x11)
if (COMPOSITIONKIT_SERVICE_FOUND)
- include_directories (${COMPOSITIONKIT_SERVICE_INCLUDE_DIRS})
+ include_directories (${CMAKE_BINARY_DIR}/generated/ckservice
+ ${COMPOSITIONKIT_SERVICE_INCLUDE_DIRS})
link_directories (${COMPOSITIONKIT_SERVICE_LIBRARY_DIRS})
+ file (MAKE_DIRECTORY ${CMAKE_BINARY_DIR}/generated/ckservice)
+ add_custom_command (OUTPUT ${CMAKE_BINARY_DIR}/generated/ckservice/compositionkit-service.c
+ COMMAND gdbus-codegen ARGS --c-namespace=CompositionKit
+ --interface-prefix=com.canonical.CompositionKit
+ ${CMAKE_SOURCE_DIR}/ckservice/ckservice.xml
+ --generate-c-code=compositionkit-service
+ --c-generate-object-manager
+ --generate-docbook=compositionkit-service
+ WORKING_DIRECTORY ${CMAKE_BINARY_DIR}/generated/ckservice
+ COMMENT "Generating GDBus Boilerplate")
+
add_executable (ckservice
- ckservice/ckservice-main.c)
+ ckservice/ckservice-new-main.c
+ ${CMAKE_BINARY_DIR}/generated/ckservice/compositionkit-service.c)
+
target_link_libraries (ckservice ${COMPOSITIONKIT_SERVICE_LIBRARIES})
else (COMPOSITIONKIT_SERVICE_FOUND)
diff --git a/ckservice/ckservice-main.c b/ckservice/ckservice-main.c
index f167aec..b8ee105 100644
--- a/ckservice/ckservice-main.c
+++ b/ckservice/ckservice-main.c
@@ -16,41 +16,22 @@
* Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/
-
-#include <glib.h>
-#include <gio/gio.h>
+#include "compositionkit-service.h"
#ifndef _COMPOSITIONKIT_SERVICE_H_
#define _COMPOSITIONKIT_SERVICE_H_
-#include <glib-object.h>
-
G_BEGIN_DECLS
-typedef struct _CompositionKitService CompositionKitService;
-typedef struct _CompositionKitServiceClass CompositionKitServiceClass;
typedef struct _CompositionKitServicePrivate CompositionKitServicePrivate;
typedef struct _CompositionKitSurface CompositionKitSurface;
typedef struct _CompositionKitShader CompositionKitShader;
typedef struct _CompositionKitUniform CompositionKitUniform;
typedef struct _CompositionKitAttribute CompositionKitAttribute;
-struct _CompositionKitService
-{
- GObject parent;
- CompositionKitServicePrivate *priv;
-};
-
-struct _CompositionKitServiceClass
-{
- GObjectClass parent_class;
-};
-
-static CompositionKitService *static_service = NULL;
-
struct _CompositionKitServicePrivate
{
- GList *surfaces;
+ GList *surfaces;
};
struct _CompositionKitSurface
@@ -88,51 +69,10 @@ struct _CompositionKitShader
GList *attributes;
};
-#define COMPOSITIONKIT_TYPE_SERVICE (compositionkit_service_get_type ())
-
-#define COMPOSITIONKIT_SERVICE(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj),\
- COMPOSITIONKIT_TYPE_SERVICE, CompositionKitService))
-
-#define COMPOSITIONKIT_SERVICE_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass),\
- COMPOSITIONKIT_TYPE_SERVICE, CompositionKitServiceClass))
-
-#define COMPOSITIONKIT_IS_SERVICE(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj),\
- COMPOSITIONKIT_TYPE_SERVICE))
-
-#define COMPOSITIONKIT_IS_SERVICE_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass),\
- COMPOSITIONKIT_TYPE_SERVICE))
-
-#define COMPOSITIONKIT_SERVICE_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj),\
- COMPOSITIONKIT_TYPE_SERVICE, CompositionKitServiceClass))
-
-G_DEFINE_TYPE (CompositionKitService, compositionkit_service, G_TYPE_OBJECT);
-
-#define GET_PRIVATE(o) \
- (G_TYPE_INSTANCE_GET_PRIVATE ((o), COMPOSITIONKIT_TYPE_SERVICE, CompositionKitServicePrivate))
-
G_END_DECLS
#endif
-/* Forwards */
-static void
-handle_method_call (GDBusConnection *connection,
- const gchar *sender,
- const gchar *object_path,
- const gchar *interface_name,
- const gchar *method_name,
- GVariant *parameters,
- GDBusMethodInvocation *invocation,
- gpointer user_data);
-
-
-static const GDBusInterfaceVTable interface_vtable =
-{
- handle_method_call,
- NULL,
- NULL
-};
-
/* Methods */
@@ -196,9 +136,9 @@ list_shaders (CompositionKitSurface *surface)
}
static GVariant *
-list_surfaces (CompositionKitService *service)
+list_surfaces (CompositionKitServicePrivate *priv)
{
- GList *list = service->priv->surfaces;
+ GList *list = priv->surfaces;
GVariantBuilder *builder = g_variant_builder_new (G_VARIANT_TYPE ("ai"));
GVariant *return_value;
@@ -214,7 +154,7 @@ list_surfaces (CompositionKitService *service)
list = g_list_next (list);
}
- return_value = g_variant_new ("(ai)", builder);
+ return_value = g_variant_new ("ai", builder);
g_variant_builder_unref (builder);
return return_value;
@@ -343,7 +283,7 @@ new_attribute (const gchar *name, const gchar *type)
return cka;
}
-
+#if 0
static void
handle_method_call (GDBusConnection *connection,
const gchar *sender,
@@ -754,199 +694,145 @@ handle_method_call (GDBusConnection *connection,
}
}
}
+#endif
-/*
- * GObject stuff
- */
+static GDBusObjectManagerServer *manager = NULL;
-static void
-compositionkit_service_class_dispose (GObject *object)
+static gboolean
+on_handle_add_surface (CompositionKitService *service,
+ GDBusMethodInvocation *invocation,
+ gint id,
+ gpointer *user_data)
{
- CompositionKitServicePrivate *priv = COMPOSITIONKIT_SERVICE (object)->priv;
- gint i;
- GList *iter;
+ CompositionKitServicePrivate *priv = (CompositionKitServicePrivate *) user_data;
- iter = priv->surfaces;
- while (iter)
- {
- CompositionKitSurface *surface = (CompositionKitSurface *) iter;
- GList *siter = surface->shaders;
-
- while (siter)
+ if (id)
{
- delete_shader ((CompositionKitShader *) siter->data);
- siter = surface->shaders = g_list_remove_link (siter, siter);
+ CompositionKitSurface *surf = new_surface (id);
+ priv->surfaces = g_list_append (priv->surfaces, (gpointer) surf);
}
- }
- G_OBJECT_CLASS (compositionkit_service_parent_class)->dispose (object);
+
+ composition_kit_service_complete_add_surface (service, invocation);
}
-void
-compositionkit_service_class_init (CompositionKitServiceClass *klass)
+static gboolean
+on_handle_list_surfaces (CompositionKitService *service,
+ GDBusMethodInvocation *invocation,
+ gpointer *user_data)
{
- GObjectClass *obj_class = G_OBJECT_CLASS (klass);
- obj_class->dispose = compositionkit_service_class_dispose;
+ CompositionKitServicePrivate *priv = (CompositionKitServicePrivate *) user_data;
- g_type_class_add_private (obj_class, sizeof (CompositionKitServicePrivate));
-}
+ GVariant *surfaces = list_surfaces (priv);
-void
-compositionkit_service_init (CompositionKitService *self)
-{
- CompositionKitServicePrivate *priv;
- priv = self->priv = GET_PRIVATE (self);
+ if (surfaces)
+ {
+ composition_kit_service_complete_list_surfaces (service, invocation, surfaces);
+ }
+ else
+ composition_kit_service_complete_list_surfaces (service, invocation, NULL);
}
-CompositionKitService *
-compositionkit_service_get_default ()
+static gboolean
+on_handle_remove_surface (CompositionKitService *service,
+ GDBusMethodInvocation *invocation,
+ gint id,
+ gpointer *user_data)
{
- if (static_service == NULL || !COMPOSITIONKIT_IS_SERVICE (static_service))
- static_service = g_object_new (COMPOSITIONKIT_TYPE_SERVICE, NULL);
+ CompositionKitServicePrivate *priv = (CompositionKitServicePrivate *) user_data;
- return static_service;
-}
+ GList *list;
+ list = g_list_find_custom (priv->surfaces, &id, find_surface_by_id);
-static GDBusNodeInfo *introspection_data = NULL;
-
-static const gchar introspection_xml[] =
- "<node>"
- " <interface name='com.canonical.CompositionKit.Service'>"
- ""
- " <method name='AddSurface'>"
- " <arg type='i' name='id' direction='in'/>"
- " </method>"
- ""
- " <method name='AddShader'>"
- " <arg type='s' name='shader_name' direction='in'/>"
- " <arg type='i' name='id' direction='in'/>"
- " </method>"
- ""
- " <method name='AddUniform'>"
- " <arg type='s' name='uniform_name' direction='in'/>"
- " <arg type='s' name='uniform_type' direction='in'/>"
- " <arg type='s' name='shader_name' direction='in'/>"
- " <arg type='i' name='id' direction='in'/>"
- " </method>"
- ""
- " <method name='AddAttribute'>"
- " <arg type='s' name='attribute_name' direction='in'/>"
- " <arg type='s' name='attribute_type' direction='in'/>"
- " <arg type='s' name='shader_name' direction='in'/>"
- " <arg type='i' name='id' direction='in'/>"
- " </method>"
- ""
- " <method name='SetShaderSource'>"
- " <arg type='s' name='shader_source' direction='in'/>"
- " <arg type='s' name='shader_name' direction='in'/>"
- " <arg type='i' name='id' direction='in'/>"
- " </method>"
- ""
- " <method name='GetShaderSource'>"
- " <arg type='s' name='shader_source' direction='out'/>"
- " <arg type='s' name='shader_name' direction='in'/>"
- " <arg type='i' name='id' direction='in'/>"
- " </method>"
- ""
- " <method name='RemoveAttribute'>"
- " <arg type='s' name='attribute_name' direction='in'/>"
- " <arg type='s' name='attribute_name' direction='in'/> "
- " <arg type='i' name='id' direction='in'/> "
- " </method>"
- ""
- " <method name='RemoveUniform'>"
- " <arg type='s' name='uniform_name' direction='in'/>"
- " <arg type='s' name='shader_name' direction='in'/> "
- " <arg type='i' name='id' direction='in'/> "
- " </method>"
- ""
- " <method name='RemoveShader'>"
- " <arg type='s' name='shader_name' direction='in'/> "
- " <arg type='i' name='id' direction='in'/> "
- " </method>"
- ""
- " <method name='RemoveSurface'>"
- " <arg type='i' name='id' direction='in'/> "
- " </method>"
- ""
- " <method name='ListSurfaces'>"
- " <arg type='ai' name='surfaces' direction='out'/>"
- " </method>"
- ""
- " <method name='ListShaders'>"
- " <arg type='i' name='id' direction='in'/>"
- " <arg type='as' name='shaders' direction='out'/>"
- " </method>"
- ""
- " </interface>"
- "</node>";
-
-#define S_NAME "com.canonical.CompositionKit.Service"
-#define S_PATH "/com/canonical/CompositionKit"
-#define S_IFACE "com.canonical.CompositionKit.Service"
+ if (list)
+ {
+ CompositionKitSurface *surface = (CompositionKitSurface *) list->data;
+ delete_surface (surface);
+ priv->surfaces = g_list_remove_link (priv->surfaces, list);
+ }
+
+ composition_kit_service_complete_remove_surface (service, invocation);
+}
static void
on_bus_acquired (GDBusConnection *connection,
- const gchar *name,
- gpointer user_data)
+ const gchar *name,
+ gpointer user_data)
{
- CompositionKitService *service = COMPOSITIONKIT_SERVICE (user_data);
- guint reg_id;
+ manager = g_dbus_object_manager_server_new ("/com/canonical/CompositionKit");
+
+ /* create a new com.canonical.CompositionKit.Service object at
+ * /com/canonical/CompositionKit/Server/N where N is 000.. */
+
+ gchar *s = g_strdup_printf ("/com/canonical/CompositionKit/Server/%03d", 1);
+ CompositionKitObjectSkeleton *object = composition_kit_object_skeleton_new (s);
+ CompositionKitService *service = composition_kit_service_skeleton_new ();
+ CompositionKitServicePrivate *priv = g_new0 (CompositionKitServicePrivate, 1);
+
+ composition_kit_object_skeleton_set_service (object, service);
+ g_object_unref (service);
+
+ g_free (s);
+ s = NULL;
- reg_id = g_dbus_connection_register_object (connection,
- S_PATH,
- introspection_data->interfaces[0],
- &interface_vtable,
- service,
- NULL,
- NULL);
+ g_signal_connect (G_OBJECT (service), "handle-add-surface",
+ G_CALLBACK (on_handle_add_surface),
+ (gpointer) priv);
- g_assert (reg_id > 0);
+ g_signal_connect (G_OBJECT (service), "handle-remove-surface",
+ G_CALLBACK (on_handle_remove_surface),
+ (gpointer) priv);
+
+ g_signal_connect (G_OBJECT (service), "handle-list-surfaces",
+ G_CALLBACK (on_handle_list_surfaces),
+ (gpointer) priv);
+
+ g_dbus_object_manager_server_export (manager, G_DBUS_OBJECT_SKELETON (object));
+ g_object_unref (object);
+
+ g_dbus_object_manager_server_set_connection (manager, connection);
}
static void
on_name_acquired (GDBusConnection *connection,
- const gchar *name,
- gpointer user_data)
+ const gchar *name,
+ gpointer user_data)
{
+ g_debug ("Acquired name %s\n", name);
}
static void
on_name_lost (GDBusConnection *connection,
- const gchar *name,
- gpointer user_data)
+ const gchar *name,
+ gpointer user_data)
{
- CompositionKitService *service = COMPOSITIONKIT_SERVICE (user_data);
-
- gtk_main_quit ();
+ g_debug ("Lost name %s\n", name);
}
gint
main (gint argc, gchar **argv)
{
- CompositionKitService *service;
- guint owner_id;
-
- gtk_init (&argc, &argv);
+ CompositionKitService *service;
+ GMainLoop *loop;
+ GError *error;
+ guint id;
- service = compositionkit_service_get_default ();
+ g_type_init ();
- introspection_data = g_dbus_node_info_new_for_xml (introspection_xml, NULL);
- g_assert (introspection_data != NULL);
+ loop = g_main_loop_new (NULL, FALSE);
- owner_id = g_bus_own_name (G_BUS_TYPE_SESSION,
- S_NAME,
- G_BUS_NAME_OWNER_FLAGS_NONE,
- on_bus_acquired,
- on_name_acquired,
- on_name_lost,
- service,
- NULL);
+ id = g_bus_own_name (G_BUS_TYPE_SESSION, "com.canonical.CompositionKit.ObjectManager",
+ G_BUS_NAME_OWNER_FLAGS_ALLOW_REPLACEMENT |
+ G_BUS_NAME_OWNER_FLAGS_REPLACE,
+ on_bus_acquired,
+ on_name_acquired,
+ on_name_lost,
+ loop,
+ NULL);
- gtk_main ();
+ g_main_loop_run (loop);
- g_bus_unown_name (owner_id);
- g_dbus_node_info_unref (introspection_data);
- g_object_unref (service);
+ g_bus_unown_name (id);
+ g_main_loop_unref (loop);
return 0;
}
diff --git a/ckservice/ckservice.xml b/ckservice/ckservice.xml
index 24719c1..f3d6fce 100644
--- a/ckservice/ckservice.xml
+++ b/ckservice/ckservice.xml
@@ -38,7 +38,7 @@
<method name='RemoveAttribute'>
<arg type='s' name='attribute_name' direction='in'/>
- <arg type='s' name='attribute_name' direction='in'/>
+ <arg type='s' name='shader_name' direction='in'/>
<arg type='i' name='id' direction='in'/>
</method>