3 * @brief Mini Mbedthis Portable Runtime (MPR) Environment.
6 * Copyright (c) Mbedthis Software LLC, 2003-2005. All Rights Reserved.
8 * This software is distributed under commercial and open source licenses.
9 * You may use the GPL open source license described below or you may acquire
10 * a commercial license from Mbedthis Software. You agree to be fully bound
11 * by the terms of either license. Consult the LICENSE.TXT distributed with
12 * this software for full details.
14 * This software is open source; you can redistribute it and/or modify it
15 * under the terms of the GNU General Public License as published by the
16 * Free Software Foundation; either version 2 of the License, or (at your
17 * option) any later version. See the GNU General Public License for more
18 * details at: http://www.mbedthis.com/downloads/gplLicense.html
20 * This program is distributed WITHOUT ANY WARRANTY; without even the
21 * implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
23 * This GPL license does NOT permit incorporating this software into
24 * proprietary programs. If you are unable to comply with the GPL, you must
25 * acquire a commercial license to use this software. Commercial licenses
26 * for this software and support services are available from Mbedthis
27 * Software at http://www.mbedthis.com
34 /********************************** Includes **********************************/
36 * Find out about our configuration
42 /* allow this library to use strcpy() */
48 * If building within AppWeb, use the full MPR
67 #include "CE/wincompat.h"
78 /********************************** Defines ***********************************/
84 #if BLD_FEATURE_SQUEEZE
86 /// Reasonable length of a file path name to use in most cases where you know
87 /// the expected file name and it is certain to be less than this limit.
89 #define MPR_MAX_FNAME 128
90 #define MPR_MAX_STRING 512
91 #define MPR_DEFAULT_HASH_SIZE 23 // Default size of hash table index
92 #define MPR_MAX_HEAP_SIZE (32 * 1024)
94 #define MPR_MAX_FNAME 256
95 #define MPR_MAX_STRING 4096
96 #define MPR_DEFAULT_HASH_SIZE 43 // Default size of hash table index
97 #define MPR_MAX_HEAP_SIZE (64 * 1024)
101 * Useful for debugging
103 #define MPR_L __FILE__, __LINE__
105 #if BLD_FEATURE_ASSERT
106 #define mprAssert(C) \
107 if (C) ; else mprBreakpoint(__FILE__, __LINE__, #C)
109 #define mprAssert(C) if (1) ; else
113 /// Standard MPR return and error codes
115 #define MPR_ERR_BASE (-200) ///< Error code
116 #define MPR_ERR_GENERAL (MPR_ERR_BASE - 1) ///< Error code
117 #define MPR_ERR_ABORTED (MPR_ERR_BASE - 2) ///< Error code
118 #define MPR_ERR_ALREADY_EXISTS (MPR_ERR_BASE - 3) ///< Error code
119 #define MPR_ERR_BAD_ARGS (MPR_ERR_BASE - 4) ///< Error code
120 #define MPR_ERR_BAD_FORMAT (MPR_ERR_BASE - 5) ///< Error code
121 #define MPR_ERR_BAD_HANDLE (MPR_ERR_BASE - 6) ///< Error code
122 #define MPR_ERR_BAD_STATE (MPR_ERR_BASE - 7) ///< Error code
123 #define MPR_ERR_BAD_SYNTAX (MPR_ERR_BASE - 8) ///< Error code
124 #define MPR_ERR_BAD_TYPE (MPR_ERR_BASE - 9) ///< Error code
125 #define MPR_ERR_BAD_VALUE (MPR_ERR_BASE - 10) ///< Error code
126 #define MPR_ERR_BUSY (MPR_ERR_BASE - 11) ///< Error code
127 #define MPR_ERR_CANT_ACCESS (MPR_ERR_BASE - 12) ///< Error code
128 #define MPR_ERR_CANT_COMPLETE (MPR_ERR_BASE - 13) ///< Error code
129 #define MPR_ERR_CANT_CREATE (MPR_ERR_BASE - 14) ///< Error code
130 #define MPR_ERR_CANT_INITIALIZE (MPR_ERR_BASE - 15) ///< Error code
131 #define MPR_ERR_CANT_OPEN (MPR_ERR_BASE - 16) ///< Error code
132 #define MPR_ERR_CANT_READ (MPR_ERR_BASE - 17) ///< Error code
133 #define MPR_ERR_CANT_WRITE (MPR_ERR_BASE - 18) ///< Error code
134 #define MPR_ERR_DELETED (MPR_ERR_BASE - 19) ///< Error code
135 #define MPR_ERR_NETWORK (MPR_ERR_BASE - 20) ///< Error code
136 #define MPR_ERR_NOT_FOUND (MPR_ERR_BASE - 21) ///< Error code
137 #define MPR_ERR_NOT_INITIALIZED (MPR_ERR_BASE - 22) ///< Error code
138 #define MPR_ERR_NOT_READY (MPR_ERR_BASE - 23) ///< Error code
139 #define MPR_ERR_READ_ONLY (MPR_ERR_BASE - 24) ///< Error code
140 #define MPR_ERR_TIMEOUT (MPR_ERR_BASE - 25) ///< Error code
141 #define MPR_ERR_TOO_MANY (MPR_ERR_BASE - 26) ///< Error code
142 #define MPR_ERR_WONT_FIT (MPR_ERR_BASE - 27) ///< Error code
143 #define MPR_ERR_WOULD_BLOCK (MPR_ERR_BASE - 28) ///< Error code
144 #define MPR_ERR_CANT_ALLOCATE (MPR_ERR_BASE - 29) ///< Error code
145 #define MPR_ERR_MAX (MPR_ERR_BASE - 30) ///< Error code
148 // Standard error severity and trace levels. These are ored with the error
149 // severities below. The MPR_LOG_MASK is used to extract the trace level
150 // from a flags word. We expect most apps to run with level 2 trace.
152 #define MPR_FATAL 0 ///< Fatal error. Cant continue.
153 #define MPR_ERROR 1 ///< Hard error
154 #define MPR_WARN 2 ///< Soft warning
155 #define MPR_CONFIG 2 ///< Essential configuration settings
156 #define MPR_INFO 3 ///< Informational only
157 #define MPR_DEBUG 4 ///< Debug information
158 #define MPR_VERBOSE 9 ///< Highest level of trace
159 #define MPR_LOG_MASK 0xf ///< Level mask
162 // Error flags. Specify where the error should be sent to. Note that the
163 // product.xml setting "headless" will modify how errors are reported.
164 // Assert errors are trapped when in DEV mode. Otherwise ignored.
166 #define MPR_TRAP 0x10 ///< Assert error -- trap in debugger
167 #define MPR_LOG 0x20 ///< Log the error in the O/S event log
168 #define MPR_USER 0x40 ///< Display to the user
169 #define MPR_ALERT 0x80 ///< Send a management alert
170 #define MPR_TRACE 0x100 ///< Trace
173 // Error format flags
175 #define MPR_RAW 0x200 // Raw trace output
178 // Error line number information
180 #define MPR_L __FILE__, __LINE__
182 typedef char* MprStr;
185 typedef unsigned char uchar;
190 * Porters: put other operating system type defines here
193 typedef unsigned int uint;
194 typedef __int64 int64;
195 typedef unsigned __int64 uint64;
199 #define uint unsigned
201 __extension__ typedef long long int int64;
202 __extension__ typedef unsigned long long int uint64;
206 * Flexible array data type
209 int max; /* Size of the handles array */
210 int used; /* Count of used entries in handles */
214 #if BLD_FEATURE_SQUEEZE
215 #define MPR_ARRAY_INCR 8
217 #define MPR_ARRAY_INCR 16
221 #define max(a,b) (((a) > (b)) ? (a) : (b))
224 /********************************* Prototypes *********************************/
226 * If running in the GoAhead WebServer, map some MPR routines to WebServer
230 #if BLD_GOAHEAD_WEBSERVER
232 #define mprMalloc(size) balloc(B_L, size)
233 #define mprFree(ptr) bfreeSafe(B_L, ptr)
234 #define mprRealloc(ptr, size) brealloc(B_L, ptr, size)
235 #define mprStrdup(ptr) bstrdup(B_L, ptr)
236 #define mprAllocSprintf fmtAlloc
237 #define mprAllocVsprintf fmtValloc
238 #define mprSprintf fmtStatic
239 #define mprItoa stritoa
241 #define mprBreakpoint(file, line, cond) \
242 error(file, line, E_BLD_FEATURE_ASSERT, T("%s"), cond)
244 #else /* !BLD_GOAHEAD_WEBSERVER */
245 //#define mprMalloc malloc
246 #define mprSprintf snprintf
247 #define mtVsprintf vsnprintf
248 extern void *mprMalloc(uint size);
249 extern void *mprRealloc(void *ptr, uint size);
250 extern void mprFree(void *ptr);
251 extern char *mprStrdup(const char *str);
252 extern int mprAllocVsprintf(char **msgbuf, int maxSize, const char *fmt,
253 va_list args) PRINTF_ATTRIBUTE(3,0);
254 extern int mprAllocSprintf(char **msgbuf, int maxSize, const char *fmt, ...) PRINTF_ATTRIBUTE(3,4);
255 extern char *mprItoa(int num, char *buf, int width);
256 extern void mprLog(int level, const char *fmt, ...) PRINTF_ATTRIBUTE(2,3);
257 extern void mprBreakpoint(const char *file, int line, const char *msg);
258 #endif /* BLD_GOAHEAD_WEBSERVER */
260 extern MprArray *mprCreateArray(void);
261 extern void mprDestroyArray(MprArray *array);
262 extern int mprAddToArray(MprArray *array, void *item);
263 extern int mprRemoveFromArray(MprArray *array, int idx);
264 extern char *mprStrTok(char *str, const char *delim, char **tok);
266 extern int mprGetDirName(char *buf, int bufsize, char *path);
267 extern int mprReallocStrcat(char **dest, int max, int existingLen,
268 const char *delim, const char *src, ...);
269 extern int mprStrcpy(char *dest, int destMax, const char *src);
270 extern int mprMemcpy(char *dest, int destMax, const char *src, int nbytes);
272 extern void mprSetCtx(void *ctx);
277 #endif /* !BLD_APPWEB */
278 #endif /* _h_MINI_MPR */
280 /*****************************************************************************/
288 * vim600: sw=4 ts=4 fdm=marker