libcm is a C development framework with an emphasis on audio signal processing applications.
Ви не можете вибрати більше 25 тем Теми мають розпочинатися з літери або цифри, можуть містити дефіси (-) і не повинні перевищувати 35 символів.

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115
  1. #ifndef cmNet_h
  2. #define cmNet_h
  3. #ifdef __cplusplus
  4. extern "C" {
  5. #endif
  6. enum
  7. {
  8. kOkNetRC = cmOkRC,
  9. kUdpPortFailNetRC,
  10. kInvalidLabelNetRC,
  11. kDuplLabelNetRC,
  12. kDuplLocalNetRC,
  13. kDuplEndNetRC,
  14. kThreadFailNetRC,
  15. kBufToSmallNetRC,
  16. kNodeNotFoundNetRC,
  17. kNodeStateErrNetRC,
  18. kTimeOutErrNetRC,
  19. kLocalNodeNetRC,
  20. };
  21. typedef cmRC_t cmRtNetRC_t;
  22. typedef cmHandle_t cmRtNetH_t;
  23. extern cmRtNetH_t cmRtNetNullHandle;
  24. // 'cbFunc' will be called within the context of cmRtNetReceive() to receive
  25. // incoming network messages.
  26. cmRtNetRC_t cmRtNetAlloc( cmCtx_t* ctx, cmRtNetH_t* hp, cmUdpCallback_t cbFunc, void* cbArg );
  27. cmRtNetRC_t cmRtNetFree( cmRtNetH_t* hp );
  28. bool cmRtNetIsValid( cmRtNetH_t h );
  29. // Create a network node.
  30. // The 'nodeLabel' refers to a network device cfg. (see cmDevCfg).
  31. // Set 'ipAddr' to NULL if this is the local node.
  32. // During sync mode this node will attempt to sync with all
  33. // nodes in the node list.
  34. cmRtNetRC_t cmRtNetCreateNode( cmRtNetH_t h, const cmChar_t* nodeLabel, const cmChar_t* ipAddr, cmUdpPort_t ipPort );
  35. // Register the local endpoints.
  36. // Remote nodes will be able to send messages to these endpoints by
  37. // referring to (nodeLabel/endPtLabel)
  38. cmRtNetRC_t cmRtNetRegisterEndPoint( cmRtNetH_t h, const cmChar_t* endPtLabel, unsigned endPtId );
  39. // Delete all nodes and endpoints.
  40. cmRtNetRC_t cmRtNetClearAll( cmRtNetH_t h );
  41. // Go into 'sync' node.
  42. // When a node enters sync mode it systematically transmits all of it's
  43. // local endpoint information to each registered remote node. Prior to
  44. // entering sync mode a node must therefore have been setup with a list
  45. // of remote nodes (via cmRtNetCreateNode()) and a list of local endpoints
  46. // (cmRtNetRegisterEndpoint()). During sync mode a node sends it's local
  47. // endpoint list to each registered remote node. When a remote node receives
  48. // an endpoint it updates it's own remote node/endpoint
  49. // list.
  50. cmRtNetRC_t cmRtNetBeginSyncMode( cmRtNetH_t h );
  51. bool cmRtNetIsInSyncMode( cmRtNetH_t h );
  52. // When the network message recieve function (See cmRtNetAlloc() 'cbFunc')
  53. // receives a message with the cmRtSysMsgHdr_t.selId == kNetSyncSelRtId
  54. // it should call this function to update the current sync state of the
  55. // cmRtNet.
  56. cmRtNetRC_t cmRtNetSyncModeRecv( cmRtNetH_t h, const char* data, unsigned dataByteCnt, const struct sockaddr_in* fromAddr );
  57. // When in the network is in sync mode (cmRtNetIsSync()==true)
  58. // the client system must poll this function to update the networks sync state.
  59. cmRtNetRC_t cmRtNetSyncModeSend( cmRtNetH_t h );
  60. // This function must be polled to receive incoming network messages
  61. // via the callback funcion 'cbFunc' as passed to cmRtNetAlloc()
  62. cmRtNetRC_t cmRtNetReceive( cmRtNetH_t h );
  63. bool cmRtNetIsSyncModeMsg( const void* data, unsigned dataByteCnt );
  64. unsigned cmRtNetEndPointIndex( cmRtNetH_t h, const cmChar_t* nodeLabel, const cmChar_t* endPtLabel );
  65. cmRtNetRC_t cmRtNetSend( cmRtNetH_t h, unsigned endPointIndex, const void* msg, unsigned msgByteCnt );
  66. void cmRtNetReport( cmRtNetH_t h );
  67. void cmRtNetTest( cmCtx_t* ctx, bool mstrFl );
  68. /*
  69. Master:
  70. cmRtNetBeginSyncMode().
  71. while( cmRtNetIsSyncMode())
  72. {
  73. // Give the master an oppurtunity to advance it's sync mode state.
  74. // When the master is has sync'd with all remote nodes in it's
  75. // remote node list then it will automatically exit sync mode.
  76. cmRtNetSyncModeSend()
  77. }
  78. _myNetRecv(dataV,dataN,addr)
  79. {
  80. if( cmRtNetIsSyncModeMsg(dataV,dataN) )
  81. cmRtNetSyncModeRecv(dataV,dataN,addr)
  82. }
  83. */
  84. #ifdef __cplusplus
  85. }
  86. #endif
  87. #endif