|
NCBI Home IEB Home C Toolkit docs C++ Toolkit source browser C Toolkit source browser (2) |
NCBI C Toolkit Cross ReferenceC/connect/ncbi_priv.h |
source navigation diff markup identifier search freetext search file search |
1 #ifndef CONNECT___NCBI_PRIV__H
2 #define CONNECT___NCBI_PRIV__H
3
4 /* $Id: ncbi_priv.h,v 6.48 2009/10/30 14:39:33 kazimird Exp $
5 * ===========================================================================
6 *
7 * PUBLIC DOMAIN NOTICE
8 * National Center for Biotechnology Information
9 *
10 * This software/database is a "United States Government Work" under the
11 * terms of the United States Copyright Act. It was written as part of
12 * the author's official duties as a United States Government employee and
13 * thus cannot be copyrighted. This software/database is freely available
14 * to the public for use. The National Library of Medicine and the U.S.
15 * Government have not placed any restriction on its use or reproduction.
16 *
17 * Although all reasonable efforts have been taken to ensure the accuracy
18 * and reliability of the software and data, the NLM and the U.S.
19 * Government do not and cannot warrant the performance or results that
20 * may be obtained by using this software or data. The NLM and the U.S.
21 * Government disclaim all warranties, express or implied, including
22 * warranties of performance, merchantability or fitness for any particular
23 * purpose.
24 *
25 * Please cite the author in any work or product based on this material.
26 *
27 * ===========================================================================
28 *
29 * Author: Denis Vakatov
30 *
31 * File Description:
32 * Private aux. code for the "ncbi_*.[ch]"
33 *
34 *********************************
35 * Random generator seeding support
36 * private global: g_NCBI_ConnectRandomSeed
37 * macro: NCBI_CONNECT_SRAND_ADDEND
38 * Critical section (basic multi-thread synchronization):
39 * private global: g_CORE_MT_Lock
40 * macros: CORE_LOCK_WRITE, CORE_LOCK_READ, CORE_UNLOCK
41 * Tracing and logging:
42 * private global: g_CORE_Log
43 * macros: CORE_LOG[F](), CORE_DATA[F](), CORE_LOG[F]_ERRNO[_EX]()
44 *
45 */
46
47 #include "ncbi_assert.h"
48 #include <connect/ncbi_util.h>
49
50
51 #ifdef __cplusplus
52 extern "C" {
53 #endif
54
55
56 /******************************************************************************
57 * Random generator seeding support
58 */
59
60 extern NCBI_XCONNECT_EXPORT int g_NCBI_ConnectRandomSeed;
61 extern NCBI_XCONNECT_EXPORT int g_NCBI_ConnectSrandAddend(void);
62 #define NCBI_CONNECT_SRAND_ADDEND g_NCBI_ConnectSrandAddend()
63
64
65 /******************************************************************************
66 * Multi-Thread SAFETY
67 */
68
69 /* Always use the following macros and functions to access "g_CORE_MT_Lock",
70 * dont access/change it directly!
71 */
72 extern NCBI_XCONNECT_EXPORT MT_LOCK g_CORE_MT_Lock;
73
74 #define CORE_LOCK_WRITE verify(MT_LOCK_Do(g_CORE_MT_Lock, eMT_Lock ))
75 #define CORE_LOCK_READ verify(MT_LOCK_Do(g_CORE_MT_Lock, eMT_LockRead))
76 #define CORE_UNLOCK verify(MT_LOCK_Do(g_CORE_MT_Lock, eMT_Unlock ))
77
78
79
80 /******************************************************************************
81 * ERROR HANDLING and LOGGING
82 */
83
84 /* Always use the following macros and functions to access "g_CORE_Log",
85 * dont access/change it directly!
86 */
87 extern NCBI_XCONNECT_EXPORT LOG g_CORE_Log;
88
89 extern NCBI_XCONNECT_EXPORT const char* g_CORE_Sprintf(const char* fmt, ...)
90 #ifdef __GNUC__
91 __attribute__((format(printf, 1, 2)))
92 #endif
93 ;
94
95 #define DO_CORE_LOG_X(_code, _subcode, _level, _message, _dynamic, \
96 _error, _descr, _raw_data, _raw_size) \
97 do { \
98 if (g_CORE_Log || (_level) == eLOG_Fatal) { \
99 SLOG_Handler _mess; \
100 _mess.dynamic = _dynamic; \
101 _mess.message = NcbiMessagePlusError(&_mess.dynamic, \
102 _message, \
103 _error, \
104 _descr); \
105 _mess.level = (_level); \
106 _mess.module = THIS_MODULE; \
107 _mess.file = THIS_FILE; \
108 _mess.line = __LINE__; \
109 _mess.raw_data = (_raw_data); \
110 _mess.raw_size = (_raw_size); \
111 _mess.err_code = (_code); \
112 _mess.err_subcode = (_subcode); \
113 CORE_LOCK_READ; \
114 LOG_WriteInternal(g_CORE_Log, &_mess); \
115 CORE_UNLOCK; \
116 } \
117 } while (0)
118
119
120 #define DO_CORE_LOG_WRITE(code, subcode, level, \
121 message, dynamic) \
122 DO_CORE_LOG_X(code, subcode, level, message, dynamic, 0, 0, 0, 0)
123
124 #define DO_CORE_LOG_DATA(code, subcode, level, data, size, \
125 message, dynamic) \
126 DO_CORE_LOG_X(code, subcode, level, message, dynamic, 0, 0, data, size)
127
128 #define DO_CORE_LOG_ERRNO(code, subcode, level, error, descr, \
129 message, dynamic) \
130 DO_CORE_LOG_X(code, subcode, level, message, dynamic, error, descr, 0, 0)
131
132 #define CORE_LOG_X(subcode, level, message) \
133 DO_CORE_LOG_WRITE(NCBI_C_ERRCODE_X, subcode, level, \
134 message, 0)
135
136 #define CORE_LOGF_X(subcode, level, fmt_args) \
137 DO_CORE_LOG_WRITE(NCBI_C_ERRCODE_X, subcode, level, \
138 g_CORE_Sprintf fmt_args, 1)
139
140 #define CORE_LOG(level, message) \
141 DO_CORE_LOG_WRITE(0, 0, level, \
142 message, 0)
143
144 #define CORE_LOGF(level, fmt_args) \
145 DO_CORE_LOG_WRITE(0, 0, level, \
146 g_CORE_Sprintf fmt_args, 1)
147
148 #ifdef _DEBUG
149 # define CORE_TRACE(message) CORE_LOG(eLOG_Trace, message)
150 # define CORE_TRACEF(fmt_args) CORE_LOGF(eLOG_Trace, fmt_args)
151 # define CORE_DEBUG_ARG(arg) arg
152 #else
153 # define CORE_TRACE(message) ((void) 0)
154 # define CORE_TRACEF(fmt_args) ((void) 0)
155 # define CORE_DEBUG_ARG(arg) /*arg*/
156 #endif /*_DEBUG*/
157
158 #define CORE_DATA_X(subcode, data, size, message) \
159 DO_CORE_LOG_DATA(NCBI_C_ERRCODE_X, subcode, eLOG_Trace, data, size, \
160 message, 0)
161
162 #define CORE_DATAF_X(subcode, data, size, fmt_args) \
163 DO_CORE_LOG_DATA(NCBI_C_ERRCODE_X, subcode, eLOG_Trace, data, size, \
164 g_CORE_Sprintf fmt_args, 1)
165
166 #define CORE_DATA_EXX(subcode, level, data, size, message) \
167 DO_CORE_LOG_DATA(NCBI_C_ERRCODE_X, subcode, level, data, size, \
168 message, 0)
169
170 #define CORE_DATAF_EXX(subcode, level, data, size, fmt_args) \
171 DO_CORE_LOG_DATA(NCBI_C_ERRCODE_X, subcode, level, data, size, \
172 g_CORE_Sprintf fmt_args, 1)
173
174 #define CORE_DATA(data, size, message) \
175 DO_CORE_LOG_DATA(0, 0, eLOG_Trace, data, size, \
176 message, 0)
177
178 #define CORE_DATAF(data, size, fmt_args) \
179 DO_CORE_LOG_DATA(0, 0, eLOG_Trace, data, size, \
180 g_CORE_Sprintf fmt_args, 1)
181
182 #define CORE_DATA_EX(level, data, size, message) \
183 DO_CORE_LOG_DATA(0, 0, level, data, size, \
184 message, 0)
185
186 #define CORE_DATAF_EX(level, data, size, fmt_args) \
187 DO_CORE_LOG_DATA(0, 0, level, data, size, \
188 g_CORE_Sprintf fmt_args, 1)
189
190 #define CORE_LOG_ERRNO_X(subcode, level, error, message) \
191 DO_CORE_LOG_ERRNO(NCBI_C_ERRCODE_X, subcode, level, error, 0, \
192 message, 0)
193
194 #define CORE_LOGF_ERRNO_X(subcode, level, error, fmt_args) \
195 DO_CORE_LOG_ERRNO(NCBI_C_ERRCODE_X, subcode, level, error, 0, \
196 g_CORE_Sprintf fmt_args, 1)
197
198 #define CORE_LOG_ERRNO_EXX(subcode, level, error, descr, message) \
199 DO_CORE_LOG_ERRNO(NCBI_C_ERRCODE_X, subcode, level, error, descr, \
200 message, 0)
201
202 #define CORE_LOGF_ERRNO_EXX(subcode, level, error, descr, fmt_args) \
203 DO_CORE_LOG_ERRNO(NCBI_C_ERRCODE_X, subcode, level, error, descr, \
204 g_CORE_Sprintf fmt_args, 1)
205
206 #define CORE_LOG_ERRNO(level, error, message) \
207 DO_CORE_LOG_ERRNO(0, 0, level, error, 0, \
208 message, 0)
209
210 #define CORE_LOGF_ERRNO(level, error, fmt_args) \
211 DO_CORE_LOG_ERRNO(0, 0, level, error, 0, \
212 g_CORE_Sprintf fmt_args, 1)
213
214 #define CORE_LOG_ERRNO_EX(level, error, descr, message) \
215 DO_CORE_LOG_ERRNO(0, 0, level, error, descr, \
216 message, 0)
217
218 #define CORE_LOGF_ERRNO_EX(level, error, descr, fmt_args) \
219 DO_CORE_LOG_ERRNO(0, 0, level, error, descr, \
220 g_CORE_Sprintf fmt_args, 1)
221
222
223 /******************************************************************************
224 * Error codes used throughout C-code
225 */
226
227 /* Here are only error codes used in C sources. For error codes used in
228 * C++ sources (in C++ Toolkit) see include/connect/error_codes.hpp.
229 */
230 NCBI_C_DEFINE_ERRCODE_X(Connect_Connection, 301, 32);
231 NCBI_C_DEFINE_ERRCODE_X(Connect_MetaConn, 302, 2);
232 NCBI_C_DEFINE_ERRCODE_X(Connect_Util, 303, 14);
233 NCBI_C_DEFINE_ERRCODE_X(Connect_Dispd, 304, 2);
234 NCBI_C_DEFINE_ERRCODE_X(Connect_FTP, 305, 2);
235 NCBI_C_DEFINE_ERRCODE_X(Connect_HeapMgr, 306, 33);
236 NCBI_C_DEFINE_ERRCODE_X(Connect_HTTP, 307, 20);
237 NCBI_C_DEFINE_ERRCODE_X(Connect_LB, 308, 0);
238 NCBI_C_DEFINE_ERRCODE_X(Connect_Sendmail, 309, 31);
239 NCBI_C_DEFINE_ERRCODE_X(Connect_Service, 310, 8);
240 NCBI_C_DEFINE_ERRCODE_X(Connect_Socket, 311, 144);
241 NCBI_C_DEFINE_ERRCODE_X(Connect_Crypt, 312, 6);
242 NCBI_C_DEFINE_ERRCODE_X(Connect_LocalNet, 313, 11);
243 NCBI_C_DEFINE_ERRCODE_X(Connect_Mghbn, 319, 16);
244 NCBI_C_DEFINE_ERRCODE_X(Connect_LBSM, 320, 23);
245 NCBI_C_DEFINE_ERRCODE_X(Connect_LBSMD, 321, 8);
246
247
248 /******************************************************************************
249 * REGISTRY
250 */
251
252 /* Always use the following macros and functions to access "g_CORE_Registry",
253 * dont access/change it directly!
254 */
255 extern NCBI_XCONNECT_EXPORT REG g_CORE_Registry;
256
257 #define CORE_REG_GET(section, name, value, value_size, def_value) \
258 g_CORE_RegistryGET(section, name, value, value_size, def_value)
259
260 #define CORE_REG_SET(section, name, value, storage) do { \
261 CORE_LOCK_READ; \
262 REG_Set(g_CORE_Registry, section, name, value, storage); \
263 CORE_UNLOCK; \
264 } while (0)
265
266
267 /* (private, to be used exclusively by the above macro CORE_REG_GET) */
268 extern NCBI_XCONNECT_EXPORT const char* g_CORE_RegistryGET
269 (const char* section,
270 const char* name,
271 char* value,
272 size_t value_size,
273 const char* def_value);
274
275
276 #ifdef __cplusplus
277 } /* extern "C" */
278 #endif
279
280 #endif /* CONNECT___NCBI_PRIV__H */
281 |
This page was automatically generated by the
LXR engine.
Visit the LXR main site for more information. |