diff --git a/lib/App/mojo/mojoRemoteClient.cpp b/lib/App/mojo/mojoRemoteClient.cpp index 974cc178..ca03d223 100644 --- a/lib/App/mojo/mojoRemoteClient.cpp +++ b/lib/App/mojo/mojoRemoteClient.cpp @@ -24,6 +24,7 @@ mojoRemoteClient::mojoRemoteClient( mojoKernel * ptr ):protocolParser(){ m_bRegisteredWithRemotePeer = false; m_bUseBackupServer = false; m_bActiveServer = 0; + m_bCloseCommunicationReason = 0; //m_pVideoHelper = new mojoVideoTransferHelper( ARGUS_RPC_DEFAULT_MEDIA_CHUNK ); memset(&m_sINFO, 0, sizeof(ARGUS_DATA_MOJO_INFO)); m_qCMD = new RPC_CMD_QUEUE(); @@ -33,25 +34,26 @@ mojoRemoteClient::~mojoRemoteClient(){ LOG("Destructor"); if( m_bRegisteredWithRemotePeer ) { LOG("Flushing"); - //if( m_pVideoHelper ) delete( m_pVideoHelper ); while ( m_bRegisteredWithRemotePeer ) { m_mCurrentVTRProtector.lock(); - if ( m_vVTRHelpers.size() == 0 ) break; + if ( m_vVTRHelpers.size() == 0 ){ + m_mCurrentVTRProtector.unlock(); + break; + }; m_mCurrentVTRProtector.unlock(); SLEEP( DEFAULT_THREAD_SLEEP_TIME ); }; - // If disconnected but still have mem structs! + m_mCurrentVTRProtector.lock(); if ( m_vVTRHelpers.size() ) { - //while ( m_vVTRHelpers.size() ) { - // mojoVideoTransferHelper *tPtr = m_qVTRHelpers.first(); - // delete( tPtr ); - // m_qVTRHelpers.pop(); - //}; + for (V_VIDEO_TRANSFER_HELPERS::iterator idx = m_vVTRHelpers.begin(); idx != m_vVTRHelpers.end(); idx++ ) delete( *idx ); + m_vVTRHelpers.clear(); } else { - // Still connected - // Unregister Mojo - } + //Send Disconmnect + enqueueDisconnect( m_bCloseCommunicationReason ); + }; + m_mCurrentVTRProtector.unlock(); }; + LOG("Flushing Done!"); waitThreadEnd( true ); flushTransactions(); @@ -361,7 +363,14 @@ bool mojoRemoteClient::fetchNewTransaction(){ m_mCurrentCMDProtector.unlock(); return false; }; - +void mojoRemoteClient::enqueueDisconnect( uint8_t reason ){ + static uint8_t pBuffer[400]; + if( !m_bCommunicationEstablished ) return; + pBuffer[ARGUS_HEADER_SIZE] = ARGUS_DATA_MSG_DISCONNECT; + pBuffer[ARGUS_HEADER_SIZE+1] = reason; + m_nOutbondSerial++; + m_pPort->sendData( pBuffer, argus_rpc_finishupPackage( pBuffer, m_nOutbondSerial, ARGUS_HEADER_SIZE + 2 ) ); +}; void mojoRemoteClient::enqueueInfoMsg(){ RPC_CMD_RECORD *tCMD = (RPC_CMD_RECORD *)malloc(sizeof(RPC_CMD_RECORD)); if ( tCMD ) { diff --git a/lib/App/mojo/mojoRemoteClient.h b/lib/App/mojo/mojoRemoteClient.h index c42df78f..fa12068d 100644 --- a/lib/App/mojo/mojoRemoteClient.h +++ b/lib/App/mojo/mojoRemoteClient.h @@ -58,6 +58,7 @@ class mojoRemoteClient: public basicThread, public protocolParser{ ARGUS_DATA_MOJO_INFO m_sINFO; bool m_bUseBackupServer; uint8_t m_bActiveServer; + uint8_t m_bCloseCommunicationReason; clientPort * m_pPort; basicMutex m_mQueryProtector; basicMutex m_mAutomationStageProtector; @@ -83,6 +84,7 @@ class mojoRemoteClient: public basicThread, public protocolParser{ void enqueueInfoMsg(); void enqueueStatMsg(); void enqueueTimeReq(); + void enqueueDisconnect( uint8_t reason = 0 ); uint8_t getAutomationStage( ); void setAutomationStage( uint8_t stg ); diff --git a/lib/App/serva/servaKernel.cpp b/lib/App/serva/servaKernel.cpp index c7c21c7d..3e8e4a29 100644 --- a/lib/App/serva/servaKernel.cpp +++ b/lib/App/serva/servaKernel.cpp @@ -383,7 +383,7 @@ bool servaKernel::processVideoFile( uint64_t dbid ){ if ( NFO ) { servaMediaEncoder *ptr = new servaMediaEncoder( dbid ); if ( ptr ) { -#ifdef DEBUG_EXTRA +#ifdef DEBUG LOG("Encoder Constructed!"); #endif char tA[MAX_PATH]; @@ -407,7 +407,7 @@ bool servaKernel::processVideoFile( uint64_t dbid ){ delete( ptr ); }; free( NFO ); - }; + } else LOG("No Video Info!!"); return false; }; diff --git a/lib/components/base/basicFunctionality.cpp b/lib/components/base/basicFunctionality.cpp index aeaf9765..242d9a05 100644 --- a/lib/components/base/basicFunctionality.cpp +++ b/lib/components/base/basicFunctionality.cpp @@ -652,6 +652,7 @@ unsigned __int64 getMilliseconds( void ){ #ifdef __linux__ +#ifndef USE_SYSTEM_CALL_TO_PING #include // Define the Packet Constants // ping packet size @@ -674,10 +675,16 @@ struct ping_pkt { char msg[PING_PKT_S-sizeof(struct icmphdr)]; }; -bool pingIP4( CSTR ip4 ){ +#endif //!USE_SYSTEM_CALL_TO_PING +bool pingIP4( CSTR ip4 ){ +#ifdef USE_SYSTEM_CALL_TO_PING + // Ping google.com once, redirect output to /dev/null, and check the return value + char tB[256]; + sprintf( tB, "ping -c 1 %s > /dev/null 2>&1", ip4 ); + if ( system( tB ) == 0) return true; return false; - +#else // !USE_SYSTEM_CALL_TO_PING bool RetVal = false; if ( ip4 == NULL ) return false; if ( strlen( ip4 ) < 7 ) return false; @@ -758,6 +765,7 @@ bool pingIP4( CSTR ip4 ){ }; shutdown( sockfd, SHUT_RDWR ); return RetVal; +#endif //!USE_SYSTEM_CALL_TO_PING }; bool enumerateDevices( enumeratorInfo *mlist, const char *dTemplate){ diff --git a/lib/components/base/basicFunctionality.h b/lib/components/base/basicFunctionality.h index b1aa73be..d1493497 100644 --- a/lib/components/base/basicFunctionality.h +++ b/lib/components/base/basicFunctionality.h @@ -7,6 +7,8 @@ #include #include +#define USE_SYSTEM_CALL_TO_PING + #if defined(__APPLE__) || defined(__FreeBSD__) #include #else