Add skeleton for internal resolver library
authorMarcel Holtmann <marcel@holtmann.org>
Mon, 26 Jul 2010 17:13:22 +0000 (10:13 -0700)
committerMarcel Holtmann <marcel@holtmann.org>
Mon, 26 Jul 2010 17:13:22 +0000 (10:13 -0700)
Makefile.am
gresolv/gresolv.c [new file with mode: 0644]
gresolv/gresolv.h [new file with mode: 0644]

index 2aeaaac..2999afe 100644 (file)
@@ -27,6 +27,8 @@ gdbus_sources = gdbus/gdbus.h gdbus/mainloop.c gdbus/object.c gdbus/watch.c
 
 gdhcp_sources = gdhcp/gdhcp.h gdhcp/common.h gdhcp/common.c gdhcp/client.c
 
+gresolv_sources = gresolv/gresolv.h gresolv/gresolv.c
+
 if DATAFILES
 dbusdir = @DBUS_DATADIR@
 
@@ -46,7 +48,8 @@ noinst_PROGRAMS =
 
 sbin_PROGRAMS = src/connmand
 
-src_connmand_SOURCES = $(gdbus_sources) $(gdhcp_sources) $(builtin_sources) \
+src_connmand_SOURCES = $(gdbus_sources) $(gdhcp_sources) \
+                               $(gresolv_sources) $(builtin_sources) \
                        src/main.c src/connman.h src/log.c src/selftest.c \
                        src/error.c src/plugin.c src/task.c src/element.c \
                        src/device.c src/network.c src/connection.c \
diff --git a/gresolv/gresolv.c b/gresolv/gresolv.c
new file mode 100644 (file)
index 0000000..2605676
--- /dev/null
@@ -0,0 +1,84 @@
+/*
+ *
+ *  Resolver library with GLib integration
+ *
+ *  Copyright (C) 2009-2010  Intel Corporation. All rights reserved.
+ *
+ *  This program is free software; you can redistribute it and/or modify
+ *  it under the terms of the GNU General Public License version 2 as
+ *  published by the Free Software Foundation.
+ *
+ *  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 General Public License for more details.
+ *
+ *  You should have received a copy of the GNU General Public License
+ *  along with this program; if not, write to the Free Software
+ *  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
+ *
+ */
+
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#endif
+
+#include "gresolv.h"
+
+struct _GResolv {
+       gint ref_count;
+
+       int index;
+
+       GResolvDebugFunc debug_func;
+       gpointer debug_data;
+};
+
+GResolv *g_resolv_new(int index)
+{
+       GResolv *resolv;
+
+       if (index < 0)
+               return NULL;
+
+       resolv = g_try_new0(GResolv, 1);
+       if (resolv == NULL)
+               return NULL;
+
+       resolv->ref_count = 1;
+
+       resolv->index = index;
+
+       return resolv;
+}
+
+GResolv *g_resolv_ref(GResolv *resolv)
+{
+       if (resolv == NULL)
+               return NULL;
+
+       g_atomic_int_inc(&resolv->ref_count);
+
+       return resolv;
+}
+
+void g_resolv_unref(GResolv *resolv)
+{
+       if (resolv == NULL)
+               return;
+
+       if (g_atomic_int_dec_and_test(&resolv->ref_count) == FALSE)
+               return;
+
+       g_free(resolv);
+}
+
+void g_resolv_set_debug(GResolv *resolv,
+                                GResolvDebugFunc func, gpointer data)
+{
+       if (resolv == NULL)
+               return;
+
+       resolv->debug_func = func;
+       resolv->debug_data = data;
+}
diff --git a/gresolv/gresolv.h b/gresolv/gresolv.h
new file mode 100644 (file)
index 0000000..521abd3
--- /dev/null
@@ -0,0 +1,49 @@
+/*
+ *
+ *  Resolver library with GLib integration
+ *
+ *  Copyright (C) 2009-2010  Intel Corporation. All rights reserved.
+ *
+ *  This program is free software; you can redistribute it and/or modify
+ *  it under the terms of the GNU General Public License version 2 as
+ *  published by the Free Software Foundation.
+ *
+ *  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 General Public License for more details.
+ *
+ *  You should have received a copy of the GNU General Public License
+ *  along with this program; if not, write to the Free Software
+ *  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
+ *
+ */
+
+#ifndef __G_RESOLV_H
+#define __G_RESOLV_H
+
+#include <glib.h>
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+struct _GResolv;
+
+typedef struct _GResolv GResolv;
+
+typedef void (*GResolvDebugFunc)(const char *str, gpointer user_data);
+
+GResolv *g_resolv_new(int index);
+
+GResolv *g_resolv_ref(GResolv *resolv);
+void g_resolv_unref(GResolv *resolv);
+
+void g_resolv_set_debug(GResolv *resolv,
+                               GResolvDebugFunc func, gpointer data);
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* __G_RESOLV_H */