Added LmResolver interface.
authorMikael Hallendal <micke@imendio.com>
Sun, 13 Jul 2008 19:22:27 +0200
changeset 452 ad59c48027f2
parent 451 0c8ea9d1bec2
child 453 deebf7d6750b
Added LmResolver interface. The LmResolver interface will be implemented in one blocking fashion and one implementation that uses Libasyncns. Designing this as an interface will make it easy to implement an asynchronous version using platform specific technologies for Windows and Mac OS X. It will also make it easier to create a mock implementation to simulate various error codes to test the layers using the resolver.
loudmouth/Makefile.am
loudmouth/lm-resolver.c
loudmouth/lm-resolver.h
--- a/loudmouth/Makefile.am	Sun Jul 13 19:05:23 2008 +0200
+++ b/loudmouth/Makefile.am	Sun Jul 13 19:22:27 2008 +0200
@@ -42,6 +42,8 @@
 	lm-misc.h                       \
 	lm-parser.c			\
 	lm-parser.h			\
+	lm-resolver.c                   \
+	lm-resolver.h                   \
 	lm-internals.h			\
 	lm-sha.c			\
 	lm-sha.h			\
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/loudmouth/lm-resolver.c	Sun Jul 13 19:22:27 2008 +0200
@@ -0,0 +1,119 @@
+/* -*- 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-resolver.h"
+
+static void    resolver_base_init (LmResolverIface *iface);
+
+enum {
+        READABLE,
+        WRITABLE,
+        DISCONNECTED,
+        LAST_SIGNAL
+};
+
+static guint signals[LAST_SIGNAL] = { 0 };
+
+GType
+lm_resolver_get_type (void)
+{
+	static GType iface_type = 0;
+
+	if (!iface_type) {
+		static const GTypeInfo iface_info = {
+			sizeof (LmResolverIface),
+			(GBaseInitFunc)     resolver_base_init,
+			(GBaseFinalizeFunc) NULL,
+		};
+
+		iface_type = g_type_register_static (G_TYPE_INTERFACE,
+						     "LmResolverIface",
+						     &iface_info,
+						     0);
+
+		g_type_interface_add_prerequisite (iface_type, G_TYPE_OBJECT);
+	}
+
+	return iface_type;
+}
+
+static void
+resolver_base_init (LmResolverIface *iface)
+{
+	static gboolean initialized = FALSE;
+
+	if (!initialized) {
+                signals[READABLE] =
+                        g_signal_new ("readable",
+                                      LM_TYPE_RESOLVER,
+                                      G_SIGNAL_RUN_LAST,
+                                      0,
+                                      NULL, NULL,
+                                      lm_marshal_VOID__VOID,
+                                      G_TYPE_NONE,
+                                      0);
+                signals[WRITABLE] = 
+                        g_signal_new ("writable",
+                                      LM_TYPE_RESOLVER,
+                                      G_SIGNAL_RUN_LAST,
+                                      0,
+                                      NULL, NULL,
+                                      lm_marshal_VOID__VOID,
+                                      G_TYPE_NONE,
+                                      0);
+                signals[DISCONNECTED] =
+                        g_signal_new ("disconnected",
+                                      LM_TYPE_RESOLVER,
+                                      G_SIGNAL_RUN_LAST,
+                                      0,
+                                      NULL, NULL,
+                                      lm_marshal_VOID__VOID,
+                                      G_TYPE_NONE,
+                                      0);
+		initialized = TRUE;
+	}
+}
+
+LmResolver *
+lm_resolver_new (LmResolverCallback callback, gpointer user_data)
+{
+        return NULL;
+}
+
+void 
+lm_resolver_lookup_host (LmResolver  *resolver, const gchar *host)
+{
+}
+
+void 
+lm_resolver_lookup_srv (LmResolver  *resolver,
+                        const gchar *domain,
+                        const gchar *srv)
+{
+}
+
+void 
+lm_resolver_cancel (LmResolver *resolver)
+{
+}
+
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/loudmouth/lm-resolver.h	Sun Jul 13 19:22:27 2008 +0200
@@ -0,0 +1,65 @@
+/* -*- 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_RESOLVER_H__
+#define __LM_RESOLVER_H__
+
+#include <glib-object.h>
+
+G_BEGIN_DECLS
+
+#define LM_TYPE_RESOLVER             (lm_resolver_get_type())
+#define LM_RESOLVER(o)               (G_TYPE_CHECK_INSTANCE_CAST((o), LM_TYPE_RESOLVER, LmResolver))
+#define LM_IS_RESOLVER(o)            (G_TYPE_CHECK_INSTANCE_TYPE((o), LM_TYPE_RESOLVER))
+#define LM_RESOLVER_GET_IFACE(o)     (G_TYPE_INSTANCE_GET_INTERFACE((o), LM_TYPE_RESOLVER, LmResolverIface))
+
+typedef struct _LmResolver      LmResolver;
+typedef struct _LmResolverIface LmResolverIface;
+
+struct _LmResolverIface {
+	GTypeInterface parent;
+
+	/* <vtable> */
+        void     (*lookup_host)       (LmResolver  *resolver,
+                                       const gchar *host);
+        void     (*lookup_srv)        (LmResolver  *resolver,
+                                       const gchar *domain,
+                                       const gchar *srv);
+        void     (*cancel)            (LmResolver  *resolver);
+};
+
+typedef void  (*LmResolverCallback)  (LmResolver  *resolver,
+                                      guint        status_code,
+                                      gpointer     user_data);
+
+GType          lm_resolver_get_type          (void);
+
+LmResolver *   lm_resolver_new               (LmResolverCallback  callback,
+                                              gpointer            user_data);
+void           lm_resolver_lookup_host       (LmResolver         *resolver,
+                                              const gchar        *host);
+void           lm_resolver_lookup_srv        (LmResolver         *resolver,
+                                              const gchar        *domain,
+                                              const gchar        *srv);
+void           lm_resolver_cancel            (LmResolver         *resolver);
+
+G_END_DECLS
+
+#endif /* __LM_RESOLVER_H__ */