distNodeLibP.h
上传用户:nvosite88
上传日期:2007-01-17
资源大小:4983k
文件大小:7k
源码类别:

VxWorks

开发平台:

C/C++

  1. /* distNodeLibP - distributed objects node layer private header (VxFusion) */
  2. /* Copyright 1999 - 2001 Wind River Systems, Inc. */
  3. /*
  4. modification history
  5. --------------------
  6. 01e,04oct01,jws  final fixes for SPR 34770
  7. 01d,27sep01,p_r  Fixes for SPR#34770
  8. 01c,24may99,drm  added vxfusion to VxFusion related includes
  9. 01b,10nov98,drm  moved node-related control function codes to public .h file
  10. 01a,18jul97,ur   written.
  11. */
  12. #ifndef __INCdistNodeLibPh
  13. #define __INCdistNodeLibPh
  14. #ifdef __cplusplus
  15. extern "C" {
  16. #endif
  17. #include "vxWorks.h"
  18. #include "hashLib.h"
  19. #include "sysLib.h"
  20. #include "vxfusion/distNodeLib.h"
  21. #include "vxfusion/private/distTBufLibP.h"
  22. #include "private/semLibP.h"
  23. /* defines */
  24. /*
  25.  * Modification 01d changed wakeup interval from 500 ms to 100ms
  26.  * to allow better granularity in timeouts.  This is the
  27.  * vxWorks AE interval at the time of this writing.
  28.  */
  29.  
  30. #define DIST_NODE_MGR_WAKEUP_MSEC  100
  31. #define DIST_NODE_MGR_PRIO    10
  32. #define DIST_NODE_MGR_STACK_SZ    5000
  33. #define DIST_BOOTSTRAP_PRIO    0
  34. /*
  35.  * The following timeouts are in units of DIST_NODE_MGR_WAKEUP_MSEC.
  36.  */
  37.  
  38. #define DIST_NODE_RETRY_TIMEOUT    2 /* 2 times DIST_NODE_MGR_WAKEUP_MSEC */
  39. #define DIST_NODE_MAX_RETRIES    5 /* max retries before giving up */
  40. #define DIST_NODE_STATE_UNREACH    0x00
  41. #define DIST_NODE_STATE_ALIVE    0x80
  42. #define DIST_NODE_STATE_IS_ALIVE(state) 
  43. ((state) & DIST_NODE_STATE_ALIVE)
  44. #define DIST_NODE_IS_ALIVE(pNode) 
  45. (DIST_NODE_STATE_IS_ALIVE ((pNode)->nodeState))
  46. #define DIST_NODE_STATE_IS_ACTIVE(state) 
  47. ((state) >= DIST_NODE_STATE_NETWORK)
  48. #define DIST_NODE_STATE_IS_PASSIVE(state) 
  49. ((state) < DIST_NODE_STATE_NETWORK)
  50. #define DIST_NODE_STATE_CRASHED (1 | DIST_NODE_STATE_UNREACH)
  51. #define DIST_NODE_STATE_BOOT (1 | DIST_NODE_STATE_ALIVE)
  52. #define DIST_NODE_STATE_RESYNC (2 | DIST_NODE_STATE_ALIVE)
  53. #define DIST_NODE_STATE_NETWORK (3 | DIST_NODE_STATE_ALIVE)
  54. #define DIST_NODE_STATE_OPERATIONAL (4 | DIST_NODE_STATE_ALIVE)
  55. /*
  56.  * distNodeGetNumNodes() types
  57.  */
  58. #define DIST_NODE_NUM_NODES_ALL 0
  59. #define DIST_NODE_NUM_NODES_ALIVE 1
  60. #define DIST_NODE_NUM_NODES_OPERATIONAL 2
  61. /*
  62.  * distNodePktAck() options
  63.  */
  64. #define DIST_NODE_ACK_IMMEDIATELY 0x01
  65. #define DIST_NODE_ACK_EXTENDED 0x02
  66. #define DIST_NODE_WIN_SZ
  67. ((DIST_IF_RNG_BUF_SZ + 1) >> 1)
  68. #define DIST_NODE_MGR_WAKEUP_TICKS
  69. (DIST_NODE_MGR_WAKEUP_MSEC * sysClkRateGet () / 1000)
  70. #define DIST_NODE_IN_PKT_ZERO(pNode)
  71. {
  72. (pNode)->nodeInPkt.low = 0;
  73. (pNode)->nodeInPkt.high = 0;
  74. }
  75. #define DIST_NODE_IN_PKT_INC(pNode)
  76. {
  77. if (!(++(pNode)->nodeInPkt.low))
  78. (pNode)->nodeInPkt.high++;
  79. }
  80. #define DIST_NODE_BFLD_SIZEOF(numBits) 
  81. (((numBits) + 7) / 8)
  82. #define DIST_NODE_BSET(varName, bit) 
  83. (varName[((bit) / 8)] |= (1 << ((bit) % 8)))
  84. #define DIST_NODE_BCLR(varName, bit) 
  85. (varName[((bit) / 8)] &= ~(1 << ((bit) % 8)))
  86. #define DIST_NODE_BTST(varName, bit) 
  87.     (varName[((bit) / 8)] & (1 << ((bit) % 8)))
  88. #define DIST_NODE_BPRINT(varName, numBits) 
  89. int i, j; 
  90. unsigned char c; 
  91. for (i=0; i<(((numBits) + 7) / 8); i++) 
  92. c = varName[i]; 
  93. for (j=0; j<8; j++) 
  94. printf ("%c", ((c & 0x1) ? 'x' : '.')); 
  95. c >>= 1; 
  96. }
  97. #define distNodeGetState(pNode) ((pNode)->nodeState)
  98. #define distNodeDbLock() semTake (distNodeDbSem, WAIT_FOREVER)
  99. #define distNodeDbUnlock() semGive (distNodeDbSem);
  100. /* typedefs */
  101. typedef uint8_t DIST_NODE_BFLD; /* DIST_NODE_BFLD */
  102. typedef struct /* DIST_NODE_COMM */
  103.     {
  104. /* incoming */
  105.     DIST_NODE_BFLD * pCommCompleted;
  106.     DIST_TBUF_HDR * pCommQReass; /* telegrams to be reassembled */
  107.     DIST_TBUF_HDR * pCommQNextDeliver; /* ptr to packet to deliver next */
  108.     short commPktNextExpect; /* id of packet expected next */
  109.     short commAckLastRecvd; /* last ACK received */
  110.     /* outgoing */
  111.     DIST_TBUF_HDR * pCommQWinOut; /* packets waiting for a slide */
  112.     DIST_TBUF_HDR * pCommQAck; /* packets waiting for an ACK */
  113.     short commAckNextExpect; /* id of ACK expected next */
  114.     short commPktNextSend; /* id of packet to send next */
  115.     BOOL commAckDelayed; /* do an ACK if no piggybacking */
  116.     } DIST_NODE_COMM;
  117. typedef struct /* DIST_NODE_QUAD */
  118.     {
  119.     u_long high;
  120.     u_long low;
  121.     } DIST_NODE_QUAD;
  122. /*
  123.  * Next structure forms a node of the network node DB
  124.  */
  125. typedef struct /* DIST_NODE_DB_NODE */
  126.     {
  127.     HASH_NODE nodeHashNode;
  128.     /* information about the node itself */
  129.     DIST_NODE_ID nodeId;
  130.     int nodeState; /* state of the node (ALIVE, etc.) */
  131.     DIST_NODE_QUAD nodeInPkt;
  132.     /* communication related information */
  133.     DIST_NODE_COMM nodeUnicast;
  134.     DIST_NODE_COMM nodeBroadcast;
  135.     } DIST_NODE_DB_NODE;
  136. typedef struct /* DIST_XACK */
  137.     {
  138.     uint16_t xAckPktNextSend;
  139.     uint16_t xAckPktNodeState;
  140.     } DIST_XACK;
  141. typedef struct /* DIST_NODE_BTIMO */
  142.     {
  143.     BOOL btimoTimedOut;
  144.     short btimoWinLo;
  145.     short btimoWinHi;
  146.     } DIST_NODE_BTIMO;
  147. /* Globals */
  148. extern SEM_ID distNodeDbSem;   /* used to lock node DB */
  149. /* function declarations */
  150. #if defined(__STDC__) || defined(__cplusplus)
  151. void distNodeLibInit (void);
  152. STATUS distNodeInit (int sizeLog2);
  153. STATUS distNodeCtl (int function, int arg);
  154. DIST_NODE_DB_NODE * distNodeCreate (DIST_NODE_ID distNodeId, int state);
  155. DIST_NODE_DB_NODE * distNodeOperational (DIST_NODE_ID distNodeId);
  156. DIST_NODE_DB_NODE * distNodeCrashed (DIST_NODE_ID distNodeId);
  157. DIST_NODE_DB_NODE * distNodeEach (FUNCPTR routine, int routineArg);
  158. STATUS distNodeGetGodfatherId (DIST_NODE_ID *pNodeId);
  159. int distNodeGetNumNodes (int typeSet);
  160. DIST_TBUF_HDR * distNodeGetReassembled (DIST_NODE_COMM *pComm);
  161. DIST_NODE_COMM * distNodeReassemble (DIST_NODE_ID nodeIdSrc,
  162.                                             int prio,
  163.     DIST_TBUF *pTBufNew);
  164. STATUS distNodePktAck (DIST_NODE_ID nodeIdSrc,
  165. DIST_TBUF_HDR *pTBufHdr,
  166.         int options);
  167. STATUS distNodePktDiscard (DIST_NODE_ID nodeIdSrc,
  168.     DIST_TBUF_HDR *pTBufHdr);
  169. STATUS distNodePktSend (DIST_TBUF_HDR *pTBufHdr);
  170. void distNodeLocalSetId (DIST_NODE_ID id);
  171. DIST_NODE_ID distNodeLocalGetId (void);
  172. void distNodeLocalSetState (int state);
  173. int distNodeLocalGetState (void);
  174. STATUS distNodeBootstrap (int timeout);
  175. #else   /* __STDC__ */
  176. void distNodeLibInit ();
  177. STATUS distNodeInit ();
  178. STATUS distNodeCtl ();
  179. DIST_NODE_DB_NODE * distNodeCreate ();
  180. DIST_NODE_DB_NODE * distNodeOperational ();
  181. DIST_NODE_DB_NODE * distNodeCrashed ();
  182. DIST_NODE_DB_NODE * distNodeEach ();
  183. STATUS distNodeGetGodfatherId ();
  184. int distNodeGetNumNodes ();
  185. DIST_TBUF_HDR * distNodeGetReassembled ();
  186. DIST_NODE_COMM * distNodeReassemble ();
  187. STATUS distNodePktAck ();
  188. STATUS distNodePktDiscard ();
  189. STATUS distNodePktSend ();
  190. void distNodeLocalSetId ();
  191. DIST_NODE_ID distNodeLocalGetId ();
  192. void distNodeLocalSetState ();
  193. int distNodeLocalGetState ();
  194. STATUS distNodeBootstrap ();
  195. #endif  /* __STDC__ */
  196. #ifdef __cplusplus
  197. }
  198. #endif
  199. #endif  /* __INCdistNodeLibPh */