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

📄 distnamelib.c

📁 VXWORKS源代码
💻 C
📖 第 1 页 / 共 4 页
字号:
/* distNameLib.c - distributed name database library (VxFusion option) *//* Copyright 1999-2002 Wind River Systems, Inc. *//*modification history--------------------01r,05dec01,jws  no ARM cross endian FP support (SPR 70116 final)01q,06nov01,jws  move tmp declaration01p,22oct01,jws  eliminate compiler warnings (SPR 71117)                 man pages update (SPR 71239)01o,15oct01,jws  merge ARM FP format handling back from AE (SPR 70116 prelim)01n,24may99,drm  added vxfusion prefix to VxFusion related includes01m,23feb99,wlf  doc edits01l,18feb99,wlf  doc cleanup01k,13feb99,drm  Added two routines for flipping bytes of UINT64/double01j,12feb99,drm  Fixed a bug in DistNameMatchOne to fix SPR #2500201i,28oct98,drm  documentation modifications01h,11sep98,drm  added #include to pick up distPanic()01g,13may98,ur   some cleanup, when distNameInit() fails01f,08may98,ur   removed 8 bit node id restriction01e,15apr98,ur   distNameRemove() returns node to free list01d,15apr98,ur   name database update returns OK, even if broadcast failed01c,30mar98,ur   added some more errnos;				 changed VALUE_TOO_LONG to ILLEGAL_LENGTH.01b,27jun97,ur   tested - ok.01a,06jun97,ur   written.*//*DESCRIPTIONThis library contains the distributed objects distributed name database androutines for manipulating it.  Symbolic names are bound to values, such asmessage queue identifiers or simple integers. Entries can be found by nameor by value and type.  The distributed name database is replicatedthroughout the system, with a copy sitting on each node.The distributed name database library is initialized by callingdistInit() in distLib.AVAILABILITYThis module is distributed as a component of the unbundled distributedmessage queues option, VxFusion.INCLUDE FILES: distNameLib.hSEE ALSO: distLib, distNameShow*/#include "vxWorks.h"#if defined (DIST_NAME_REPORT) || defined (DIST_DIAGNOSTIC)#include "stdio.h"#endif#include "stdlib.h"#include "string.h"#include "semLib.h"#include "private/semLibP.h"#include "sllLib.h"#include "hashLib.h"#include "msgQLib.h"#include "errnoLib.h"#include "netinet/in.h"#include "vxfusion/msgQDistLib.h"#include "vxfusion/distNameLib.h"#include "vxfusion/distIfLib.h"#include "vxfusion/distStatLib.h"#include "vxfusion/private/distLibP.h"#include "vxfusion/private/distObjLibP.h"#include "vxfusion/private/msgQDistLibP.h"#include "vxfusion/private/distTBufLibP.h"#include "vxfusion/private/distNetLibP.h"#include "vxfusion/private/distPktLibP.h"#include "vxfusion/private/distNameLibP.h"/* defines */#define UNUSED_ARG(x)  if(sizeof(x)) {} /* to suppress compiler warnings */#define XFLOAT 0     /* no ARM cross-endian support for VxWorks 5.x */#define KEY_ARG			65537	/* seed for hash function */#define KEY_CMP_ARG		0	/* not used *//* locals */LOCAL HASH_ID			distNameDbId;LOCAL SEMAPHORE			distNameDbLock;LOCAL SEMAPHORE			distNameDbUpdate;LOCAL SL_LIST			distNameFreeList;LOCAL BOOL			distNameLibInstalled = FALSE;/* local prototypes */LOCAL STATUS		distNameLclAdd (char *name, int nameLen, void *value,					int valueLen, DIST_NAME_TYPE type);LOCAL DIST_NAME_DB_NODE	* distNameLclAddRaw (char *name, int nameLen,			  		     void *value, int valueLen,					     DIST_NAME_TYPE type);LOCAL STATUS		distNameRmtAdd (DIST_NODE_ID nodeId, char *name,					int nameLen, void *value,					int valueLen,					DIST_NAME_TYPE type);LOCAL STATUS		distNameLclRemove (char *name, int nameLen);LOCAL int		distNameHFunc (int elements,                                       DIST_NAME_DB_NODE *pHNode,				       int seed);LOCAL BOOL		distNameHCmp (DIST_NAME_DB_NODE *pMatchHNode,				      DIST_NAME_DB_NODE *pHNode,				      int keyCmpArg);LOCAL DIST_STATUS	distNameInput (DIST_NODE_ID nodeIdSrc,				       DIST_TBUF_HDR *pTBufHdr);LOCAL BOOL		distNameMatchOne (DIST_NAME_DB_NODE *pNode,					  DIST_NAME_MATCH *pMatch);LOCAL BOOL		distNameBurstOne (DIST_NAME_DB_NODE *pNode,					  DIST_NAME_BURST *pBurst);LOCAL uint32_t * distHton64 (uint32_t* hostValue, DIST_NAME_TYPE type);LOCAL uint32_t * distNtoh64 (uint32_t* networkValue, DIST_NAME_TYPE type);/***************************************************************************** distNameLibInit - initialize the distributed name database package (VxFusion option)** Initialize the distributed name database package.  This routine currently* does nothing.** AVAILABILITY* This routine is distributed as a component of the unbundled distributed* message queues option, VxFusion.** RETURNS: N/A** NOMANUAL*/void distNameLibInit (void)    {    }/***************************************************************************** distNameInit - initialize the distributed name database (VxFusion option)** This routine allocates space for the distributed name database and* initializes it. The database has 2^<sizeLog2> nodes.** NOTE: This routine is called by distInit(). If you use distInit() to* initialize a node, you need not call distNameInit().** AVAILABILITY* This routine is distributed as a component of the unbundled distributed* message queues option, VxFusion.** RETURNS: OK, if nodes successfully initialized.** SEE ALSO: distLib** NOMANUAL*/STATUS distNameInit    (    int sizeLog2        /* init 2^sizeLog2 elements */    )    {    DIST_NAME_DB_NODE *   nameDb;    STATUS                status;    int                   hashTblSizeLog2;    int                   nameDbNBytes;    int                   nameDbSize;    int                   ix;    if (sizeLog2 < 1)        return (ERROR);    if (distNameLibInstalled == TRUE)        return (OK);    if (hashLibInit () == ERROR)    /* hashLibInit() failed */        return (ERROR);    semBInit (&distNameDbLock, SEM_Q_PRIORITY, SEM_EMPTY);    semBInit (&distNameDbUpdate, SEM_Q_PRIORITY, SEM_EMPTY);    hashTblSizeLog2 = sizeLog2 - 1;    distNameDbId = hashTblCreate (hashTblSizeLog2, distNameHCmp,                                  distNameHFunc, KEY_ARG);    if (distNameDbId == NULL)   /* hashTblCreate() failed */        return (ERROR);    nameDbSize = 1 << sizeLog2;    nameDbNBytes = nameDbSize * sizeof (DIST_NAME_DB_NODE);    nameDb = (DIST_NAME_DB_NODE *) malloc (nameDbNBytes);    if (nameDb == NULL)        {        distStat.memShortage++;         /* out of memory */        hashTblDelete (distNameDbId);   /* delete the hash table */        return (ERROR);                 /* init failed */        }    sllInit (&distNameFreeList);    for (ix = 0; ix < nameDbSize; ix++)        sllPutAtHead (&distNameFreeList, (SL_NODE *) &nameDb[ix]);    /* we are open for requests now */    semGive (&distNameDbLock);    /*     * Add GAP service to table of services.     */    status = distNetServAdd (DIST_PKT_TYPE_DNDB, distNameInput,                             DIST_DNDB_SERV_NAME, DIST_DNDB_SERV_NET_PRIO,                             DIST_DNDB_SERV_TASK_PRIO,                             DIST_DNDB_SERV_TASK_STACK_SZ);    if (status == ERROR)        {        free (nameDb);                 /* free database memory */        hashTblDelete (distNameDbId);  /* delete the hash table */        return (ERROR);                /* init failed */        }    distNameLibInstalled = TRUE;    return (OK);    }/***************************************************************************** distNameAdd - add an entry to the distributed name database (VxFusion option)** This routine adds the name of a specified object, along with its type and * value, to the distributed objects distributed name database. All copies of * the distributed name database within the system are updated.* * The <name> parameter is an arbitrary, null-terminated string with a* maximum of 20 characters, including the null terminator.** The value associated with <name> is located at <value> and is of length* <valueLen>, currently limited to 8 bytes.** By convention, <type> values of less than 0x1000 are reserved by VxWorks;* all other values are user definable.  The following types are pre-defined* in distNameLib.h :** \ts* Type Name | Value | Datum* ----------|------------|------*     T_DIST_MSG_Q |  =  0 | distributed message queue *     T_DIST_NODE | = 16 | node ID*     T_DIST_UINT8 | = 64 | 8-bit unsigned integer*     T_DIST_UINT16 | = 65 | 16-bit unsigned integer*     T_DIST_UINT32 | = 66 | 32-bit unsigned integer*     T_DIST_UINT64 | = 67 | 64-bit unsigned integer*     T_DIST_FLOAT | = 68 | float (32-bit)*     T_DIST_DOUBLE | = 69 | double (64-bit)* \te** The byte-order of pre-defined types is preserved in a* byte-order-heterogeneous network.** The value (and type!) bound to a symbolic name can be changed by calling* distNameAdd() with a new value (and type).** This routine returns OK, even if some nodes on the system do not* respond to the add request broadcast. A node that does not acknowledge* a transmission is assumed to have crashed. You can use the distCtl() routine* in distLib to set a routine to be called in the event that a node crashes.** NOTE:* If you add a distributed object ID (T_DIST_MSG_Q) to the database,* another reference to the object is built. This reference is stored* in the database. After the return of distNameAdd(), <value> holds the* reference (a new object ID). Use the ID returned by* distNameAdd() each time you want to address the global object bound* to <name>. Subsequent updates of the binding in the database are* transparent. The original object ID specifies exactly the* locally created object.** AVAILABILITY* This routine is distributed as a component of the unbundled distributed* message queues option, VxFusion.** RETURNS: OK, or ERROR if the operation fails.** ERRNO:* \is* \i S_distNameLib_NAME_TOO_LONG* The name being added to the database is too long.* \i S_distNameLib_ILLEGAL_LENGTH* The argument <valueLen> is not in the range 1 to 8.* \i S_distNameLib_DATABASE_FULL* The database is full.* \i S_distNameLib_INCORRECT_LENGTH* The argument <valueLen> is incorrect for the pre-defined <type>.* \ie** SEE ALSO: distLib*/STATUS distNameAdd    (    char *          name,       /* name to enter in database  */    void *          value,      /* ptr to value to associate with name */    int             valueLen,   /* size of value in bytes     */    DIST_NAME_TYPE  type        /* type associated with name  */    )    {    int        nameLen;#ifdef DIST_DIAGNOSTIC    STATUS    status;#endif    if ((nameLen = strlen (name)) > DIST_NAME_MAX_LENGTH)        {        errnoSet (S_distNameLib_NAME_TOO_LONG);        return (ERROR);    /* name too long */        }    if (valueLen <= 0 || valueLen > DIST_VALUE_MAX_LENGTH)        {        errnoSet (S_distNameLib_ILLEGAL_LENGTH);        return (ERROR);    /* size of value out of range */        }    switch (type)        {        case T_DIST_UINT8:            if (valueLen != 1)                {                errnoSet (S_distNameLib_INCORRECT_LENGTH);                return (ERROR);                }            break;        case T_DIST_UINT16:            if (valueLen != 2)                {                errnoSet (S_distNameLib_INCORRECT_LENGTH);                return (ERROR);                }            break;        case T_DIST_FLOAT:        case T_DIST_UINT32:        case T_DIST_NODE:            if (valueLen != 4)                {                errnoSet (S_distNameLib_INCORRECT_LENGTH);                return (ERROR);                }            break;        case T_DIST_UINT64:        case T_DIST_DOUBLE:            if (valueLen != 8)                {                errnoSet (S_distNameLib_INCORRECT_LENGTH);                return (ERROR);                }        /* case T_DIST_MSG_Q: no checking for complex object type */        }    /* Local name database update. */    if (distNameLclAdd (name, nameLen, value, valueLen, type) == ERROR)        {#ifdef DIST_DIAGNOSTIC        distLog ("distNameAdd: error updating local name database\n");#endif        errnoSet (S_distNameLib_DATABASE_FULL);        return (ERROR);        }    /* Remote name database update. */#ifdef DIST_DIAGNOSTIC    status = distNameRmtAdd (DIST_IF_BROADCAST_ADDR, name, nameLen, value,                             valueLen, type);    if (status == ERROR)        {        /* Local node has binding--one of the remote nodes may not. */        distLog ("distNameAdd: error updating remote name databases\n");

⌨️ 快捷键说明

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