53d45ea8a4183fac6790c073b6a28208c5a1222f
[runtime.git] / lib / silcutil / silcruntime.h.in
1 /*
2
3   silcruntime.h
4
5   Author: Pekka Riikonen <priikone@silcnet.org>
6
7   Copyright (C) 2008 Pekka Riikonen
8
9   This program is free software; you can redistribute it and/or modify
10   it under the terms of the GNU General Public License as published by
11   the Free Software Foundation; version 2 of the License.
12
13   This program is distributed in the hope that it will be useful,
14   but WITHOUT ANY WARRANTY; without even the implied warranty of
15   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16   GNU General Public License for more details.
17
18 */
19
20 /****h* silcutil/Runtime Toolkit Interface
21  *
22  * DESCRIPTION
23  *
24  * The SILC Runtime Toolkit API is used to initialize and uninitialize the
25  * Runtime Toolkit.  The application should call silc_runtime_init at the
26  * very start of the application and the silc_runtime_uninit at the very end
27  * of the application before it is exited.
28  *
29  ***/
30
31 #ifndef SILCRUNTIME_H
32 #define SILCRUNTIME_H
33
34 /* Version check macro.  Use this to check that package is of specific
35    version compile time.  Use the __SILC_XXX_VERSION below in comparison.
36    Example:
37
38    #if __SILC_RUNTIME_VERSION < SILC_VERSION(1,2,0)
39      ...
40    #endif
41 */
42 #ifndef SILC_VERSION
43 #define SILC_VERSION(a, b, c) (((a) << 24) + ((b) << 16) + ((c) << 8)
44 #endif /* !SILC_VERSION */
45
46 /* SILC Runtime Toolkit version */
47 @__RUNTIME_PACKAGE_VERSION@
48
49 /* Compilation time defines, for third-party software.  Use these to check
50    in configuration/compilation time how the SILC Runtime Toolkit was
51    configured/compiled. */
52 @__SILC_HAVE_PTHREAD@
53 @__SILC_ENABLE_DEBUG@
54 @__SILC_ENABLE_STACKTRACE@
55 @__SILC_VA_COPY@
56
57 /* Types */
58 #define SILC_SIZEOF_LONG_LONG @SILC_SIZEOF_LONG_LONG@
59 #define SILC_SIZEOF_LONG @SILC_SIZEOF_LONG@
60 #define SILC_SIZEOF_INT @SILC_SIZEOF_INT@
61 #define SILC_SIZEOF_SHORT @SILC_SIZEOF_SHORT@
62 #define SILC_SIZEOF_CHAR @SILC_SIZEOF_CHAR@
63 #define SILC_SIZEOF_VOID_P @SILC_SIZEOF_VOID_P@
64
65 /* Detect OS */
66 #define SILC_UNIX
67
68 #ifdef WIN32
69 #ifndef SILC_WIN32
70 #define SILC_WIN32
71 #undef SILC_UNIX
72 #endif
73 #endif
74
75 #if defined(__EPOC32__) || defined(__SYMBIAN32__)
76 #ifndef SILC_SYMBIAN
77 #define SILC_SYMBIAN
78 #undef SILC_UNIX
79 #undef SILC_WIN32
80 #endif
81 #endif
82
83 #if defined(__MACH__) && defined(__APPLE__)
84 #ifndef SILC_MACOSX
85 #define SILC_MACOSX
86 #undef SILC_WIN32
87 #undef SILC_SYMBIAN
88 #endif
89 #endif
90
91 #ifdef __cplusplus
92 extern "C" {
93 #endif
94
95 /* Platform specific includes */
96 #if defined(SILC_WIN32)
97 #include <silcwin32.h>
98 #endif
99
100 #if defined(SILC_SYMBIAN)
101 #include <silcsymbian.h>
102 #endif
103
104 #ifndef DLLAPI
105 #define DLLAPI
106 #endif
107
108 /* We except all systems to have these include files */
109 #include <stdio.h>
110 #include <stdlib.h>
111 #include <string.h>
112
113 #if defined(HAVE_RUNTIMEDEFS_H)
114
115 /* Automatically generated configuration header.  These are included only
116    when the SILC Runtime Toolkit itself is compiled. */
117 #ifndef SILC_SYMBIAN
118 #include "runtimedefs.h"
119 #else
120 #include "../../symbian/silcdefs.h"
121 #endif /* SILC_SYMBIAN */
122 #include "silcdistdefs.h"
123 #include "silccompile.h"
124
125 #else
126
127 /* Autodetect CPU so that inline assembly in headers are enabled */
128
129 #if defined(__i386__)
130 #undef SILC_I386
131 #undef SILC_I486
132 #define SILC_I386
133 #define SILC_I486
134 #endif /* __i386__ */
135
136 #if defined(__i486__)
137 #undef SILC_I386
138 #undef SILC_I486
139 #define SILC_I386
140 #define SILC_I486
141 #endif /* __i486__ */
142
143 #if defined(__i586__)
144 #undef SILC_I386
145 #undef SILC_I486
146 #undef SILC_I586
147 #define SILC_I386
148 #define SILC_I486
149 #define SILC_I586
150 #endif /* __i586__ */
151
152 #if defined(__i686__)
153 #undef SILC_I386
154 #undef SILC_I486
155 #undef SILC_I586
156 #undef SILC_I686
157 #define SILC_I386
158 #define SILC_I486
159 #define SILC_I586
160 #define SILC_I686
161 #endif /* __i686__ */
162
163 #if defined(__x86_64__)
164 #undef SILC_X86_64
165 #define SILC_X86_64
166 #endif /* __x86_64__ */
167
168 #if defined(__ia64__)
169 #undef SILC_IA64
170 #define SILC_IA64
171 #endif /* __ia64__ */
172
173 #if defined(__ppc__) || defined(__ppc64__)
174 #undef SILC_POWERPC
175 #define SILC_POWERPC
176 #endif /* __ppc__ || __ppc64__ */
177
178 #ifndef SILC_ALIGNMENT
179 #define SILC_ALIGNMENT SILC_SIZEOF_VOID_P
180 #endif /* SILC_ALIGNMENT */
181
182 #endif /* HAVE_RUNTIMEDEFS_H */
183
184 /* Feature defines */
185 #ifdef __SILC_HAVE_PTHREAD
186 #undef SILC_THREADS
187 #define SILC_THREADS 1
188 #endif /* __SILC_HAVE_PTHREAD */
189
190 #ifdef __SILC_ENABLE_DEBUG
191 #undef SILC_DEBUG
192 #define SILC_DEBUG 1
193 #endif /* __SILC_ENABLE_DEBUG */
194
195 #ifdef __SILC_ENABLE_STACKTRACE
196 #undef SILC_STACKTRACE
197 #define SILC_STACKTRACE 1
198 #endif /* __SILC_ENABLE_STACKTRACE */
199
200 /* SILC Runtime Toolkit includes */
201 #include <silctypes.h>
202 #include <silcerrno.h>
203 #include <silcbitops.h>
204 #include <silcmutex.h>
205 #include <silcatomic.h>
206 #include <silcgetopt.h>
207 #include <silcstack.h>
208 #include <silcmemory.h>
209 #include <silclist.h>
210 #include <silcdlist.h>
211 #include <silctree.h>
212 #include <silcsnprintf.h>
213 #include <silctime.h>
214 #include <silctimer.h>
215 #include <silccond.h>
216 #include <silcglobal.h>
217 #include <silcthread.h>
218 #include <silcthreadqueue.h>
219 #include <silcschedule.h>
220 #include <silclog.h>
221 #include <silcfileutil.h>
222 #include <silcdir.h>
223 #include <silcbuffer.h>
224 #include <silcbuffmt.h>
225 #include <silcasync.h>
226 #include <silcregex.h>
227 #include <silcenv.h>
228 #include <silcdll.h>
229 #include <silchashtable.h>
230 #include <silcstream.h>
231 #include <silcnet.h>
232 #include <silcbase64.h>
233 #include <silcstrutil.h>
234 #include <silcutf8.h>
235 #include <silcstringprep.h>
236 #include <silcutil.h>
237 #include <silcconfig.h>
238 #include <silcfsm.h>
239 #include <silcsocketstream.h>
240 #include <silcfdstream.h>
241 #include <silcmime.h>
242 #include <silcrand.h>
243 #include <silcbufferstream.h>
244 #include <silclocalnetstream.h>
245 #include <silcxml.h>
246 #include <silchttpserver.h>
247 #include <silchttpphp.h>
248
249 /* Runtime Toolkit API */
250
251 /****f* silcutil/silc_runtime_init
252  *
253  * SYNOPSIS
254  *
255  *    static inline void silc_runtime_init(void)
256  *
257  * DESCRIPTION
258  *
259  *    Initializes the Runtime Toolkit.  Application should call this as the
260  *    very first call to the Runtime Toolkit.  The function initializes some
261  *    of the Toolkit features.
262  *
263  ***/
264 static inline
265 void silc_runtime_init(void)
266 {
267   /* For now we don't have much here.  Strictly speaking, calling this
268      currently isn't required.  But in the future we may have something that
269      really must be initialized at the very start.  Even the Tls doesn't
270      actually require initialization since any routine using Tls currently
271      takes care of that. */
272
273   /* Initialize Tls for this thread (probably main process thread). */
274   silc_thread_tls_init();
275 }
276
277 /****f* silcutil/silc_runtime_uninit
278  *
279  * SYNOPSIS
280  *
281  *    static inline void silc_runtime_uninit(void)
282  *
283  * DESCRIPTION
284  *
285  *    Uninitializes the Runtime Toolkit.  Application should call this as the
286  *    very last call to the Runtime Toolkit.  The function uninitializes and
287  *    frees all allocated resources.
288  *
289  ***/
290 static inline
291 void silc_runtime_uninit(void)
292 {
293   /* Uninitialize the whole Tls system (not just one thread). */
294   silc_thread_tls_uninit();
295 }
296
297 #ifdef __cplusplus
298 }
299 #endif
300
301 #endif /* SILCRUNTIME_H */