Worked on the LmSocket interface and added a LmSoupSocket class.
authorMikael Hallendal <micke@imendio.com>
Fri, 11 Jul 2008 17:29:07 +0300
changeset 434 579db9f99cc5
parent 433 2ed69f025f4a
child 435 8bc7875aed38
Worked on the LmSocket interface and added a LmSoupSocket class. LmSoupSocket will be a possibly temporary implementation of the LmSocket interface on top of the SoupSocket API in order to get something going quickly. Depending on how it works out it might be made the default implementation. Added signals and worked a bit to model the LmSocket API after the SoupSocket API as it seems quite similar to what I had in mind.
loudmouth/Makefile.am
loudmouth/lm-socket.c
loudmouth/lm-socket.h
loudmouth/lm-soup-socket.c
loudmouth/lm-soup-socket.h
--- a/loudmouth/Makefile.am	Wed Jul 09 15:56:07 2008 +0300
+++ b/loudmouth/Makefile.am	Fri Jul 11 17:29:07 2008 +0300
@@ -56,6 +56,8 @@
 	lm-sock.c			\
 	lm-socket.c                     \
 	lm-socket.h                     \
+	lm-soup-socket.c                \
+	lm-soup-socket.h                \
 	lm-tcp-socket.c                 \
 	lm-tcp-socket.h                 \
 	lm-old-socket.c                 \
--- a/loudmouth/lm-socket.c	Wed Jul 09 15:56:07 2008 +0300
+++ b/loudmouth/lm-socket.c	Fri Jul 11 17:29:07 2008 +0300
@@ -20,10 +20,20 @@
 
 #include <config.h>
 
+#include "lm-marshal.h"
 #include "lm-socket.h"
 
 static void    socket_base_init (LmSocketIface *iface);
 
+enum {
+        READABLE,
+        WRITABLE,
+        DISCONNECTED,
+        LAST_SIGNAL
+};
+
+static guint signals[LAST_SIGNAL] = { 0 };
+
 GType
 lm_socket_get_type (void)
 {
@@ -53,7 +63,35 @@
 	static gboolean initialized = FALSE;
 
 	if (!initialized) {
-		/* create interface signals here. */
+                signals[READABLE] =
+                        g_signal_new ("readable",
+                                      LM_TYPE_SOCKET,
+                                      G_SIGNAL_RUN_LAST,
+                                      0,
+                                      NULL, NULL,
+                                      lm_marshal_VOID__BOOLEAN,
+                                      G_TYPE_NONE,
+                                      1, G_TYPE_BOOLEAN);
+
+                signals[WRITABLE] = 
+                        g_signal_new ("writable",
+                                      LM_TYPE_SOCKET,
+                                      G_SIGNAL_RUN_LAST,
+                                      0,
+                                      NULL, NULL,
+                                      lm_marshal_VOID__BOOLEAN,
+                                      G_TYPE_NONE,
+                                      1, G_TYPE_BOOLEAN);
+                signals[DISCONNECTED] =
+                        g_signal_new ("disconnected",
+                                      LM_TYPE_SOCKET,
+                                      G_SIGNAL_RUN_LAST,
+                                      0,
+                                      NULL, NULL,
+                                      lm_marshal_VOID__BOOLEAN,
+                                      G_TYPE_NONE,
+                                      1, G_TYPE_BOOLEAN);
+
 		initialized = TRUE;
 	}
 }
--- a/loudmouth/lm-socket.h	Wed Jul 09 15:56:07 2008 +0300
+++ b/loudmouth/lm-socket.h	Fri Jul 11 17:29:07 2008 +0300
@@ -51,6 +51,10 @@
         void     (*disconnect)   (LmSocket *socket);
 };
 
+typedef void  (*LmSocketCallback)  (LmSocket *socket,
+                                    guint     status_code,
+                                    gpointer  user_data);
+
 GType          lm_socket_get_type          (void);
 
 LmSocket *     lm_socket_new               (const gchar *host,
@@ -59,6 +63,7 @@
 LmSocket *     lm_socket_new_to_service    (const gchar *service);
 
 /* All async functions so doesn't make a lot of sense to return anything */
+/* Use LmSocketCallback instead of signal for the connect result */
 void           lm_socket_connect           (LmSocket    *socket);
 gboolean       lm_socket_write             (LmSocket    *socket,
                                             gchar       *buf,
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/loudmouth/lm-soup-socket.c	Fri Jul 11 17:29:07 2008 +0300
@@ -0,0 +1,145 @@
+/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */
+/*
+ * Copyright (C) 2008 Imendio AB
+ *
+ * This program 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 of the
+ * License, or (at your option) any later version.
+ *
+ * This program 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 program; if not, write to the
+ * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ * Boston, MA 02111-1307, USA.
+ */
+
+#include <config.h>
+
+#include "lm-marshal.h"
+#include "lm-soup-socket.h"
+
+#define GET_PRIV(obj) (G_TYPE_INSTANCE_GET_PRIVATE ((obj), LM_TYPE_SOUP_SOCKET, LmSoupSocketPriv))
+
+typedef struct LmSoupSocketPriv LmSoupSocketPriv;
+struct LmSoupSocketPriv {
+	gint my_prop;
+};
+
+static void     soup_socket_finalize            (GObject           *object);
+static void     soup_socket_get_property        (GObject           *object,
+					   guint              param_id,
+					   GValue            *value,
+					   GParamSpec        *pspec);
+static void     soup_socket_set_property        (GObject           *object,
+					   guint              param_id,
+					   const GValue      *value,
+					   GParamSpec        *pspec);
+
+G_DEFINE_TYPE (LmSoupSocket, lm_soup_socket, G_TYPE_OBJECT)
+
+enum {
+	PROP_0,
+	PROP_MY_PROP
+};
+
+enum {
+	SIGNAL_NAME,
+	LAST_SIGNAL
+};
+
+static guint signals[LAST_SIGNAL] = { 0 };
+
+static void
+lm_soup_socket_class_init (LmSoupSocketClass *class)
+{
+	GObjectClass *object_class = G_OBJECT_CLASS (class);
+
+	object_class->finalize     = soup_socket_finalize;
+	object_class->get_property = soup_socket_get_property;
+	object_class->set_property = soup_socket_set_property;
+
+	g_object_class_install_property (object_class,
+					 PROP_MY_PROP,
+					 g_param_spec_string ("my-prop",
+							      "My Prop",
+							      "My Property",
+							      NULL,
+							      G_PARAM_READWRITE));
+	
+	signals[SIGNAL_NAME] = 
+		g_signal_new ("signal-name",
+			      G_OBJECT_CLASS_TYPE (object_class),
+			      G_SIGNAL_RUN_LAST,
+			      0,
+			      NULL, NULL,
+			      lm_marshal_VOID__INT,
+			      G_TYPE_NONE, 
+			      1, G_TYPE_INT);
+	
+	g_type_class_add_private (object_class, sizeof (LmSoupSocketPriv));
+}
+
+static void
+lm_soup_socket_init (LmSoupSocket *soup_socket)
+{
+	LmSoupSocketPriv *priv;
+
+	priv = GET_PRIV (soup_socket);
+
+}
+
+static void
+soup_socket_finalize (GObject *object)
+{
+	LmSoupSocketPriv *priv;
+
+	priv = GET_PRIV (object);
+
+	(G_OBJECT_CLASS (lm_soup_socket_parent_class)->finalize) (object);
+}
+
+static void
+soup_socket_get_property (GObject    *object,
+		   guint       param_id,
+		   GValue     *value,
+		   GParamSpec *pspec)
+{
+	LmSoupSocketPriv *priv;
+
+	priv = GET_PRIV (object);
+
+	switch (param_id) {
+	case PROP_MY_PROP:
+		g_value_set_int (value, priv->my_prop);
+		break;
+	default:
+		G_OBJECT_WARN_INVALID_PROPERTY_ID (object, param_id, pspec);
+		break;
+	};
+}
+
+static void
+soup_socket_set_property (GObject      *object,
+		   guint         param_id,
+		   const GValue *value,
+		   GParamSpec   *pspec)
+{
+	LmSoupSocketPriv *priv;
+
+	priv = GET_PRIV (object);
+
+	switch (param_id) {
+	case PROP_MY_PROP:
+		priv->my_prop = g_value_get_int (value);
+		break;
+	default:
+		G_OBJECT_WARN_INVALID_PROPERTY_ID (object, param_id, pspec);
+		break;
+	};
+}
+
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/loudmouth/lm-soup-socket.h	Fri Jul 11 17:29:07 2008 +0300
@@ -0,0 +1,59 @@
+/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */
+/*
+ * Copyright (C) 2008 Imendio AB
+ *
+ * This program 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 of the
+ * License, or (at your option) any later version.
+ *
+ * This program 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 program; if not, write to the
+ * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ * Boston, MA 02111-1307, USA.
+ */
+
+#ifndef __LM_SOUP_SOCKET_H__
+#define __LM_SOUP_SOCKET_H__
+
+#include <glib-object.h>
+
+G_BEGIN_DECLS
+
+#define LM_TYPE_SOUP_SOCKET            (lm_soup_socket_get_type ())
+#define LM_SOUP_SOCKET(obj)            (G_TYPE_CHECK_INSTANCE_CAST ((obj), LM_TYPE_SOUP_SOCKET, LmSoupSocket))
+#define LM_SOUP_SOCKET_CLASS(klass)    (G_TYPE_CHECK_CLASS_CAST ((klass), LM_TYPE_SOUP_SOCKET, LmSoupSocketClass))
+#define LM_IS_SOUP_SOCKET(obj)         (G_TYPE_CHECK_INSTANCE_TYPE ((obj), LM_TYPE_SOUP_SOCKET))
+#define LM_IS_SOUP_SOCKET_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), LM_TYPE_SOUP_SOCKET))
+#define LM_SOUP_SOCKET_GET_CLASS(obj)  (G_TYPE_INSTANCE_GET_CLASS ((obj), LM_TYPE_SOUP_SOCKET, LmSoupSocketClass))
+
+typedef struct LmSoupSocket      LmSoupSocket;
+typedef struct LmSoupSocketClass LmSoupSocketClass;
+
+struct LmSoupSocket {
+	GObject parent;
+};
+
+struct LmSoupSocketClass {
+	GObjectClass parent_class;
+	
+	/* <vtable> */
+	void  (*initialize)    (LmSoupSocket     *soup_socket,
+				const char *username,
+				const char *server,
+				const char *password);
+	void  (*begin)         (LmSoupSocket     *soup_socket);
+	void  (*cancel)        (LmSoupSocket     *soup_socket);
+};
+
+GType   lm_soup_socket_get_type  (void);
+
+G_END_DECLS
+
+#endif /* __LM_SOUP_SOCKET_H__ */
+