summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSam Spilsbury <sam.spilsbury@canonical.com>2011-06-19 00:19:49 +0800
committerSam Spilsbury <sam.spilsbury@canonical.com>2011-06-19 00:19:49 +0800
commitbf659aff8eebd94bd69849b8e87fbafad5677513 (patch)
treee751abca23b6ffa82aec58b14dc923d2759b5c90
parentfb2014fd063ccd73f492b2b378cbd6abfe3ec182 (diff)
downloadcompositionkit-bf659aff8eebd94bd69849b8e87fbafad5677513.tar.gz
compositionkit-bf659aff8eebd94bd69849b8e87fbafad5677513.tar.bz2
Port all functions to gdbus-codegen
-rw-r--r--CMakeLists.txt2
-rw-r--r--ckservice/ckservice-main.c904
-rw-r--r--ckservice/ckservice.xml71
3 files changed, 458 insertions, 519 deletions
diff --git a/CMakeLists.txt b/CMakeLists.txt
index 802bb77..943e12e 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -197,7 +197,7 @@ if (BUILD_COMPOSITIONKIT_SERVICE)
COMMENT "Generating GDBus Boilerplate")
add_executable (ckservice
- ckservice/ckservice-new-main.c
+ ckservice/ckservice-main.c
${CMAKE_BINARY_DIR}/generated/ckservice/compositionkit-service.c)
target_link_libraries (ckservice ${COMPOSITIONKIT_SERVICE_LIBRARIES})
diff --git a/ckservice/ckservice-main.c b/ckservice/ckservice-main.c
index b8ee105..298e26f 100644
--- a/ckservice/ckservice-main.c
+++ b/ckservice/ckservice-main.c
@@ -23,21 +23,24 @@
G_BEGIN_DECLS
-typedef struct _CompositionKitServicePrivate CompositionKitServicePrivate;
-typedef struct _CompositionKitSurface CompositionKitSurface;
-typedef struct _CompositionKitShader CompositionKitShader;
-typedef struct _CompositionKitUniform CompositionKitUniform;
-typedef struct _CompositionKitAttribute CompositionKitAttribute;
+typedef struct _CompositionKitServicePrivate CompositionKitServicePrivate;
+typedef struct _CompositionKitSurfacePrivate CompositionKitSurfacePrivate;
+typedef struct _CompositionKitShaderPrivate CompositionKitShaderPrivate;
+typedef struct _CompositionKitUniformPrivate CompositionKitUniformPrivate;
+typedef struct _CompositionKitAttributePrivate CompositionKitAttributePrivate;
struct _CompositionKitServicePrivate
{
- GList *surfaces;
+ CompositionKitObjectSkeleton *object;
+ GList *surfaces;
};
-struct _CompositionKitSurface
+struct _CompositionKitSurfacePrivate
{
- gint id;
- GList *shaders;
+ CompositionKitServicePrivate *service;
+ CompositionKitObjectSkeleton *object;
+ gint id;
+ GList *shaders;
};
typedef enum
@@ -46,33 +49,40 @@ typedef enum
SHADER_TYPE_VERTEX
} CKShaderType;
-struct _CompositionKitUniform
+struct _CompositionKitUniformPrivate
{
+ CompositionKitShaderPrivate *shader;
+ CompositionKitObjectSkeleton *object;
gchar *name;
gchar *type;
GVariant *data;
};
-struct _CompositionKitAttribute
+struct _CompositionKitAttributePrivate
{
+ CompositionKitShaderPrivate *shader;
+ CompositionKitObjectSkeleton *object;
gchar *name;
gchar *type;
GVariant *data;
};
-struct _CompositionKitShader
+struct _CompositionKitShaderPrivate
{
- gchar *name;
- CKShaderType type;
- gchar *source;
- GList *uniforms;
- GList *attributes;
+ CompositionKitSurfacePrivate *surface;
+ gchar *name;
+ CKShaderType type;
+ gchar *source;
+ GList *uniforms;
+ GList *attributes;
+ CompositionKitObjectSkeleton *object;
};
G_END_DECLS
#endif
+static GDBusObjectManagerServer *manager = NULL;
/* Methods */
@@ -80,59 +90,65 @@ static gint
find_surface_by_id (gconstpointer a,
gconstpointer b)
{
- CompositionKitSurface *cks = (CompositionKitSurface *) a;
+ CompositionKitSurfacePrivate *cksp = (CompositionKitSurfacePrivate *) a;
gint *req_id = (gint *) b;
- return cks->id == *req_id ? 0 : 1;
+ return cksp->id == *req_id ? 0 : 1;
}
static gint
find_attribute_by_name (gconstpointer a,
gconstpointer b)
{
- CompositionKitAttribute *cka = (CompositionKitAttribute *) a;
- gchar *req_name = (gchar *) b;
+ CompositionKitAttributePrivate *ckap = (CompositionKitAttributePrivate *) a;
+ gchar *req_name = (gchar *) b;
- return g_strcmp0 (cka->name, req_name);
+ return g_strcmp0 (ckap->name, req_name);
}
static gint
find_uniform_by_name (gconstpointer a,
gconstpointer b)
{
- CompositionKitUniform *cku = (CompositionKitUniform *) a;
- gchar *req_name = (gchar *) b;
+ CompositionKitUniformPrivate *ckup = (CompositionKitUniformPrivate *) a;
+ gchar *req_name = (gchar *) b;
- return g_strcmp0 (cku->name, req_name);
+ return g_strcmp0 (ckup->name, req_name);
}
static gint
find_shader_by_name (gconstpointer a,
gconstpointer b)
{
- CompositionKitShader *cks = (CompositionKitShader *) a;
+ CompositionKitShaderPrivate *cksp = (CompositionKitShaderPrivate *) a;
gchar *req_name = (gchar *) b;
- return g_strcmp0 (cks->name, req_name);
+ return g_strcmp0 (cksp->name, req_name);
}
static GVariant *
-list_shaders (CompositionKitSurface *surface)
+list_shaders (CompositionKitSurfacePrivate *priv)
{
- GList *list = surface->shaders;
- GVariantBuilder builder;
- g_variant_builder_init (&builder, G_VARIANT_TYPE ("(as)"));
- g_variant_builder_open (&builder, G_VARIANT_TYPE ("as"));
+ GList *list = priv->shaders;
+ GVariantBuilder *builder = g_variant_builder_new (G_VARIANT_TYPE ("as"));
GVariant *return_value;
+ if (!list)
+ {
+ g_variant_builder_unref (builder);
+ return NULL;
+ }
+
while (list)
{
- g_variant_builder_add (&builder, "s", ((CompositionKitShader *) list->data)->name);
+ g_variant_builder_add (builder, "s", ((CompositionKitShaderPrivate *) list->data)->name);
list = g_list_next (list);
}
- g_variant_builder_close (&builder);
- return g_variant_builder_end (&builder);
+ return_value = g_variant_new ("as", builder);
+ g_variant_builder_unref (builder);
+
+ return return_value;
}
static GVariant *
@@ -150,7 +166,7 @@ list_surfaces (CompositionKitServicePrivate *priv)
while (list)
{
- g_variant_builder_add (builder, "i", ((CompositionKitSurface *) list->data)->id);
+ g_variant_builder_add (builder, "i", ((CompositionKitSurfacePrivate *) list->data)->id);
list = g_list_next (list);
}
@@ -161,542 +177,423 @@ list_surfaces (CompositionKitServicePrivate *priv)
}
void
-delete_uniform (CompositionKitUniform *uniform)
+delete_uniform (CompositionKitUniformPrivate *priv)
{
- if (uniform->name)
- g_free (uniform->name);
+ gchar *s = g_strdup_printf ("/com/canonical/CompositionKit/Surface/%d/Shader/%s/Uniform/%s",
+ priv->shader->surface->id, priv->shader->name, priv->name);
+
+ if (priv->name)
+ g_free (priv->name);
- if (uniform->type)
- g_free (uniform->type);
+ if (priv->type)
+ g_free (priv->type);
- if (uniform->data)
- g_variant_unref (uniform->data);
+ if (priv->data)
+ g_variant_unref (priv->data);
- g_free (uniform);
+ g_dbus_object_manager_server_unexport (manager, s);
+
+ g_free (s);
+ g_free (priv);
}
void
-delete_attribute (CompositionKitAttribute *attribute)
+delete_attribute (CompositionKitAttributePrivate *priv)
{
- if (attribute->name)
- g_free (attribute->name);
+ gchar *s = g_strdup_printf ("/com/canonical/CompositionKit/Surface/%d/Shader/%s/Attribute/%s",
+ priv->shader->surface->id, priv->shader->name, priv->name);
+
+ if (priv->name)
+ g_free (priv->name);
+
+ if (priv->type)
+ g_free (priv->type);
- if (attribute->type)
- g_free (attribute->type);
+ if (priv->data)
+ g_variant_unref (priv->data);
- if (attribute->data)
- g_variant_unref (attribute->data);
+ g_dbus_object_manager_server_unexport (manager, s);
- g_free (attribute);
+ g_free (s);
+ g_free (priv);
}
void
-delete_shader (CompositionKitShader *shader)
+delete_shader (CompositionKitShaderPrivate *priv)
{
GList *iter;
+ gchar *s = g_strdup_printf ("/com/canonical/CompositionKit/Surface/%d/Shader/%s", priv->surface->id, priv->name);
- if (shader->name)
- g_free (shader->name);
+ if (priv->name)
+ g_free (priv->name);
- if (shader->source)
- g_free (shader->source);
+ if (priv->source)
+ g_free (priv->source);
- iter = shader->uniforms;
+ iter = priv->uniforms;
while (iter)
{
- CompositionKitUniform *uniform = (CompositionKitUniform *) iter;
+ CompositionKitUniformPrivate *uniform = (CompositionKitUniformPrivate *) iter;
delete_uniform (uniform);
iter = g_list_remove_link (iter, iter);
}
- iter = shader->attributes;
+ iter = priv->attributes;
while (iter)
{
- CompositionKitAttribute *attribute = (CompositionKitAttribute *) iter;
+ CompositionKitAttributePrivate *attribute = (CompositionKitAttributePrivate *) iter;
delete_attribute (attribute);
iter = g_list_remove_link (iter, iter);
}
- g_free (shader);
+ g_dbus_object_manager_server_unexport (manager, s);
+
+ g_free (s);
+ g_free (priv);
}
void
-delete_surface (CompositionKitSurface *surface)
+delete_surface (CompositionKitSurfacePrivate *priv)
{
- GList *iter = surface->shaders;
+ GList *iter = priv->shaders;
+ gchar *s = g_strdup_printf ("/com/canonical/CompositionKit/Surface/%d", priv->id);
+
while (iter)
{
- CompositionKitShader *shader = (CompositionKitShader *) iter;
- delete_shader (shader);
+ CompositionKitShaderPrivate *priv = (CompositionKitShaderPrivate *) iter;
+ delete_shader (priv);
iter = g_list_remove_link (iter, iter);
}
- g_free (surface);
+ g_dbus_object_manager_server_unexport (manager, s);
+
+ g_free (s);
+ g_free (priv);
}
-CompositionKitSurface *
-new_surface (gint id)
+CompositionKitSurfacePrivate *
+new_surface (gint id, CompositionKitObjectSkeleton *object, CompositionKitServicePrivate *service)
{
- CompositionKitSurface *cks = g_new0 (CompositionKitSurface, 1);
+ CompositionKitSurfacePrivate *cksp = g_new0 (CompositionKitSurfacePrivate, 1);
- cks->id = id;
- cks->shaders = NULL;
+ cksp->id = id;
+ cksp->shaders = NULL;
+ cksp->object = object;
+ cksp->service = service;
- return cks;
+ return cksp;
}
-CompositionKitShader *
-new_shader (const gchar *name, gint shader_type, gint parent_surface)
+CompositionKitShaderPrivate *
+new_shader (const gchar *name, gint shader_type, CompositionKitObjectSkeleton *object, CompositionKitSurfacePrivate *surface)
{
- CompositionKitShader *cks = g_new0 (CompositionKitShader, 1);
-
- cks->name = g_strdup (name);
- cks->type = shader_type;
- cks->source = NULL;
- cks->uniforms = NULL;
- cks->attributes = NULL;
+ CompositionKitShaderPrivate *cksp = g_new0 (CompositionKitShaderPrivate, 1);
+
+ cksp->name = g_strdup (name);
+ cksp->type = shader_type;
+ cksp->source = NULL;
+ cksp->uniforms = NULL;
+ cksp->attributes = NULL;
+ cksp->object = object;
+ cksp->surface = surface;
}
-CompositionKitUniform *
-new_uniform (const gchar *name, const gchar *type)
+CompositionKitUniformPrivate *
+new_uniform (const gchar *name, const gchar *type, CompositionKitObjectSkeleton *object, CompositionKitShaderPrivate *shader)
{
- CompositionKitUniform *cku = g_new0 (CompositionKitUniform, 1);
+ CompositionKitUniformPrivate *ckup = g_new0 (CompositionKitUniformPrivate, 1);
- cku->name = g_strdup (name);
- cku->type = g_strdup (type);
- cku->data = NULL;
+ ckup->name = g_strdup (name);
+ ckup->type = g_strdup (type);
+ ckup->object = object;
+ ckup->shader = shader;
+ ckup->data = NULL;
- return cku;
+ return ckup;
}
-CompositionKitAttribute *
-new_attribute (const gchar *name, const gchar *type)
+CompositionKitAttributePrivate *
+new_attribute (const gchar *name, const gchar *type, CompositionKitObjectSkeleton *object, CompositionKitShaderPrivate *shader)
{
- CompositionKitAttribute *cka = g_new0 (CompositionKitAttribute, 1);
+ CompositionKitAttributePrivate *ckap = g_new0 (CompositionKitAttributePrivate, 1);
- cka->name = g_strdup (name);
- cka->type = g_strdup (type);
- cka->data = NULL;
+ ckap->name = g_strdup (name);
+ ckap->type = g_strdup (type);
+ ckap->object = object;
+ ckap->shader = shader;
+ ckap->data = NULL;
- return cka;
+ return ckap;
}
-#if 0
-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)
-{
- CompositionKitService *service = COMPOSITIONKIT_SERVICE (user_data);
-
- if (g_strcmp0 (method_name, "ListSurfaces") == 0)
+
+static gboolean
+on_handle_add_uniform (CompositionKitShader *shader,
+ GDBusMethodInvocation *invocation,
+ gchar *uniform_name,
+ gchar *uniform_type,
+ gpointer *user_data)
+{
+ CompositionKitShaderPrivate *priv = (CompositionKitShaderPrivate *) user_data;
+
+ if (uniform_name && uniform_type)
{
- GVariant *surfaces = list_surfaces (service);
- if (surfaces)
- {
- g_dbus_method_invocation_return_value (invocation,
- surfaces);
- g_variant_unref (surfaces);
- }
- else
- g_dbus_method_invocation_return_error (invocation, G_DBUS_ERROR, G_DBUS_ERROR_FAILED, "No Surfaces");
+ /* create a new com.canonical.CompositionKit.Uniform object at
+ * /com/canonical/CompositionKit/Surface/N/Shader/sname/Uniform/name where N is 000..
+ * and sname is priv->name and name is uniform_name */
+
+ gchar *s = g_strdup_printf ("/com/canonical/CompositionKit/Surface/%d/Shader/%s/Uniform/%s",
+ priv->surface->id, priv->name, uniform_name);
+ g_debug ("path is %s\n", s);
+ CompositionKitObjectSkeleton *object = composition_kit_object_skeleton_new (s);
+ CompositionKitUniform *uniform = composition_kit_uniform_skeleton_new ();
+ CompositionKitUniformPrivate *upriv = new_uniform (uniform_name, uniform_type, object, priv);
+
+ priv->uniforms = g_list_append (priv->uniforms, (gpointer) upriv);
+
+ composition_kit_object_skeleton_set_uniform (object, uniform);
+ g_object_unref (uniform);
+
+ g_dbus_object_manager_server_export (manager, G_DBUS_OBJECT_SKELETON (object));
+ g_object_unref (object);
+
+ g_free (s);
+ s = NULL;
}
- else if (g_strcmp0 (method_name, "ListShaders") == 0)
+
+ composition_kit_shader_complete_add_uniform (shader, invocation);
+}
+
+static gboolean
+on_handle_add_attribute (CompositionKitShader *shader,
+ GDBusMethodInvocation *invocation,
+ gchar *attribute_name,
+ gchar *attribute_type,
+ gpointer *user_data)
+{
+ CompositionKitShaderPrivate *priv = (CompositionKitShaderPrivate *) user_data;
+
+ if (priv->type != SHADER_TYPE_VERTEX)
+ g_dbus_method_invocation_return_error (invocation, G_DBUS_ERROR,
+ G_DBUS_ERROR_FAILED,
+ "Attempted to add an attribute to a non-vertex shader. This is not allowed");
+ else if (attribute_name && attribute_type)
{
- guint32 id;
- GList *list = service->priv->surfaces;
-
- g_variant_get (parameters, "(i)", &id, NULL);
- list = g_list_find_custom (list, &id, find_surface_by_id);
-
- if (list)
- {
- GVariant *shaders = list_shaders ((CompositionKitSurface *) list->data);
- g_dbus_method_invocation_return_value (invocation,
- shaders);
- g_variant_unref (shaders);
- }
- else
- g_dbus_method_invocation_return_error (invocation, G_DBUS_ERROR, G_DBUS_ERROR_FAILED, "Surface 0x%x not found", id);
+ /* create a new com.canonical.CompositionKit.Uniform object at
+ * /com/canonical/CompositionKit/Surface/N/Shader/sname/Uniform/name where N is 000..
+ * and sname is priv->name and name is uniform_name */
+
+ gchar *s = g_strdup_printf ("/com/canonical/CompositionKit/Surface/%d/Shader/%s/Attribute/%s",
+ priv->surface->id, priv->name, attribute_name);
+ CompositionKitObjectSkeleton *object = composition_kit_object_skeleton_new (s);
+ CompositionKitAttribute *attribute = composition_kit_attribute_skeleton_new ();
+ CompositionKitAttributePrivate *apriv = new_attribute (attribute_name, attribute_type, object, priv);
+
+ priv->uniforms = g_list_append (priv->attributes, (gpointer) apriv);
+
+ composition_kit_object_skeleton_set_attribute (object, attribute);
+ g_object_unref (attribute);
+
+ g_dbus_object_manager_server_export (manager, G_DBUS_OBJECT_SKELETON (object));
+ g_object_unref (object);
+
+ g_free (s);
+ s = NULL;
+
+ composition_kit_shader_complete_add_attribute (shader, invocation);
}
- else if (g_strcmp0 (method_name, "AddSurface") == 0)
+}
+
+static gboolean
+on_handle_remove_attribute (CompositionKitShader *shader,
+ GDBusMethodInvocation *invocation,
+ gchar *attribute_name,
+ gpointer *user_data)
+{
+ CompositionKitShaderPrivate *priv = (CompositionKitShaderPrivate *) user_data;
+
+ GList *list;
+ list = g_list_find_custom (priv->attributes, attribute_name, find_attribute_by_name);
+
+ if (list)
{
- guint32 id;
-
- g_variant_get (parameters, "(i)", &id, NULL);
-
- if (id)
- {
- CompositionKitSurface *surf = new_surface (id);
- service->priv->surfaces = g_list_append (service->priv->surfaces, (gpointer) surf);
- g_dbus_method_invocation_return_value (invocation, NULL);
- }
- else
- {
- g_dbus_method_invocation_return_error (invocation, G_DBUS_ERROR, G_DBUS_ERROR_FAILED, "ID 0x%x not valid", id);
- }
+ CompositionKitAttributePrivate *apriv = (CompositionKitAttributePrivate *) list->data;
+
+ delete_attribute (apriv);
+ priv->attributes = g_list_remove_link (priv->attributes, list);
}
- else if (g_strcmp0 (method_name, "AddShader") == 0)
- {
- guint32 id;
- gchar *string;
- GList *list;
- g_variant_get (parameters, "(si)", &string, &id, NULL);
+ composition_kit_shader_complete_remove_attribute (shader, invocation);
+}
- list = g_list_find_custom (service->priv->surfaces, &id, find_surface_by_id);
+static gboolean
+on_handle_remove_uniform (CompositionKitShader *shader,
+ GDBusMethodInvocation *invocation,
+ gchar *uniform_name,
+ gpointer *user_data)
+{
+ CompositionKitShaderPrivate *priv = (CompositionKitShaderPrivate *) user_data;
- if (list)
- {
- CompositionKitSurface *surf = (CompositionKitSurface *) list->data;
- CompositionKitShader *shader = new_shader (string, SHADER_TYPE_FRAGMENT, surf->id);
+ GList *list;
+ list = g_list_find_custom (priv->uniforms, uniform_name, find_uniform_by_name);
- surf->shaders = g_list_append (surf->shaders, (gpointer) shader);
- g_dbus_method_invocation_return_value (invocation, NULL);
- }
- else
- {
- g_dbus_method_invocation_return_error (invocation, G_DBUS_ERROR, G_DBUS_ERROR_FAILED, "ID 0x%x not valid for shader %s", id, string);
- }
+ if (list)
+ {
+ CompositionKitUniformPrivate *upriv = (CompositionKitUniformPrivate *) list->data;
- if (string)
- g_free (string);
+ delete_uniform (upriv);
+ priv->uniforms = g_list_remove_link (priv->uniforms, list);
}
- else if (g_strcmp0 (method_name, "RemoveShader") == 0)
+
+ composition_kit_shader_complete_remove_uniform (shader, invocation);
+}
+
+static gboolean
+on_handle_set_shader_source (CompositionKitShader *shader,
+ GDBusMethodInvocation *invocation,
+ gchar *source,
+ gpointer *user_data)
+{
+ CompositionKitShaderPrivate *priv = (CompositionKitShaderPrivate *) user_data;
+
+ if (priv->source)
{
- guint32 id;
- gchar *string;
- GList *list;
-
- g_variant_get (parameters, "(si)", &string, &id, NULL);
-
- list = g_list_find_custom (service->priv->surfaces, &id, find_surface_by_id);
-
- if (list)
- {
- CompositionKitSurface *surface = (CompositionKitSurface *) list->data;
- GList *siter;
-
- siter = g_list_find_custom (surface->shaders, string, find_shader_by_name);
-
- if (siter)
- {
- CompositionKitShader *shader = (CompositionKitShader *) siter->data;
- delete_shader (shader);
- surface->shaders = g_list_remove_link (surface->shaders, siter);
- g_dbus_method_invocation_return_value (invocation, NULL);
- }
- else
- {
- g_dbus_method_invocation_return_error (invocation, G_DBUS_ERROR, G_DBUS_ERROR_FAILED, "No shader %s for id %i", string, id);
- }
- }
- {
- g_dbus_method_invocation_return_error (invocation, G_DBUS_ERROR, G_DBUS_ERROR_FAILED, "ID %i not valid for shader %s", id, string);
- }
-
- if (string)
- g_free (string);
+ g_free (priv->source);
+ priv->source = NULL;
}
- else if (g_strcmp0 (method_name, "SetShaderSource") == 0)
+
+ if (source)
{
- guint32 id;
- gchar *shader_name;
- gchar *shader_source;
- GList *list;
-
- g_variant_get (parameters, "(ssi)", &shader_source, &shader_name, &id, NULL);
-
- list = g_list_find_custom (service->priv->surfaces, &id, find_surface_by_id);
-
- if (list)
- {
- CompositionKitSurface *surface = (CompositionKitSurface *) list->data;
- GList *siter;
-
- siter = g_list_find_custom (surface->shaders, shader_name, find_shader_by_name);
-
- if (siter)
- {
- CompositionKitShader *shader = (CompositionKitShader *) siter->data;
- shader->source = g_strdup (shader_source);
- g_dbus_method_invocation_return_value (invocation, NULL);
- }
- else
- {
- g_dbus_method_invocation_return_error (invocation, G_DBUS_ERROR, G_DBUS_ERROR_FAILED, "No shader %s for id %i", shader_name, id);
- }
- }
- {
- g_dbus_method_invocation_return_error (invocation, G_DBUS_ERROR, G_DBUS_ERROR_FAILED, "ID %i not valid for shader %s", id, shader_name);
- }
-
- if (shader_name)
- g_free (shader_name);
-
- if (shader_source)
- g_free (shader_source);
+ priv->source = g_strdup (source);
}
- else if (g_strcmp0 (method_name, "GetShaderSource") == 0)
- {
- guint32 id;
- gchar *shader_name;
- GList *list;
- GVariant *reply;
-
- g_variant_get (parameters, "(si)", &shader_name, &id, NULL);
-
- list = g_list_find_custom (service->priv->surfaces, &id, find_surface_by_id);
-
- if (list)
- {
- CompositionKitSurface *surface = (CompositionKitSurface *) list->data;
- GList *siter;
-
- siter = g_list_find_custom (surface->shaders, shader_name, find_shader_by_name);
-
- if (siter)
- {
- CompositionKitShader *shader = (CompositionKitShader *) siter->data;
- reply = g_variant_new ("(s)", shader->source);
- g_dbus_method_invocation_return_value (invocation, reply);
- g_variant_unref (reply);
- }
- else
- {
- g_dbus_method_invocation_return_error (invocation, G_DBUS_ERROR, G_DBUS_ERROR_FAILED, "No shader %s for id %i\n", shader_name, id);
- }
- }
- {
- g_dbus_method_invocation_return_error (invocation, G_DBUS_ERROR, G_DBUS_ERROR_FAILED, "ID %i not valid for shader %s\n", id, shader_name);
- }
-
- if (shader_name)
- g_free (shader_name);
- }
- else if (g_strcmp0 (method_name, "AddUniform") == 0)
+ composition_kit_shader_complete_set_shader_source (shader, invocation);
+}
+
+static gboolean
+on_handle_get_shader_source (CompositionKitShader *shader,
+ GDBusMethodInvocation *invocation,
+ gpointer *user_data)
+{
+ CompositionKitShaderPrivate *priv = (CompositionKitShaderPrivate *) user_data;
+
+ if (priv->source)
{
- guint32 id;
- gchar *shader_name;
- gchar *uniform_name;
- gchar *uniform_type;
- GList *iter, *siter;
-
- g_variant_get (parameters, "(sssi)", &uniform_name, &uniform_type, &shader_name, &id);
-
- iter = g_list_find_custom (service->priv->surfaces, &id, find_surface_by_id);
-
- if (iter)
- {
- CompositionKitSurface *cks = (CompositionKitSurface *) iter->data;
-
- siter = g_list_find_custom (cks->shaders, shader_name, find_shader_by_name);
-
- if (siter)
- {
- CompositionKitShader *cksh = (CompositionKitShader *) siter->data;
- CompositionKitUniform *cku = new_uniform (uniform_name, uniform_type);
- cksh->uniforms = g_list_append (cksh->uniforms, cku);
- g_dbus_method_invocation_return_value (invocation, NULL);
- }
- else
- {
- g_dbus_method_invocation_return_error (invocation, G_DBUS_ERROR, G_DBUS_ERROR_FAILED, "No shader %s for id %i\n", shader_name, id);
- }
- }
- else
- {
- g_dbus_method_invocation_return_error (invocation, G_DBUS_ERROR, G_DBUS_ERROR_FAILED, "ID %i not valid\n", id);
- }
-
- if (uniform_name)
- g_free (uniform_name);
-
- if (uniform_type)
- g_free (uniform_type);
-
- if (shader_name)
- g_free (shader_name);
+ composition_kit_shader_complete_get_shader_source (shader, invocation, priv->source);
}
- else if (g_strcmp0 (method_name, "RemoveUniform") == 0)
+ else
{
- guint32 id;
- gchar *shader_name;
- gchar *uniform_name;
- GList *iter, *siter, *uiter;
-
- g_variant_get (parameters, "(ssi)", &uniform_name, &shader_name, &id);
-
- iter = g_list_find_custom (service->priv->surfaces, &id, find_surface_by_id);
-
- if (iter)
- {
- CompositionKitSurface *cks = (CompositionKitSurface *) iter->data;
-
- siter = g_list_find_custom (cks->shaders, shader_name, find_shader_by_name);
-
- if (siter)
- {
- CompositionKitShader *cksh = (CompositionKitShader *) siter->data;
-
- uiter = g_list_find_custom (cksh->uniforms, uniform_name, find_uniform_by_name);
-
- if (uiter)
- {
- CompositionKitUniform *cku = (CompositionKitUniform *) uiter->data;
- delete_uniform (cku);
- cksh->uniforms = g_list_remove_link (cksh->uniforms, uiter);
- g_dbus_method_invocation_return_value (invocation, NULL);
- }
- else
- {
- g_dbus_method_invocation_return_error (invocation, G_DBUS_ERROR, G_DBUS_ERROR_FAILED, "No uniform %s shader %s for id %i\n", uniform_name, shader_name, id);
- }
- }
- else
- {
- g_dbus_method_invocation_return_error (invocation, G_DBUS_ERROR, G_DBUS_ERROR_FAILED, "No shader %s for id %i\n", shader_name, id);
- }
- }
- else
- {
- g_dbus_method_invocation_return_error (invocation, G_DBUS_ERROR, G_DBUS_ERROR_FAILED, "ID %i not valid\n", id);
- }
-
- if (uniform_name)
- g_free (uniform_name);
-
- if (shader_name)
- g_free (shader_name);
+ g_dbus_method_invocation_return_error (invocation, G_DBUS_ERROR,
+ G_DBUS_ERROR_FAILED,
+ "Shader %s does not have a source\n", priv->name);
}
- else if (g_strcmp0 (method_name, "AddAttribute") == 0)
+}
+
+static gboolean
+on_handle_add_shader (CompositionKitSurface *surface,
+ GDBusMethodInvocation *invocation,
+ gchar *shader_name,
+ gpointer *user_data)
+{
+ CompositionKitSurfacePrivate *priv = (CompositionKitSurfacePrivate *) user_data;
+
+ if (shader_name)
{
- guint32 id;
- gchar *shader_name;
- gchar *attribute_name;
- gchar *attribute_type;
- GList *iter, *siter;
-
- g_variant_get (parameters, "(sssi)", &attribute_name, &attribute_type, &shader_name, &id);
-
- iter = g_list_find_custom (service->priv->surfaces, &id, find_surface_by_id);
-
- if (iter)
- {
- CompositionKitSurface *cks = (CompositionKitSurface *) iter->data;
-
- siter = g_list_find_custom (cks->shaders, shader_name, find_shader_by_name);
-
- if (siter)
- {
- CompositionKitShader *cksh = (CompositionKitShader *) siter->data;
- CompositionKitAttribute *cku = new_attribute (attribute_name, attribute_type);
- cksh->attributes = g_list_append (cksh->attributes, cku);
- g_dbus_method_invocation_return_value (invocation, NULL);
- }
- else
- {
- g_dbus_method_invocation_return_error (invocation, G_DBUS_ERROR, G_DBUS_ERROR_FAILED, "No shader %s for id %i\n", shader_name, id);
- }
- }
- else
- {
- g_dbus_method_invocation_return_error (invocation, G_DBUS_ERROR, G_DBUS_ERROR_FAILED, "ID %i not valid\n", id);
- }
-
- if (attribute_name)
- g_free (attribute_name);
-
- if (attribute_type)
- g_free (attribute_type);
-
- if (shader_name)
- g_free (shader_name);
+ /* create a new com.canonical.CompositionKit.Surface object at
+ * /com/canonical/CompositionKit/Surface/N/Shader/name where N is 000..
+ * and name is shader_name */
+
+ gchar *s = g_strdup_printf ("/com/canonical/CompositionKit/Surface/%d/Shader/%s", priv->id, shader_name);
+ CompositionKitObjectSkeleton *object = composition_kit_object_skeleton_new (s);
+ CompositionKitShader *shader = composition_kit_shader_skeleton_new ();
+ CompositionKitShaderPrivate *spriv = new_shader (shader_name, SHADER_TYPE_FRAGMENT, object, priv);
+
+ priv->shaders = g_list_append (priv->shaders, (gpointer) spriv);
+
+ composition_kit_object_skeleton_set_shader (object, shader);
+ g_object_unref (shader);
+
+ g_free (s);
+ s = NULL;
+
+ g_signal_connect (G_OBJECT (shader), "handle-add-uniform",
+ G_CALLBACK (on_handle_add_uniform),
+ (gpointer) spriv);
+
+ g_signal_connect (G_OBJECT (shader), "handle-remove-uniform",
+ G_CALLBACK (on_handle_remove_uniform),
+ (gpointer) spriv);
+
+ g_signal_connect (G_OBJECT (shader), "handle-add-attribute",
+ G_CALLBACK (on_handle_add_attribute),
+ (gpointer) spriv);
+
+ g_signal_connect (G_OBJECT (shader), "handle-remove-attribute",
+ G_CALLBACK (on_handle_remove_attribute),
+ (gpointer) spriv);
+
+ g_signal_connect (G_OBJECT (shader), "handle-set-shader-source",
+ G_CALLBACK (on_handle_set_shader_source),
+ (gpointer) spriv);
+
+ g_signal_connect (G_OBJECT (shader), "handle-get-shader-source",
+ G_CALLBACK (on_handle_get_shader_source),
+ (gpointer) spriv);
+
+
+ g_dbus_object_manager_server_export (manager, G_DBUS_OBJECT_SKELETON (object));
+ g_object_unref (object);
}
- else if (g_strcmp0 (method_name, "RemoveAttribute") == 0)
+
+ composition_kit_surface_complete_add_shader (surface, invocation);
+}
+
+static gboolean
+on_handle_list_shaders (CompositionKitSurface *surface,
+ GDBusMethodInvocation *invocation,
+ gpointer *user_data)
+{
+ CompositionKitSurfacePrivate *priv = (CompositionKitSurfacePrivate *) user_data;
+ GVariant *shaders = list_shaders (priv);
+ gsize ret_size;
+ const gchar **ret = g_variant_get_strv (shaders, &ret_size);
+
+
+ if (ret)
{
- guint32 id;
- gchar *shader_name;
- gchar *attribute_name;
- GList *iter, *siter, *aiter;
-
- g_variant_get (parameters, "(ssi)", &attribute_name, &attribute_name, &id);
-
- iter = g_list_find_custom (service->priv->surfaces, &id, find_surface_by_id);
-
- if (iter)
- {
- CompositionKitSurface *cks = (CompositionKitSurface *) iter->data;
-
- siter = g_list_find_custom (cks->shaders, shader_name, find_shader_by_name);
-
- if (siter)
- {
- CompositionKitShader *cksh = (CompositionKitShader *) siter->data;
-
- aiter = g_list_find_custom (cksh->attributes, attribute_name, find_attribute_by_name);
-
- if (aiter)
- {
- CompositionKitAttribute *cka = (CompositionKitAttribute *) aiter->data;
- delete_attribute (cka);
- cksh->attributes = g_list_remove_link (cksh->attributes, aiter);
- g_dbus_method_invocation_return_value (invocation, NULL);
- }
- else
- {
- g_dbus_method_invocation_return_error (invocation, G_DBUS_ERROR, G_DBUS_ERROR_FAILED, "No attribute %s shader %s for id %i\n", attribute_name, shader_name, id);
- }
- }
- else
- {
- g_dbus_method_invocation_return_error (invocation, G_DBUS_ERROR, G_DBUS_ERROR_FAILED, "No shader %s for id %i\n", shader_name, id);
- }
- }
- else
- {
- g_dbus_method_invocation_return_error (invocation, G_DBUS_ERROR, G_DBUS_ERROR_FAILED, "ID %i not valid\n", id);
- }
-
- if (attribute_name)
- g_free (attribute_name);
-
- if (shader_name)
- g_free (shader_name);
+ composition_kit_surface_complete_list_shaders (surface, invocation, ret);
}
- else if (g_strcmp0 (method_name, "RemoveSurface") == 0)
+ else
{
- guint32 id;
- GList *list;
-
- g_variant_get (parameters, "(i)", &id, NULL);
-
- list = g_list_find_custom (service->priv->surfaces, &id, find_surface_by_id);
-
- if (list)
- {
- CompositionKitSurface *surface = (CompositionKitSurface *) list->data;
- delete_surface (surface);
- service->priv->surfaces = g_list_remove_link (service->priv->surfaces, list);
- g_dbus_method_invocation_return_value (invocation, NULL);
- }
- else
- {
- g_dbus_method_invocation_return_error (invocation, G_DBUS_ERROR, G_DBUS_ERROR_FAILED, "ID %i not valid\n", id);
- }
- }
+ g_dbus_method_invocation_return_error (invocation, G_DBUS_ERROR,
+ G_DBUS_ERROR_FAILED,
+ "No shaders attached to surface %i\n", priv->id);
+ }
}
-#endif
-static GDBusObjectManagerServer *manager = NULL;
+static gboolean
+on_handle_remove_shader (CompositionKitSurface *surface,
+ GDBusMethodInvocation *invocation,
+ gchar *shader_name,
+ gpointer *user_data)
+{
+ CompositionKitSurfacePrivate *priv = (CompositionKitSurfacePrivate *) user_data;
+
+ GList *list;
+ list = g_list_find_custom (priv->shaders, shader_name, find_shader_by_name);
+
+ if (list)
+ {
+ CompositionKitShaderPrivate *spriv = (CompositionKitShaderPrivate *) list->data;
+
+ delete_shader (spriv);
+ priv->shaders = g_list_remove_link (priv->shaders, list);
+ }
+
+ composition_kit_surface_complete_remove_shader (surface, invocation);
+}
static gboolean
on_handle_add_surface (CompositionKitService *service,
@@ -708,8 +605,36 @@ on_handle_add_surface (CompositionKitService *service,
if (id)
{
- CompositionKitSurface *surf = new_surface (id);
- priv->surfaces = g_list_append (priv->surfaces, (gpointer) surf);
+ /* create a new com.canonical.CompositionKit.Surface object at
+ * /com/canonical/CompositionKit/Surface/N where N is 000.. */
+
+ gchar *s = g_strdup_printf ("/com/canonical/CompositionKit/Surface/%d", id);
+ CompositionKitObjectSkeleton *object = composition_kit_object_skeleton_new (s);
+ CompositionKitSurface *surface = composition_kit_surface_skeleton_new ();
+ CompositionKitSurfacePrivate *spriv = new_surface (id, object, priv);
+
+ priv->surfaces = g_list_append (priv->surfaces, (gpointer) spriv);
+
+ composition_kit_object_skeleton_set_surface (object, surface);
+ g_object_unref (surface);
+
+ g_free (s);
+ s = NULL;
+
+ g_signal_connect (G_OBJECT (surface), "handle-add-shader",
+ G_CALLBACK (on_handle_add_shader),
+ (gpointer) spriv);
+
+ g_signal_connect (G_OBJECT (surface), "handle-remove-shader",
+ G_CALLBACK (on_handle_remove_shader),
+ (gpointer) spriv);
+
+ g_signal_connect (G_OBJECT (surface), "handle-list-shaders",
+ G_CALLBACK (on_handle_list_shaders),
+ (gpointer) spriv);
+
+ g_dbus_object_manager_server_export (manager, G_DBUS_OBJECT_SKELETON (object));
+ g_object_unref (object);
}
composition_kit_service_complete_add_surface (service, invocation);
@@ -729,7 +654,11 @@ on_handle_list_surfaces (CompositionKitService *service,
composition_kit_service_complete_list_surfaces (service, invocation, surfaces);
}
else
- composition_kit_service_complete_list_surfaces (service, invocation, NULL);
+ {
+ g_dbus_method_invocation_return_error (invocation, G_DBUS_ERROR,
+ G_DBUS_ERROR_FAILED,
+ "No surfaces on server\n");
+ }
}
static gboolean
@@ -745,8 +674,9 @@ on_handle_remove_surface (CompositionKitService *service,
if (list)
{
- CompositionKitSurface *surface = (CompositionKitSurface *) list->data;
- delete_surface (surface);
+ CompositionKitSurfacePrivate *spriv = (CompositionKitSurfacePrivate *) list->data;
+
+ delete_surface (spriv);
priv->surfaces = g_list_remove_link (priv->surfaces, list);
}
diff --git a/ckservice/ckservice.xml b/ckservice/ckservice.xml
index f3d6fce..95aa931 100644
--- a/ckservice/ckservice.xml
+++ b/ckservice/ckservice.xml
@@ -5,66 +5,75 @@
<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>
+
+ </interface>
+ <interface name='com.canonical.CompositionKit.Surface'>
+
<method name='AddShader'>
<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'/>
+ </method>
+
+ <method name='ListShaders'>
+ <arg type='as' name='shaders' direction='out'/>
+ </method>
+
+ </interface>
+
+ <interface name='com.canonical.CompositionKit.Shader'>
+
<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='shader_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 name='SetShaderSource'>
+ <arg type='s' name='shader_source' direction='in'/>
</method>
- <method name='RemoveSurface'>
- <arg type='i' name='id' direction='in'/>
+ <method name='GetShaderSource'>
+ <arg type='s' name='shader_source' direction='out'/>
</method>
- <method name='ListSurfaces'>
- <arg type='ai' name='surfaces' direction='out'/>
+ </interface>
+
+ <interface name='com.canonical.CompositionKit.Uniform'>
+
+ <method name='SetData'>
+ <arg type='v' name='uniform_data' direction='in'/>
</method>
- <method name='ListShaders'>
- <arg type='i' name='id' direction='in'/>
- <arg type='as' name='shaders' direction='out'/>
+ </interface>
+
+ <interface name='com.canonical.CompositionKit.Attribute'>
+
+ <method name='SetData'>
+ <arg type='v' name='attribute_data' direction='in'/>
</method>
</interface>
+
</node>