You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

137 lines
3.6 KiB

​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
  1. #ifndef __MOJO_REMOTE_CLIENT_HEADER__
  2. #define __MOJO_REMOTE_CLIENT_HEADER__
  3. #include "../../components/base/basicLogCollection.h"
  4. #include "../../components/base/basicThread.h"
  5. #include "../../data/net/clientPort.h"
  6. #include "../../data/protocol/protocol.h"
  7. #include "../../data/protocol/protocolARGUS_DATA.h"
  8. #include "../common/dataBinder.h"
  9. class mojoKernel;
  10. typedef struct S_RPC_CMD_RECORD
  11. {
  12. uint8_t CMD;
  13. size_t DATA_SIZE;
  14. void * DATA;
  15. } RPC_CMD_RECORD;
  16. typedef basicRing<RPC_CMD_RECORD> RPC_CMD_QUEUE;
  17. class mojoVideoTransferHelper
  18. {
  19. private:
  20. basicLogCollection * m_pLog;
  21. char m_cCurrentFile[MAX_PATH];
  22. bool m_bVideoExists;
  23. bool m_bVideoOpened;
  24. uint64_t m_nRemoteRefID;
  25. FILE * m_pFD;
  26. ARGUS_DATA_VIDEO_INFO m_sIn;
  27. uint32_t m_nBufferSize;
  28. uint8_t * m_pBuffer;
  29. uint64_t m_nCTSMS; // future use for Target Binding ( history filtering )
  30. public:
  31. explicit mojoVideoTransferHelper(uint32_t buffer_size = ARGUS_RPC_DEFAULT_MEDIA_CHUNK);
  32. ~mojoVideoTransferHelper();
  33. bool init(VIDEO_SEGMENT_INFO * ptr);
  34. uint8_t * getNextChunk(uint32_t req_chunk_size, uint32_t * ack_size);
  35. ARGUS_DATA_VIDEO_INFO * getVideoInfo();
  36. void clear();
  37. void abort();
  38. void registerEventID(uint32_t local, uint64_t remote);
  39. void setRemoteReferenceID(uint64_t rid)
  40. {
  41. m_nRemoteRefID = rid;
  42. }
  43. uint64_t getRemoteReferenceID()
  44. {
  45. return m_nRemoteRefID;
  46. }
  47. };
  48. typedef struct S_VTR_HELPER
  49. {
  50. mojoVideoTransferHelper * ptr;
  51. uint8_t state;
  52. uint32_t ts;
  53. } VTR_HELPER;
  54. typedef std::vector<VTR_HELPER *> V_VIDEO_TRANSFER_HELPERS;
  55. typedef std::queue<mojoVideoTransferHelper *> Q_VIDEO_TRANSFER_HELPERS;
  56. class mojoRemoteClient : public basicThread, public protocolParser
  57. {
  58. private:
  59. basicLogCollection * m_pLog;
  60. mojoKernel * m_pMaster;
  61. ARGUS_DATA_MOJO_INFO m_sINFO;
  62. bool m_bUseBackupServer;
  63. uint8_t m_bActiveServer;
  64. uint8_t m_bCloseCommunicationReason;
  65. clientPort * m_pPort;
  66. basicMutex m_mQueryProtector;
  67. basicMutex m_mAutomationStageProtector;
  68. basicMutex m_mAutomationFreezer;
  69. RPC_CMD_QUEUE * m_qCMD;
  70. basicMutex m_mCurrentCMDProtector;
  71. RPC_CMD_RECORD * m_pCurrentCMD;
  72. basicMutex m_mCurrentVTRProtector;
  73. V_VIDEO_TRANSFER_HELPERS m_vVTRHelpers;
  74. // mojoVideoTransferHelper * m_pVideoHelper;
  75. uint32_t m_nQueryMessage;
  76. uint32_t m_nInbondSerial;
  77. uint32_t m_nOutbondSerial;
  78. uint8_t m_bAutomationStage;
  79. uint8_t m_bTOCounter;
  80. bool m_bShutdownCommunication;
  81. bool m_bCommunicationEstablished;
  82. bool m_bRegisteredWithRemotePeer;
  83. bool peer_send_rpc_pack(RPC_CMD_RECORD * ptr);
  84. void enqueueInfoMsg();
  85. void enqueueStatMsg();
  86. void enqueueTimeReq();
  87. void enqueueDisconnect(uint8_t reason = 0);
  88. uint8_t getAutomationStage();
  89. void setAutomationStage(uint8_t stg);
  90. bool validateTransaction();
  91. bool pushNewTransaction(RPC_CMD_RECORD * ptr);
  92. bool fetchNewTransaction();
  93. void finishTransaction();
  94. void flushTransactions();
  95. basicMutex m_mTOProtoctor;
  96. void setTO(uint8_t seconds);
  97. bool decTO();
  98. VTR_HELPER * getHelperByDBID(uint64_t dbid);
  99. protected:
  100. virtual int packetChecker(U8 * Buffer, size_t BufferSize);
  101. virtual protocolPackage * packetExtractor(U8 * Buffer, size_t BufferSize);
  102. virtual bool packetHandler(protocolPackage * Package);
  103. virtual void m_fThreadProc(void);
  104. public:
  105. explicit mojoRemoteClient(mojoKernel * ptr);
  106. ~mojoRemoteClient();
  107. virtual bool create();
  108. // bool createVideoTransferTask( ARGUS_DATA_VIDEO_SEGMENT *ptr );
  109. bool validate();
  110. bool addEvent(EVENT_CONTAINER * ptr);
  111. bool addVideo(VIDEO_SEGMENT_INFO * ptr);
  112. };
  113. #endif