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"
79 /********************************** Defines ***********************************/
85 #if BLD_FEATURE_SQUEEZE
87 * Reasonable length of a file path name to use in most cases where you know
88 * the expected file name and it is certain to be less than this limit.
90 #define MPR_MAX_FNAME 128
91 #define MPR_MAX_STRING 512
92 #define MPR_DEFAULT_HASH_SIZE 23 /* Default size of hash table index */
93 #define MPR_MAX_HEAP_SIZE (32 * 1024)
95 #define MPR_MAX_FNAME 256
96 #define MPR_MAX_STRING 4096
97 #define MPR_DEFAULT_HASH_SIZE 43 /* Default size of hash table index */
98 #define MPR_MAX_HEAP_SIZE (64 * 1024)
102 * Useful for debugging
104 #define MPR_L __FILE__, __LINE__
106 #if BLD_FEATURE_ASSERT
107 #define mprAssert(C) \
108 if (C) ; else mprBreakpoint(__FILE__, __LINE__, #C)
110 #define mprAssert(C) if (1) ; else
114 * Standard MPR return and error codes
116 #define MPR_ERR_BASE (-200) /* Error code */
117 #define MPR_ERR_GENERAL (MPR_ERR_BASE - 1) /* Error code */
118 #define MPR_ERR_ABORTED (MPR_ERR_BASE - 2) /* Error code */
119 #define MPR_ERR_ALREADY_EXISTS (MPR_ERR_BASE - 3) /* Error code */
120 #define MPR_ERR_BAD_ARGS (MPR_ERR_BASE - 4) /* Error code */
121 #define MPR_ERR_BAD_FORMAT (MPR_ERR_BASE - 5) /* Error code */
122 #define MPR_ERR_BAD_HANDLE (MPR_ERR_BASE - 6) /* Error code */
123 #define MPR_ERR_BAD_STATE (MPR_ERR_BASE - 7) /* Error code */
124 #define MPR_ERR_BAD_SYNTAX (MPR_ERR_BASE - 8) /* Error code */
125 #define MPR_ERR_BAD_TYPE (MPR_ERR_BASE - 9) /* Error code */
126 #define MPR_ERR_BAD_VALUE (MPR_ERR_BASE - 10) /* Error code */
127 #define MPR_ERR_BUSY (MPR_ERR_BASE - 11) /* Error code */
128 #define MPR_ERR_CANT_ACCESS (MPR_ERR_BASE - 12) /* Error code */
129 #define MPR_ERR_CANT_COMPLETE (MPR_ERR_BASE - 13) /* Error code */
130 #define MPR_ERR_CANT_CREATE (MPR_ERR_BASE - 14) /* Error code */
131 #define MPR_ERR_CANT_INITIALIZE (MPR_ERR_BASE - 15) /* Error code */
132 #define MPR_ERR_CANT_OPEN (MPR_ERR_BASE - 16) /* Error code */
133 #define MPR_ERR_CANT_READ (MPR_ERR_BASE - 17) /* Error code */
134 #define MPR_ERR_CANT_WRITE (MPR_ERR_BASE - 18) /* Error code */
135 #define MPR_ERR_DELETED (MPR_ERR_BASE - 19) /* Error code */
136 #define MPR_ERR_NETWORK (MPR_ERR_BASE - 20) /* Error code */
137 #define MPR_ERR_NOT_FOUND (MPR_ERR_BASE - 21) /* Error code */
138 #define MPR_ERR_NOT_INITIALIZED (MPR_ERR_BASE - 22) /* Error code */
139 #define MPR_ERR_NOT_READY (MPR_ERR_BASE - 23) /* Error code */
140 #define MPR_ERR_READ_ONLY (MPR_ERR_BASE - 24) /* Error code */
141 #define MPR_ERR_TIMEOUT (MPR_ERR_BASE - 25) /* Error code */
142 #define MPR_ERR_TOO_MANY (MPR_ERR_BASE - 26) /* Error code */
143 #define MPR_ERR_WONT_FIT (MPR_ERR_BASE - 27) /* Error code */
144 #define MPR_ERR_WOULD_BLOCK (MPR_ERR_BASE - 28) /* Error code */
145 #define MPR_ERR_CANT_ALLOCATE (MPR_ERR_BASE - 29) /* Error code */
146 #define MPR_ERR_MAX (MPR_ERR_BASE - 30) /* Error code */
149 * Standard error severity and trace levels. These are ored with the error
150 * severities below. The MPR_LOG_MASK is used to extract the trace level
151 * from a flags word. We expect most apps to run with level 2 trace.
153 #define MPR_FATAL 0 /* Fatal error. Cant continue. */
154 #define MPR_ERROR 1 /* Hard error */
155 #define MPR_WARN 2 /* Soft warning */
156 #define MPR_CONFIG 2 /* Essential configuration settings */
157 #define MPR_INFO 3 /* Informational only */
158 #define MPR_DEBUG 4 /* Debug information */
159 #define MPR_VERBOSE 9 /* Highest level of trace */
160 #define MPR_LOG_MASK 0xf /* Level mask */
163 * Error flags. Specify where the error should be sent to. Note that the
164 * product.xml setting "headless" will modify how errors are reported.
165 * Assert errors are trapped when in DEV mode. Otherwise ignored.
167 #define MPR_TRAP 0x10 /* Assert error -- trap in debugger */
168 #define MPR_LOG 0x20 /* Log the error in the O/S event log */
169 #define MPR_USER 0x40 /* Display to the user */
170 #define MPR_ALERT 0x80 /* Send a management alert */
171 #define MPR_TRACE 0x100 /* Trace */
176 #define MPR_RAW 0x200 /* Raw trace output */
179 * Error line number information
181 #define MPR_L __FILE__, __LINE__
183 typedef char* MprStr;
186 typedef unsigned char uchar;
191 * Porters: put other operating system type defines here
194 typedef unsigned int uint;
195 typedef __int64 int64;
196 typedef unsigned __int64 uint64;
200 #define uint unsigned
202 __extension__ typedef long long int int64;
203 __extension__ typedef unsigned long long int uint64;
207 * Flexible array data type
210 int max; /* Size of the handles array */
211 int used; /* Count of used entries in handles */
215 #if BLD_FEATURE_SQUEEZE
216 #define MPR_ARRAY_INCR 8
218 #define MPR_ARRAY_INCR 16
222 #define max(a,b) (((a) > (b)) ? (a) : (b))
225 /********************************* Prototypes *********************************/
227 * If running in the GoAhead WebServer, map some MPR routines to WebServer
231 #if BLD_GOAHEAD_WEBSERVER
233 #define mprMalloc(size) balloc(B_L, size)
234 #define mprFree(ptr) bfreeSafe(B_L, ptr)
235 #define mprRealloc(ptr, size) brealloc(B_L, ptr, size)
236 #define mprStrdup(ptr) bstrdup(B_L, ptr)
237 #define mprAllocSprintf fmtAlloc
238 #define mprAllocVsprintf fmtValloc
239 #define mprSprintf fmtStatic
240 #define mprItoa stritoa
242 #define mprBreakpoint(file, line, cond) \
243 error(file, line, E_BLD_FEATURE_ASSERT, T("%s"), cond)
245 #else /* !BLD_GOAHEAD_WEBSERVER */
246 /* #define mprMalloc malloc */
247 #define mprSprintf snprintf
248 #define mtVsprintf vsnprintf
249 extern void *mprMalloc(uint size);
250 extern void *mprRealloc(void *ptr, uint size);
251 extern void mprFree(void *ptr);
252 extern char *mprStrdup(const char *str);
253 extern int mprAllocVsprintf(char **msgbuf, int maxSize, const char *fmt,
254 va_list args) PRINTF_ATTRIBUTE(3,0);
255 extern int mprAllocSprintf(char **msgbuf, int maxSize, const char *fmt, ...) PRINTF_ATTRIBUTE(3,4);
256 extern char *mprItoa(int num, char *buf, int width);
257 extern void mprLog(int level, const char *fmt, ...) PRINTF_ATTRIBUTE(2,3);
258 extern void mprBreakpoint(const char *file, int line, const char *msg);
259 #endif /* BLD_GOAHEAD_WEBSERVER */
261 extern MprArray *mprCreateArray(void);
262 extern void mprDestroyArray(MprArray *array);
263 extern int mprAddToArray(MprArray *array, void *item);
264 extern int mprRemoveFromArray(MprArray *array, int idx);
265 extern char *mprStrTok(char *str, const char *delim, char **tok);
267 extern int mprGetDirName(char *buf, int bufsize, char *path);
268 extern int mprReallocStrcat(char **dest, int max, int existingLen,
269 const char *delim, const char *src, ...);
270 extern int mprStrcpy(char *dest, int destMax, const char *src);
271 extern int mprMemcpy(char *dest, int destMax, const char *src, int nbytes);
273 extern void mprSetCtx(void *ctx);
274 extern void *mprMemCtx(void);
279 #endif /* !BLD_APPWEB */
280 #endif /* _h_MINI_MPR */
282 /*****************************************************************************/
290 * vim600: sw=4 ts=4 fdm=marker