[telepathy-gabble/master] Add a basic endpoint object
Sjoerd Simons
sjoerd.simons at collabora.co.uk
Tue Dec 29 05:34:44 PST 2009
---
src/Makefile.am | 2 +
src/call-stream-endpoint.c | 236 ++++++++++++++++++++++++++++++++++++++++++++
src/call-stream-endpoint.h | 77 ++++++++++++++
src/call-stream.c | 39 +++++++
4 files changed, 354 insertions(+), 0 deletions(-)
create mode 100644 src/call-stream-endpoint.c
create mode 100644 src/call-stream-endpoint.h
diff --git a/src/Makefile.am b/src/Makefile.am
index 6d6f73a..497c036 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -33,6 +33,8 @@ libgabble_convenience_la_SOURCES = \
call-channel.c \
call-stream.h \
call-stream.c \
+ call-stream-endpoint.h \
+ call-stream-endpoint.c \
capabilities.h \
capabilities.c \
caps-hash.h \
diff --git a/src/call-stream-endpoint.c b/src/call-stream-endpoint.c
new file mode 100644
index 0000000..47528dd
--- /dev/null
+++ b/src/call-stream-endpoint.c
@@ -0,0 +1,236 @@
+/*
+ * gabble-call-stream-endpoint.c - Source for GabbleCallStreamEndpoint
+ * Copyright (C) 2009 Collabora Ltd.
+ * @author Sjoerd Simons <sjoerd.simons at collabora.co.uk>
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+
+#include <stdio.h>
+#include <stdlib.h>
+
+
+#include <telepathy-glib/dbus.h>
+#include <telepathy-glib/dbus-properties-mixin.h>
+#include <telepathy-glib/svc-properties-interface.h>
+
+#include "call-stream-endpoint.h"
+#include <extensions/extensions.h>
+
+#define DEBUG_FLAG GABBLE_DEBUG_MEDIA
+#include "debug.h"
+
+static void call_stream_endpoint_iface_init (gpointer, gpointer);
+
+G_DEFINE_TYPE_WITH_CODE(GabbleCallStreamEndpoint,
+ gabble_call_stream_endpoint,
+ G_TYPE_OBJECT,
+ G_IMPLEMENT_INTERFACE (GABBLE_TYPE_SVC_CALL_STREAM_ENDPOINT,
+ call_stream_endpoint_iface_init);
+ G_IMPLEMENT_INTERFACE (TP_TYPE_SVC_DBUS_PROPERTIES,
+ tp_dbus_properties_mixin_iface_init);
+);
+
+/* properties */
+enum
+{
+ PROP_OBJECT_PATH = 1,
+ PROP_JINGLE_CONTENT,
+};
+
+struct _GabbleCallStreamEndpointPrivate
+{
+ gboolean dispose_has_run;
+
+ gchar *object_path;
+ GabbleJingleContent *content;
+};
+
+static void
+gabble_call_stream_endpoint_init (GabbleCallStreamEndpoint *self)
+{
+ GabbleCallStreamEndpointPrivate *priv = G_TYPE_INSTANCE_GET_PRIVATE (self,
+ GABBLE_TYPE_CALL_STREAM_ENDPOINT,
+ GabbleCallStreamEndpointPrivate);
+
+ self->priv = priv;
+}
+
+static void gabble_call_stream_endpoint_dispose (GObject *object);
+static void gabble_call_stream_endpoint_finalize (GObject *object);
+
+static void
+gabble_call_stream_endpoint_get_property (GObject *object,
+ guint property_id,
+ GValue *value,
+ GParamSpec *pspec)
+{
+ GabbleCallStreamEndpoint *endpoint = GABBLE_CALL_STREAM_ENDPOINT (object);
+ GabbleCallStreamEndpointPrivate *priv = endpoint->priv;
+
+ switch (property_id)
+ {
+ case PROP_OBJECT_PATH:
+ g_value_set_string (value, priv->object_path);
+ break;
+ case PROP_JINGLE_CONTENT:
+ g_value_set_object (value, priv->content);
+ break;
+ default:
+ G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
+ break;
+ }
+}
+
+static void
+gabble_call_stream_endpoint_set_property (GObject *object,
+ guint property_id,
+ const GValue *value,
+ GParamSpec *pspec)
+{
+ GabbleCallStreamEndpoint *endpoint = GABBLE_CALL_STREAM_ENDPOINT (object);
+ GabbleCallStreamEndpointPrivate *priv = endpoint->priv;
+
+ switch (property_id)
+ {
+ case PROP_OBJECT_PATH:
+ g_free (priv->object_path);
+ priv->object_path = g_value_dup_string (value);
+ break;
+ case PROP_JINGLE_CONTENT:
+ priv->content = g_value_dup_object (value);
+ break;
+ default:
+ G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
+ break;
+ }
+}
+
+static void
+gabble_call_stream_endpoint_constructed (GObject *obj)
+{
+ GabbleCallStreamEndpointPrivate *priv;
+ DBusGConnection *bus;
+
+ priv = GABBLE_CALL_STREAM_ENDPOINT (obj)->priv;
+
+ /* register object on the bus */
+ bus = tp_get_bus ();
+ DEBUG ("Registering %s", priv->object_path);
+ dbus_g_connection_register_g_object (bus, priv->object_path, obj);
+
+ if (G_OBJECT_CLASS (gabble_call_stream_endpoint_parent_class)->constructed
+ != NULL)
+ G_OBJECT_CLASS (gabble_call_stream_endpoint_parent_class)->constructed (
+ obj);
+}
+
+static void
+gabble_call_stream_endpoint_class_init (
+ GabbleCallStreamEndpointClass *gabble_call_stream_endpoint_class)
+{
+ GObjectClass *object_class =
+ G_OBJECT_CLASS (gabble_call_stream_endpoint_class);
+ GParamSpec *param_spec;
+
+ g_type_class_add_private (gabble_call_stream_endpoint_class,
+ sizeof (GabbleCallStreamEndpointPrivate));
+
+ object_class->dispose = gabble_call_stream_endpoint_dispose;
+ object_class->finalize = gabble_call_stream_endpoint_finalize;
+ object_class->constructed = gabble_call_stream_endpoint_constructed;
+
+ object_class->set_property = gabble_call_stream_endpoint_set_property;
+ object_class->get_property = gabble_call_stream_endpoint_get_property;
+
+ param_spec = g_param_spec_string ("object-path", "D-Bus object path",
+ "The D-Bus object path used for this "
+ "object on the bus.",
+ NULL,
+ G_PARAM_CONSTRUCT_ONLY |
+ G_PARAM_READWRITE |
+ G_PARAM_STATIC_NAME |
+ G_PARAM_STATIC_BLURB);
+ g_object_class_install_property (object_class, PROP_OBJECT_PATH, param_spec);
+
+ param_spec = g_param_spec_object ("jingle-content", "Jingle Content",
+ "The Jingle Content related to this content object",
+ GABBLE_TYPE_JINGLE_CONTENT,
+ G_PARAM_CONSTRUCT_ONLY |
+ G_PARAM_READWRITE |
+ G_PARAM_STATIC_NAME |
+ G_PARAM_STATIC_BLURB);
+ g_object_class_install_property (object_class, PROP_JINGLE_CONTENT,
+ param_spec);
+}
+
+void
+gabble_call_stream_endpoint_dispose (GObject *object)
+{
+ GabbleCallStreamEndpoint *self = GABBLE_CALL_STREAM_ENDPOINT (object);
+ GabbleCallStreamEndpointPrivate *priv = self->priv;
+
+ if (priv->dispose_has_run)
+ return;
+
+ priv->dispose_has_run = TRUE;
+
+ if (priv->content != NULL)
+ g_object_unref (priv->content);
+
+ priv->content = NULL;
+
+ /* release any references held by the object here */
+
+ if (G_OBJECT_CLASS (gabble_call_stream_endpoint_parent_class)->dispose)
+ G_OBJECT_CLASS (gabble_call_stream_endpoint_parent_class)->dispose (
+ object);
+}
+
+void
+gabble_call_stream_endpoint_finalize (GObject *object)
+{
+ GabbleCallStreamEndpoint *self = GABBLE_CALL_STREAM_ENDPOINT (object);
+ GabbleCallStreamEndpointPrivate *priv = self->priv;
+
+ /* free any data held directly by the object here */
+ g_free (priv->object_path);
+
+ G_OBJECT_CLASS (gabble_call_stream_endpoint_parent_class)->finalize (object);
+}
+
+
+static void
+call_stream_endpoint_iface_init (gpointer iface, gpointer data)
+{
+}
+
+GabbleCallStreamEndpoint *
+gabble_call_stream_endpoint_new (const gchar *object_path,
+ GabbleJingleContent *content)
+{
+ return g_object_new (GABBLE_TYPE_CALL_STREAM_ENDPOINT,
+ "object-path", object_path,
+ "jingle-content", content,
+ NULL);
+}
+
+const gchar *
+gabble_call_stream_endpoint_get_object_path (
+ GabbleCallStreamEndpoint *endpoint)
+{
+ return endpoint->priv->object_path;
+}
diff --git a/src/call-stream-endpoint.h b/src/call-stream-endpoint.h
new file mode 100644
index 0000000..16d10a3
--- /dev/null
+++ b/src/call-stream-endpoint.h
@@ -0,0 +1,77 @@
+/*
+ * gabble-call-stream-endpoint.h - Header for GabbleCallStreamEndpoint
+ * Copyright (C) 2009 Collabora Ltd.
+ * @author Sjoerd Simons <sjoerd.simons at collabora.co.uk>
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+#ifndef __GABBLE_CALL_STREAM_ENDPOINT_H__
+#define __GABBLE_CALL_STREAM_ENDPOINT_H__
+
+#include <glib-object.h>
+#include <gio/gio.h>
+
+#include <telepathy-glib/dbus-properties-mixin.h>
+#include "jingle-content.h"
+
+G_BEGIN_DECLS
+
+typedef struct _GabbleCallStreamEndpoint GabbleCallStreamEndpoint;
+typedef struct _GabbleCallStreamEndpointPrivate
+ GabbleCallStreamEndpointPrivate;
+typedef struct _GabbleCallStreamEndpointClass GabbleCallStreamEndpointClass;
+
+struct _GabbleCallStreamEndpointClass {
+ GObjectClass parent_class;
+
+ TpDBusPropertiesMixinClass dbus_props_class;
+};
+
+struct _GabbleCallStreamEndpoint {
+ GObject parent;
+
+ GabbleCallStreamEndpointPrivate *priv;
+};
+
+GType gabble_call_stream_endpoint_get_type (void);
+
+/* TYPE MACROS */
+#define GABBLE_TYPE_CALL_STREAM_ENDPOINT \
+ (gabble_call_stream_endpoint_get_type ())
+#define GABBLE_CALL_STREAM_ENDPOINT(obj) \
+ (G_TYPE_CHECK_INSTANCE_CAST((obj), \
+ GABBLE_TYPE_CALL_STREAM_ENDPOINT, GabbleCallStreamEndpoint))
+#define GABBLE_CALL_STREAM_ENDPOINT_CLASS(klass) \
+ (G_TYPE_CHECK_CLASS_CAST((klass), \
+ GABBLE_TYPE_CALL_STREAM_ENDPOINT, GabbleCallStreamEndpointClass))
+#define GABBLE_IS_CALL_STREAM_ENDPOINT(obj) \
+ (G_TYPE_CHECK_INSTANCE_TYPE((obj), GABBLE_TYPE_CALL_STREAM_ENDPOINT))
+#define GABBLE_IS_CALL_STREAM_ENDPOINT_CLASS(klass) \
+ (G_TYPE_CHECK_CLASS_TYPE((klass), GABBLE_TYPE_CALL_STREAM_ENDPOINT))
+#define GABBLE_CALL_STREAM_ENDPOINT_GET_CLASS(obj) \
+ (G_TYPE_INSTANCE_GET_CLASS ((obj), \
+ GABBLE_TYPE_CALL_STREAM_ENDPOINT, GabbleCallStreamEndpointClass))
+
+GabbleCallStreamEndpoint *
+gabble_call_stream_endpoint_new (const gchar *object_path,
+ GabbleJingleContent *content);
+
+const gchar *gabble_call_stream_endpoint_get_object_path (
+ GabbleCallStreamEndpoint *endpoint);
+
+G_END_DECLS
+
+#endif /* #ifndef __GABBLE_CALL_STREAM_ENDPOINT_H__*/
diff --git a/src/call-stream.c b/src/call-stream.c
index ff33bdf..5fe28e0 100644
--- a/src/call-stream.c
+++ b/src/call-stream.c
@@ -25,9 +25,11 @@
#include <telepathy-glib/dbus.h>
#include <telepathy-glib/svc-properties-interface.h>
#include <telepathy-glib/base-connection.h>
+#include <telepathy-glib/gtypes.h>
#include <extensions/extensions.h>
#include "call-stream.h"
+#include "call-stream-endpoint.h"
#include "jingle-content.h"
#include "util.h"
@@ -54,6 +56,8 @@ enum
PROP_OBJECT_PATH = 1,
PROP_JINGLE_CONTENT,
PROP_LOCAL_CANDIDATES,
+
+ PROP_ENDPOINTS
};
#if 0
@@ -74,6 +78,7 @@ struct _GabbleCallStreamPrivate
gchar *object_path;
GabbleJingleContent *content;
+ GList *endpoints;
};
static void
@@ -143,6 +148,24 @@ gabble_call_stream_get_property (GObject *object,
g_value_set_boxed (value, arr);
break;
}
+
+ case PROP_ENDPOINTS:
+ {
+ GPtrArray *arr = g_ptr_array_sized_new (1);
+ GList *l;
+
+ for (l = priv->endpoints; l != NULL; l = g_list_next (l))
+ {
+ GabbleCallStreamEndpoint *e =
+ GABBLE_CALL_STREAM_ENDPOINT (l->data);
+ g_ptr_array_add (arr,
+ (gpointer) gabble_call_stream_endpoint_get_object_path (e));
+ }
+
+ g_value_set_boxed (value, arr);
+ g_ptr_array_free (arr, TRUE);
+ break;
+ }
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
break;
@@ -178,6 +201,8 @@ gabble_call_stream_constructed (GObject *obj)
{
GabbleCallStreamPrivate *priv;
DBusGConnection *bus;
+ GabbleCallStreamEndpoint *endpoint;
+ gchar *path;
priv = GABBLE_CALL_STREAM (obj)->priv;
@@ -186,6 +211,12 @@ gabble_call_stream_constructed (GObject *obj)
DEBUG ("Registering %s", priv->object_path);
dbus_g_connection_register_g_object (bus, priv->object_path, obj);
+ /* Currently we'll only have one endpoint we know right away */
+ path = g_strdup_printf ("%s/Endpoint", priv->object_path);
+ endpoint = gabble_call_stream_endpoint_new (path, priv->content);
+ priv->endpoints = g_list_append (priv->endpoints, endpoint);
+ g_free (path);
+
if (G_OBJECT_CLASS (gabble_call_stream_parent_class)->constructed != NULL)
G_OBJECT_CLASS (gabble_call_stream_parent_class)->constructed (obj);
}
@@ -200,6 +231,7 @@ gabble_call_stream_class_init (GabbleCallStreamClass *gabble_call_stream_class)
};
static TpDBusPropertiesMixinPropImpl stream_media_props[] = {
{ "LocalCandidates", "local-candidates", NULL },
+ { "Endpoints", "endpoints", NULL },
{ NULL }
};
static TpDBusPropertiesMixinIfaceImpl prop_interfaces[] = {
@@ -253,6 +285,13 @@ gabble_call_stream_class_init (GabbleCallStreamClass *gabble_call_stream_class)
g_object_class_install_property (object_class, PROP_LOCAL_CANDIDATES,
param_spec);
+ param_spec = g_param_spec_boxed ("endpoints", "Endpoints",
+ "The endpoints of this content",
+ TP_ARRAY_TYPE_OBJECT_PATH_LIST,
+ G_PARAM_READABLE | G_PARAM_STATIC_STRINGS);
+ g_object_class_install_property (object_class, PROP_ENDPOINTS,
+ param_spec);
+
gabble_call_stream_class->dbus_props_class.interfaces = prop_interfaces;
tp_dbus_properties_mixin_class_init (object_class,
G_STRUCT_OFFSET (GabbleCallStreamClass, dbus_props_class));
--
1.5.6.5
More information about the telepathy-commits
mailing list