[Telepathy-commits] [telepathy-glib/master] add lib/params-cm.[ch]

Guillaume Desmottes guillaume.desmottes at collabora.co.uk
Thu Mar 26 05:07:05 PDT 2009


Start of a fake CM used to test CM parameter
---
 tests/lib/Makefile.am |    2 +
 tests/lib/params-cm.c |  118 +++++++++++++++++++++++++++++++++++++++++++++++++
 tests/lib/params-cm.h |   82 ++++++++++++++++++++++++++++++++++
 3 files changed, 202 insertions(+), 0 deletions(-)
 create mode 100644 tests/lib/params-cm.c
 create mode 100644 tests/lib/params-cm.h

diff --git a/tests/lib/Makefile.am b/tests/lib/Makefile.am
index 857a17e..064dcfc 100644
--- a/tests/lib/Makefile.am
+++ b/tests/lib/Makefile.am
@@ -9,6 +9,8 @@ libtp_glib_tests_la_SOURCES = \
     contacts-conn.h \
     debug.h \
     myassert.h \
+    params-cm.h \
+    params-cm.c \
     simple-conn.c \
     simple-conn.h \
     simple-manager.c \
diff --git a/tests/lib/params-cm.c b/tests/lib/params-cm.c
new file mode 100644
index 0000000..97cb74f
--- /dev/null
+++ b/tests/lib/params-cm.c
@@ -0,0 +1,118 @@
+/*
+ * params-cm.h - source for ParamConnectionManager
+ *
+ * Copyright © 2007-2009 Collabora Ltd. <http://www.collabora.co.uk/>
+ * Copyright © 2007-2009 Nokia Corporation
+ *
+ * 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 "params-cm.h"
+
+#include <dbus/dbus-glib.h>
+
+#include <telepathy-glib/dbus.h>
+#include <telepathy-glib/errors.h>
+
+G_DEFINE_TYPE (ParamConnectionManager,
+    param_connection_manager,
+    TP_TYPE_BASE_CONNECTION_MANAGER)
+
+struct _ParamConnectionManagerPrivate
+{
+  int dummy;
+};
+
+static void
+param_connection_manager_init (
+    ParamConnectionManager *self)
+{
+  self->priv = G_TYPE_INSTANCE_GET_PRIVATE (self,
+      TYPE_PARAM_CONNECTION_MANAGER,
+      ParamConnectionManagerPrivate);
+}
+
+static const TpCMParamSpec param_example_params[] = {
+  { "a-string", "s", G_TYPE_STRING, 0, NULL,
+    G_STRUCT_OFFSET (CMParams, a_string), NULL, NULL, NULL },
+  { "a-int16", "n", G_TYPE_INT, 0, NULL,
+    G_STRUCT_OFFSET (CMParams, a_int16), NULL, NULL, NULL },
+  { "a-int32", "i", G_TYPE_INT, 0, NULL,
+    G_STRUCT_OFFSET (CMParams, a_int32), NULL, NULL, NULL },
+  { NULL }
+};
+
+static CMParams *params = NULL;
+
+static gpointer
+alloc_params (void)
+{
+  params = g_slice_new0 (CMParams);
+
+  return params;
+}
+
+static void
+free_params (gpointer p)
+{
+  /* CM user is responsible to free params so he can check their values */
+}
+
+static const TpCMProtocolSpec example_protocols[] = {
+  { "example", param_example_params,
+    alloc_params, free_params },
+  { NULL, NULL }
+};
+
+static TpBaseConnection *
+new_connection (TpBaseConnectionManager *self,
+                const gchar *proto,
+                TpIntSet *params_present,
+                gpointer parsed_params,
+                GError **error)
+{
+  g_set_error (error, TP_ERRORS, TP_ERROR_NOT_IMPLEMENTED,
+      "No connection for you");
+  return NULL;
+}
+
+static void
+param_connection_manager_class_init (
+    ParamConnectionManagerClass *klass)
+{
+  TpBaseConnectionManagerClass *base_class =
+      (TpBaseConnectionManagerClass *) klass;
+
+  g_type_class_add_private (klass,
+      sizeof (ParamConnectionManagerPrivate));
+
+  base_class->new_connection = new_connection;
+  base_class->cm_dbus_name = "params_cm";
+  base_class->protocol_params = example_protocols;
+}
+
+CMParams *
+param_connection_manager_get_params_last_conn (void)
+{
+  return params;
+}
+
+void
+free_cm_params (CMParams *p)
+{
+  g_free (p->a_string);
+
+  g_slice_free (CMParams, p);
+}
diff --git a/tests/lib/params-cm.h b/tests/lib/params-cm.h
new file mode 100644
index 0000000..56dc5c3
--- /dev/null
+++ b/tests/lib/params-cm.h
@@ -0,0 +1,82 @@
+/*
+ * params-cm.h - header for ParamConnectionManager
+ *
+ * Copyright © 2007-2009 Collabora Ltd. <http://www.collabora.co.uk/>
+ * Copyright © 2007-2009 Nokia Corporation
+ *
+ * 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 __PARAM_CONNECTION_MANAGER_H__
+#define __PARAM_CONNECTION_MANAGER_H__
+
+#include <glib-object.h>
+#include <telepathy-glib/base-connection-manager.h>
+
+G_BEGIN_DECLS
+
+typedef struct _ParamConnectionManager
+    ParamConnectionManager;
+typedef struct _ParamConnectionManagerPrivate
+    ParamConnectionManagerPrivate;
+
+typedef struct _ParamConnectionManagerClass
+    ParamConnectionManagerClass;
+typedef struct _ParamConnectionManagerClassPrivate
+    ParamConnectionManagerClassPrivate;
+
+struct _ParamConnectionManagerClass {
+    TpBaseConnectionManagerClass parent_class;
+
+    ParamConnectionManagerClassPrivate *priv;
+};
+
+struct _ParamConnectionManager {
+    TpBaseConnectionManager parent;
+
+    ParamConnectionManagerPrivate *priv;
+};
+
+GType param_connection_manager_get_type (void);
+
+/* TYPE MACROS */
+#define TYPE_PARAM_CONNECTION_MANAGER \
+  (param_connection_manager_get_type ())
+#define PARAM_CONNECTION_MANAGER(obj) \
+  (G_TYPE_CHECK_INSTANCE_CAST((obj), TYPE_PARAM_CONNECTION_MANAGER, \
+                              ParamConnectionManager))
+#define PARAM_CONNECTION_MANAGER_CLASS(klass) \
+  (G_TYPE_CHECK_CLASS_CAST((klass), TYPE_PARAM_CONNECTION_MANAGER, \
+                           ParamConnectionManagerClass))
+#define IS_PARAM_CONNECTION_MANAGER(obj) \
+  (G_TYPE_CHECK_INSTANCE_TYPE((obj), TYPE_PARAM_CONNECTION_MANAGER))
+#define IS_PARAM_CONNECTION_MANAGER_CLASS(klass) \
+  (G_TYPE_CHECK_CLASS_TYPE((klass), TYPE_PARAM_CONNECTION_MANAGER))
+#define PARAM_CONNECTION_MANAGER_GET_CLASS(obj) \
+  (G_TYPE_INSTANCE_GET_CLASS ((obj), TYPE_PARAM_CONNECTION_MANAGER, \
+                              ParamConnectionManagerClass))
+
+typedef struct {
+    gchar *a_string;
+    gint16 a_int16;
+    gint32 a_int32;
+} CMParams;
+
+CMParams * param_connection_manager_get_params_last_conn (void);
+void free_cm_params (CMParams *params);
+
+G_END_DECLS
+
+#endif
-- 
1.5.6.5




More information about the telepathy-commits mailing list