[Xfce4-commits] r26802 - in xfconf/trunk: common xfconfd
Brian Tarricone
kelnos at xfce.org
Wed Apr 9 07:29:53 CEST 2008
Author: kelnos
Date: 2008-04-09 05:29:53 +0000 (Wed, 09 Apr 2008)
New Revision: 26802
Added:
xfconf/trunk/common/xfconf-gvaluefuncs.c
xfconf/trunk/common/xfconf-gvaluefuncs.h
Modified:
xfconf/trunk/common/Makefile.am
xfconf/trunk/common/xfconf-util.h
xfconf/trunk/xfconfd/Makefile.am
xfconf/trunk/xfconfd/xfconf-backend-perchannel-xml.c
xfconf/trunk/xfconfd/xfconf-daemon.c
Log:
move GValue convenience funcs to their own libtool convenience lib
Modified: xfconf/trunk/common/Makefile.am
===================================================================
--- xfconf/trunk/common/Makefile.am 2008-04-09 05:29:41 UTC (rev 26801)
+++ xfconf/trunk/common/Makefile.am 2008-04-09 05:29:53 UTC (rev 26802)
@@ -1,5 +1,7 @@
-noinst_LTLIBRARIES = libxfconf-common.la
+noinst_LTLIBRARIES = \
+ libxfconf-common.la \
+ libxfconf-gvaluefuncs.la
libxfconf_common_la_SOURCES = \
xfconf-errors.c \
@@ -19,6 +21,16 @@
xfconf-aliasdef.c
+libxfconf_gvaluefuncs_la_SOURCES = \
+ xfconf-gvaluefuncs.c
+
+libxfconf_gvaluefuncs_la_CFLAGS = \
+ -DLIBXFCONF_COMPILATION \
+ -I$(top_srcdir) \
+ $(GLIB_CFLAGS) \
+ $(DBUS_GLIB_CFLAGS)
+
+
if MAINTAINER_MODE
BUILT_SOURCES = \
Added: xfconf/trunk/common/xfconf-gvaluefuncs.c
===================================================================
--- xfconf/trunk/common/xfconf-gvaluefuncs.c (rev 0)
+++ xfconf/trunk/common/xfconf-gvaluefuncs.c 2008-04-09 05:29:53 UTC (rev 26802)
@@ -0,0 +1,182 @@
+/*
+ * xfconf
+ *
+ * Copyright (c) 2008 Brian Tarricone <bjt23 at cornell.edu>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; version 2 of the License ONLY.
+ *
+ * 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 Street, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#endif
+
+#ifdef HAVE_STDLIB_H
+#include <stdlib.h>
+#endif
+
+#ifdef HAVE_STRING_H
+#include <string.h>
+#endif
+
+#ifdef HAVE_ERRNO_H
+#include <errno.h>
+#endif
+
+#include <dbus/dbus-glib.h>
+
+#include "xfconf-gvaluefuncs.h"
+#include "xfconf/xfconf-types.h"
+#include "xfconf-common-private.h"
+
+#ifdef CHAR_MIN
+#define XFCONF_MINCHAR CHAR_MIN
+#else
+#define XFCONF_MINCHAR (-128)
+#endif
+
+#ifdef CHAR_MAX
+#define XFCONF_MAXCHAR CHAR_MAX
+#else
+#define XFCONF_MAXCHAR (127)
+#endif
+
+#ifdef UCHAR_MAX
+#define XFCONF_MAXUCHAR UCHAR_MAX
+#else
+#define XFCONF_MAXUCHAR (255)
+#endif
+
+gboolean
+_xfconf_gvalue_from_string(GValue *value,
+ const gchar *str)
+{
+#define CHECK_CONVERT_STATUS() \
+ if(*str == 0 || *endptr != 0) \
+ return FALSE
+#define CHECK_CONVERT_VALUE(val, minval, maxval) \
+ if((val) < (minval) || (val) > (maxval)) \
+ return FALSE
+
+#define REAL_HANDLE_INT(minval, maxval, convertfunc, setfunc) \
+ G_STMT_START{ \
+ errno = 0; \
+ intval = convertfunc(str, &endptr, 0); \
+ if(0 == intval && ERANGE == errno) \
+ return FALSE; \
+ CHECK_CONVERT_STATUS(); \
+ CHECK_CONVERT_VALUE(intval, minval, maxval); \
+ setfunc(value, intval); \
+ return TRUE; \
+ }G_STMT_END
+
+#define HANDLE_UINT(minval, maxval, setfunc) REAL_HANDLE_INT(minval, maxval, strtoul, setfunc)
+#define HANDLE_INT(minval, maxval, setfunc) REAL_HANDLE_INT(minval, maxval, strtol, setfunc)
+
+ guint64 uintval;
+ gint64 intval;
+ gdouble dval;
+ gchar *endptr = NULL;
+
+ switch(G_VALUE_TYPE(value)) {
+ case G_TYPE_STRING:
+ g_value_set_string(value, str);
+ return TRUE;
+
+ case G_TYPE_UCHAR:
+ HANDLE_UINT(0, XFCONF_MAXUCHAR, g_value_set_uchar);
+ case G_TYPE_CHAR:
+ HANDLE_INT(XFCONF_MINCHAR, XFCONF_MAXCHAR, g_value_set_char);
+ case G_TYPE_UINT:
+ HANDLE_UINT(0, G_MAXUINT, g_value_set_uint);
+ case G_TYPE_INT:
+ HANDLE_INT(G_MININT, G_MAXINT, g_value_set_int);
+
+ case G_TYPE_UINT64:
+ errno = 0;
+ uintval = g_ascii_strtoull(str, &endptr, 0);
+ if(0 == uintval && ERANGE == errno)
+ return FALSE;
+ CHECK_CONVERT_STATUS();
+ g_value_set_uint64(value, uintval);
+ return TRUE;
+
+ case G_TYPE_INT64:
+ errno = 0;
+ intval = g_ascii_strtoll(str, &endptr, 0);
+ if(0 == intval && ERANGE == errno)
+ return FALSE;
+ CHECK_CONVERT_STATUS();
+ g_value_set_int64(value, intval);
+ return TRUE;
+
+ case G_TYPE_FLOAT:
+ errno = 0;
+ dval = g_ascii_strtod(str, &endptr);
+ if(0.0 == dval && ERANGE == errno)
+ return FALSE;
+ CHECK_CONVERT_STATUS();
+ if(dval < G_MINFLOAT || dval > G_MAXFLOAT)
+ return FALSE;
+ g_value_set_float(value, (gfloat)dval);
+ return TRUE;
+
+ case G_TYPE_DOUBLE:
+ errno = 0;
+ dval = g_ascii_strtod(str, &endptr);
+ if(0.0 == dval && ERANGE == errno)
+ return FALSE;
+ CHECK_CONVERT_STATUS();
+ g_value_set_double(value, dval);
+ return TRUE;
+
+ case G_TYPE_BOOLEAN:
+ if(!strcmp(str, "true")) {
+ g_value_set_boolean(value, TRUE);
+ return TRUE;
+ } else if(!strcmp(str, "false")) {
+ g_value_set_boolean(value, FALSE);
+ return TRUE;
+ } else
+ return FALSE;
+
+ default:
+ if(XFCONF_TYPE_UINT16 == G_VALUE_TYPE(value)) {
+ HANDLE_INT(0, G_MAXUSHORT, xfconf_g_value_set_uint16);
+ return TRUE;
+ } else if(XFCONF_TYPE_INT16 == G_VALUE_TYPE(value)) {
+ HANDLE_INT(G_MINSHORT, G_MAXSHORT, xfconf_g_value_set_int16);
+ return TRUE;
+ } else if(XFCONF_TYPE_G_VALUE_ARRAY == G_VALUE_TYPE(value)) {
+ GPtrArray *arr = g_ptr_array_sized_new(1);
+ g_value_take_boxed(value, arr);
+ return TRUE;
+ }
+ return FALSE;
+ }
+
+#undef CHECK_CONVERT_STATUS
+#undef CHECK_CONVERT_VALUE
+#undef REAL_HANDLE_INT
+#undef HANDLE_INT
+#undef HANDLE_UINT
+}
+
+void
+_xfconf_gvalue_free(GValue *value)
+{
+ if(!value)
+ return;
+ g_value_unset(value);
+ g_free(value);
+}
Copied: xfconf/trunk/common/xfconf-gvaluefuncs.h (from rev 26801, xfconf/trunk/common/xfconf-util.h)
===================================================================
--- xfconf/trunk/common/xfconf-gvaluefuncs.h (rev 0)
+++ xfconf/trunk/common/xfconf-gvaluefuncs.h 2008-04-09 05:29:53 UTC (rev 26802)
@@ -0,0 +1,34 @@
+/*
+ * xfconf
+ *
+ * Copyright (c) 2008 Brian Tarricone <bjt23 at cornell.edu>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; version 2 of the License ONLY.
+ *
+ * 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 Street, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+#ifndef __XFCONF_GVALUEFUNCS_H__
+#define __XFCONF_GVALUEFUNCS_H__
+
+#include <glib-object.h>
+
+G_BEGIN_DECLS
+
+gboolean _xfconf_gvalue_from_string(GValue *value,
+ const gchar *str) G_GNUC_INTERNAL;
+
+void _xfconf_gvalue_free(GValue *value) G_GNUC_INTERNAL;
+
+G_END_DECLS
+
+#endif /* __XFCONF_GVALUEFUNCS_H__ */
Modified: xfconf/trunk/common/xfconf-util.h
===================================================================
--- xfconf/trunk/common/xfconf-util.h 2008-04-09 05:29:41 UTC (rev 26801)
+++ xfconf/trunk/common/xfconf-util.h 2008-04-09 05:29:53 UTC (rev 26802)
@@ -26,8 +26,6 @@
#define XFCONF_DBUS_TYPE_G_DOUBLE_ARRAY (dbus_g_type_get_collection("GArray", G_TYPE_DOUBLE))
-void xfconf_g_value_free(GValue *value) G_GNUC_INTERNAL;
-
gboolean xfconf_user_is_in_list(const gchar *list) G_GNUC_INTERNAL;
G_END_DECLS
Modified: xfconf/trunk/xfconfd/Makefile.am
===================================================================
--- xfconf/trunk/xfconfd/Makefile.am 2008-04-09 05:29:41 UTC (rev 26801)
+++ xfconf/trunk/xfconfd/Makefile.am 2008-04-09 05:29:53 UTC (rev 26802)
@@ -26,7 +26,6 @@
-DLOCALEDIR=\"$(localedir)\" \
-I$(top_srcdir) \
-I$(top_srcdir)/common \
- -I$(top_srcdir)/xfconf \
$(GLIB_CFLAGS) \
$(DBUS_CFLAGS) \
$(DBUS_GLIB_CFLAGS) \
@@ -34,6 +33,7 @@
xfconfd_LDADD = \
$(top_builddir)/common/libxfconf-common.la \
+ $(top_builddir)/common/libxfconf-gvaluefuncs.la \
$(GLIB_LIBS) \
$(DBUS_LIBS) \
$(DBUS_GLIB_LIBS) \
Modified: xfconf/trunk/xfconfd/xfconf-backend-perchannel-xml.c
===================================================================
--- xfconf/trunk/xfconfd/xfconf-backend-perchannel-xml.c 2008-04-09 05:29:41 UTC (rev 26801)
+++ xfconf/trunk/xfconfd/xfconf-backend-perchannel-xml.c 2008-04-09 05:29:53 UTC (rev 26802)
@@ -57,7 +57,8 @@
#include "xfconf-backend-perchannel-xml.h"
#include "xfconf-backend.h"
#include "xfconf-util.h"
-#include "xfconf-types.h"
+#include "xfconf-gvaluefuncs.h"
+#include "xfconf/xfconf-types.h"
#include "xfconf-common-private.h"
#define FILE_VERSION_MAJOR "1"
@@ -71,24 +72,6 @@
#define WRITE_TIMEOUT (5*1000) /* 5 secionds */
#define MAX_PROP_PATH (4096)
-#ifdef CHAR_MIN
-#define XFCONF_MINCHAR CHAR_MIN
-#else
-#define XFCONF_MINCHAR (-128)
-#endif
-
-#ifdef CHAR_MAX
-#define XFCONF_MAXCHAR CHAR_MAX
-#else
-#define XFCONF_MAXCHAR (127)
-#endif
-
-#ifdef UCHAR_MAX
-#define XFCONF_MAXUCHAR UCHAR_MAX
-#else
-#define XFCONF_MAXUCHAR (255)
-#endif
-
struct _XfconfBackendPerchannelXml
{
GObject parent;
@@ -845,121 +828,6 @@
return G_TYPE_INVALID;
}
-static gboolean
-xfconf_string_to_value(const gchar *str,
- GValue *value)
-{
-#define CHECK_CONVERT_STATUS() \
- if(*str == 0 || *endptr != 0) \
- return FALSE
-#define CHECK_CONVERT_VALUE(val, minval, maxval) \
- if((val) < (minval) || (val) > (maxval)) \
- return FALSE
-
-#define REAL_HANDLE_INT(minval, maxval, convertfunc, setfunc) \
- G_STMT_START{ \
- errno = 0; \
- intval = convertfunc(str, &endptr, 0); \
- if(0 == intval && ERANGE == errno) \
- return FALSE; \
- CHECK_CONVERT_STATUS(); \
- CHECK_CONVERT_VALUE(intval, minval, maxval); \
- setfunc(value, intval); \
- return TRUE; \
- }G_STMT_END
-
-#define HANDLE_UINT(minval, maxval, setfunc) REAL_HANDLE_INT(minval, maxval, strtoul, setfunc)
-#define HANDLE_INT(minval, maxval, setfunc) REAL_HANDLE_INT(minval, maxval, strtol, setfunc)
-
- guint64 uintval;
- gint64 intval;
- gdouble dval;
- gchar *endptr = NULL;
-
- switch(G_VALUE_TYPE(value)) {
- case G_TYPE_STRING:
- g_value_set_string(value, str);
- return TRUE;
-
- case G_TYPE_UCHAR:
- HANDLE_UINT(0, XFCONF_MAXUCHAR, g_value_set_uchar);
- case G_TYPE_CHAR:
- HANDLE_INT(XFCONF_MINCHAR, XFCONF_MAXCHAR, g_value_set_char);
- case G_TYPE_UINT:
- HANDLE_UINT(0, G_MAXUINT, g_value_set_uint);
- case G_TYPE_INT:
- HANDLE_INT(G_MININT, G_MAXINT, g_value_set_int);
-
- case G_TYPE_UINT64:
- errno = 0;
- uintval = g_ascii_strtoull(str, &endptr, 0);
- if(0 == uintval && ERANGE == errno)
- return FALSE;
- CHECK_CONVERT_STATUS();
- g_value_set_uint64(value, uintval);
- return TRUE;
-
- case G_TYPE_INT64:
- errno = 0;
- intval = g_ascii_strtoll(str, &endptr, 0);
- if(0 == intval && ERANGE == errno)
- return FALSE;
- CHECK_CONVERT_STATUS();
- g_value_set_int64(value, intval);
- return TRUE;
-
- case G_TYPE_FLOAT:
- errno = 0;
- dval = g_ascii_strtod(str, &endptr);
- if(0.0 == dval && ERANGE == errno)
- return FALSE;
- CHECK_CONVERT_STATUS();
- if(dval < G_MINFLOAT || dval > G_MAXFLOAT)
- return FALSE;
- g_value_set_float(value, (gfloat)dval);
- return TRUE;
-
- case G_TYPE_DOUBLE:
- errno = 0;
- dval = g_ascii_strtod(str, &endptr);
- if(0.0 == dval && ERANGE == errno)
- return FALSE;
- CHECK_CONVERT_STATUS();
- g_value_set_double(value, dval);
- return TRUE;
-
- case G_TYPE_BOOLEAN:
- if(!strcmp(str, "true")) {
- g_value_set_boolean(value, TRUE);
- return TRUE;
- } else if(!strcmp(str, "false")) {
- g_value_set_boolean(value, FALSE);
- return TRUE;
- } else
- return FALSE;
-
- default:
- if(XFCONF_TYPE_UINT16 == G_VALUE_TYPE(value)) {
- HANDLE_INT(0, G_MAXUSHORT, xfconf_g_value_set_uint16);
- return TRUE;
- } else if(XFCONF_TYPE_INT16 == G_VALUE_TYPE(value)) {
- HANDLE_INT(G_MINSHORT, G_MAXSHORT, xfconf_g_value_set_int16);
- return TRUE;
- } else if(XFCONF_TYPE_G_VALUE_ARRAY == G_VALUE_TYPE(value)) {
- GPtrArray *arr = g_ptr_array_sized_new(1);
- g_value_take_boxed(value, arr);
- return TRUE;
- }
- return FALSE;
- }
-
-#undef CHECK_CONVERT_STATUS
-#undef CHECK_CONVERT_VALUE
-#undef REAL_HANDLE_INT
-#undef HANDLE_INT
-#undef HANDLE_UINT
-}
-
static void
xfconf_backend_perchannel_xml_start_elem(GMarkupParseContext *context,
const gchar *element_name,
@@ -1174,7 +1042,7 @@
if(G_TYPE_NONE != value_type) {
g_value_init(&prop->value, value_type);
- if(!xfconf_string_to_value(value, &prop->value)) {
+ if(!_xfconf_gvalue_from_string(&prop->value, value)) {
if(error) {
g_set_error(error, G_MARKUP_ERROR,
G_MARKUP_ERROR_INVALID_CONTENT,
@@ -1244,7 +1112,7 @@
val = g_new0(GValue, 1);
g_value_init(val, value_type);
- if(!xfconf_string_to_value(value, val)) {
+ if(!_xfconf_gvalue_from_string(val, value)) {
if(error) {
g_set_error(error, G_MARKUP_ERROR,
G_MARKUP_ERROR_INVALID_CONTENT,
Modified: xfconf/trunk/xfconfd/xfconf-daemon.c
===================================================================
--- xfconf/trunk/xfconfd/xfconf-daemon.c 2008-04-09 05:29:41 UTC (rev 26801)
+++ xfconf/trunk/xfconfd/xfconf-daemon.c 2008-04-09 05:29:53 UTC (rev 26802)
@@ -29,6 +29,7 @@
#include "xfconf-backend.h"
#include "xfconf-marshal.h"
#include "xfconf-util.h"
+#include "xfconf-gvaluefuncs.h"
#include "xfconf/xfconf-errors.h"
static gboolean xfconf_set_property(XfconfDaemon *xfconfd,
@@ -215,7 +216,7 @@
*properties = g_hash_table_new_full(g_str_hash, g_str_equal,
(GDestroyNotify)g_free,
- (GDestroyNotify)xfconf_g_value_free);
+ (GDestroyNotify)_xfconf_gvalue_free);
/* get all properties from all backends. if they all fail, return FALSE */
for(l = xfconfd->backends; l; l = l->next) {
More information about the Xfce4-commits
mailing list