From: <svn...@op...> - 2009-07-03 14:29:53
|
Author: bellmich Date: Fri Jul 3 16:29:48 2009 New Revision: 1151 URL: http://libsyncml.opensync.org/changeset/1151 Log: migrated sml_support from SmlError to GError Modified: trunk/libsyncml/sml_support.c trunk/libsyncml/sml_support.h Modified: trunk/libsyncml/sml_support.c ============================================================================== --- trunk/libsyncml/sml_support.c Fri Jul 3 16:16:21 2009 (r1150) +++ trunk/libsyncml/sml_support.c Fri Jul 3 16:29:48 2009 (r1151) @@ -1,7 +1,7 @@ /* * libsyncml - A syncml protocol implementation * Copyright (C) 2005 Armin Bauer <arm...@op...> - * Copyright (C) 2007-2008 Michael Bell <mic...@op...> + * Copyright (C) 2007-2009 Michael Bell <mic...@op...> * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public @@ -40,7 +40,8 @@ #define G_ERRORCHECK_MUTEXES -static const char* smlCheckDebugDirectory(const char *env) +static const gchar* +smlCheckDebugDirectory (const gchar *env) { const char *dirname = g_getenv(env); if (!dirname) @@ -70,7 +71,10 @@ /*@{*/ -void smlLog(const char *logname, const char *data, unsigned int size) +void +smlLog (const gchar *logname, + const gchar *data, + gsize size) { #if defined ENABLE_TRACE @@ -117,7 +121,9 @@ * @param message The message to save * */ -void smlTrace(SmlTraceType type, const char *message, ...) +void +smlTrace (SmlTraceType type, + const gchar *message, ...) { #if defined ENABLE_TRACE @@ -165,7 +171,7 @@ { gchar** filters = g_strsplit(filter, ",", 0); gint i; - SmlBool matched = FALSE; + gboolean matched = FALSE; for (i=0; filters[i] != NULL && !matched ; i++) { if (strstr(buffer, filters[i])) @@ -249,7 +255,9 @@ * @param len The length to print * */ -char *smlPrintBinary(const char *data, int len) +gchar* +smlPrintBinary (const gchar *data, + gsize len) { int t; GString *str = g_string_new(""); @@ -268,7 +276,9 @@ * @param len The length to print * */ -char *smlPrintHex(const char *data, int len) +gchar* +smlPrintHex (const gchar *data, + gsize len) { int t; GString *str = g_string_new(""); @@ -299,7 +309,9 @@ * @returns The random string * */ -char *smlRandStr(int maxlength, SmlBool exact) +gchar* +smlRandStr (gsize maxlength, + gboolean exact) { const char *randchars = "abcdefghijklmnopqrstuvwxyzABCDEFGHIKLMNOPQRSTUVWXYZ1234567890"; @@ -332,7 +344,9 @@ * @returns The newly allocated memory or NULL in case of error * */ -void *smlTryMalloc0(long n_bytes, SmlError **error) +void* +smlTryMalloc0 (gsize n_bytes, + GError **error) { CHECK_ERROR_REF @@ -341,7 +355,7 @@ /* set error */ char *msg = NULL; if (n_bytes > 0) - msg = g_strdup_printf("No memory left (needed %ld).", n_bytes); + msg = g_strdup_printf("No memory left (needed %ulld).", n_bytes); else msg = g_strdup_printf("Malloc of zero bytes requested."); @@ -349,7 +363,7 @@ if (error == NULL) g_error("%s", msg); else - smlErrorSet(error, SML_ERROR_INTERNAL_NO_MEMORY, "%s", msg); + g_set_error(error, SML_ERROR, SML_ERROR_INTERNAL_NO_MEMORY, "%s", msg); return NULL; } memset(result, 0, n_bytes); @@ -361,7 +375,8 @@ * @returns The version as const string * */ -const char *smlGetVersion(void) +const gchar* +smlGetVersion (void) { /** * @version $Id$ @@ -369,7 +384,9 @@ return "$Id$"; } -SmlThread *smlThreadNew(GMainContext *context, SmlError **error) +SmlThread* +smlThreadNew (GMainContext *context, + GError **error) { smlTrace(TRACE_ENTRY, "%s(%p, %p)", __func__, context, error); CHECK_ERROR_REF @@ -391,7 +408,7 @@ if (!g_thread_supported ()) g_thread_init (NULL); if (!g_thread_supported ()) { - smlErrorSet(error, SML_ERROR_INTERNAL_MISCONFIGURATION, + g_set_error(error, SML_ERROR, SML_ERROR_INTERNAL_MISCONFIGURATION, "Threads are not supported."); goto error; } @@ -405,13 +422,13 @@ smlTrace(TRACE_EXIT, "%s: %p", __func__, thread); return thread; - error: - smlTrace(TRACE_EXIT_ERROR, "%s: %s", __func__, smlErrorPrint(error)); + smlTrace(TRACE_EXIT_ERROR, "%s: %s", __func__, (*error)->message); return NULL; } -void smlThreadFree(SmlThread *thread) +void +smlThreadFree (SmlThread *thread) { smlTrace(TRACE_ENTRY, "%s(%p)", __func__, thread); smlAssert(thread); @@ -432,7 +449,8 @@ smlTrace(TRACE_EXIT, "%s", __func__); } -static gpointer smlThreadStartCallback(gpointer data) +static gpointer +smlThreadStartCallback (gpointer data) { smlTrace(TRACE_ENTRY, "%s(%p)", __func__, data); SmlThread *thread = data; @@ -462,7 +480,8 @@ return FALSE; } -static gboolean smlThreadStopCallback(gpointer data) +static gboolean +smlThreadStopCallback (gpointer data) { smlTrace(TRACE_ENTRY, "%s(%p)", __func__, data); SmlThread *thread = data; @@ -474,7 +493,8 @@ return FALSE; } -void smlThreadStart(SmlThread *thread) +void +smlThreadStart (SmlThread *thread) { smlTrace(TRACE_ENTRY, "%s(%p)", __func__, thread); smlAssert(thread); @@ -496,7 +516,8 @@ smlTrace(TRACE_EXIT, "%s", __func__); } -void smlThreadStop(SmlThread *thread) +void +smlThreadStop (SmlThread *thread) { smlTrace(TRACE_ENTRY, "%s(%p)", __func__, thread); smlAssert(thread); @@ -523,15 +544,16 @@ GCond *cond; SmlThreadCallFunctionType func; gpointer data; - SmlBool result; - SmlError **error; + gboolean result; + GError **error; } SmlThreadFunctionContext; /** * This callback is used to call a function within a special thread. * Please see smlThreadCallFunction for more details. */ -gboolean smlThreadCallFunctionCallback(gpointer data) +gboolean +smlThreadCallFunctionCallback (gpointer data) { smlTrace(TRACE_ENTRY, "%s(%p)", __func__, data); smlAssert(data); @@ -558,11 +580,11 @@ * Please note: This function is blocking. * Please note: The glib source priority is IDLE. */ -SmlBool smlThreadCallFunction( - SmlThread *thread, - SmlThreadCallFunctionType func, - gpointer data, - SmlError **error) +gboolean +smlThreadCallFunction(SmlThread *thread, + SmlThreadCallFunctionType func, + gpointer data, + GError **error) { smlTrace(TRACE_ENTRY, "%s(%p => %p, %p, %p, %p)", __func__, thread, thread?thread->context:NULL, func, data, error); CHECK_ERROR_REF @@ -576,12 +598,12 @@ goto error; ctx->mutex = g_mutex_new(); if (!ctx->mutex) { - smlErrorSet(error, SML_ERROR_GENERIC, "Cannot create new mutex."); + g_set_error(error, SML_ERROR, SML_ERROR_GENERIC, "Cannot create new mutex."); goto error; } ctx->cond = g_cond_new(); if (!ctx->cond) { - smlErrorSet(error, SML_ERROR_GENERIC, "Cannot create new condition."); + g_set_error(error, SML_ERROR, SML_ERROR_GENERIC, "Cannot create new condition."); goto error; } ctx->func = func; @@ -604,7 +626,7 @@ /* cleanup */ smlTrace(TRACE_INTERNAL, "%s: cleanup", __func__); - SmlBool result = ctx->result; + gboolean result = ctx->result; g_source_unref(source); g_mutex_free(ctx->mutex); g_cond_free(ctx->cond); @@ -620,11 +642,12 @@ g_mutex_free(ctx->mutex); if (ctx) smlSafeFree((gpointer *) &ctx); - smlTrace(TRACE_EXIT_ERROR, "%s - %s", __func__, smlErrorPrint(error)); + smlTrace(TRACE_EXIT_ERROR, "%s - %s", __func__, (*error)->message); return FALSE; } -void smlSafeFree(gpointer *address) +void +smlSafeFree (gpointer *address) { smlAssert(address); smlAssert(*address); @@ -632,17 +655,20 @@ *address = NULL; } -void smlSafeCFree(char **address) +void +smlSafeCFree (gchar **address) { smlSafeFree((gpointer *)address); } -const char *smlGetLibraryVersion() +const gchar* +smlGetLibraryVersion() { return PACKAGE_VERSION; } -const char *smlGetLibrarySoName() +const gchar* +smlGetLibrarySoName() { return PACKAGE_SONAME; } Modified: trunk/libsyncml/sml_support.h ============================================================================== --- trunk/libsyncml/sml_support.h Fri Jul 3 16:16:21 2009 (r1150) +++ trunk/libsyncml/sml_support.h Fri Jul 3 16:29:48 2009 (r1151) @@ -1,7 +1,7 @@ /* * libsyncml - A syncml protocol implementation * Copyright (C) 2005 Armin Bauer <arm...@op...> - * Copyright (C) 2008 Michael Bell <mic...@op...> + * Copyright (C) 2008-2009 Michael Bell <mic...@op...> * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public @@ -63,17 +63,17 @@ void smlThreadStart (SmlThread *thread); void smlThreadStop (SmlThread *thread); -typedef SmlBool (* SmlThreadCallFunctionType) ( +typedef gboolean (* SmlThreadCallFunctionType) ( gpointer data, GError **error); -SmlBool smlThreadCallFunction( +gboolean smlThreadCallFunction( SmlThread *thread, SmlThreadCallFunctionType func, gpointer data, GError **error); void smlSafeFree (gpointer *address); -void smlSafeCFree (char **address); +void smlSafeCFree (gchar **address); #endif //_SML_SUPPORT_H_ |