diff options
author | Marcel Holtmann <marcel@holtmann.org> | 2010-07-26 10:13:22 -0700 |
---|---|---|
committer | Marcel Holtmann <marcel@holtmann.org> | 2010-07-26 10:13:22 -0700 |
commit | 36a887f312bf14c265613a5a209c7de661e1bf48 (patch) | |
tree | 79ebec9032b735ca1ff0857bfa5253563a18c48a /gresolv | |
parent | 30310708307fb1ec5bc2d90cbe6ef4c66a683397 (diff) | |
download | connman-36a887f312bf14c265613a5a209c7de661e1bf48.tar.gz connman-36a887f312bf14c265613a5a209c7de661e1bf48.tar.bz2 connman-36a887f312bf14c265613a5a209c7de661e1bf48.zip |
Add skeleton for internal resolver library
Diffstat (limited to 'gresolv')
-rw-r--r-- | gresolv/gresolv.c | 84 | ||||
-rw-r--r-- | gresolv/gresolv.h | 49 |
2 files changed, 133 insertions, 0 deletions
diff --git a/gresolv/gresolv.c b/gresolv/gresolv.c new file mode 100644 index 00000000..26056767 --- /dev/null +++ b/gresolv/gresolv.c @@ -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 index 00000000..521abd30 --- /dev/null +++ b/gresolv/gresolv.h @@ -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 */ |