📄 mpr.h
字号:
/** * @overview File structure * @description MprFile is the cross platform File I/O abstraction control * structure. * @stability Prototype. * @library libmpr. * @see mprOpen, mprClose, mprRead, mprWrite */typedef struct MprFile{ MprBuf *buf; /* Buffer for I/O */#if BREW IFile *fd; /* File handle */#else int fd;#endif} MprFile;/** * File information structure * @overview File information structure * @description MprFileInfo is the cross platform File information structure. * @stability Prototype. * @see mprGetFileInfo, mprOpen, mprClose, mprRead, mprWrite */typedef struct MprFileInfo { uint size; /* File length */ uint ctime; /* Create time */ uint mtime; /* Modified time */ uint inode; /* Inode number */ int isDir; /* Set if directory */ int isReg; /* Set if a regular file */} MprFileInfo;/** * @overview Mpr time structure. * @description MprTime is the cross platform time abstraction structure. * @stability Prototype. * @library libmpr. * @see mprGetTime */typedef struct MprTime { uint sec; /* Seconds */ uint msec; /* Milliseconds */} MprTime;/** * @overview Generic array type * @description The MprArray is a dynamic growable array suitable for storing * pointers to arbitrary objects. * @stability Prototype. * @library libmpr. * @see mprCreateItemArray, mprFree, MprBuf */typedef struct MprArray { int capacity; /* Current capacity of the array */ int length; /* Count of used items */ int incr; /* Growth increment */ int maxSize; /* Maximum capacity */ void **items;} MprArray;#if BLD_FEATURE_MULTITHREAD/** * @overview Multithreading lock control structure * @description MprLock is used for multithread locking in multithreaded * applications. * @library libmpr. * @see mprCreateLock, mprDestroyLock, mprLock, mprUnlock */typedef struct { #if WIN CRITICAL_SECTION cs; /* O/S critical section */ #endif #if LINUX || MACOSX || SOLARIS pthread_mutex_t cs; /* O/S critical section */ #endif #if VXWORKS SEM_ID cs; /* Semaphore */ #endif} MprLock;#endif/* * Error and Logging callback */typedef void (*MprLogHandler)(MPR_LOC_DEC(ctx, loc), int flags, int level, const char *msg);/* * Symbol table * MOB -- rename hash */typedef struct MprSymbol{ struct MprSymbol *next; /* Next symbol in hash chain */ char *key; /* Symbol key */ void *data; /* Pointer to symbol data */ int bucket; /* Hash bucket index */} MprSymbol;typedef struct MprSymbolTable{ MprSymbol **buckets; int hashSize; /* Size of the buckets array */ int count; /* Number of symbols in the table */} MprSymbolTable;/* * Memory allocation error callback */struct MprApp;typedef int (*MprAllocCback)(struct MprApp *app, uint size, uint total, bool granted);/* * Slab block pointer links */typedef struct MprSlabBlock { struct MprSlabBlock *next;} MprSlabBlock;#if BLD_FEATURE_ALLOC_STATS/* * Memory Slab Statistics */typedef struct MprSlabStats { uint allocCount; /* Number of allocated blocks */ uint freeCount; /* Number of blocks on the slab freelist */ uint peakAllocCount; /* Peak allocated */ uint totalAllocCount; /* Total count of allocation calls */ uint peakFreeCount; /* Peak on the free list */ MprSlabBlock *next;} MprSlabStats;#endif/* * Slab control structure */typedef struct MprSlab { MprSlabBlock *next; uint preAllocateIncr; /* Pre-allocation increment */#if BLD_FEATURE_ALLOC_STATS MprSlabStats stats;#endif} MprSlab;/* * Allocation stats (kept even in production code so we can detect memory * allocation failures) */typedef struct MprAllocStats{ uint bytesAllocated; /* Bytes currently allocated */ uint peakAllocated; /* Peak bytes allocated */ uint allocCount; /* Number of allocated blocks */ uint redLine; /* Warn above this level */ uint maxMemory; /* Max memory to allocate */ uint errors; /* Allocation errors */} MprAllocStats;/* * Memory allocation control */typedef struct MprAlloc { MprSlab *slabs; /* Array[MPR_MAX_SLAB] of MprSlab */ MprAllocCback cback; /* Memory allocation callback */ MprAllocStats stats; /* Keep stats even in release */ int inAllocException; /* Recursive protect */} MprAlloc;/* * MprApp State Flags */#define MPR_APP_EXITING 0x1 /* App is exiting */#define MPR_APP_ALLOC_ERROR 0x2 /* App has allocation error *//* MOB -- temporary */#define MPR_APP_NEED_GC 0x4 /* App needs GC *//** * @overview Primary MPR application control structure * @description The MprApp structure stores critical application state * information and is the root memory allocation context block. It is * used as the MprCtx context for other memory allocations and is thus * the ultimate parent of all allocated memory. * \n\n * The MprApp structure is allocated by the mprInit API. */typedef struct MprApp { uint magic; /* Corruption protection */ MprFile *console; /* Stdout file */ bool debugMode; /* Run in debug mode (no timers) */ MprFile *error; /* Stderr file */ int logLevel; /* Log trace level */ MprFile *logFile; /* Log file */ MprLogHandler logHandler; /* Current log handler callback */ MprSymbolTable *table; char *name; /* Product name */ char *title; /* Product title */ char *version; /* Product version */#if BREW uint classId; /* Brew class ID */ IShell *shell; /* Brew shell object */ IDisplay *display; /* Brew display object */ IFileMgr *fileMgr; /* File manager */ ITAPI *tapi; /* TAPI object */ int displayHeight; /* Display height */ int displayWidth; /* Display width */ char *args; /* Command line args */#endif void *stackStart; /* Start of app stack */ uint maxStack; /* Max stack size recorded */ MprAlloc alloc; /* Memory allocation data */ int flags; /* App state flags */#if BLD_FEATURE_MULTITHREAD MprLock *globalLock; MprLock *allocLock;#endif} MprApp;/* * String type. Minimum size is 8 words (32 bytes). */#define MPR_MAX_INLINE_STR 24/* * The block header structure for all allocated memory blocks (32 bytes) * WARNING: Don't increase the size of this structure. It just fits into * 32 bytes currently. Alignment requirements will double this size if you * add one byte! */typedef struct MprBlk{ MprApp *app; /* app is the top level alloc context */ struct MprBlk *parent; /* Parent block */ struct MprBlk *children; /* First child block */ struct MprBlk *next; /* Next sibling */ struct MprBlk *prev; /* Previous sibling */ MprDestructor destructor; /* Destructor function (optional) */ uint size; /* Size of block sans HDR_SIZE */ uint flags; /* Allocation flags and magic number */#if BLD_FEATURE_ALLOC_LEAK_TRACK const char *location; /* Allocating code (file + line) */#endif} MprBlk;/******************************************************************************//****************************** Internal Prototypes ***************************//******************************************************************************/extern void mprSignalAllocError(MprCtx ctx);/******************************************************************************//********************************** Prototypes ********************************//******************************************************************************/extern MprApp *mprInit(MprAllocCback cback);extern MprApp *mprInitEx(MprAllocCback cback, void *shell);extern void mprTerm(MprApp *app, bool doStats);extern void mprSignalExit(MprCtx ctx);extern bool mprIsExiting(MprCtx ctx);extern bool mprHasAllocError(MprCtx ctx);#if BLD_DEBUG && UNUSEDextern MprApp *mprGetApp(MprCtx ctx);#else#define mprGetApp(ctx) \ (((MprBlk*) ((char*) ctx - MPR_BLK_HDR_SIZE))->app)#endif/******************************************************************************/extern int mprSetKeyValue(MprCtx ctx, const char *key, void *ptr);/* MOB -- should this be delete or remove or unset */extern int mprRemoveKeyValue(MprCtx ctx, const char *key);extern void *mprGetKeyValue(MprCtx ctx, const char *key);/* MOB -- should be setAppName, getAppName */extern int mprSetAppName(MprCtx ctx, const char *name, const char *title, const char *version);extern const char *mprGetAppName(MprCtx ctx);extern const char *mprGetAppTitle(MprCtx ctx);extern const char *mprGetAppVersion(MprCtx ctx);/* * File services */extern void mprStopFileServices(MprCtx ctx);extern int mprStartFileServices(MprCtx ctx);/* * Item Array */#define mprCreateItemArray(ctx, initialSize, maxSize) \ mprCreateItemArrayInternal(MPR_LOC_ARGS(ctx), initialSize, \ maxSize)extern MprArray *mprCreateItemArrayInternal(MPR_LOC_DEC(ctx, loc), int initialSize, int maxSize);/* MOB -- should be insert not add/delete or insert / remove */extern int mprAddItem(MprArray *array, void *item);extern void mprClearItems(MprArray *array);extern void mprClearAndFreeItems(MprArray *array);extern int mprFindItem(MprArray *array, void *item);extern void *mprGetFirstItem(MprArray *array, int *lastIndex);extern void *mprGetItem(MprArray *array, int index);extern int mprGetItemCapacity(MprArray *array);extern int mprGetItemCount(MprArray *array);extern void *mprGetNextItem(MprArray *array, int *lastIndex);extern void *mprGetPrevItem(MprArray *array, int *lastIndex);extern int mprRemoveItem(MprArray *array, void *item);extern int mprRemoveItemByIndex(MprArray *array, int index);extern int mprRemoveRangeOfItems(MprArray *array, int start, int end);/* * Printf replacements */extern int mprSprintf(char *buf, int maxSize, const char *fmt, ...) PRINTF_ATTRIBUTE(3,4);extern int mprVsprintf(char *buf, int maxSize, const char *fmt, va_list arg) PRINTF_ATTRIBUTE(3,0);extern char *mprItoa(char *buf, int size, int value);extern int mprAtoi(const char *str, int radix);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -