80539dab865499185612f0082d516e24b606ff91
[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
56 /* Types */
57 #define SILC_SIZEOF_LONG_LONG @SILC_SIZEOF_LONG_LONG@
58 #define SILC_SIZEOF_LONG @SILC_SIZEOF_LONG@
59 #define SILC_SIZEOF_INT @SILC_SIZEOF_INT@
60 #define SILC_SIZEOF_SHORT @SILC_SIZEOF_SHORT@
61 #define SILC_SIZEOF_CHAR @SILC_SIZEOF_CHAR@
62 #define SILC_SIZEOF_VOID_P @SILC_SIZEOF_VOID_P@
63
64 /* Detect OS */
65 #define SILC_UNIX
66
67 #ifdef WIN32
68 #ifndef SILC_WIN32
69 #define SILC_WIN32
70 #undef SILC_UNIX
71 #endif
72 #endif
73
74 #if defined(__EPOC32__) || defined(__SYMBIAN32__)
75 #ifndef SILC_SYMBIAN
76 #define SILC_SYMBIAN
77 #undef SILC_UNIX
78 #undef SILC_WIN32
79 #endif
80 #endif
81
82 #if defined(__MACH__) && defined(__APPLE__)
83 #ifndef SILC_MACOSX
84 #define SILC_MACOSX
85 #undef SILC_WIN32
86 #undef SILC_SYMBIAN
87 #endif
88 #endif
89
90 #ifdef __cplusplus
91 extern "C" {
92 #endif
93
94 /* Platform specific includes */
95 #if defined(SILC_WIN32)
96 #include <silcwin32.h>
97 #endif
98
99 #if defined(SILC_SYMBIAN)
100 #include <silcsymbian.h>
101 #endif
102
103 #ifndef DLLAPI
104 #define DLLAPI
105 #endif
106
107 /* We except all systems to have these include files */
108 #include <stdio.h>
109 #include <stdlib.h>
110 #include <string.h>
111
112 #if defined(HAVE_RUNTIMEDEFS_H)
113
114 /* Automatically generated configuration header.  These are included only
115    when the SILC Runtime Toolkit itself is compiled. */
116 #ifndef SILC_SYMBIAN
117 #include "runtimedefs.h"
118 #else
119 #include "../../symbian/silcdefs.h"
120 #endif /* SILC_SYMBIAN */
121 #include "silcdistdefs.h"
122 #include "silccompile.h"
123
124 #else
125
126 /* Autodetect CPU so that inline assembly in headers are enabled */
127
128 #if defined(__i386__)
129 #undef SILC_I386
130 #undef SILC_I486
131 #define SILC_I386
132 #define SILC_I486
133 #endif /* __i386__ */
134
135 #if defined(__i486__)
136 #undef SILC_I386
137 #undef SILC_I486
138 #define SILC_I386
139 #define SILC_I486
140 #endif /* __i486__ */
141
142 #if defined(__i586__)
143 #undef SILC_I386
144 #undef SILC_I486
145 #undef SILC_I586
146 #define SILC_I386
147 #define SILC_I486
148 #define SILC_I586
149 #endif /* __i586__ */
150
151 #if defined(__i686__)
152 #undef SILC_I386
153 #undef SILC_I486
154 #undef SILC_I586
155 #undef SILC_I686
156 #define SILC_I386
157 #define SILC_I486
158 #define SILC_I586
159 #define SILC_I686
160 #endif /* __i686__ */
161
162 #if defined(__x86_64__)
163 #undef SILC_X86_64
164 #define SILC_X86_64
165 #endif /* __x86_64__ */
166
167 #if defined(__ia64__)
168 #undef SILC_IA64
169 #define SILC_IA64
170 #endif /* __ia64__ */
171
172 #if defined(__ppc__) || defined(__ppc64__)
173 #undef SILC_POWERPC
174 #define SILC_POWERPC
175 #endif /* __ppc__ || __ppc64__ */
176
177 #ifndef SILC_ALIGNMENT
178 #define SILC_ALIGNMENT SILC_SIZEOF_VOID_P
179 #endif /* SILC_ALIGNMENT */
180
181 #endif /* HAVE_RUNTIMEDEFS_H */
182
183 /* Feature defines */
184 #ifdef __SILC_HAVE_PTHREAD
185 #undef SILC_THREADS
186 #define SILC_THREADS 1
187 #endif /* __SILC_HAVE_PTHREAD */
188
189 #ifdef __SILC_ENABLE_DEBUG
190 #undef SILC_DEBUG
191 #define SILC_DEBUG 1
192 #endif /* __SILC_ENABLE_DEBUG */
193
194 #ifdef __SILC_ENABLE_STACKTRACE
195 #undef SILC_STACKTRACE
196 #define SILC_STACKTRACE 1
197 #endif /* __SILC_ENABLE_STACKTRACE */
198
199 /* SILC Runtime Toolkit includes */
200 #include <silcerrno.h>
201 #include <silctypes.h>
202 #include <silcbitops.h>
203 #include <silcmutex.h>
204 #include <silcatomic.h>
205 #include <silcgetopt.h>
206 #include <silcstack.h>
207 #include <silcmemory.h>
208 #include <silclist.h>
209 #include <silcdlist.h>
210 #include <silcsnprintf.h>
211 #include <silctime.h>
212 #include <silctimer.h>
213 #include <silccond.h>
214 #include <silcglobal.h>
215 #include <silcthread.h>
216 #include <silcthreadqueue.h>
217 #include <silcschedule.h>
218 #include <silclog.h>
219 #include <silcfileutil.h>
220 #include <silcdir.h>
221 #include <silcbuffer.h>
222 #include <silcbuffmt.h>
223 #include <silcasync.h>
224 #include <silcregex.h>
225 #include <silcenv.h>
226 #include <silcdll.h>
227 #include <silchashtable.h>
228 #include <silcstream.h>
229 #include <silcnet.h>
230 #include <silcbase64.h>
231 #include <silcstrutil.h>
232 #include <silcutf8.h>
233 #include <silcstringprep.h>
234 #include <silcutil.h>
235 #include <silcconfig.h>
236 #include <silcfsm.h>
237 #include <silcsocketstream.h>
238 #include <silcfdstream.h>
239 #include <silcmime.h>
240 #include <silcrand.h>
241
242 /* Runtime Toolkit API */
243
244 /****f* silcutil/silc_runtime_init
245  *
246  * SYNOPSIS
247  *
248  *    static inline void silc_runtime_init(void)
249  *
250  * DESCRIPTION
251  *
252  *    Initializes the Runtime Toolkit.  Application should call this as the
253  *    very first call to the Runtime Toolkit.  The function initializes some
254  *    of the Toolkit features.
255  *
256  ***/
257 static inline
258 void silc_runtime_init(void)
259 {
260   /* For now we don't have much here.  Strictly speaking, calling this
261      currently isn't required.  But in the future we may have something that
262      really must be initialized at the very start.  Even the Tls doesn't
263      actually require initialization since any routine using Tls currently
264      takes care of that. */
265
266   /* Initialize Tls for this thread (probably main process thread). */
267   silc_thread_tls_init();
268 }
269
270 /****f* silcutil/silc_runtime_uninit
271  *
272  * SYNOPSIS
273  *
274  *    static inline void silc_runtime_uninit(void)
275  *
276  * DESCRIPTION
277  *
278  *    Uninitializes the Runtime Toolkit.  Application should call this as the
279  *    very last call to the Runtime Toolkit.  The function uninitializes and
280  *    frees all allocated resources.
281  *
282  ***/
283 static inline
284 void silc_runtime_uninit(void)
285 {
286   /* Uninitialize the whole Tls system (not just one thread). */
287   silc_thread_tls_uninit();
288 }
289
290 #ifdef __cplusplus
291 }
292 #endif
293
294 #endif /* SILCRUNTIME_H */