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.

506 lines
20 KiB

​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
2 years ago
​
​
​
​
2 years ago
​
​
​
​
​
​
​
​
2 years ago
​
​
​
​
​
2 years ago
2 years ago
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
2 years ago
​
​
2 years ago
​
​
​
​
​
​
2 years ago
2 years ago
​
2 years ago
2 years ago
​
​
​
​
​
​
​
2 years ago
​
​
​
​
​
2 years ago
2 years ago
​
2 years ago
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
2 years ago
2 years ago
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
2 years ago
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
2 years ago
​
​
2 years ago
2 years ago
2 years ago
2 years ago
​
​
​
2 years ago
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
2 years ago
​
​
​
2 years ago
2 years ago
​
​
​
​
​
​
​
​
​
​
​
​
​
2 years ago
2 years ago
2 years ago
​
​
​
2 years ago
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
2 years ago
2 years ago
​
​
​
​
​
​
​
​
​
2 years ago
​
​
2 years ago
​
​
​
​
​
2 years ago
​
​
2 years ago
​
​
​
​
2 years ago
​
2 years ago
​
​
​
2 years ago
​
​
2 years ago
2 years ago
2 years ago
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
2 years ago
2 years ago
​
2 years ago
​
​
​
​
​
​
​
​
​
2 years ago
2 years ago
​
​
​
​
2 years ago
2 years ago
​
​
2 years ago
2 years ago
​
​
​
​
​
​
​
​
​
​
​
2 years ago
2 years ago
2 years 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. char _tBfrErrMSG234[256];\
  7. sprintf( _tBfrErrMSG234, "In file %s[%d] in func:%s %s",__FILE__, __LINE__, __func__, X );\
  8. m_pLog->Log( "RPC", this, _LOG_ERROR, _tBfrErrMSG234 );\
  9. }
  10. #else
  11. #define LOG_ERROR( X ) m_pLog->Log( "RPC", this, _LOG_ERROR, X );
  12. #endif
  13. mojoRemoteClient::mojoRemoteClient( mojoKernel * ptr ):protocolParser(){
  14. m_pLog = basicLogCollection::getInstance();
  15. m_pPort = NULL;
  16. m_pMaster = ptr;
  17. m_nOutbondSerial = 0;
  18. m_nInbondSerial = 0;
  19. m_bShutdownCommunication = true;
  20. m_bCommunicationEstablished = false;
  21. m_bRegisteredWithRemotePeer = false;
  22. m_qCMD = new RPC_CMD_QUEUE();
  23. };
  24. mojoRemoteClient::~mojoRemoteClient(){
  25. waitThreadEnd( true );
  26. if( m_bRegisteredWithRemotePeer ) {
  27. //Unregister Mojo
  28. };
  29. m_bShutdownCommunication = true;
  30. m_bCommunicationEstablished = false;
  31. m_bRegisteredWithRemotePeer = false;
  32. if ( m_pPort ) delete( m_pPort );
  33. delete( m_qCMD );
  34. };
  35. bool mojoRemoteClient::create(){
  36. if( m_pMaster == NULL ) return false;
  37. if( m_bCommunicationEstablished && ( m_bThreadStatus == TH_WORKING ) ) return true;
  38. m_bAutomationStage = ARGUS_RPC_STAGE_CONNECT;
  39. return init();
  40. };
  41. int mojoRemoteClient::packetChecker(U8 *Buffer, size_t BufferSize){
  42. //char tB[64];
  43. if ( Buffer[0] == ARGUS_START_SERVER_FLAG ) {
  44. if( BufferSize > ARGUS_DATA_MSG_MIN_SIZE ){
  45. uint32_t SIZE = Buffer[1];
  46. SIZE = ( SIZE << 8 ) | Buffer[2];
  47. SIZE = ( SIZE << 8 ) | Buffer[3];
  48. SIZE = ( SIZE << 8 ) | Buffer[4];
  49. //sprintf( tB, "Pack Size: %08X", SIZE );
  50. //LOG(tB);
  51. if ( ( SIZE + ARGUS_HEADER_SIZE + ARGUS_CHECKSUM_SIZE ) <= BufferSize ) {
  52. uint16_t tCRC = checksum16( Buffer, SIZE + ARGUS_HEADER_SIZE );
  53. uint16_t cCRC = Buffer[SIZE + ARGUS_HEADER_SIZE];
  54. cCRC = ( cCRC << 8 ) | Buffer[SIZE + ARGUS_HEADER_SIZE+1];
  55. //sprintf( tB, "cCRC: %04X tCRC: %04X", tCRC, cCRC );
  56. //LOG(tB);
  57. if ( tCRC == cCRC ) return 0;
  58. } else return 1; // to grou
  59. } else return 1; //to grow
  60. };
  61. return -1; // to skip
  62. };
  63. protocolPackage *mojoRemoteClient::packetExtractor(U8 *Buffer, size_t BufferSize){
  64. protocolPackage *tPack = (protocolPackage*) malloc( sizeof(protocolPackage));
  65. if ( tPack ) {
  66. tPack->m_nCode = Buffer[ARGUS_HEADER_SIZE];
  67. tPack->m_nSize = Buffer[1];
  68. tPack->m_nSize = ( tPack->m_nSize << 8 ) | Buffer[2];
  69. tPack->m_nSize = ( tPack->m_nSize << 8 ) | Buffer[3];
  70. tPack->m_nSize = ( tPack->m_nSize << 8 ) | Buffer[4];
  71. tPack->m_nSize = tPack->m_nSize + ARGUS_HEADER_SIZE + ARGUS_CHECKSUM_SIZE;
  72. tPack->m_pData = (U8 *) malloc( tPack->m_nSize );
  73. if ( tPack->m_pData ) {
  74. memcpy( tPack->m_pData, Buffer, tPack->m_nSize );
  75. } else {
  76. free( tPack );
  77. tPack = NULL;
  78. };
  79. };
  80. return tPack;
  81. };
  82. bool mojoRemoteClient::packetHandler( protocolPackage *Package ){
  83. m_nInbondSerial = Package->m_pData[1];
  84. m_nInbondSerial = ( m_nInbondSerial << 8 ) | Package->m_pData[2];
  85. m_nInbondSerial = ( m_nInbondSerial << 8 ) | Package->m_pData[3];
  86. m_nInbondSerial = ( m_nInbondSerial << 8 ) | Package->m_pData[4];
  87. switch( Package->m_nCode ){
  88. case ARGUS_DATA_MSG_REGISTER:
  89. m_bRegisteredWithRemotePeer = true;
  90. enqueueInfoMsg();
  91. finishTransaction();
  92. break;
  93. case ARGUS_DATA_MSG_ACCESS_DENIED: m_bRegisteredWithRemotePeer = false;
  94. case ARGUS_DATA_MSG_DISABLED: finishTransaction(); break;
  95. case ARGUS_DATA_MSG_REQ_TIME_SYNC:{
  96. RPC_CMD_RECORD *tCMD = (RPC_CMD_RECORD *)malloc(sizeof(RPC_CMD_RECORD));
  97. if ( tCMD ) {
  98. tCMD->CMD = ARGUS_DATA_MSG_TIME_SYNC;
  99. tCMD->DATA_SIZE = sizeof( ARGUS_DATA_TIME_SYNC_REQ );
  100. tCMD->DATA = malloc(tCMD->DATA_SIZE);
  101. if (tCMD->DATA) {
  102. ARGUS_DATA_TIME_SYNC_REQ *tDATA = (ARGUS_DATA_TIME_SYNC_REQ*)tCMD->DATA;
  103. tDATA->STS = getMilliseconds();
  104. if ( peer_send_rpc_pack( tCMD ) ) {
  105. setTO( 3 );
  106. free( tCMD->DATA );
  107. free( tCMD );
  108. break;
  109. };
  110. free( tCMD->DATA );
  111. };
  112. free( tCMD );
  113. };
  114. finishTransaction();
  115. break;
  116. };
  117. case ARGUS_DATA_MSG_TIME_SYNC:{
  118. struct timespec tS = { 0 };
  119. uint64_t cT = getMilliseconds();
  120. ARGUS_DATA_TIME_SYNC_ACK *tPTR = (ARGUS_DATA_TIME_SYNC_ACK *)(Package->m_pData+ARGUS_HEADER_SIZE+1);
  121. uint64_t eTime = tPTR->ATS + ( (cT - tPTR->STS) >> 1 );
  122. tS.tv_sec = eTime / 1000;
  123. tS.tv_nsec = ( eTime % 1000 ) * 1000000;
  124. if( clock_settime( CLOCK_REALTIME, &tS ) != 0){
  125. LOG_ERROR("Time Correction Failed!");
  126. switch ( errno ) {
  127. case EACCES: LOG_ERROR("Not have write permission for the dynamic POSIX clock device indicated!"); break;
  128. case EFAULT: LOG_ERROR("tS points outside the accessible address space!"); break;
  129. case EINVAL: LOG_ERROR("Parameter specified is invalid!"); break;
  130. 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;
  131. case ENOTSUP: LOG_ERROR("The operation is not supported by the dynamic POSIX clock device specified!"); break;
  132. case EPERM: LOG_ERROR("clock_settime() does not have permission to set the clock indicated!"); break;
  133. };
  134. };
  135. #ifdef DEBUG_EXTRA
  136. LOG("Time Sync ACK!");
  137. char tB[256];
  138. sprintf( tB,"RT:%lld ST:%lld CT:%lld", tPTR->STS, tPTR->ATS, cT );
  139. LOG( tB );
  140. sprintf( tB,"tv_s:%lld tv_ns:%lld", tS.tv_sec, tS.tv_nsec );
  141. LOG( tB );
  142. #endif
  143. finishTransaction();
  144. break;
  145. };
  146. };
  147. return true;
  148. };
  149. uint8_t mojoRemoteClient::getAutomationStage( ){
  150. m_mAutomationStageProtector.lock();
  151. uint8_t retVal = m_bAutomationStage;
  152. m_mAutomationStageProtector.unlock();
  153. return retVal;
  154. };
  155. void mojoRemoteClient::setAutomationStage( uint8_t stg ){
  156. m_mAutomationStageProtector.lock();
  157. m_bAutomationStage = stg;
  158. m_mAutomationStageProtector.unlock();
  159. };
  160. void mojoRemoteClient::finishTransaction(){
  161. m_mCurrentCMDProtector.lock();
  162. if ( m_pCurrentCMD ) {
  163. if ( m_pCurrentCMD->DATA ) free( m_pCurrentCMD->DATA );
  164. free( m_pCurrentCMD );
  165. m_pCurrentCMD = NULL;
  166. };
  167. m_mCurrentCMDProtector.unlock();
  168. };
  169. bool mojoRemoteClient::validateTransaction(){
  170. if ( m_mCurrentCMDProtector.try_lock() ) {
  171. if ( m_pCurrentCMD == NULL ) {
  172. m_mCurrentCMDProtector.unlock();
  173. return true;
  174. };
  175. m_mCurrentCMDProtector.unlock();
  176. };
  177. return false;
  178. };
  179. bool mojoRemoteClient::pushNewTransaction( RPC_CMD_RECORD *ptr ){
  180. if ( ptr == NULL ) return false;
  181. m_mCurrentCMDProtector.lock();
  182. if ( m_qCMD->push( ptr ) != -1 ){
  183. m_mCurrentCMDProtector.unlock();
  184. return true;
  185. };
  186. m_mCurrentCMDProtector.unlock();
  187. return false;
  188. };
  189. bool mojoRemoteClient::fetchNewTransaction(){
  190. m_mCurrentCMDProtector.lock();
  191. if ( m_pCurrentCMD ) {
  192. m_mCurrentCMDProtector.unlock();
  193. return false;
  194. };
  195. m_pCurrentCMD = m_qCMD->pop();
  196. if ( m_pCurrentCMD ) {
  197. m_mCurrentCMDProtector.unlock();
  198. return true;
  199. };
  200. m_mCurrentCMDProtector.unlock();
  201. return false;
  202. };
  203. void mojoRemoteClient::enqueueInfoMsg(){
  204. RPC_CMD_RECORD *tCMD = (RPC_CMD_RECORD *)malloc(sizeof(RPC_CMD_RECORD));
  205. if ( tCMD ) {
  206. tCMD->CMD = ARGUS_DATA_MSG_INFO;
  207. tCMD->DATA_SIZE = sizeof( ARGUS_DATA_MOJO_INFO );
  208. tCMD->DATA = malloc(tCMD->DATA_SIZE);
  209. if (tCMD->DATA) {
  210. ARGUS_DATA_MOJO_INFO *tINFO = (ARGUS_DATA_MOJO_INFO*)tCMD->DATA;
  211. tINFO->MOJO_WORK_MODE = 2;
  212. tINFO->UPPER_ID = 2;
  213. tINFO->BOTTOM_ID = 3;
  214. tINFO->CAM_ID = 4;
  215. tINFO->CPU_COUNT = m_pMaster->m_sSysInfo.CPU_CORES;
  216. tINFO->TOT_DISK = m_pMaster->m_sSysInfo.T_DISK;
  217. tINFO->TOT_MEMO = m_pMaster->m_sSysInfo.T_MEM;
  218. if ( pushNewTransaction( tCMD ) ) return;
  219. free( tCMD->DATA );
  220. };
  221. free( tCMD );
  222. };
  223. };
  224. void mojoRemoteClient::enqueueStatMsg(){
  225. RPC_CMD_RECORD *tCMD = (RPC_CMD_RECORD *)malloc(sizeof(RPC_CMD_RECORD));
  226. if ( tCMD ) {
  227. tCMD->CMD = ARGUS_DATA_MSG_INFO;
  228. tCMD->DATA_SIZE = sizeof( ARGUS_DATA_MOJO_STATUS );
  229. tCMD->DATA = malloc(tCMD->DATA_SIZE);
  230. if (tCMD->DATA) {
  231. ARGUS_DATA_MOJO_STATUS *cSTATUS = (ARGUS_DATA_MOJO_STATUS*)tCMD->DATA;
  232. DBC_SYS_LOAD_INFO cSYSSTAT;
  233. uint8_t tS = m_pMaster->m_pDBC->getLRFDataStatus( 1 );
  234. cSTATUS->STATUSES = 0xff00ff00 | tS;
  235. m_pMaster->getSystemUtilization( &cSYSSTAT );
  236. cSTATUS->CPU_LOAD = round( cSYSSTAT.cpu15 );
  237. cSTATUS->CPU_TEMP = round( cSYSSTAT.temperature );
  238. //if( cSTATUS->CPU_LOAD == 0xFF ) cSTATUS->CPU_LOAD = 0;
  239. //if( cSTATUS->CPU_TEMP == 0xFF ) cSTATUS->CPU_TEMP = 0;
  240. cSTATUS->DISK_UTI = cSYSSTAT.disk;
  241. cSTATUS->MEMO_UTI = cSYSSTAT.mem;
  242. if ( pushNewTransaction( tCMD ) ) return;
  243. free( tCMD->DATA );
  244. };
  245. free( tCMD );
  246. };
  247. };
  248. void mojoRemoteClient::enqueueTimeReq(){
  249. RPC_CMD_RECORD *tCMD = (RPC_CMD_RECORD *)malloc(sizeof(RPC_CMD_RECORD));
  250. if ( tCMD ) {
  251. tCMD->CMD = ARGUS_DATA_MSG_REQ_TIME_SYNC;
  252. tCMD->DATA_SIZE = 0;
  253. tCMD->DATA = NULL;
  254. if ( pushNewTransaction( tCMD ) ) return;
  255. free( tCMD );
  256. };
  257. };
  258. void mojoRemoteClient::setTO( uint8_t seconds ){
  259. m_mTOProtoctor.lock();
  260. m_bTOCounter = seconds;
  261. m_mTOProtoctor.unlock();
  262. };
  263. bool mojoRemoteClient::decTO(){
  264. m_mTOProtoctor.lock();
  265. if ( m_bTOCounter ) {
  266. m_bTOCounter--;
  267. m_mTOProtoctor.unlock();
  268. return true;
  269. };
  270. m_mTOProtoctor.unlock();
  271. return false;
  272. };
  273. void mojoRemoteClient::m_fThreadProc( void ){
  274. time_t tTimeTSeconds = 0;
  275. time_t cTimeTSeconds = 0;
  276. uint32_t tSecondsCounter = 0;
  277. m_bThreadStatus = TH_WORKING;
  278. #ifdef DEBUG
  279. LOG("Connector Thread Started");
  280. #endif
  281. while ( m_bThreadStatus < TH_ENDED ) {
  282. // seconds Counter (for internal purposes)
  283. cTimeTSeconds = time( NULL );
  284. //Process each second
  285. if ( cTimeTSeconds != tTimeTSeconds ) {
  286. tSecondsCounter++;
  287. tTimeTSeconds = cTimeTSeconds;
  288. switch ( getAutomationStage() ) {
  289. case ARGUS_RPC_STAGE_CONNECT:{
  290. #ifdef DEBUG
  291. char tB[128];
  292. sprintf(tB,"Creating Remote connection to [%s:%d]", m_pMaster->m_sSiteData.remote_ip, m_pMaster->m_sSiteData.remote_port );
  293. LOG( tB );
  294. #endif
  295. if( m_pMaster->m_sSiteData.remote_port ) {
  296. m_pPort = new clientPort( m_pMaster->m_sSiteData.remote_ip, m_pMaster->m_sSiteData.remote_port );
  297. if( m_pPort ) {
  298. if( m_pPort->create() ) {
  299. #ifdef DEBUG
  300. LOG("Connection Sucessfull");
  301. #endif
  302. m_bShutdownCommunication = false;
  303. m_bCommunicationEstablished = true;
  304. m_bRegisteredWithRemotePeer = false;
  305. setTransport( m_pPort, false );
  306. setAutomationStage( ARGUS_RPC_STAGE_REGISTER );
  307. } else {
  308. delete( m_pPort );
  309. m_pPort = NULL;
  310. m_bShutdownCommunication = true;
  311. m_bCommunicationEstablished = false;
  312. m_bRegisteredWithRemotePeer = false;
  313. setTO( 30 ); //30 sec to wait
  314. setAutomationStage( ARGUS_RPC_STAGE_WAIT_RECONNECT );
  315. };
  316. };
  317. };
  318. break;
  319. };
  320. case ARGUS_RPC_STAGE_WAIT_RECONNECT:{
  321. if ( !decTO() ) setAutomationStage( ARGUS_RPC_STAGE_CONNECT );
  322. break;
  323. };
  324. case ARGUS_RPC_STAGE_REGISTER:{
  325. RPC_CMD_RECORD *tCMD = (RPC_CMD_RECORD*) malloc(sizeof(RPC_CMD_RECORD));
  326. if ( tCMD ) {
  327. tCMD->CMD = ARGUS_DATA_MSG_REGISTER;
  328. tCMD->DATA_SIZE = strlen( m_pMaster->m_sIdentity );
  329. tCMD->DATA = malloc(tCMD->DATA_SIZE);
  330. if ( tCMD->DATA ) {
  331. strncpy( (char *)tCMD->DATA, m_pMaster->m_sIdentity, tCMD->DATA_SIZE );
  332. if( pushNewTransaction( tCMD ) ){
  333. setAutomationStage( ARGUS_RPC_STAGE_WAIT_ACK );
  334. setTO( 3 ); // Wait for 3 seconds to be registered with server
  335. break;
  336. };
  337. free( tCMD->DATA );
  338. };
  339. free( tCMD );
  340. };
  341. break;
  342. };
  343. case ARGUS_RPC_STAGE_WAIT_ACK:{
  344. LOG("TO On Waiting Responce!");
  345. if ( !decTO() ) setAutomationStage( ARGUS_RPC_STAGE_CLOSE );
  346. break;
  347. };
  348. case ARGUS_RPC_STAGE_IDLE: if( ( tSecondsCounter % ARGUS_SECONDS_TO_SYNC_TIME ) == 15 ) enqueueTimeReq(); else enqueueStatMsg(); break;
  349. case ARGUS_RPC_STAGE_DISCONNECT:{
  350. // Gracefully Disconnect
  351. //if( peer_send_disconnect() ){
  352. // bTO_COUNTER = 1;
  353. // setAutomationStage( ARGUS_RPC_STAGE_WAIT_ACK );
  354. //} else setAutomationStage( ARGUS_RPC_STAGE_CLOSE );
  355. break;
  356. };
  357. case ARGUS_RPC_STAGE_CLOSE:{
  358. // Just Disconnect
  359. delete( m_pPort );
  360. m_pPort = NULL;
  361. m_bShutdownCommunication = true;
  362. m_bCommunicationEstablished = false;
  363. m_bRegisteredWithRemotePeer = false;
  364. setTO( 30 ); //30 sec to wait
  365. setAutomationStage( ARGUS_RPC_STAGE_WAIT_RECONNECT );
  366. break;
  367. };
  368. };
  369. };
  370. if ( validateTransaction() ) {
  371. if ( fetchNewTransaction() ) {
  372. if( peer_send_rpc_pack( m_pCurrentCMD ) ) {
  373. setTO( 1 );
  374. setAutomationStage( ARGUS_RPC_STAGE_WAIT_ACK );
  375. };
  376. } else SLEEP( DEFAULT_THREAD_SLEEP_TIME );
  377. } else SLEEP( DEFAULT_THREAD_SLEEP_TIME );
  378. };
  379. LOG("Connector Thread Ended!");
  380. };
  381. /*
  382. Register With Server and make Time Sync With Server
  383. */
  384. bool mojoRemoteClient::peer_send_rpc_pack( RPC_CMD_RECORD *ptr){
  385. bool retVal;
  386. if ( ptr == NULL ) return false;
  387. if( !m_bCommunicationEstablished ) return false;
  388. if( !m_bRegisteredWithRemotePeer ) return false;
  389. m_mBufferProtector.lock();
  390. m_pBuffer[ARGUS_HEADER_SIZE] = ptr->CMD;
  391. uint16_t i = 0;
  392. for (; i < ptr->DATA_SIZE; i++) m_pBuffer[ARGUS_HEADER_SIZE+1+i] = ((uint8_t *)ptr->DATA)[i];
  393. m_nOutbondSerial++;
  394. retVal = m_pPort->sendData( m_pBuffer, argus_rpc_finishupPackage( m_pBuffer, m_nOutbondSerial, ARGUS_HEADER_SIZE+1+i ));
  395. m_mBufferProtector.unlock();
  396. return retVal;
  397. };
  398. bool mojoRemoteClient::createVideoTransferTask( ARGUS_DATA_VIDEO_SEGMENT *ptr ){
  399. if( ptr == NULL ) return false;
  400. if( !m_bCommunicationEstablished ) return false;
  401. if( !m_bRegisteredWithRemotePeer ) return false;
  402. uint8_t tBuffer[1024];
  403. tBuffer[ARGUS_HEADER_SIZE] = ARGUS_DATA_MSG_VIDEO_INFO;
  404. uint16_t i = 0;
  405. for(; i < sizeof(ARGUS_DATA_VIDEO_SEGMENT); i++) tBuffer[ARGUS_HEADER_SIZE+1+i] = ((uint8_t*)ptr)[i];
  406. m_nOutbondSerial++;
  407. return m_pPort->sendData(tBuffer, argus_rpc_finishupPackage(tBuffer, m_nOutbondSerial, ARGUS_HEADER_SIZE+1+i ));
  408. };
  409. bool mojoRemoteClient::validate(){
  410. if( m_bCommunicationEstablished ){
  411. if ( getConnectionStatus() == CS_DISCONNECTED ) {
  412. m_bCommunicationEstablished = false;
  413. if( m_pPort ) {
  414. // Cancel all ongoing Queries
  415. m_bShutdownCommunication = true;
  416. setTransport( NULL, false );
  417. delete( m_pPort );
  418. };
  419. m_bAutomationStage = ARGUS_RPC_STAGE_CONNECT;
  420. /*m_pPort = new clientPort( m_pMaster->m_sSiteData.remote_ip, m_pMaster->m_sSiteData.remote_port );
  421. if( m_pPort ) {
  422. if( m_pPort->create() ) {
  423. m_bShutdownCommunication = false;
  424. m_bCommunicationEstablished = true;
  425. m_bRegisteredWithRemotePeer = false;
  426. setTransport( m_pPort, false );
  427. } else {
  428. delete( m_pPort );
  429. m_pPort = NULL;
  430. };
  431. };
  432. */
  433. };
  434. } else {
  435. /*
  436. if( m_pPort ) {
  437. // Cancel all ongoing Queries
  438. m_bShutdownCommunication = true;
  439. setTransport( NULL, false );
  440. delete( m_pPort );
  441. };
  442. //Try To connect
  443. m_pPort = new clientPort( m_pMaster->m_sSiteData.remote_ip, m_pMaster->m_sSiteData.remote_port );
  444. if( m_pPort ) {
  445. if( m_pPort->create() ) {
  446. m_bShutdownCommunication = false;
  447. m_bCommunicationEstablished = true;
  448. m_bRegisteredWithRemotePeer = false;
  449. setTransport( m_pPort, false );
  450. } else {
  451. delete( m_pPort );
  452. m_pPort = NULL;
  453. };
  454. };
  455. */
  456. };
  457. return true;
  458. };
  459. bool mojoRemoteClient::addEvent( EVENT_CONTAINER *Evt ){
  460. #ifdef DEBUG
  461. LOG("Add Evt!");
  462. #endif
  463. if ( Evt == NULL ) return false;
  464. RPC_CMD_RECORD *tPack = (RPC_CMD_RECORD *)malloc(sizeof(RPC_CMD_RECORD));
  465. if ( tPack ) {
  466. tPack->DATA = (void*) argus_rpc_convert_evt( Evt );
  467. if ( tPack->DATA ) {
  468. tPack->CMD = ARGUS_DATA_MSG_EVT;
  469. tPack->DATA_SIZE = sizeof( ARGUS_DATA_EVENT );
  470. if( m_qCMD->push( tPack ) ) return true;
  471. free( tPack->DATA );
  472. };
  473. free( tPack );
  474. };
  475. return false;
  476. };
  477. #undef LOG
  478. #undef LOG_ERROR