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.

1363 lines
35 KiB

​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
la_mojo: fix memory leaks and heap corruption Continuous leaks: - protocolParser: on package-pool overflow the oldest package was removed but never freed while the newest (still pooled) one was freed. Every packet a handler does not consume (e.g. other sensors on a shared bus) leaked once the pool was full. Free the removed package, free pooled packages in the destructor and getPackage(), use memmove for the overlapping buffer shifts. - SQLite_Connector::Query: loop only while sqlite3_step() returns SQLITE_ROW. Looping until SQLITE_DONE spun forever allocating rows on SQLITE_BUSY/ERROR. Set a busy timeout, close handles after a failed open, fix escapeBinary() writing into uninitialised buffers. - basicThread/basicDualThread: threads that ended by themselves were never joined, leaking their stacks on every stream drop/restart. Always join once (detach when called from the thread itself); check pthread_create result correctly. - curlRequest: free the header list; initialise m_pPostData and the content type; curlRequestsManager deletes requests it cannot queue. - kernelModuleModemManager: free the phonebook ID list on every reload. - deviceNodeFactory: do not append the same pending node every cycle. - streamHandler: free frames left in the encoding queue on destruction. Heap corruption: - kernelModuleFactory: module that failed to start was deleted twice. - mojoRemoteClient: basicRing::push() returns an ID (may be 0), not a bool; compare with -1. Fix packetExtractor and destructor leaks. - utilizeBasicEvent: payloads are malloc'ed, release with free(). - videoAVLIBSource: avoid sws context double free, NULL check order. - trim(): memmove for overlapping copy. Smaller leaks: dropSession duplicate query, LRF upload data, report backupper / fly hunter settings, Kafka consumer handle, BVMS uniq ID. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_0139veDo3XyavMuVhdnHcN16
23 hours ago
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
la_mojo: fix memory leaks and heap corruption Continuous leaks: - protocolParser: on package-pool overflow the oldest package was removed but never freed while the newest (still pooled) one was freed. Every packet a handler does not consume (e.g. other sensors on a shared bus) leaked once the pool was full. Free the removed package, free pooled packages in the destructor and getPackage(), use memmove for the overlapping buffer shifts. - SQLite_Connector::Query: loop only while sqlite3_step() returns SQLITE_ROW. Looping until SQLITE_DONE spun forever allocating rows on SQLITE_BUSY/ERROR. Set a busy timeout, close handles after a failed open, fix escapeBinary() writing into uninitialised buffers. - basicThread/basicDualThread: threads that ended by themselves were never joined, leaking their stacks on every stream drop/restart. Always join once (detach when called from the thread itself); check pthread_create result correctly. - curlRequest: free the header list; initialise m_pPostData and the content type; curlRequestsManager deletes requests it cannot queue. - kernelModuleModemManager: free the phonebook ID list on every reload. - deviceNodeFactory: do not append the same pending node every cycle. - streamHandler: free frames left in the encoding queue on destruction. Heap corruption: - kernelModuleFactory: module that failed to start was deleted twice. - mojoRemoteClient: basicRing::push() returns an ID (may be 0), not a bool; compare with -1. Fix packetExtractor and destructor leaks. - utilizeBasicEvent: payloads are malloc'ed, release with free(). - videoAVLIBSource: avoid sws context double free, NULL check order. - trim(): memmove for overlapping copy. Smaller leaks: dropSession duplicate query, LRF upload data, report backupper / fly hunter settings, Kafka consumer handle, BVMS uniq ID. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_0139veDo3XyavMuVhdnHcN16
23 hours ago
​
​
​
​
​
​
​
​
​
la_mojo: fix memory leaks and heap corruption Continuous leaks: - protocolParser: on package-pool overflow the oldest package was removed but never freed while the newest (still pooled) one was freed. Every packet a handler does not consume (e.g. other sensors on a shared bus) leaked once the pool was full. Free the removed package, free pooled packages in the destructor and getPackage(), use memmove for the overlapping buffer shifts. - SQLite_Connector::Query: loop only while sqlite3_step() returns SQLITE_ROW. Looping until SQLITE_DONE spun forever allocating rows on SQLITE_BUSY/ERROR. Set a busy timeout, close handles after a failed open, fix escapeBinary() writing into uninitialised buffers. - basicThread/basicDualThread: threads that ended by themselves were never joined, leaking their stacks on every stream drop/restart. Always join once (detach when called from the thread itself); check pthread_create result correctly. - curlRequest: free the header list; initialise m_pPostData and the content type; curlRequestsManager deletes requests it cannot queue. - kernelModuleModemManager: free the phonebook ID list on every reload. - deviceNodeFactory: do not append the same pending node every cycle. - streamHandler: free frames left in the encoding queue on destruction. Heap corruption: - kernelModuleFactory: module that failed to start was deleted twice. - mojoRemoteClient: basicRing::push() returns an ID (may be 0), not a bool; compare with -1. Fix packetExtractor and destructor leaks. - utilizeBasicEvent: payloads are malloc'ed, release with free(). - videoAVLIBSource: avoid sws context double free, NULL check order. - trim(): memmove for overlapping copy. Smaller leaks: dropSession duplicate query, LRF upload data, report backupper / fly hunter settings, Kafka consumer handle, BVMS uniq ID. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_0139veDo3XyavMuVhdnHcN16
23 hours ago
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
la_mojo: fix memory leaks and heap corruption Continuous leaks: - protocolParser: on package-pool overflow the oldest package was removed but never freed while the newest (still pooled) one was freed. Every packet a handler does not consume (e.g. other sensors on a shared bus) leaked once the pool was full. Free the removed package, free pooled packages in the destructor and getPackage(), use memmove for the overlapping buffer shifts. - SQLite_Connector::Query: loop only while sqlite3_step() returns SQLITE_ROW. Looping until SQLITE_DONE spun forever allocating rows on SQLITE_BUSY/ERROR. Set a busy timeout, close handles after a failed open, fix escapeBinary() writing into uninitialised buffers. - basicThread/basicDualThread: threads that ended by themselves were never joined, leaking their stacks on every stream drop/restart. Always join once (detach when called from the thread itself); check pthread_create result correctly. - curlRequest: free the header list; initialise m_pPostData and the content type; curlRequestsManager deletes requests it cannot queue. - kernelModuleModemManager: free the phonebook ID list on every reload. - deviceNodeFactory: do not append the same pending node every cycle. - streamHandler: free frames left in the encoding queue on destruction. Heap corruption: - kernelModuleFactory: module that failed to start was deleted twice. - mojoRemoteClient: basicRing::push() returns an ID (may be 0), not a bool; compare with -1. Fix packetExtractor and destructor leaks. - utilizeBasicEvent: payloads are malloc'ed, release with free(). - videoAVLIBSource: avoid sws context double free, NULL check order. - trim(): memmove for overlapping copy. Smaller leaks: dropSession duplicate query, LRF upload data, report backupper / fly hunter settings, Kafka consumer handle, BVMS uniq ID. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_0139veDo3XyavMuVhdnHcN16
23 hours ago
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
la_mojo: fix memory leaks and heap corruption Continuous leaks: - protocolParser: on package-pool overflow the oldest package was removed but never freed while the newest (still pooled) one was freed. Every packet a handler does not consume (e.g. other sensors on a shared bus) leaked once the pool was full. Free the removed package, free pooled packages in the destructor and getPackage(), use memmove for the overlapping buffer shifts. - SQLite_Connector::Query: loop only while sqlite3_step() returns SQLITE_ROW. Looping until SQLITE_DONE spun forever allocating rows on SQLITE_BUSY/ERROR. Set a busy timeout, close handles after a failed open, fix escapeBinary() writing into uninitialised buffers. - basicThread/basicDualThread: threads that ended by themselves were never joined, leaking their stacks on every stream drop/restart. Always join once (detach when called from the thread itself); check pthread_create result correctly. - curlRequest: free the header list; initialise m_pPostData and the content type; curlRequestsManager deletes requests it cannot queue. - kernelModuleModemManager: free the phonebook ID list on every reload. - deviceNodeFactory: do not append the same pending node every cycle. - streamHandler: free frames left in the encoding queue on destruction. Heap corruption: - kernelModuleFactory: module that failed to start was deleted twice. - mojoRemoteClient: basicRing::push() returns an ID (may be 0), not a bool; compare with -1. Fix packetExtractor and destructor leaks. - utilizeBasicEvent: payloads are malloc'ed, release with free(). - videoAVLIBSource: avoid sws context double free, NULL check order. - trim(): memmove for overlapping copy. Smaller leaks: dropSession duplicate query, LRF upload data, report backupper / fly hunter settings, Kafka consumer handle, BVMS uniq ID. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_0139veDo3XyavMuVhdnHcN16
23 hours ago
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
la_mojo: fix memory leaks and heap corruption Continuous leaks: - protocolParser: on package-pool overflow the oldest package was removed but never freed while the newest (still pooled) one was freed. Every packet a handler does not consume (e.g. other sensors on a shared bus) leaked once the pool was full. Free the removed package, free pooled packages in the destructor and getPackage(), use memmove for the overlapping buffer shifts. - SQLite_Connector::Query: loop only while sqlite3_step() returns SQLITE_ROW. Looping until SQLITE_DONE spun forever allocating rows on SQLITE_BUSY/ERROR. Set a busy timeout, close handles after a failed open, fix escapeBinary() writing into uninitialised buffers. - basicThread/basicDualThread: threads that ended by themselves were never joined, leaking their stacks on every stream drop/restart. Always join once (detach when called from the thread itself); check pthread_create result correctly. - curlRequest: free the header list; initialise m_pPostData and the content type; curlRequestsManager deletes requests it cannot queue. - kernelModuleModemManager: free the phonebook ID list on every reload. - deviceNodeFactory: do not append the same pending node every cycle. - streamHandler: free frames left in the encoding queue on destruction. Heap corruption: - kernelModuleFactory: module that failed to start was deleted twice. - mojoRemoteClient: basicRing::push() returns an ID (may be 0), not a bool; compare with -1. Fix packetExtractor and destructor leaks. - utilizeBasicEvent: payloads are malloc'ed, release with free(). - videoAVLIBSource: avoid sws context double free, NULL check order. - trim(): memmove for overlapping copy. Smaller leaks: dropSession duplicate query, LRF upload data, report backupper / fly hunter settings, Kafka consumer handle, BVMS uniq ID. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_0139veDo3XyavMuVhdnHcN16
23 hours ago
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
la_mojo: fix memory leaks and heap corruption Continuous leaks: - protocolParser: on package-pool overflow the oldest package was removed but never freed while the newest (still pooled) one was freed. Every packet a handler does not consume (e.g. other sensors on a shared bus) leaked once the pool was full. Free the removed package, free pooled packages in the destructor and getPackage(), use memmove for the overlapping buffer shifts. - SQLite_Connector::Query: loop only while sqlite3_step() returns SQLITE_ROW. Looping until SQLITE_DONE spun forever allocating rows on SQLITE_BUSY/ERROR. Set a busy timeout, close handles after a failed open, fix escapeBinary() writing into uninitialised buffers. - basicThread/basicDualThread: threads that ended by themselves were never joined, leaking their stacks on every stream drop/restart. Always join once (detach when called from the thread itself); check pthread_create result correctly. - curlRequest: free the header list; initialise m_pPostData and the content type; curlRequestsManager deletes requests it cannot queue. - kernelModuleModemManager: free the phonebook ID list on every reload. - deviceNodeFactory: do not append the same pending node every cycle. - streamHandler: free frames left in the encoding queue on destruction. Heap corruption: - kernelModuleFactory: module that failed to start was deleted twice. - mojoRemoteClient: basicRing::push() returns an ID (may be 0), not a bool; compare with -1. Fix packetExtractor and destructor leaks. - utilizeBasicEvent: payloads are malloc'ed, release with free(). - videoAVLIBSource: avoid sws context double free, NULL check order. - trim(): memmove for overlapping copy. Smaller leaks: dropSession duplicate query, LRF upload data, report backupper / fly hunter settings, Kafka consumer handle, BVMS uniq ID. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_0139veDo3XyavMuVhdnHcN16
23 hours ago
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
  1. #include "mojoRemoteClient.h"
  2. #include "mojoKernel.h"
  3. #define LOG(X) m_pLog->Log("RPC", this, X)
  4. #ifdef DEBUG
  5. #define LOG_ERROR(X) \
  6. { \
  7. char _tBfrErrMSG234[256]; \
  8. sprintf(_tBfrErrMSG234, "In file %s[%d] in func:%s %s", __FILE__, __LINE__, __func__, X); \
  9. m_pLog->Log("RPC", this, _LOG_ERROR, _tBfrErrMSG234); \
  10. }
  11. #else
  12. #define LOG_ERROR(X) m_pLog->Log("RPC", this, _LOG_ERROR, X);
  13. #endif
  14. mojoRemoteClient::mojoRemoteClient(mojoKernel * ptr) :
  15. protocolParser()
  16. {
  17. m_pLog = basicLogCollection::getInstance();
  18. m_pPort = NULL;
  19. m_pCurrentCMD = NULL;
  20. m_pMaster = ptr;
  21. m_nOutbondSerial = 0;
  22. m_nInbondSerial = 0;
  23. m_bShutdownCommunication = true;
  24. m_bCommunicationEstablished = false;
  25. m_bRegisteredWithRemotePeer = false;
  26. m_bUseBackupServer = false;
  27. m_bActiveServer = 0;
  28. m_bCloseCommunicationReason = 0;
  29. // m_pVideoHelper = new mojoVideoTransferHelper( ARGUS_RPC_DEFAULT_MEDIA_CHUNK );
  30. memset(&m_sINFO, 0, sizeof(ARGUS_DATA_MOJO_INFO));
  31. m_qCMD = new RPC_CMD_QUEUE();
  32. }
  33. mojoRemoteClient::~mojoRemoteClient()
  34. {
  35. if (m_bRegisteredWithRemotePeer)
  36. {
  37. while (m_bRegisteredWithRemotePeer)
  38. {
  39. m_mCurrentVTRProtector.lock();
  40. if (m_vVTRHelpers.size() == 0)
  41. {
  42. m_mCurrentVTRProtector.unlock();
  43. break;
  44. };
  45. m_mCurrentVTRProtector.unlock();
  46. SLEEP(DEFAULT_THREAD_SLEEP_TIME);
  47. };
  48. m_mCurrentVTRProtector.lock();
  49. if (m_vVTRHelpers.size())
  50. {
  51. for (V_VIDEO_TRANSFER_HELPERS::iterator idx = m_vVTRHelpers.begin(); idx != m_vVTRHelpers.end(); idx++)
  52. {
  53. // VTR_HELPER is malloc'ed, the helper object inside is new'ed
  54. delete ((*idx)->ptr);
  55. free(*idx);
  56. }
  57. m_vVTRHelpers.clear();
  58. };
  59. m_mCurrentVTRProtector.unlock();
  60. setAutomationStage( ARGUS_RPC_STAGE_DISCONNECT );
  61. //Waitiung to send to server graceful disconnection req
  62. SLEEP( 50 );
  63. };
  64. waitThreadEnd(true);
  65. flushTransactions();
  66. m_bShutdownCommunication = true;
  67. m_bCommunicationEstablished = false;
  68. m_bRegisteredWithRemotePeer = false;
  69. if (m_pPort)
  70. {
  71. delete(m_pPort);
  72. }
  73. delete(m_qCMD);
  74. }
  75. bool mojoRemoteClient::create()
  76. {
  77. if (m_pMaster == NULL)
  78. {
  79. return false;
  80. }
  81. m_pMaster->fillMojoInfo(&m_sINFO);
  82. if (m_bCommunicationEstablished && (m_bThreadStatus == TH_WORKING))
  83. {
  84. return true;
  85. }
  86. m_bAutomationStage = ARGUS_RPC_STAGE_CONNECT;
  87. m_pCurrentCMD = NULL;
  88. m_bActiveServer = 0;
  89. m_bUseBackupServer = ((m_pMaster->m_sSiteData.remote_backup_port > 0) && (strlen(m_pMaster->m_sSiteData.remote_backup_ip) > 7));
  90. return init();
  91. }
  92. int mojoRemoteClient::packetChecker(U8 * Buffer, size_t BufferSize)
  93. {
  94. if (Buffer[0] == ARGUS_START_SERVER_FLAG)
  95. {
  96. if (BufferSize > ARGUS_DATA_MSG_MIN_SIZE)
  97. {
  98. uint32_t SIZE = Buffer[5];
  99. SIZE = (SIZE << 8) | Buffer[6];
  100. SIZE = (SIZE << 8) | Buffer[7];
  101. SIZE = (SIZE << 8) | Buffer[8];
  102. if ((SIZE + ARGUS_HEADER_SIZE + ARGUS_CHECKSUM_SIZE) <= BufferSize)
  103. {
  104. uint16_t tCRC = checksum16(Buffer, SIZE + ARGUS_HEADER_SIZE);
  105. uint16_t cCRC = Buffer[SIZE + ARGUS_HEADER_SIZE];
  106. cCRC = (cCRC << 8) | Buffer[SIZE + ARGUS_HEADER_SIZE + 1];
  107. if (tCRC == cCRC)
  108. {
  109. return 0;
  110. }
  111. }
  112. else
  113. {
  114. return 1; // to grou
  115. }
  116. }
  117. else
  118. {
  119. return 1; // to grow
  120. }
  121. };
  122. return -1; // to skip
  123. }
  124. protocolPackage * mojoRemoteClient::packetExtractor(U8 * Buffer, size_t BufferSize)
  125. {
  126. protocolPackage * tPack = (protocolPackage *) malloc(sizeof(protocolPackage));
  127. if (tPack)
  128. {
  129. tPack->m_nCode = Buffer[ARGUS_HEADER_SIZE];
  130. tPack->m_nSize = Buffer[5];
  131. tPack->m_nSize = (tPack->m_nSize << 8) | Buffer[6];
  132. tPack->m_nSize = (tPack->m_nSize << 8) | Buffer[7];
  133. tPack->m_nSize = (tPack->m_nSize << 8) | Buffer[8];
  134. tPack->m_nSize = tPack->m_nSize + ARGUS_HEADER_SIZE + ARGUS_CHECKSUM_SIZE;
  135. tPack->m_pData = NULL;
  136. if (tPack->m_nSize <= BufferSize)
  137. {
  138. tPack->m_pData = (U8 *) malloc(tPack->m_nSize);
  139. }
  140. if (tPack->m_pData)
  141. {
  142. memcpy(tPack->m_pData, Buffer, tPack->m_nSize);
  143. }
  144. else
  145. {
  146. // m_pData was leaked here when the size check failed
  147. free(tPack);
  148. tPack = NULL;
  149. };
  150. };
  151. return tPack;
  152. }
  153. bool mojoRemoteClient::packetHandler(protocolPackage * Package)
  154. {
  155. m_nInbondSerial = Package->m_pData[1];
  156. m_nInbondSerial = (m_nInbondSerial << 8) | Package->m_pData[2];
  157. m_nInbondSerial = (m_nInbondSerial << 8) | Package->m_pData[3];
  158. m_nInbondSerial = (m_nInbondSerial << 8) | Package->m_pData[4];
  159. #ifdef DEBUG_EXTRA
  160. char bB[129];
  161. sprintf(bB, "Code: %02X", Package->m_nCode);
  162. LOG(bB);
  163. #endif
  164. switch (Package->m_nCode)
  165. {
  166. case ARGUS_DATA_MSG_REGISTER:
  167. #ifdef DEBUG
  168. LOG("Sucessfull Registration at Remote Server");
  169. #endif
  170. m_bRegisteredWithRemotePeer = true;
  171. setAutomationStage(ARGUS_RPC_STAGE_SEND_HELLO);
  172. //finishTransaction();
  173. break;
  174. case ARGUS_DATA_MSG_ACCESS_DENIED:
  175. //m_bRegisteredWithRemotePeer = false;
  176. LOG("Access denied!");
  177. /* fallthrough */
  178. case ARGUS_DATA_MSG_DISABLED:
  179. #ifdef DEBUG_EXTRA
  180. LOG("Communication is disabled!");
  181. #endif
  182. setAutomationStage(ARGUS_RPC_STAGE_CLOSE);
  183. //finishTransaction();
  184. break;
  185. case ARGUS_DATA_MSG_STAT : finishTransaction(); break;
  186. case ARGUS_DATA_MSG_INFO : finishTransaction(); break;
  187. case ARGUS_DATA_MSG_GET_INFO: enqueueInfoMsg(); break;
  188. case ARGUS_DATA_MSG_REQ_TIME_SYNC:
  189. {
  190. #ifdef DEBUG_EXTRA
  191. LOG("TSYNC REQ");
  192. #endif
  193. RPC_CMD_RECORD * tCMD = (RPC_CMD_RECORD *) malloc(sizeof(RPC_CMD_RECORD));
  194. if (tCMD)
  195. {
  196. tCMD->CMD = ARGUS_DATA_MSG_TIME_SYNC;
  197. tCMD->DATA_SIZE = sizeof(ARGUS_DATA_TIME_SYNC_REQ);
  198. tCMD->DATA = malloc(tCMD->DATA_SIZE);
  199. if (tCMD->DATA)
  200. {
  201. ARGUS_DATA_TIME_SYNC_REQ * tDATA = (ARGUS_DATA_TIME_SYNC_REQ *) tCMD->DATA;
  202. tDATA->STS = getMilliseconds();
  203. if (peer_send_rpc_pack(tCMD))
  204. {
  205. setTO(3);
  206. free(tCMD->DATA);
  207. free(tCMD);
  208. break;
  209. };
  210. free(tCMD->DATA);
  211. };
  212. free(tCMD);
  213. };
  214. // Only On failure
  215. finishTransaction();
  216. break;
  217. };
  218. case ARGUS_DATA_MSG_EVT: finishTransaction(); break;
  219. case ARGUS_DATA_MSG_VIDEO_INFO:
  220. {
  221. // get DATABASE ID
  222. uint64_t tDBID = Package->m_pData[ARGUS_HEADER_SIZE + 1];
  223. tDBID = (tDBID << 8) | Package->m_pData[ARGUS_HEADER_SIZE + 2];
  224. tDBID = (tDBID << 8) | Package->m_pData[ARGUS_HEADER_SIZE + 3];
  225. tDBID = (tDBID << 8) | Package->m_pData[ARGUS_HEADER_SIZE + 4];
  226. tDBID = (tDBID << 8) | Package->m_pData[ARGUS_HEADER_SIZE + 5];
  227. tDBID = (tDBID << 8) | Package->m_pData[ARGUS_HEADER_SIZE + 6];
  228. tDBID = (tDBID << 8) | Package->m_pData[ARGUS_HEADER_SIZE + 7];
  229. tDBID = (tDBID << 8) | Package->m_pData[ARGUS_HEADER_SIZE + 8];
  230. #ifdef DEBUG
  231. char tZ[128];
  232. sprintf(tZ, "Video Ack %lu ID", tDBID);
  233. LOG(tZ);
  234. #endif
  235. m_mCurrentVTRProtector.lock();
  236. if (tDBID)
  237. {
  238. VTR_HELPER * tHELP = m_vVTRHelpers.at(0);
  239. tHELP->ptr->setRemoteReferenceID(tDBID);
  240. tHELP->state = 2;
  241. tHELP->ts = time(NULL);
  242. }
  243. else
  244. {
  245. // Abort Transaction
  246. m_vVTRHelpers.at(0)->state = 3;
  247. m_mCurrentVTRProtector.unlock();
  248. break;
  249. };
  250. m_mCurrentVTRProtector.unlock();
  251. };
  252. /* fallthrough */
  253. case ARGUS_DATA_MSG_VIDEO_DATA:
  254. {
  255. RPC_CMD_RECORD * tCMD = (RPC_CMD_RECORD *) malloc(sizeof(RPC_CMD_RECORD));
  256. if (tCMD)
  257. {
  258. uint32_t tSize;
  259. tCMD->CMD = ARGUS_DATA_MSG_VIDEO_DATA;
  260. m_mCurrentVTRProtector.lock();
  261. if (m_vVTRHelpers.size() == 0)
  262. {
  263. tCMD->DATA = NULL;
  264. tCMD->DATA_SIZE = 0;
  265. if (m_qCMD->push(tCMD) == -1) // push() returns the element ID (may be 0) or -1 on failure
  266. {
  267. free(tCMD);
  268. };
  269. m_mCurrentVTRProtector.unlock();
  270. finishTransaction(); //?? Do we need it
  271. break;
  272. };
  273. tCMD->DATA = (void *) m_vVTRHelpers.at(0)->ptr->getNextChunk(ARGUS_RPC_DEFAULT_MEDIA_CHUNK, &tSize);
  274. m_mCurrentVTRProtector.unlock();
  275. tCMD->DATA_SIZE = tSize;
  276. #ifdef DEBUG_EXTRA
  277. char tC[128];
  278. sprintf(tC, "Sending Video Chunk %d bytes", tSize);
  279. LOG(tC);
  280. #endif
  281. if (tCMD->DATA)
  282. {
  283. /*
  284. //Direct Send to peer data
  285. if ( peer_send_rpc_pack( tCMD ) ) {
  286. setTO( 1 );
  287. free( tCMD->DATA );
  288. free( tCMD );
  289. if ( tSize < ARGUS_RPC_DEFAULT_MEDIA_CHUNK ) {
  290. //Last Chunk
  291. m_mCurrentVTRProtector.lock();
  292. mojoVideoTransferHelper tPtr = m_qVTRHelpers.first();
  293. delte( tPtr );
  294. m_qVTRHelpers.pop();
  295. if ( !m_qVTRHelpers.empty() ) {
  296. };
  297. m_mCurrentVTRProtector.unlock();
  298. };
  299. break;
  300. };
  301. free( tCMD->DATA );
  302. */
  303. // Send Via Queue
  304. if (m_qCMD->push(tCMD) != -1) // push() returns the element ID (may be 0) or -1 on failure
  305. {
  306. m_mCurrentVTRProtector.lock();
  307. m_vVTRHelpers.at(0)->ts = time(NULL);
  308. m_mCurrentVTRProtector.unlock();
  309. finishTransaction(); //?? Do we need it
  310. break;
  311. };
  312. free(tCMD->DATA);
  313. }
  314. else
  315. {
  316. LOG("Finish");
  317. // Finish Send That File
  318. m_mCurrentVTRProtector.lock();
  319. m_vVTRHelpers.at(0)->state = 3;
  320. m_mCurrentVTRProtector.unlock();
  321. };
  322. free(tCMD);
  323. };
  324. // Only On failure
  325. finishTransaction();
  326. break;
  327. };
  328. case ARGUS_DATA_MSG_TIME_SYNC:
  329. {
  330. struct timespec tS;// = {0}; initialized manually
  331. uint64_t cT = getMilliseconds();
  332. ARGUS_DATA_TIME_SYNC_ACK * tPTR = (ARGUS_DATA_TIME_SYNC_ACK *) (Package->m_pData + ARGUS_HEADER_SIZE + 1);
  333. uint64_t eTime = tPTR->ATS + ((cT - tPTR->STS) >> 1);
  334. tS.tv_sec = eTime / 1000;
  335. tS.tv_nsec = (eTime % 1000) * 1000000;
  336. if (clock_settime(CLOCK_REALTIME, &tS) != 0)
  337. {
  338. LOG_ERROR("Time Correction Failed!");
  339. switch (errno)
  340. {
  341. case EACCES : LOG_ERROR("Not have write permission for the dynamic POSIX clock device indicated!"); break;
  342. case EFAULT : LOG_ERROR("tS points outside the accessible address space!"); break;
  343. case EINVAL : LOG_ERROR("Parameter specified is invalid!"); break;
  344. case ENODEV : LOG_ERROR("The hot-pluggable device (like USB for example) represented by a dynamic clk_id has disappeared after its character device was opened!"); break;
  345. case ENOTSUP: LOG_ERROR("The operation is not supported by the dynamic POSIX clock device specified!"); break;
  346. case EPERM : LOG_ERROR("clock_settime() does not have permission to set the clock indicated!"); break;
  347. };
  348. };
  349. #ifdef DEBUG_EXTRA
  350. LOG("Time Sync ACK!");
  351. char tB[256];
  352. sprintf(tB, "RT:%lld ST:%lld CT:%lld", tPTR->STS, tPTR->ATS, cT);
  353. LOG(tB);
  354. sprintf(tB, "tv_s:%lld tv_ns:%lld", tS.tv_sec, tS.tv_nsec);
  355. LOG(tB);
  356. #endif
  357. finishTransaction();
  358. break;
  359. };
  360. case ARGUS_DATA_MSG_RPC:
  361. {
  362. ARGUS_DATA_RPC * tPTR = (ARGUS_DATA_RPC *) (Package->m_pData + ARGUS_HEADER_SIZE + 1);
  363. m_pMaster->m_pDBC->pushMemCMD(tPTR->NODE_ID, tPTR->CMD, tPTR->DATA);
  364. break;
  365. };
  366. case ARGUS_DATA_MSG_FREEZE_BUBBLES:
  367. {
  368. // Freeze Current Active Bubbles
  369. break;
  370. };
  371. case ARGUS_DATA_MSG_CLEAN_BUBBLES:
  372. {
  373. // Clear All Frozen Bubbles!
  374. break;
  375. };
  376. };
  377. return true;
  378. }
  379. uint8_t mojoRemoteClient::getAutomationStage()
  380. {
  381. m_mAutomationStageProtector.lock();
  382. uint8_t retVal = m_bAutomationStage;
  383. m_mAutomationStageProtector.unlock();
  384. return retVal;
  385. }
  386. void mojoRemoteClient::setAutomationStage(uint8_t stg)
  387. {
  388. m_mAutomationStageProtector.lock();
  389. m_bAutomationStage = stg;
  390. m_mAutomationStageProtector.unlock();
  391. }
  392. void mojoRemoteClient::finishTransaction()
  393. {
  394. m_mCurrentCMDProtector.lock();
  395. if (m_pCurrentCMD)
  396. {
  397. if (m_pCurrentCMD->DATA)
  398. {
  399. free(m_pCurrentCMD->DATA);
  400. }
  401. free(m_pCurrentCMD);
  402. m_pCurrentCMD = NULL;
  403. };
  404. m_mCurrentCMDProtector.unlock();
  405. setAutomationStage(ARGUS_RPC_STAGE_IDLE);
  406. }
  407. bool mojoRemoteClient::validateTransaction()
  408. {
  409. if (! m_bRegisteredWithRemotePeer)
  410. {
  411. return false;
  412. }
  413. if (m_bShutdownCommunication)
  414. {
  415. return false;
  416. }
  417. m_mCurrentCMDProtector.lock();
  418. if (m_pCurrentCMD == NULL)
  419. {
  420. m_mCurrentCMDProtector.unlock();
  421. return true;
  422. };
  423. m_mCurrentCMDProtector.unlock();
  424. return false;
  425. }
  426. bool mojoRemoteClient::pushNewTransaction(RPC_CMD_RECORD * ptr)
  427. {
  428. if (ptr == NULL)
  429. {
  430. return false;
  431. }
  432. m_mCurrentCMDProtector.lock();
  433. if (m_qCMD->push(ptr) != -1)
  434. {
  435. m_mCurrentCMDProtector.unlock();
  436. return true;
  437. };
  438. m_mCurrentCMDProtector.unlock();
  439. return false;
  440. }
  441. bool mojoRemoteClient::fetchNewTransaction()
  442. {
  443. if (m_bShutdownCommunication)
  444. {
  445. return false;
  446. }
  447. m_mCurrentCMDProtector.lock();
  448. if (m_pCurrentCMD)
  449. {
  450. m_mCurrentCMDProtector.unlock();
  451. return false;
  452. };
  453. m_pCurrentCMD = m_qCMD->pop();
  454. if (m_pCurrentCMD)
  455. {
  456. m_mCurrentCMDProtector.unlock();
  457. return true;
  458. };
  459. m_mCurrentCMDProtector.unlock();
  460. return false;
  461. }
  462. void mojoRemoteClient::enqueueDisconnect(uint8_t reason)
  463. {
  464. static uint8_t pBuffer[400];
  465. if (! m_bCommunicationEstablished)
  466. {
  467. return;
  468. }
  469. pBuffer[ARGUS_HEADER_SIZE] = ARGUS_DATA_MSG_DISCONNECT;
  470. pBuffer[ARGUS_HEADER_SIZE + 1] = reason;
  471. m_nOutbondSerial++;
  472. m_pPort->sendData(pBuffer, argus_rpc_finishupPackage(pBuffer, m_nOutbondSerial, ARGUS_HEADER_SIZE + 2));
  473. }
  474. void mojoRemoteClient::enqueueInfoMsg()
  475. {
  476. RPC_CMD_RECORD * tCMD = (RPC_CMD_RECORD *) malloc(sizeof(RPC_CMD_RECORD));
  477. if (tCMD)
  478. {
  479. tCMD->CMD = ARGUS_DATA_MSG_INFO;
  480. tCMD->DATA_SIZE = sizeof(ARGUS_DATA_MOJO_INFO);
  481. tCMD->DATA = malloc(tCMD->DATA_SIZE);
  482. if (tCMD->DATA)
  483. {
  484. memcpy(tCMD->DATA, &m_sINFO, sizeof(ARGUS_DATA_MOJO_INFO));
  485. LOG("ARGUS_DATA_MOJO_INFO");
  486. if (pushNewTransaction(tCMD))
  487. {
  488. return;
  489. }
  490. free(tCMD->DATA);
  491. };
  492. free(tCMD);
  493. };
  494. }
  495. #include "../common/deviceNodeCamera.h"
  496. #include "../common/deviceNodeFactory.h"
  497. #include "../common/deviceNodeSensor.h"
  498. void mojoRemoteClient::enqueueStatMsg()
  499. {
  500. RPC_CMD_RECORD * tCMD = (RPC_CMD_RECORD *) malloc(sizeof(RPC_CMD_RECORD));
  501. if (tCMD)
  502. {
  503. tCMD->CMD = ARGUS_DATA_MSG_STAT;
  504. tCMD->DATA_SIZE = sizeof(ARGUS_DATA_MOJO_STATUS);
  505. tCMD->DATA = malloc(tCMD->DATA_SIZE);
  506. if (tCMD->DATA)
  507. {
  508. memset(tCMD->DATA, 0, tCMD->DATA_SIZE);
  509. ARGUS_DATA_MOJO_STATUS * cSTATUS = (ARGUS_DATA_MOJO_STATUS *) tCMD->DATA;
  510. DBC_SYS_LOAD_INFO cSYSSTAT;
  511. m_pMaster->getSystemUtilization(&cSYSSTAT);
  512. cSTATUS->CPU_LOAD = round(cSYSSTAT.cpu15);
  513. cSTATUS->CPU_TEMP = round(cSYSSTAT.temperature);
  514. // if( cSTATUS->CPU_LOAD == 0xFF ) cSTATUS->CPU_LOAD = 0;
  515. // if( cSTATUS->CPU_TEMP == 0xFF ) cSTATUS->CPU_TEMP = 0;
  516. cSTATUS->DISK_UTI = cSYSSTAT.disk;
  517. cSTATUS->MEMO_UTI = cSYSSTAT.mem;
  518. deviceNode ** tA = NULL;
  519. uint32_t tCNT = deviceNodeFactory::getInstance()->fetchNodes(ARGUS_ALS_SENSOR, tA);
  520. if (! tCNT)
  521. {
  522. tCNT = deviceNodeFactory::getInstance()->fetchNodes(ARGUS_LFS_SENSOR, tA);
  523. if (! tCNT)
  524. {
  525. tCNT = deviceNodeFactory::getInstance()->fetchNodes(ARGUS_PLS_200_SENSOR, tA);
  526. if (! tCNT)
  527. {
  528. tCNT = deviceNodeFactory::getInstance()->fetchNodes(ARGUS_PLS_360_SENSOR, tA);
  529. if (! tCNT)
  530. {
  531. tCNT = deviceNodeFactory::getInstance()->fetchNodes(ARGUS_3D_SENSOR, tA);
  532. if (! tCNT)
  533. {
  534. tCNT = deviceNodeFactory::getInstance()->fetchNodes(ARGUS_NET_PLS_200, tA);
  535. };
  536. };
  537. };
  538. };
  539. };
  540. cSTATUS->STATUSES.b_sensor = SENOR_STATUS_NA;
  541. cSTATUS->STATUSES.u_sensor = SENOR_STATUS_NA;
  542. if (tCNT)
  543. {
  544. for (uint32_t i = 0; i < tCNT; i++)
  545. {
  546. deviceNodeSensor * tSENS = (deviceNodeSensor *) tA[i];
  547. if (tSENS)
  548. {
  549. // Sensor's IDs are Sensor's NodeID's
  550. if (tSENS->getNodeID() == m_sINFO.BOTTOM_ID)
  551. {
  552. cSTATUS->STATUSES.b_sensor = tSENS->getSensStatus();
  553. };
  554. if (tSENS->getNodeID() == m_sINFO.UPPER_ID)
  555. {
  556. cSTATUS->STATUSES.u_sensor = tSENS->getSensStatus();
  557. };
  558. };
  559. };
  560. // Not Freeing tA[] -> those are pointers to static structs
  561. free(tA);
  562. tA = NULL;
  563. #ifdef DEBUG_EXTRA
  564. }
  565. else
  566. {
  567. LOG("No Sensors Defined/Enabled In the system!");
  568. #endif
  569. };
  570. tCNT = deviceNodeFactory::getInstance()->fetchNodes(ARGUS_ANALOG_STATIC_CAMERA, tA);
  571. if (! tCNT)
  572. {
  573. tCNT = deviceNodeFactory::getInstance()->fetchNodes(ARGUS_ANALOG_PTZ_CAMERA, tA);
  574. if (! tCNT)
  575. {
  576. tCNT = deviceNodeFactory::getInstance()->fetchNodes(ARGUS_IP_STATIC_CAMERA, tA);
  577. if (! tCNT)
  578. {
  579. tCNT = deviceNodeFactory::getInstance()->fetchNodes(ARGUS_IP_PTZ_CAMERA, tA);
  580. if (! tCNT)
  581. {
  582. tCNT = deviceNodeFactory::getInstance()->fetchNodes(ARGUS_IP_PRESET_CAMERA, tA);
  583. if (! tCNT)
  584. {
  585. tCNT = deviceNodeFactory::getInstance()->fetchNodes(ARGUS_ANALOG_PRESET_CAMERA, tA);
  586. };
  587. };
  588. };
  589. };
  590. };
  591. cSTATUS->STATUSES.camera = CAMERA_STATUS_NA;
  592. if (tCNT)
  593. {
  594. for (uint32_t i = 0; i < tCNT; i++)
  595. {
  596. deviceNodeCamera * tCAM = (deviceNodeCamera *) tA[i];
  597. cSTATUS->STATUSES.camera = cSTATUS->STATUSES.camera | ((tCAM->getCamStatus() > 0) ? (CAMERA_STATUS_OK << (i * 3)) : CAMERA_STATUS_NA);
  598. cSTATUS->STATUSES.camera = cSTATUS->STATUSES.camera | ((tCAM->getStreamStatus() > 0) ? (CAMERA_STATUS_STREAM_OK << (i * 3)) : CAMERA_STATUS_NA);
  599. cSTATUS->STATUSES.camera = cSTATUS->STATUSES.camera | ((tCAM->getPtzStatus() > 0) ? (CAMERA_STATUS_PTZ_OK << (i * 3)) : CAMERA_STATUS_NA);
  600. if (i == 0)
  601. {
  602. break; // Only first camera
  603. }
  604. };
  605. // Not Freeing tA[] -> those are pointers to static structs
  606. free(tA);
  607. tA = NULL;
  608. #ifdef DEBUG_EXTRA
  609. }
  610. else
  611. {
  612. LOG("No Camera Defined/Enabled In the system!");
  613. #endif
  614. };
  615. // All System Statuses goes here
  616. cSTATUS->STATUSES.system = cSTATUS->STATUSES.system | ((m_pMaster->getTrainPresence()) ? SYSTEM_STATUS_TRAIN : SYSTEM_STATUS_NA);
  617. if (pushNewTransaction(tCMD))
  618. {
  619. return;
  620. }
  621. free(tCMD->DATA);
  622. };
  623. free(tCMD);
  624. };
  625. }
  626. void mojoRemoteClient::enqueueTimeReq()
  627. {
  628. RPC_CMD_RECORD * tCMD = (RPC_CMD_RECORD *) malloc(sizeof(RPC_CMD_RECORD));
  629. if (tCMD)
  630. {
  631. tCMD->CMD = ARGUS_DATA_MSG_REQ_TIME_SYNC;
  632. tCMD->DATA_SIZE = 0;
  633. tCMD->DATA = NULL;
  634. if (pushNewTransaction(tCMD))
  635. {
  636. return;
  637. }
  638. free(tCMD);
  639. };
  640. }
  641. void mojoRemoteClient::flushTransactions()
  642. {
  643. m_mCurrentCMDProtector.lock();
  644. if (m_pCurrentCMD)
  645. {
  646. if (m_pCurrentCMD->DATA)
  647. {
  648. free(m_pCurrentCMD->DATA);
  649. }
  650. free(m_pCurrentCMD);
  651. };
  652. while ((m_pCurrentCMD = m_qCMD->pop()))
  653. {
  654. if (m_pCurrentCMD->DATA)
  655. {
  656. free(m_pCurrentCMD->DATA);
  657. }
  658. free(m_pCurrentCMD);
  659. };
  660. m_pCurrentCMD = NULL;
  661. m_mCurrentCMDProtector.unlock();
  662. }
  663. void mojoRemoteClient::setTO(uint8_t seconds)
  664. {
  665. m_mTOProtoctor.lock();
  666. m_bTOCounter = seconds;
  667. m_mTOProtoctor.unlock();
  668. }
  669. bool mojoRemoteClient::decTO()
  670. {
  671. m_mTOProtoctor.lock();
  672. if (m_bTOCounter)
  673. {
  674. m_bTOCounter--;
  675. m_mTOProtoctor.unlock();
  676. return true;
  677. };
  678. m_mTOProtoctor.unlock();
  679. return false;
  680. }
  681. void mojoRemoteClient::m_fThreadProc(void)
  682. {
  683. time_t tTimeTSeconds = 0;
  684. time_t cTimeTSeconds = 0;
  685. uint32_t tSecondsCounter = 0;
  686. m_bThreadStatus = TH_WORKING;
  687. pthread_setname_np( pthread_self(), "remoteClient" );
  688. while (m_bThreadStatus < TH_ENDED)
  689. {
  690. // seconds Counter (for internal purposes)
  691. cTimeTSeconds = time(NULL);
  692. // Process each second
  693. if (cTimeTSeconds != tTimeTSeconds)
  694. {
  695. tSecondsCounter++;
  696. tTimeTSeconds = cTimeTSeconds;
  697. switch (getAutomationStage())
  698. {
  699. case ARGUS_RPC_STAGE_CONNECT:
  700. {
  701. flushTransactions();
  702. if (m_bUseBackupServer)
  703. {
  704. if (m_bActiveServer == 0)
  705. {
  706. #ifdef DEBUG
  707. char tB[128];
  708. sprintf(tB, "Creating Remote connection to Main Server [%s:%d]", m_pMaster->m_sSiteData.remote_ip, m_pMaster->m_sSiteData.remote_port);
  709. LOG(tB);
  710. #endif
  711. m_pPort = new clientPort(m_pMaster->m_sSiteData.remote_ip, m_pMaster->m_sSiteData.remote_port);
  712. }
  713. else
  714. {
  715. #ifdef DEBUG
  716. char tB[128];
  717. sprintf(tB, "Creating Remote connection to Backup Server [%s:%d]", m_pMaster->m_sSiteData.remote_backup_ip, m_pMaster->m_sSiteData.remote_backup_port);
  718. LOG(tB);
  719. #endif
  720. m_pPort = new clientPort(m_pMaster->m_sSiteData.remote_backup_ip, m_pMaster->m_sSiteData.remote_backup_port);
  721. }
  722. if (m_pPort)
  723. {
  724. if (m_pPort->create())
  725. {
  726. #ifdef DEBUG
  727. LOG("Connection Sucessfull");
  728. #endif
  729. m_bShutdownCommunication = false;
  730. m_bCommunicationEstablished = true;
  731. m_bRegisteredWithRemotePeer = false;
  732. setTransport(m_pPort, false);
  733. setAutomationStage(ARGUS_RPC_STAGE_REGISTER);
  734. }
  735. else
  736. {
  737. LOG_ERROR("Connection to Remote Server Failed!");
  738. setConnectionStatus(CS_DISCONNECTED);
  739. setTransport(NULL, false);
  740. delete(m_pPort);
  741. m_pPort = NULL;
  742. m_bShutdownCommunication = true;
  743. m_bCommunicationEstablished = false;
  744. m_bRegisteredWithRemotePeer = false;
  745. m_bActiveServer = 1 - m_bActiveServer;
  746. setTO(30); // 30 sec to wait
  747. setAutomationStage(ARGUS_RPC_STAGE_WAIT_RECONNECT);
  748. };
  749. };
  750. }
  751. else
  752. {
  753. if (m_pMaster->m_sSiteData.remote_port)
  754. {
  755. #ifdef DEBUG
  756. char tB[128];
  757. sprintf(tB, "Creating Remote connection to Alone Server [%s:%d]", m_pMaster->m_sSiteData.remote_ip, m_pMaster->m_sSiteData.remote_port);
  758. LOG(tB);
  759. #endif
  760. m_pPort = new clientPort(m_pMaster->m_sSiteData.remote_ip, m_pMaster->m_sSiteData.remote_port);
  761. if (m_pPort)
  762. {
  763. if (m_pPort->create())
  764. {
  765. #ifdef DEBUG
  766. LOG("Connection Sucessfull");
  767. #endif
  768. m_bShutdownCommunication = false;
  769. m_bCommunicationEstablished = true;
  770. m_bRegisteredWithRemotePeer = false;
  771. setTransport(m_pPort, false);
  772. setAutomationStage(ARGUS_RPC_STAGE_REGISTER);
  773. }
  774. else
  775. {
  776. LOG_ERROR("Connection to Remote Server Failed!");
  777. setConnectionStatus(CS_DISCONNECTED);
  778. setTransport(NULL, false);
  779. delete(m_pPort);
  780. m_pPort = NULL;
  781. m_bShutdownCommunication = true;
  782. m_bCommunicationEstablished = false;
  783. m_bRegisteredWithRemotePeer = false;
  784. setTO(30); // 30 sec to wait
  785. setAutomationStage(ARGUS_RPC_STAGE_WAIT_RECONNECT);
  786. };
  787. };
  788. };
  789. };
  790. break;
  791. };
  792. case ARGUS_RPC_STAGE_WAIT_RECONNECT:
  793. {
  794. #ifdef DEBUG_EXTRA
  795. LOG("Wait Reconnect!");
  796. #endif
  797. if (! decTO())
  798. {
  799. #ifdef DEBUG_EXTRA
  800. LOG("Go to Connect!");
  801. #endif
  802. setAutomationStage(ARGUS_RPC_STAGE_CONNECT);
  803. }
  804. break;
  805. };
  806. case ARGUS_RPC_STAGE_REGISTER:
  807. {
  808. #ifdef DEBUG_EXTRA
  809. LOG("Stage Register!");
  810. #endif
  811. CSTR tIP = m_pPort->getLocalIp4();
  812. if (tIP)
  813. {
  814. m_pCurrentCMD = (RPC_CMD_RECORD *) malloc(sizeof(RPC_CMD_RECORD));
  815. if (m_pCurrentCMD)
  816. {
  817. m_pCurrentCMD->CMD = ARGUS_DATA_MSG_REGISTER;
  818. m_pCurrentCMD->DATA_SIZE = sizeof(ARGUS_DATA_MOJO_REGISTRATION); // strlen( m_pMaster->m_sIdentity );
  819. m_pCurrentCMD->DATA = malloc(m_pCurrentCMD->DATA_SIZE);
  820. if (m_pCurrentCMD->DATA)
  821. {
  822. memset(m_pCurrentCMD->DATA, 0, m_pCurrentCMD->DATA_SIZE);
  823. strncpy(((ARGUS_DATA_MOJO_REGISTRATION *) m_pCurrentCMD->DATA)->identity, m_pMaster->m_sIdentity, 32);
  824. strncpy(((ARGUS_DATA_MOJO_REGISTRATION *) m_pCurrentCMD->DATA)->peer, tIP, 22);
  825. if (peer_send_rpc_pack(m_pCurrentCMD))
  826. {
  827. setTO(3); // Wait for 3 seconds to be registered with server
  828. setAutomationStage(ARGUS_RPC_STAGE_WAIT_ACK);
  829. free(tIP);
  830. break;
  831. };
  832. free(m_pCurrentCMD->DATA);
  833. };
  834. free(m_pCurrentCMD);
  835. };
  836. free(tIP);
  837. };
  838. m_pCurrentCMD = NULL;
  839. break;
  840. };
  841. case ARGUS_RPC_STAGE_SEND_HELLO:
  842. {
  843. #ifdef DEBUG_EXTRA
  844. LOG("Stage HELLO!");
  845. #endif
  846. m_pCurrentCMD = (RPC_CMD_RECORD *) malloc(sizeof(RPC_CMD_RECORD));
  847. if (m_pCurrentCMD)
  848. {
  849. m_pCurrentCMD->CMD = ARGUS_DATA_MSG_INFO;
  850. m_pCurrentCMD->DATA_SIZE = sizeof(ARGUS_DATA_MOJO_INFO);
  851. m_pCurrentCMD->DATA = malloc(m_pCurrentCMD->DATA_SIZE);
  852. if (m_pCurrentCMD->DATA)
  853. {
  854. #ifdef DEBUG_EXTRA
  855. LOG("Send Client Info!");
  856. #endif
  857. // Have that info on RC's Create()
  858. // m_pMaster->fillMojoInfo( (ARGUS_DATA_MOJO_INFO*)m_pCurrentCMD->DATA );
  859. memcpy(m_pCurrentCMD->DATA, &m_sINFO, sizeof(ARGUS_DATA_MOJO_INFO));
  860. #ifdef DEBUG_EXTRA
  861. LOG("ARGUS_DATA_MOJO_INFO");
  862. #endif
  863. if (peer_send_rpc_pack(m_pCurrentCMD))
  864. {
  865. setTO(1); // Wait for 3 seconds
  866. setAutomationStage(ARGUS_RPC_STAGE_WAIT_ACK);
  867. };
  868. free(m_pCurrentCMD->DATA);
  869. };
  870. free(m_pCurrentCMD);
  871. };
  872. m_pCurrentCMD = NULL;
  873. break;
  874. };
  875. case ARGUS_RPC_STAGE_WAIT_ACK:
  876. {
  877. #ifdef DEBUG_EXTRA
  878. LOG("Wait ACK!");
  879. #endif
  880. if (! decTO())
  881. {
  882. setAutomationStage(ARGUS_RPC_STAGE_CLOSE);
  883. }
  884. break;
  885. };
  886. case ARGUS_RPC_STAGE_IDLE:
  887. {
  888. if ((tSecondsCounter % ARGUS_SECONDS_TO_SYNC_TIME) == 15)
  889. {
  890. enqueueTimeReq();
  891. }
  892. else
  893. {
  894. enqueueStatMsg();
  895. }
  896. break;
  897. };
  898. case ARGUS_RPC_STAGE_DISCONNECT:
  899. {
  900. #ifdef DEBUG_EXTRA
  901. LOG("Stage Disconnect!");
  902. #endif
  903. // Gracefully Disconnect at Client Destructor
  904. if ( m_bRegisteredWithRemotePeer ){
  905. enqueueDisconnect(m_bCloseCommunicationReason);
  906. setAutomationStage( ARGUS_RPC_STAGE_WAIT_ACK );
  907. break; // ---> Go to reconnect to other server
  908. };
  909. };
  910. /* fallthrough */
  911. case ARGUS_RPC_STAGE_CLOSE:
  912. {
  913. #ifdef DEBUG_EXTRA
  914. LOG("Stage Close!");
  915. #endif
  916. flushTransactions();
  917. setTransport(NULL, false);
  918. delete(m_pPort);
  919. m_pPort = NULL;
  920. m_bShutdownCommunication = true;
  921. m_bCommunicationEstablished = false;
  922. m_bRegisteredWithRemotePeer = false;
  923. setTO(30); // 30 sec to wait
  924. m_bActiveServer = 1 - m_bActiveServer;
  925. setAutomationStage(ARGUS_RPC_STAGE_WAIT_RECONNECT);
  926. break;
  927. };
  928. };
  929. m_mCurrentVTRProtector.lock();
  930. if (m_vVTRHelpers.size())
  931. {
  932. // Handle New Video Transfer
  933. #ifdef DEBUG_EXTRA
  934. LOG("CHK HLPR");
  935. #endif
  936. if (m_vVTRHelpers.at(0)->state == 0)
  937. {
  938. RPC_CMD_RECORD * tPack = (RPC_CMD_RECORD *) malloc(sizeof(RPC_CMD_RECORD));
  939. if (tPack)
  940. {
  941. tPack->DATA_SIZE = sizeof(ARGUS_DATA_VIDEO_INFO);
  942. tPack->DATA = malloc(tPack->DATA_SIZE);
  943. if (tPack->DATA)
  944. {
  945. memcpy(tPack->DATA, m_vVTRHelpers.at(0)->ptr->getVideoInfo(), tPack->DATA_SIZE);
  946. tPack->CMD = ARGUS_DATA_MSG_VIDEO_INFO;
  947. if (m_qCMD->push(tPack) != -1) // push() returns the element ID (may be 0) or -1 on failure
  948. {
  949. m_vVTRHelpers.at(0)->state = 1;
  950. m_vVTRHelpers.at(0)->ts = cTimeTSeconds;
  951. }
  952. else
  953. {
  954. free(tPack->DATA);
  955. free(tPack);
  956. }
  957. }
  958. else
  959. {
  960. free(tPack);
  961. };
  962. };
  963. };
  964. /// Validate Stalled/ Finished Videos (Try To Send next time
  965. for (V_VIDEO_TRANSFER_HELPERS::iterator idx = m_vVTRHelpers.begin(); idx != m_vVTRHelpers.end();)
  966. {
  967. if ((*idx)->state == 2)
  968. {
  969. if ((cTimeTSeconds - (*idx)->ts) > 5)
  970. {
  971. // The transfer is staled
  972. (*idx)->state = 0;
  973. }
  974. };
  975. if ((*idx)->state == 3)
  976. {
  977. #ifdef DEBUG_EXTRA
  978. LOG("Del HLPR");
  979. #endif
  980. // Finished Transfer
  981. delete((*idx)->ptr);
  982. free(*idx);
  983. m_vVTRHelpers.erase(idx);
  984. #ifdef DEBUG_EXTRA
  985. LOG("Erase HLPR done");
  986. #endif
  987. break; // must revalidate Beg-End conditions for FOR loop
  988. }
  989. else
  990. {
  991. idx++;
  992. }
  993. };
  994. };
  995. m_mCurrentVTRProtector.unlock();
  996. };
  997. if (validateTransaction())
  998. {
  999. if (fetchNewTransaction())
  1000. {
  1001. if (peer_send_rpc_pack(m_pCurrentCMD))
  1002. {
  1003. setTO(1);
  1004. setAutomationStage(ARGUS_RPC_STAGE_WAIT_ACK);
  1005. }
  1006. else
  1007. {
  1008. LOG_ERROR("Failure!");
  1009. }
  1010. }
  1011. else
  1012. {
  1013. SLEEP(DEFAULT_THREAD_SLEEP_TIME);
  1014. }
  1015. }
  1016. else
  1017. {
  1018. SLEEP(DEFAULT_THREAD_SLEEP_TIME);
  1019. }
  1020. };
  1021. #ifdef DEBUG_EXTRA
  1022. LOG("Remote Connector Thread Ended!");
  1023. #endif
  1024. }
  1025. /*
  1026. Register With Server and make Time Sync With Server
  1027. */
  1028. bool mojoRemoteClient::peer_send_rpc_pack(RPC_CMD_RECORD * ptr)
  1029. {
  1030. bool retVal;
  1031. static uint8_t pBuffer[4194304]; // 4Mb
  1032. if (ptr == NULL)
  1033. {
  1034. return false;
  1035. }
  1036. if (! m_bCommunicationEstablished)
  1037. {
  1038. return false;
  1039. }
  1040. // if( !m_bRegisteredWithRemotePeer ) return false;
  1041. pBuffer[ARGUS_HEADER_SIZE] = ptr->CMD;
  1042. // uint16_t i = 0;
  1043. // for (; i < ptr->DATA_SIZE; i++) pBuffer[ARGUS_HEADER_SIZE+1+i] = ((uint8_t *)ptr->DATA)[i];
  1044. memcpy(pBuffer + ARGUS_HEADER_SIZE + 1, ptr->DATA, ptr->DATA_SIZE);
  1045. m_nOutbondSerial++;
  1046. // retVal = m_pPort->sendData( pBuffer, argus_rpc_finishupPackage( pBuffer, m_nOutbondSerial, ARGUS_HEADER_SIZE+1+i ));
  1047. retVal = m_pPort->sendData(pBuffer, argus_rpc_finishupPackage(pBuffer, m_nOutbondSerial, ARGUS_HEADER_SIZE + 1 + ptr->DATA_SIZE));
  1048. return retVal;
  1049. }
  1050. /*bool mojoRemoteClient::createVideoTransferTask( ARGUS_DATA_VIDEO_SEGMENT *ptr ){
  1051. if( ptr == NULL ) return false;
  1052. if( !m_bCommunicationEstablished ) return false;
  1053. if( !m_bRegisteredWithRemotePeer ) return false;
  1054. uint8_t tBuffer[1024];
  1055. tBuffer[ARGUS_HEADER_SIZE] = ARGUS_DATA_MSG_VIDEO_INFO;
  1056. uint16_t i = 0;
  1057. for(; i < sizeof(ARGUS_DATA_VIDEO_SEGMENT); i++) tBuffer[ARGUS_HEADER_SIZE+1+i] = ((uint8_t*)ptr)[i];
  1058. m_nOutbondSerial++;
  1059. return m_pPort->sendData(tBuffer, argus_rpc_finishupPackage(tBuffer, m_nOutbondSerial, ARGUS_HEADER_SIZE+1+i ));
  1060. };
  1061. */
  1062. bool mojoRemoteClient::validate()
  1063. {
  1064. if (m_bCommunicationEstablished)
  1065. {
  1066. #if 0
  1067. lk;sdf
  1068. if ( getConnectionStatus() == CS_DISCONNECTED ) {
  1069. m_bCommunicationEstablished = false;
  1070. if( m_pPort ) {
  1071. // Cancel all ongoing Queries
  1072. m_bShutdownCommunication = true;
  1073. setTransport( NULL, false );
  1074. delete( m_pPort );
  1075. };
  1076. m_bAutomationStage = ARGUS_RPC_STAGE_CONNECT;
  1077. // Revalidate Data!!!
  1078. //m_bActiveServer = 0;
  1079. m_bUseBackupServer = ( ( m_pMaster->m_sSiteData.remote_backup_port > 0 ) && strlen( ( m_pMaster->m_sSiteData.remote_backup_ip ) > 7 ) );
  1080. /*m_pPort = new clientPort( m_pMaster->m_sSiteData.remote_ip, m_pMaster->m_sSiteData.remote_port );
  1081. if( m_pPort ) {
  1082. if( m_pPort->create() ) {
  1083. m_bShutdownCommunication = false;
  1084. m_bCommunicationEstablished = true;
  1085. m_bRegisteredWithRemotePeer = false;
  1086. setTransport( m_pPort, false );
  1087. } else {
  1088. delete( m_pPort );
  1089. m_pPort = NULL;
  1090. };
  1091. };
  1092. */
  1093. };
  1094. #endif
  1095. #ifdef DEBUG_EXTRA
  1096. }
  1097. else
  1098. {
  1099. LOG("Not Connected!");
  1100. #endif
  1101. /*
  1102. if( m_pPort ) {
  1103. // Cancel all ongoing Queries
  1104. m_bShutdownCommunication = true;
  1105. setTransport( NULL, false );
  1106. delete( m_pPort );
  1107. };
  1108. //Try To connect
  1109. m_pPort = new clientPort( m_pMaster->m_sSiteData.remote_ip, m_pMaster->m_sSiteData.remote_port );
  1110. if( m_pPort ) {
  1111. if( m_pPort->create() ) {
  1112. m_bShutdownCommunication = false;
  1113. m_bCommunicationEstablished = true;
  1114. m_bRegisteredWithRemotePeer = false;
  1115. setTransport( m_pPort, false );
  1116. } else {
  1117. delete( m_pPort );
  1118. m_pPort = NULL;
  1119. };
  1120. };
  1121. */
  1122. };
  1123. return true;
  1124. }
  1125. VTR_HELPER * mojoRemoteClient::getHelperByDBID(uint64_t dbid)
  1126. {
  1127. m_mCurrentVTRProtector.lock();
  1128. if (m_vVTRHelpers.size())
  1129. {
  1130. for (V_VIDEO_TRANSFER_HELPERS::iterator idx = m_vVTRHelpers.begin(); idx != m_vVTRHelpers.end(); idx++)
  1131. {
  1132. if ((*idx)->ptr->getRemoteReferenceID() == dbid)
  1133. {
  1134. m_mCurrentVTRProtector.unlock();
  1135. return (*idx);
  1136. };
  1137. };
  1138. };
  1139. m_mCurrentVTRProtector.unlock();
  1140. return NULL;
  1141. }
  1142. bool mojoRemoteClient::addEvent(EVENT_CONTAINER * Evt)
  1143. {
  1144. #ifdef DEBUG_EXTRA
  1145. LOG("Add Evt!");
  1146. #endif
  1147. if (Evt == NULL)
  1148. {
  1149. return false;
  1150. }
  1151. RPC_CMD_RECORD * tPack = (RPC_CMD_RECORD *) malloc(sizeof(RPC_CMD_RECORD));
  1152. if (tPack)
  1153. {
  1154. #ifdef DEBUG_EXTRA
  1155. char tB[128];
  1156. sprintf(tB, "TS: %d.%d", Evt->m_UMSTS / 1000, Evt->m_UMSTS % 1000);
  1157. LOG(tB);
  1158. #endif
  1159. tPack->DATA = (void *) argus_rpc_convert_evt(Evt);
  1160. if (tPack->DATA)
  1161. {
  1162. tPack->CMD = ARGUS_DATA_MSG_EVT;
  1163. tPack->DATA_SIZE = sizeof(ARGUS_DATA_EVENT);
  1164. if (m_qCMD->push(tPack) != -1) // push() returns the element ID (may be 0) or -1 on failure
  1165. {
  1166. return true;
  1167. }
  1168. free(tPack->DATA);
  1169. };
  1170. free(tPack);
  1171. };
  1172. return false;
  1173. }
  1174. bool mojoRemoteClient::addVideo(VIDEO_SEGMENT_INFO * ptr)
  1175. {
  1176. #ifdef DEBUG_EXTRA
  1177. LOG("Add Video!");
  1178. #endif
  1179. if (ptr == NULL)
  1180. {
  1181. return false;
  1182. }
  1183. VTR_HELPER * tHLPR = (VTR_HELPER *) malloc(sizeof(VTR_HELPER));
  1184. if (tHLPR)
  1185. {
  1186. tHLPR->state = 0;
  1187. tHLPR->ptr = new mojoVideoTransferHelper(ARGUS_RPC_DEFAULT_MEDIA_CHUNK);
  1188. LOG("NW HLPR");
  1189. if (tHLPR->ptr)
  1190. {
  1191. LOG("HLPR OK");
  1192. if (tHLPR->ptr->init(ptr))
  1193. {
  1194. LOG("HLPR INIT OK");
  1195. m_mCurrentVTRProtector.lock();
  1196. m_vVTRHelpers.push_back(tHLPR);
  1197. m_mCurrentVTRProtector.unlock();
  1198. LOG("HLPR PUSH OK");
  1199. return true;
  1200. };
  1201. delete(tHLPR->ptr);
  1202. };
  1203. free(tHLPR);
  1204. };
  1205. return false;
  1206. }
  1207. mojoVideoTransferHelper::mojoVideoTransferHelper(uint32_t buffer_size)
  1208. {
  1209. m_pLog = basicLogCollection::getInstance();
  1210. m_bVideoExists = false;
  1211. m_bVideoOpened = false;
  1212. m_nBufferSize = buffer_size;
  1213. m_pBuffer = (uint8_t *) malloc(m_nBufferSize);
  1214. m_nCTSMS = 0;
  1215. m_nRemoteRefID = 0;
  1216. m_pFD = NULL;
  1217. memset(m_cCurrentFile, 0, MAX_PATH);
  1218. }
  1219. mojoVideoTransferHelper::~mojoVideoTransferHelper()
  1220. {
  1221. LOG("HDESTRC");
  1222. abort();
  1223. LOG("HDESTRC DONE");
  1224. }
  1225. #include <sys/stat.h>
  1226. bool mojoVideoTransferHelper::init(VIDEO_SEGMENT_INFO * ptr)
  1227. {
  1228. if (m_pBuffer == NULL)
  1229. {
  1230. return false;
  1231. }
  1232. if (m_bVideoExists)
  1233. {
  1234. if (m_bVideoOpened)
  1235. {
  1236. fclose(m_pFD);
  1237. }
  1238. unlink(m_cCurrentFile);
  1239. };
  1240. if (! (m_bVideoExists = fileExist(ptr->scratchPath)))
  1241. {
  1242. return false;
  1243. }
  1244. m_nRemoteRefID = 0;
  1245. strncpy(m_cCurrentFile, ptr->scratchPath, MAX_PATH);
  1246. m_cCurrentFile[MAX_PATH - 1] = (char) 0;
  1247. struct stat st;
  1248. stat(m_cCurrentFile, &st);
  1249. m_sIn.DATA_SIZE = st.st_size;
  1250. m_sIn.DTS = ptr->streamTSS;
  1251. m_sIn.DMS = ptr->streamTMS;
  1252. m_sIn.FPS = ptr->streamFPS;
  1253. m_sIn.REF_ID = m_nRemoteRefID;
  1254. strncpy(m_sIn.FMT, ptr->recordEXT, 5);
  1255. m_sIn.FMT[5] = (char) 0;
  1256. m_sIn.WIDTH = ptr->streamWidth;
  1257. m_sIn.HEIGHT = ptr->streamHeight;
  1258. #ifdef DEBUG_EXTRA
  1259. char tB[129];
  1260. sprintf(tB, "VideoInfo Init: [%dx%d]@%d TS: %d.%d", m_sIn.WIDTH, m_sIn.HEIGHT, m_sIn.FPS, m_sIn.DTS, m_sIn.DMS);
  1261. LOG(tB);
  1262. #endif
  1263. m_pFD = fopen(m_cCurrentFile, "r");
  1264. if ((m_bVideoOpened = m_pFD != NULL))
  1265. {
  1266. return true;
  1267. }
  1268. return false;
  1269. }
  1270. uint8_t * mojoVideoTransferHelper::getNextChunk(uint32_t req_chunk_size, uint32_t * ack_size)
  1271. {
  1272. uint8_t * retVal = NULL;
  1273. if (m_bVideoOpened)
  1274. {
  1275. retVal = (uint8_t *) malloc(req_chunk_size + 12); //+DB_SOURCE_ID_x_64+Size_32
  1276. if (retVal)
  1277. {
  1278. int32_t rv = fread(retVal + 12, 1, req_chunk_size, m_pFD);
  1279. if (rv < 0)
  1280. {
  1281. free(retVal);
  1282. retVal = NULL;
  1283. abort();
  1284. }
  1285. else
  1286. {
  1287. *ack_size = rv + 12;
  1288. retVal[0] = (m_nRemoteRefID >> 56) & 0xFF;
  1289. retVal[1] = (m_nRemoteRefID >> 48) & 0xFF;
  1290. retVal[2] = (m_nRemoteRefID >> 40) & 0xFF;
  1291. retVal[3] = (m_nRemoteRefID >> 32) & 0xFF;
  1292. retVal[4] = (m_nRemoteRefID >> 24) & 0xFF;
  1293. retVal[5] = (m_nRemoteRefID >> 16) & 0xFF;
  1294. retVal[6] = (m_nRemoteRefID >> 8) & 0xFF;
  1295. retVal[7] = m_nRemoteRefID & 0xFF;
  1296. retVal[8] = (rv >> 24) & 0xFF;
  1297. retVal[9] = (rv >> 16) & 0xFF;
  1298. retVal[10] = (rv >> 8) & 0xFF;
  1299. retVal[11] = rv & 0xFF;
  1300. if (feof(m_pFD))
  1301. {
  1302. fclose(m_pFD);
  1303. m_bVideoOpened = false;
  1304. };
  1305. };
  1306. };
  1307. };
  1308. return retVal;
  1309. }
  1310. ARGUS_DATA_VIDEO_INFO * mojoVideoTransferHelper::getVideoInfo()
  1311. {
  1312. return &m_sIn;
  1313. }
  1314. void mojoVideoTransferHelper::abort() {}
  1315. #undef LOG
  1316. #undef LOG_ERROR