libsyncml  0.5.4
sml_support.h
1 /*
2  * libsyncml - A syncml protocol implementation
3  * Copyright (C) 2005 Armin Bauer <armin.bauer@opensync.org>
4  * Copyright (C) 2008 Michael Bell <michael.bell@opensync.org>
5  *
6  * This library is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU Lesser General Public
8  * License as published by the Free Software Foundation; either
9  * version 2.1 of the License, or (at your option) any later version.
10  *
11  * This library is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14  * Lesser General Public License for more details.
15  *
16  * You should have received a copy of the GNU Lesser General Public
17  * License along with this library; if not, write to the Free Software
18  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19  *
20  */
21 
22 #ifndef _SML_SUPPORT_H_
23 #define _SML_SUPPORT_H_
24 
27 typedef enum {
29  TRACE_ENTRY,
31  TRACE_EXIT,
33  TRACE_INTERNAL,
35  TRACE_ERROR,
37  TRACE_EXIT_ERROR
38 } SmlTraceType;
39 
43 #define VA_STRING(param) param?param:"NULL"
44 
45 void smlLog(const char *logname, const char *data, unsigned int size);
46 void smlTrace(SmlTraceType type, const char *message, ...);
47 char *smlPrintBinary(const char *data, int len);
48 char *smlPrintHex(const char *data, int len);
49 char *smlRandStr(int maxlength, SmlBool exact);
50 void *smlTryMalloc0(long n_bytes, SmlError **error);
51 
52 typedef struct SmlThread {
53  GThread *thread;
54  gboolean started;
55  GCond *started_cond;
56  GMutex *started_mutex;
57  GMainContext *context;
58  GMainLoop *loop;
59 } SmlThread;
60 
61 SmlThread *smlThreadNew(GMainContext *context, SmlError **error);
62 void smlThreadFree(SmlThread *thread);
63 void smlThreadStart(SmlThread *thread);
64 void smlThreadStop(SmlThread *thread);
65 
66 typedef SmlBool (* SmlThreadCallFunctionType) (
67  gpointer data,
68  SmlError **error);
69 
70 SmlBool smlThreadCallFunction(
71  SmlThread *thread,
72  SmlThreadCallFunctionType func,
73  gpointer data,
74  SmlError **error);
75 
76 void smlSafeFree(gpointer *address);
77 void smlSafeCFree(char **address);
78 
79 #endif //_SML_SUPPORT_H_