⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 ncbi_core.h

📁 ncbi源码
💻 H
📖 第 1 页 / 共 2 页
字号:
/* * =========================================================================== * PRODUCTION $Log: ncbi_core.h,v $ * PRODUCTION Revision 1000.1  2004/04/12 17:05:51  gouriano * PRODUCTION PRODUCTION: UPGRADED [CATCHUP_003] Dev-tree R6.25 * PRODUCTION * =========================================================================== */#ifndef CONNECT___NCBI_CORE__H#define CONNECT___NCBI_CORE__H/*  $Id: ncbi_core.h,v 1000.1 2004/04/12 17:05:51 gouriano Exp $ * =========================================================================== * *                            PUBLIC DOMAIN NOTICE *               National Center for Biotechnology Information * *  This software/database is a "United States Government Work" under the *  terms of the United States Copyright Act.  It was written as part of *  the author's official duties as a United States Government employee and *  thus cannot be copyrighted.  This software/database is freely available *  to the public for use. The National Library of Medicine and the U.S. *  Government have not placed any restriction on its use or reproduction. * *  Although all reasonable efforts have been taken to ensure the accuracy *  and reliability of the software and data, the NLM and the U.S. *  Government do not and cannot warrant the performance or results that *  may be obtained by using this software or data. The NLM and the U.S. *  Government disclaim all warranties, express or implied, including *  warranties of performance, merchantability or fitness for any particular *  purpose. * *  Please cite the author in any work or product based on this material. * * =========================================================================== * * Author:  Denis Vakatov * * File Description: *   Types and code shared by all "ncbi_*.[ch]" modules. * ********************************* * I/O status and direction: *    enum:       EIO_ReadMethod *    enum:       EIO_WriteMethod *    enum:       EIO_Status,  verbal: IO_StatusStr() *    enum:       EIO_Event * * Critical section (basic multi-thread synchronization): *    handle:     MT_LOCK *    enum:       EMT_Lock *    callbacks:  (*FMT_LOCK_Handler)(),  (*FMT_LOCK_Cleanup)() *    methods:    MT_LOCK_Create(),  MT_LOCK_AddRef(),  MT_LOCK_Delete(), *                MT_LOCK_Do() * * Tracing and logging: *    handle:     LOG *    enum:       ELOG_Level,  verbal: LOG_LevelStr() *    flags:      TLOG_FormatFlags, ELOG_FormatFlags *    callbacks:  (*FLOG_Handler)(),  (*FLOG_Cleanup)() *    methods:    LOG_Create(),  LOG_Reset(),  LOG_AddRef(),  LOG_Delete(), *                LOG_WriteInternal() * * Registry: *    handle:     REG *    enum:       EREG_Storage *    callbacks:  (*FREG_Get)(),  (*FREG_Set)(),  (*FREG_Cleanup)() *    methods:    REG_Create(),  REG_Reset(),  REG_AddRef(),  REG_Delete(), *                REG_Get(),  REG_Set() * */#include <connect/ncbi_types.h>/* Run-time debugging */#if defined(verify)#undef verify#endif#if !defined(NDEBUG)  &&  !defined(_DEBUG)#  define NDEBUG#endif#include <assert.h>#if defined(NDEBUG)#  define verify(expr)  (void)(expr)#else/* The following 2 headers are actually only required for Codewarrior * on Mac to prototype printf() and abort() respectively :-/ */#  include <stdio.h>#  include <stdlib.h>#  define verify(expr)  assert(expr)#endif/** @addtogroup UtilityFunc * * @{ */#ifdef __cplusplusextern "C" {#endif/****************************************************************************** *  I/O *//* I/O read method */typedef enum {    eIO_ReadPlain, /* read presently available data only                     */    eIO_ReadPeek,  /* eIO_ReadPeek but dont discard the data from input queue*/    eIO_ReadPersist, /* try to read exactly "n" bytes; wait for enough data  */    /* deprecated */    eIO_Plain   = eIO_ReadPlain,    eIO_Peek    = eIO_ReadPeek,    eIO_Persist = eIO_ReadPersist} EIO_ReadMethod;/* I/O write method */typedef enum {    eIO_WritePlain,    eIO_WritePersist} EIO_WriteMethod;/* I/O event (or direction) * Note: Internally, these constants are used as bit-values, and thus should *       not be changed in this header. However, user code should not rely *       on the values of these constants. */typedef enum {    eIO_Open      = 0x0, /* also serves as no-event indicator in SOCK_Poll() */    eIO_Read      = 0x1,    eIO_Write     = 0x2,    eIO_ReadWrite = 0x3, /* eIO_Read | eIO_Write                             */    eIO_Close     = 0x4  /* also serves as error indicator in SOCK_Poll()    */} EIO_Event;/* I/O status */typedef enum {    eIO_Success = 0,  /* everything is fine, no errors occurred              */    eIO_Timeout,      /* timeout expired before the data could be i/o'd      */    eIO_Closed,       /* peer has closed the connection                      */    eIO_Interrupt,    /* signal received while the operation was in progress */    eIO_InvalidArg,   /* bad argument value(s)                               */    eIO_NotSupported, /* the requested operation is not supported            */    eIO_Unknown       /* unknown (most probably -- fatal) error              */} EIO_Status;/* Return verbal description of the I/O status */extern NCBI_XCONNECT_EXPORT const char* IO_StatusStr(EIO_Status status);/****************************************************************************** *  MT locking *//* Lock handle -- keeps all data needed for the locking and for the cleanup */struct MT_LOCK_tag;typedef struct MT_LOCK_tag* MT_LOCK;/* Set the lock/unlock callback function and its data for MT critical section. * TIP: If the RW-lock functionality is not provided by the callback, then: *   eMT_LockRead <==> eMT_Lock */typedef enum {    eMT_Lock,      /* lock    critical section             */    eMT_LockRead,  /* lock    critical section for reading */    eMT_Unlock     /* unlock  critical section             */} EMT_Lock;/* MT locking function (operates like Mutex or RW-lock) * Return non-zero value if the requested operation was successful. * NOTE:  the "-1" value is reserved for unset handler;  you also *   may want to return "-1" if your locking function does no locking, and *   you dont consider it as an error, but still want the caller to be *   aware of this "rightful non-doing" as opposed to the "rightful doing". */typedef int/*bool*/ (*FMT_LOCK_Handler)(void*    user_data,  /* see "user_data" in MT_LOCK_Create() */ EMT_Lock how         /* as passed to MT_LOCK_Do() */ );/* MT lock cleanup function;  see "MT_LOCK_Delete()" for more details */typedef void (*FMT_LOCK_Cleanup)(void* user_data  /* see "user_data" in MT_LOCK_Create() */ );/* Create new MT locking object (with reference counter := 1) */extern NCBI_XCONNECT_EXPORT MT_LOCK MT_LOCK_Create(void*            user_data, /* to call "handler" and "cleanup" with */ FMT_LOCK_Handler handler,   /* locking function */ FMT_LOCK_Cleanup cleanup    /* cleanup function */ );/* Increment ref.counter by 1,  then return "lk" */extern NCBI_XCONNECT_EXPORT MT_LOCK MT_LOCK_AddRef(MT_LOCK lk);/* Decrement ref.counter by 1. * Now, if ref.counter becomes 0, then * destroy the handle, call "lk->cleanup(lk->user_data)", and return NULL. * Otherwise (if ref.counter is still > 0), return "lk". */extern NCBI_XCONNECT_EXPORT MT_LOCK MT_LOCK_Delete(MT_LOCK lk);/* Call "lk->handler(lk->user_data, how)". * Return value returned by the lock handler ("handler" in MT_LOCK_Create()). * If lock handler is not specified then always return "-1". * NOTE:  use MT_LOCK_Do() to avoid overhead! */#define MT_LOCK_Do(lk,how)  (lk ? MT_LOCK_DoInternal(lk, how) : -1)extern NCBI_XCONNECT_EXPORT int/*bool*/ MT_LOCK_DoInternal(MT_LOCK  lk, EMT_Lock how );/****************************************************************************** *  ERROR HANDLING and LOGGING *//* Log handle -- keeps all data needed for the logging and for the cleanup */struct LOG_tag;typedef struct LOG_tag* LOG;/* Log severity level */typedef enum {    eLOG_Trace = 0,    eLOG_Note,    eLOG_Warning,    eLOG_Error,    eLOG_Critical,    eLOG_Fatal} ELOG_Level;/* Return verbal description of the log level */extern NCBI_XCONNECT_EXPORT const char* LOG_LevelStr(ELOG_Level level);/* Message and miscellaneous data to pass to the log post callback FLOG_Handler * For more details, see LOG_WriteInternal(). */typedef struct {    const char* message;   /* can be NULL */    ELOG_Level  level;    const char* module;    /* can be NULL */    const char* file;      /* can be NULL */    int         line;    const void* raw_data;  /* raw data to log (usually NULL)*/    size_t      raw_size;  /* size of the raw data (usually zero)*/} SLOG_Handler;/* Log post callback. */typedef void (*FLOG_Handler)(void*         user_data,  /* see "user_data" in LOG_Create() or LOG_Reset() */

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -