📄 distnamelib.c
字号:
* NOTE: Before calling distNameLclAddRaw(), nameLen and valueLen* must been tested to prevent overflows.** AVAILABILITY* This routine is distributed as a component of the unbundled distributed* message queues option, VxFusion.** RETURNS: Pointer to added node, or NULL.** NOMANUAL*/LOCAL DIST_NAME_DB_NODE * distNameLclAddRaw ( char * name, /* name to enter in database */ int nameLen, /* length of name in bytes */ void * value, /* value associated with name */ int valueLen, /* size of value in bytes */ DIST_NAME_TYPE type /* type associated with name */ ) { DIST_NAME_DB_NODE * pDbNode; DIST_NAME_DB_NODE * pDbNodeOld; DIST_OBJ_NODE * pObjNode; char * nameDest; char * valDest;#ifdef DIST_NAME_REPORT printf ("distNameLclAddRaw: type %d, value: ", type); distDump (value, valueLen);#endif /* Get a free database node. */ if (! (pDbNode = (DIST_NAME_DB_NODE *) sllGet (&distNameFreeList))) return (NULL); /* database is full */ nameDest = (char *) &pDbNode->symName; bcopy (name, nameDest, nameLen); *(nameDest + nameLen) = 0; distNameLclLock(); /* Try to find symbolic name in database. */ pDbNodeOld = (DIST_NAME_DB_NODE *) hashTblFind (distNameDbId, (HASH_NODE *) pDbNode, KEY_CMP_ARG); if (pDbNodeOld) { /* Symbolic name is alreay in database. Update the node. */ sllPutAtHead (&distNameFreeList, (SL_NODE *) pDbNode); pDbNode = pDbNodeOld; if (type == T_DIST_MSG_Q) { /* New object is a distributed message queue. */ MSG_Q_ID msgQId; if (pDbNode->type == T_DIST_MSG_Q) { /* Old object is also a distributed message queue. */ msgQId = *((MSG_Q_ID *) &pDbNode->value); pObjNode = MSG_Q_ID_TO_DIST_OBJ_NODE (msgQId); } else { /* Old object was *NOT* a distributed message queue. */ pObjNode = distObjNodeGet(); pObjNode->objNodeType = DIST_OBJ_TYPE_MSG_Q; pDbNode->value.msgQId = DIST_OBJ_NODE_TO_MSG_Q_ID (pObjNode); } valDest = (char *) &(pObjNode->objNodeUniqId); } else valDest = (char *) &pDbNode->value; } else { /* Symbolic name is *NOT* in the database. */ if (type == T_DIST_MSG_Q) { pObjNode = distObjNodeGet(); pObjNode->objNodeType = DIST_OBJ_TYPE_MSG_Q; pDbNode->value.msgQId = DIST_OBJ_NODE_TO_MSG_Q_ID (pObjNode); valDest = (char *) &(pObjNode->objNodeUniqId); } else valDest = (char *) &pDbNode->value; } pDbNode->type = type; pDbNode->valueLen = valueLen; bcopy (value, valDest, valueLen); if (!pDbNodeOld) hashTblPut (distNameDbId, (HASH_NODE *) pDbNode); distNameLclUnlock(); /* signal a database update to waiting tasks */ distNameLclSigAdd(); return (pDbNode); }/***************************************************************************** distNameLclRemove - remove an object from the distributed database (VxFusion option)** This routines removes a name from the local name database.** AVAILABILITY* This routine is distributed as a component of the unbundled distributed* message queues option, VxFusion.** RETURNS: OK, or ERROR if name could not be removed.** NOMANUAL*/LOCAL STATUS distNameLclRemove ( char * name, /* name of object to remove */ int nameLen /* length of name without EOS */ ) { DIST_NAME_DB_NODE * pNode; DIST_NAME_DB_NODE matchNode; bcopy (name, (char *) &matchNode.symName, nameLen); *(((char *) &matchNode.symName) + nameLen) = '\0'; distNameLclLock(); pNode = (DIST_NAME_DB_NODE *) hashTblFind (distNameDbId, (HASH_NODE *) &matchNode, KEY_CMP_ARG); if (!pNode || hashTblRemove(distNameDbId, (HASH_NODE *) pNode) == ERROR) { distNameLclUnlock(); return (ERROR); } sllPutAtHead (&distNameFreeList, (SL_NODE *) pNode); /* return node */ distNameLclUnlock(); return (OK); }/***************************************************************************** distNameHCmp - compare keys based on strings (VxFusion option)** This is the hash compare function for names in the database.** AVAILABILITY* This routine is distributed as a component of the unbundled distributed* message queues option, VxFusion.** RETURNS: TRUE, if the names of the DB nodes are the same.** NOMANUAL*/LOCAL BOOL distNameHCmp ( DIST_NAME_DB_NODE * pMatchHNode, /* first node */ DIST_NAME_DB_NODE * pHNode, /* second node */ int keyCmpArg /* not used */ ) { UNUSED_ARG(keyCmpArg); if (strcmp ((char *)&pMatchHNode->symName, (char *)&pHNode->symName) == 0) return (TRUE); else return (FALSE); }/***************************************************************************** distNameHFunc - hashing function for strings (VxFusion option)** This is the hashing function for database object names.** AVAILABILITY* This routine is distributed as a component of the unbundled distributed* message queues option, VxFusion.** RETURNS: A hash index.** NOMANUAL*/LOCAL int distNameHFunc ( int elements, /* size of hash table */ DIST_NAME_DB_NODE * pHNode, /* node whose name to hash */ int seed /* hash seed */ ) { char *tkey; int hash = 0; /* Compute string signature (sparse 32-bit hash value) */ for (tkey = (char *) &pHNode->symName; *tkey != '\0'; tkey++) hash = hash * seed + (unsigned int) *tkey; return (hash & (elements - 1)); /* mask hash to (0, elements - 1) */ }/***************************************************************************** distNameEach - each functionality on name database (VxFusion option)** Successively visits every node in the database and invokes <routine>,* passing it argument <routineArg>.** NOTE: Takes <distNameDbLock>.** AVAILABILITY* This routine is distributed as a component of the unbundled distributed* message queues option, VxFusion.** RETURNS: Pointer to last node visited.** NOMANUAL*/DIST_NAME_DB_NODE * distNameEach ( FUNCPTR routine, /* routine to invoke */ int routineArg /* argument for routine */ ) { DIST_NAME_DB_NODE * lastNode; distNameLclLock(); lastNode = (DIST_NAME_DB_NODE *) hashTblEach (distNameDbId, routine, routineArg); distNameLclUnlock(); return (lastNode); }/***************************************************************************** distHton64 - convert a 64 bit value from host to network byte order (VxFusion option)** This routine converts T_DIST_UINT64 and T_DIST_DOUBLE* values from host to network* byte order. The value is converted in place.** AVAILABILITY* This routine is distributed as a component of the unbundled distributed* message queues option, VxFusion.** RETURNS: <hostValue>** NOMANUAL*/LOCAL uint32_t * distHton64 ( uint32_t * hostValue, /* ptr to value to convert */ DIST_NAME_TYPE type /* T_DIST_UINT64 or T_DIST_DOUBLE */ ) {#if _BYTE_ORDER==_LITTLE_ENDIAN uint32_t tmp;#endif#if !XFLOAT UNUSED_ARG(type);#endif#ifndef _BYTE_ORDER# error "no byte order specified !!"#endif#if _BYTE_ORDER==_LITTLE_ENDIAN# if XFLOAT /* ARM little-endian with double cross */ if (type == T_DIST_DOUBLE) { hostValue[0] = htonl(hostValue[0]); hostValue[1] = htonl(hostValue[1]); } else { tmp = hostValue[0]; hostValue[0] = htonl (hostValue[1]); hostValue[1] = htonl (tmp); }# else /* non-ARM little-endian */ tmp = hostValue[0]; hostValue[0] = htonl (hostValue[1]); hostValue[1] = htonl (tmp);# endif /* XFLOAT */#endif /* _BYTE_ORDER test */ return hostValue; }/***************************************************************************** distNtoh64 - convert a 64 bit value from network to host byte order (VxFusion option)** This routine converts T_DIST_UINT64 and T_DIST_DOUBLE values from* network to host byte order. The value is converted in place.** AVAILABILITY* This routine is distributed as a component of the unbundled distributed* message queues option, VxFusion.** RETURNS: <networkValue>** NOMANUAL*/LOCAL uint32_t * distNtoh64 ( uint32_t * networkValue, /* ptr to value to convert */ DIST_NAME_TYPE type /* T_DIST_UINT64 or T_DIST_DOUBLE */ ) {#if _BYTE_ORDER==_LITTLE_ENDIAN uint32_t tmp;#endif#if !XFLOAT UNUSED_ARG(type);#endif#ifndef _BYTE_ORDER# error "no byte order specified !!"#endif#if _BYTE_ORDER==_LITTLE_ENDIAN # if XFLOAT if (type == T_DIST_DOUBLE) { networkValue[0] = ntohl (networkValue[0]); networkValue[1] = ntohl (networkValue[1]); } else { tmp=networkValue[0]; networkValue[0] = ntohl (networkValue[1]); networkValue[1] = ntohl (tmp); }# else tmp=networkValue[0]; networkValue[0] = ntohl (networkValue[1]); networkValue[1] = ntohl (tmp);# endif /* XFLOAT */#endif /* _BYTE_ORDER test */ return networkValue; }
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -