diff --git a/lib/App/common/SQLite_dataBinder.cpp b/lib/App/common/SQLite_dataBinder.cpp
index d90ce378..10067759 100644
--- a/lib/App/common/SQLite_dataBinder.cpp
+++ b/lib/App/common/SQLite_dataBinder.cpp
@@ -689,7 +689,7 @@ bool sqliteDBC::addDeviceDraw( uint32_t DBID, uint8_t type, uint8_t lrf, void *t
};
void sqliteDBC::updateStats( bool evt, bool video, uint8_t ses_status ){
- if (m_bStaIsConnected ) {
+ if ( m_bStaIsConnected ) {
char tQBuf[1024];
switch ( ses_status ) {
case SESSION_CONTINUE:{
@@ -707,21 +707,7 @@ void sqliteDBC::updateStats( bool evt, bool video, uint8_t ses_status ){
break;
};
case SESSION_START:{
- sprintf( tQBuf, "INSERT INTO `days`(`year`,`month`,`day`,`session_count`,`session_closed`) VALUES(%s,%s,%s,1,0) ON CONFLICT(`year`,`month`,`day`) DO UPDATE SET `session_count`=`session_count`+1, `session_closed`=0",
- m_sCRepInfo.YEAR, m_sCRepInfo.MONTH, m_sCRepInfo.DAY );
-#ifdef DEBUG_ALL
- LOG( tQBuf );
-#endif
- m_pDataStatistics->SilentQuery( tQBuf );
- break;
- };
- case SESSION_END:{
- sprintf( tQBuf, "INSERT INTO `days`(`year`,`month`,`day`,`session_count`,`session_closed`) VALUES(%s,%s,%s,0,1) ON CONFLICT(`year`,`month`,`day`) DO UPDATE SET `session_closed`=1",
- m_sCRepInfo.YEAR, m_sCRepInfo.MONTH, m_sCRepInfo.DAY );
-#ifdef DEBUG_ALL
- LOG( tQBuf );
-#endif
- m_pDataStatistics->SilentQuery( tQBuf );
+ //Check New Day Reports
REPORT_DIRINFO tRR = {0};
fillRDF( time( NULL ), tRR );
if( tRR.ts > m_sCRepInfo.ts ) {
@@ -748,13 +734,30 @@ void sqliteDBC::updateStats( bool evt, bool video, uint8_t ses_status ){
m_bRepIsConnected = true;
LOG("Report Connected!");
// Create New Day Record
- sprintf(tQBuf, "INSERT INTO `days`(`year`,`month`,`day`,`session_count`,`session_closed`) VALUES(%s,%s,%s,0,1) ON CONFLICT(`year`,`month`,`day`) DO UPDATE SET `session_count`=`session_count`+1, `session_closed`=1",
+ sprintf(tQBuf, "INSERT INTO `days`(`year`,`month`,`day`,`session_count`,`session_closed`) VALUES(%s,%s,%s,0,0) ON CONFLICT(`year`,`month`,`day`) DO UPDATE SET `session_count`=`session_count`+1, `session_closed`=0",
m_sCRepInfo.YEAR, m_sCRepInfo.MONTH, m_sCRepInfo.DAY );
LOG( tQBuf );
m_pDataStatistics->SilentQuery( tQBuf );
};
};
};
+ // Create New record
+ sprintf( tQBuf, "INSERT INTO `days`(`year`,`month`,`day`,`session_count`,`session_closed`) VALUES(%s,%s,%s,1,0) ON CONFLICT(`year`,`month`,`day`) DO UPDATE SET `session_count`=`session_count`+1, `session_closed`=0",
+ m_sCRepInfo.YEAR, m_sCRepInfo.MONTH, m_sCRepInfo.DAY );
+#ifdef DEBUG_ALL
+ LOG( tQBuf );
+#endif
+ m_pDataStatistics->SilentQuery( tQBuf );
+
+ break;
+ };
+ case SESSION_END:{
+ sprintf( tQBuf, "INSERT INTO `days`(`year`,`month`,`day`,`session_count`,`session_closed`) VALUES(%s,%s,%s,0,1) ON CONFLICT(`year`,`month`,`day`) DO UPDATE SET `session_closed`=1",
+ m_sCRepInfo.YEAR, m_sCRepInfo.MONTH, m_sCRepInfo.DAY );
+#ifdef DEBUG_ALL
+ LOG( tQBuf );
+#endif
+ m_pDataStatistics->SilentQuery( tQBuf );
break;
};
};
diff --git a/lib/App/common/kernelModuleOnvifObserver.cpp b/lib/App/common/kernelModuleOnvifObserver.cpp
index 1019cd2d..ae493a8a 100644
--- a/lib/App/common/kernelModuleOnvifObserver.cpp
+++ b/lib/App/common/kernelModuleOnvifObserver.cpp
@@ -1,622 +1,624 @@
-#include "kernelModuleOnvifObserver.h"
-#include "hardwareManager.h"
-#include "hardwareResourceNetworkProvider.h"
-
-#define SEARCH_REQUEST_STRING "uuid:84ede3de-7dec-11d0-c360-f01234567890urn:schemas-xmlsoap-org:ws:2005:04:discoveryhttp://schemas.xmlsoap.org/ws/2005/04/discovery/Probedn:NetworkVideoTransmitter"
-#define SEARCH_REQUEST_STRING2323 "\n" \
- "\n" \
- "\n" \
- "urn:uuid:ac9823ee-6813-498c-8c1b-6272a22353f7\n" \
- "\n" \
- "http ://schemas.xmlsoap.org/ws/2005/04/discovery/Probe\n" \
- "\n" \
- "urn:schemas-xmlsoap-org:ws:2005:04:discovery\n" \
- "\n" \
- "\n" \
- "\n" \
- "ssdp:any\n" \
- "\n" \
- "\n" \
- "\r\n\r\n"
-#define HTTP_OK "200 OK"
-
-/******************************************************************
-** Action Defines *
-*******************************************************************/
-#define HTTP_HEADER_ACTION "POST %s HTTP/1.1\r\n" \
- "HOST: %s:%u\r\n" \
- "SOAPACTION:\"%s#%s\"\r\n" \
- "CONTENT-TYPE: text/xml ; charset=\"utf-8\"\r\n"\
- "Content-Length: %d \r\n\r\n"
-
-#define SOAP_ACTION "\r\n" \
- "\r\n" \
- "\r\n" \
- "\r\n%s" \
- "\r\n" \
- "\r\n" \
- "\r\n"
-
-#define PORT_MAPPING_LEASE_TIME "63072000" //two year
-
-#define ADD_PORT_MAPPING_PARAMS "\r\n" \
- "%u\r\n"\
- "%s\r\n" \
- "%u\r\n"\
- "%s\r\n" \
- "1\r\n" \
- "%s\r\n" \
- "" \
- PORT_MAPPING_LEASE_TIME \
- "\r\n"
-
-
-
-#define LOG( X ) kernelModule::m_pLog->Log( "MOD_ONVIF", this, X )
-
-#ifdef DEBUG
- #define LOG_ERROR( X ) {\
- char _tBfrErrMSG2w34[256];\
- sprintf( _tBfrErrMSG2w34, "In file %s[%d] in func:%s %s",__FILE__, __LINE__, __func__, X );\
- kernelModule::m_pLog->Log( "MOD_ONVIF", this, _LOG_ERROR, _tBfrErrMSG2w34 );\
- }
-#else
- #define LOG_ERROR( X ) kernelModule::m_pLog->Log( "MOD_ONVIF", this, _LOG_ERROR, X );
-#endif
-
-
-kernelModuleOnvifObserver::kernelModuleOnvifObserver( uint32_t ModuleID ): kernelModule( ModuleID, KERNEL_MODULE_ONVIF_OBSERVER ), basicThread(){
- m_bEnabled = false;
- m_pEventHeap = basicEventHeap::getInstance();
-
- m_bCurrentNIF = 0;
- m_bProbeIsActive = false;
- m_bDetached = false;
-#ifdef __linux__
- m_bWSAOK = true;
-#else
- m_bWSAOK = false;
- WORD wVersionRequested;
- WSADATA wsaData;
- int err;
- wVersionRequested = MAKEWORD(2, 2);
- err = WSAStartup(wVersionRequested, &wsaData);
- if (err != 0){
- LOG_ERROR("WSAStartup failed with error");
- } else m_bWSAOK = true;
-#endif
-};
-
-kernelModuleOnvifObserver::~kernelModuleOnvifObserver(){
- if( !m_bDetached ) stopService( true );
-};
-
-bool kernelModuleOnvifObserver::startService(){
- LOG("Starting Service!");
- if( !m_bWSAOK ) return false;
- m_bEnabled = reloadSettings();
- return init();
-};
-
-bool kernelModuleOnvifObserver::stopService( bool force ){
- m_bEnabled = false;
- if( !m_bDetached ) m_bDetached = uninit();
- if( m_bDetached ) {
- //Clear Results
- m_mResultProtector.lock();
- if (m_vResultPool.size()){ // Clear structures
- for( vectorOBSERVER_RESULT::iterator index = m_vResultPool.begin(); index < m_vResultPool.end(); index++){
- free(*index);
- };
- m_vResultPool.clear();
- };
- m_mResultProtector.unlock();
- };
- return m_bDetached;
-};
-
-/*
-#include
-#include
-#include
-#include
-#include
-#include
-#include
-#include
-#include
-// Join multicast group, support both IPv4 and IPv6. * @param sockfd socket descripter * @param grp sockaddr * @param grplen sockaddr length * @return 0:on success; non-zero:on failed
-static int mcast_join(int sockfd, const struct sockaddr *grp, socklen_t grplen){
-
- #if MCAST_JOIN_GROUP
- struct group_req req;
- req.gr_interface = 0;
- if (grplen > sizeof(req.gr_group)) {
- errno = EINVAL;
- return -1;
- }
- memcpy(&req.gr_group, grp, grplen);
- return (setsockopt(sockfd, IPPROTO_IP, MCAST_JOIN_GROUP, &req, sizeof(req)));
-#else
- switch (grp->sa_family) {
- case AF_INET: {
- struct ip_mreq mreq;
- struct ifreq ifreq;
- memcpy(&mreq.imr_multiaddr, &((const struct sockaddr_in *) grp)->sin_addr, sizeof(struct in_addr));
- mreq.imr_interface.s_addr = htonl(INADDR_ANY);
- return (setsockopt(sockfd, IPPROTO_IP, IP_ADD_MEMBERSHIP,
- &mreq, sizeof(mreq)));
- }
- #ifdef IPV6
- #ifndef IPV6_JOIN_GROUP // APIv0 compatibility
- #define IPV6_JOIN_GROUP IPV6_ADD_MEMBERSHIP
- #endif
- case AF_INET6: {
- struct ipv6_mreq mreq6;
- memcpy(&mreq6.ipv6mr_multiaddr, &((const struct sockaddr_in6 *) grp)->sin6_addr, sizeof(struct in6_addr));
- mreq6.ipv6mr_interface = 0;
- return (setsockopt(sockfd, IPPROTO_IPV6, IPV6_JOIN_GROUP, &mreq6, sizeof(mreq6)));
- }
- #endif
- default:
- errno = EAFNOSUPPORT;
- return -1;
- }
-#endif
-};
-
-int main(int argc, char **argv){
-
- int fd = socket(AF_INET, SOCK_DGRAM, 0);
- struct sockaddr_in grp;
- bzero(&grp, sizeof(grp));
- grp.sin_family = AF_INET;
- grp.sin_addr.s_addr = inet_addr("224.0.0.1");;
- if (mcast_join(fd, (struct sockaddr*)(&grp), sizeof(grp)))
- perror("Join multicast group failed");
-}
-
-*/
-
-
-void kernelModuleOnvifObserver::m_fThreadProc(){
- int socketFD;
- int RetVal;
- struct sockaddr_in r_address;
- bool bOptVal;
- int bOptLen;
- int iOptLen;
- uint16_t bCounterTO = 600; // 3 second
- char rBuffer[MAX_BUFF_SIZE];
-#ifdef DEBUG
- char tB[128];
- LOG("Module Started!");
-#endif
- m_bDetached = false;
- m_bThreadStatus = TH_WORKING;
- while( m_bThreadStatus < TH_ENDED ) {
- if ( m_bEnabled ) {
- if ( m_bProbeIsActive ) {
- if( socketFD > -1 ){
- if( bCounterTO-- ){
- memset( rBuffer, 0, MAX_BUFF_SIZE );
-#ifdef DEBUG
- struct sockaddr src_addr;
- socklen_t addrlen = sizeof( src_addr );
- RetVal = recvfrom( socketFD, rBuffer, MAX_BUFF_SIZE, 0, &src_addr, &addrlen );
- if ( RetVal > -1 ) {
- sprintf(tB, "(%d){%d}MSG[%d] from %s", bCounterTO, socketFD, RetVal, inet_ntoa(((struct sockaddr_in *)&src_addr)->sin_addr));
- LOG( tB );
- LOG( rBuffer );
- };
-#else //http://192.168.200.127/axis-cgi/com/ptz.cgi?info=1&camera=1
- RetVal = recvfrom( socketFD, rBuffer, MAX_BUFF_SIZE, 0, NULL, NULL );
-#endif
- if ((RetVal == -1) && /*(errno != EAGAIN) &&*/ (errno != EINTR) && (errno != EWOULDBLOCK)) {
- LOG_ERROR("Error acures while reading UDP package");
- close( socketFD );
- m_bProbeIsActive = false;
- continue; // Error ocured but continue to next address
- };
- if( RetVal < 1 ){
- //LOG("SLEEP");
- SLEEP(DEFAULT_THREAD_SLEEP_TIME);
- continue; // No Data - wait to next time
- };
- OBSERVER_RESULT *tResult = parseXML( rBuffer );
- if ( tResult ) {
- m_mResultProtector.lock();
- m_vResultPool.push_back( tResult );
- m_mResultProtector.unlock();
-#ifdef DEBUG
- LOG("Probe Finished!");
-#endif
- } else {
-#ifdef DEBUG
- LOG("Probe Finished with unrecognized data!");
-#endif
- };
- continue; //To Fetch Another responces
-#ifdef DEBUG_EXTRA
- } else {
- LOG("Probe Finished By Timeout!");
-#endif
- };
-#ifdef __linux__
- close(socketFD);
-#else
- closesocket(socketFD);
-#endif
- };
- m_bProbeIsActive = false;
- //Sleep 5 minutes if done all scans
- if ( m_bCurrentNIF == 0 ){
- for( int i=12000; i, m_bThreadStatus < TH_ENDED; i-- ) SLEEP( DEFAULT_THREAD_SLEEP_TIME );
- };
- } else {
- // start new probe;
- m_mNIFMUTEX.lock();
- if ( m_vNIFIPS.size() ) {
-#ifdef DEBUG
- sprintf( tB, "Starting probe on %s address", m_vNIFIPS.at(m_bCurrentNIF) );
- LOG( tB );
-#endif
- socketFD = socket( AF_INET, SOCK_DGRAM, IPPROTO_UDP );
- if( socketFD > -1 ){
- CSTR send_buff = (CSTR)SEARCH_REQUEST_STRING;
- r_address.sin_family = AF_INET;
- r_address.sin_port = htons(HTTPMU_HOST_PORT);
- r_address.sin_addr.s_addr = inet_addr(m_vNIFIPS.at(m_bCurrentNIF));
- bOptVal = true;
-#ifdef DEBUG
- LOG("Set Broadcast Flag");
-#endif
- RetVal = setsockopt( socketFD, SOL_SOCKET, SO_BROADCAST, (char*)&bOptVal, bOptLen );
- struct group_req req;
- req.gr_interface = 0;
- memcpy( &req.gr_group, &r_address, sizeof(r_address));
-#ifdef DEBUG
- LOG("Join Broadcast Group");
-#endif
- RetVal = setsockopt( socketFD, IPPROTO_IP, MCAST_JOIN_GROUP, (char*)&req, sizeof(req) );
- //The broadcast address to be used may be determined by issuing an ioctl() with the SIOCGIFBRDADDR request.
-
- if ( RetVal > -1 ) {
- LOG_ERROR("Setting Socked as Broadcasted Error!");
- };
-
- //
- struct sockaddr_in tServerAddr;
- memset( &tServerAddr, 0, sizeof(tServerAddr) );
- tServerAddr.sin_family = AF_INET; // IPv4
- tServerAddr.sin_addr.s_addr = inet_addr( "0.0.0.0" ); //INADDR_ANY;
- tServerAddr.sin_port = htons(rand( 20000, 40000));
-
- // Bind the socket with the server address
- RetVal = bind( socketFD, (const struct sockaddr *)&tServerAddr, sizeof(tServerAddr));
- if ( RetVal > -1 ) {
- LOG_ERROR("Bind Socked Error!");
- };
-#ifdef DEBUG
- LOG("Sending Probe Request");
-#endif
- RetVal = sendto( socketFD, send_buff, strlen(send_buff), 0, (struct sockaddr*)&r_address, sizeof(struct sockaddr_in));
- if ( RetVal > -1 ) {
-#ifdef DEBUG
- sprintf( tB, "Sent %d Bytes of %d", RetVal, strlen(send_buff) );
- LOG( tB );
-#endif
-
-#ifdef __linux__
- fcntl( socketFD, F_SETFL, fcntl( socketFD, F_GETFL, 0) | O_NONBLOCK );
-#else
- u_long val = 1;
- ioctlsocket( socketFD, FIONBIO, &val );//none block
-#endif
- bCounterTO = 600;
- m_bProbeIsActive = true;
- } else {
-#ifdef DEBUG
- // Failure to send probe package
- LOG_ERROR("Error in sending Probe Request");
-#endif
-#ifdef __linux__
- close(socketFD);
-#else
- closesocket(socketFD);
-#endif
- };
- };
- m_bCurrentNIF++;
- if ( m_bCurrentNIF == m_vNIFIPS.size() ) m_bCurrentNIF = 0;
- };
- m_mNIFMUTEX.unlock();
- };
- } else {
- //Sleep 3 Sec.
- for( int i=300; i, m_bThreadStatus < TH_ENDED; i-- ) SLEEP( DEFAULT_THREAD_SLEEP_TIME );
- };
- };
- m_bDetached = true;
-};
-
-bool kernelModuleOnvifObserver::dispatchEvent(EVENT_CONTAINER *Evt){
- if(!m_bEnabled) {
-#ifdef DEBUG
- LOG("Module Disabled!");
-#endif
- return true;
- }
- if( Evt == NULL ) return false;
-
+#include "kernelModuleOnvifObserver.h"
+#include "hardwareManager.h"
+#include "hardwareResourceNetworkProvider.h"
+
+#define SEARCH_REQUEST_STRING "uuid:84ede3de-7dec-11d0-c360-f01234567890urn:schemas-xmlsoap-org:ws:2005:04:discoveryhttp://schemas.xmlsoap.org/ws/2005/04/discovery/Probedn:NetworkVideoTransmitter"
+#define SEARCH_REQUEST_STRING2323 "\n" \
+ "\n" \
+ "\n" \
+ "urn:uuid:ac9823ee-6813-498c-8c1b-6272a22353f7\n" \
+ "\n" \
+ "http ://schemas.xmlsoap.org/ws/2005/04/discovery/Probe\n" \
+ "\n" \
+ "urn:schemas-xmlsoap-org:ws:2005:04:discovery\n" \
+ "\n" \
+ "\n" \
+ "\n" \
+ "ssdp:any\n" \
+ "\n" \
+ "\n" \
+ "\r\n\r\n"
+#define HTTP_OK "200 OK"
+
+/******************************************************************
+** Action Defines *
+*******************************************************************/
+#define HTTP_HEADER_ACTION "POST %s HTTP/1.1\r\n" \
+ "HOST: %s:%u\r\n" \
+ "SOAPACTION:\"%s#%s\"\r\n" \
+ "CONTENT-TYPE: text/xml ; charset=\"utf-8\"\r\n"\
+ "Content-Length: %d \r\n\r\n"
+
+#define SOAP_ACTION "\r\n" \
+ "\r\n" \
+ "\r\n" \
+ "\r\n%s" \
+ "\r\n" \
+ "\r\n" \
+ "\r\n"
+
+#define PORT_MAPPING_LEASE_TIME "63072000" //two year
+
+#define ADD_PORT_MAPPING_PARAMS "\r\n" \
+ "%u\r\n"\
+ "%s\r\n" \
+ "%u\r\n"\
+ "%s\r\n" \
+ "1\r\n" \
+ "%s\r\n" \
+ "" \
+ PORT_MAPPING_LEASE_TIME \
+ "\r\n"
+
+
+
+#define LOG( X ) kernelModule::m_pLog->Log( "MOD_ONVIF", this, X )
+
+#ifdef DEBUG
+ #define LOG_ERROR( X ) {\
+ char _tBfrErrMSG2w34[256];\
+ sprintf( _tBfrErrMSG2w34, "In file %s[%d] in func:%s %s",__FILE__, __LINE__, __func__, X );\
+ kernelModule::m_pLog->Log( "MOD_ONVIF", this, _LOG_ERROR, _tBfrErrMSG2w34 );\
+ }
+#else
+ #define LOG_ERROR( X ) kernelModule::m_pLog->Log( "MOD_ONVIF", this, _LOG_ERROR, X );
+#endif
+
+
+kernelModuleOnvifObserver::kernelModuleOnvifObserver( uint32_t ModuleID ): kernelModule( ModuleID, KERNEL_MODULE_ONVIF_OBSERVER ), basicThread(){
+ m_bEnabled = false;
+ m_pEventHeap = basicEventHeap::getInstance();
+
+ m_bCurrentNIF = 0;
+ m_bProbeIsActive = false;
+ m_bDetached = false;
+#ifdef __linux__
+ m_bWSAOK = true;
+#else
+ m_bWSAOK = false;
+ WORD wVersionRequested;
+ WSADATA wsaData;
+ int err;
+ wVersionRequested = MAKEWORD(2, 2);
+ err = WSAStartup(wVersionRequested, &wsaData);
+ if (err != 0){
+ LOG_ERROR("WSAStartup failed with error");
+ } else m_bWSAOK = true;
+#endif
+};
+
+kernelModuleOnvifObserver::~kernelModuleOnvifObserver(){
+ if( !m_bDetached ) stopService( true );
+};
+
+bool kernelModuleOnvifObserver::startService(){
+#ifdef DEBUG_EXTRA
+ LOG("Starting Service!");
+#endif
+ if( !m_bWSAOK ) return false;
+ m_bEnabled = reloadSettings();
+ return init();
+};
+
+bool kernelModuleOnvifObserver::stopService( bool force ){
+ m_bEnabled = false;
+ if( !m_bDetached ) m_bDetached = uninit();
+ if( m_bDetached ) {
+ //Clear Results
+ m_mResultProtector.lock();
+ if (m_vResultPool.size()){ // Clear structures
+ for( vectorOBSERVER_RESULT::iterator index = m_vResultPool.begin(); index < m_vResultPool.end(); index++){
+ free(*index);
+ };
+ m_vResultPool.clear();
+ };
+ m_mResultProtector.unlock();
+ };
+ return m_bDetached;
+};
+
+/*
+#include
+#include
+#include
+#include
+#include
+#include
+#include
+#include
+#include
+// Join multicast group, support both IPv4 and IPv6. * @param sockfd socket descripter * @param grp sockaddr * @param grplen sockaddr length * @return 0:on success; non-zero:on failed
+static int mcast_join(int sockfd, const struct sockaddr *grp, socklen_t grplen){
+
+ #if MCAST_JOIN_GROUP
+ struct group_req req;
+ req.gr_interface = 0;
+ if (grplen > sizeof(req.gr_group)) {
+ errno = EINVAL;
+ return -1;
+ }
+ memcpy(&req.gr_group, grp, grplen);
+ return (setsockopt(sockfd, IPPROTO_IP, MCAST_JOIN_GROUP, &req, sizeof(req)));
+#else
+ switch (grp->sa_family) {
+ case AF_INET: {
+ struct ip_mreq mreq;
+ struct ifreq ifreq;
+ memcpy(&mreq.imr_multiaddr, &((const struct sockaddr_in *) grp)->sin_addr, sizeof(struct in_addr));
+ mreq.imr_interface.s_addr = htonl(INADDR_ANY);
+ return (setsockopt(sockfd, IPPROTO_IP, IP_ADD_MEMBERSHIP,
+ &mreq, sizeof(mreq)));
+ }
+ #ifdef IPV6
+ #ifndef IPV6_JOIN_GROUP // APIv0 compatibility
+ #define IPV6_JOIN_GROUP IPV6_ADD_MEMBERSHIP
+ #endif
+ case AF_INET6: {
+ struct ipv6_mreq mreq6;
+ memcpy(&mreq6.ipv6mr_multiaddr, &((const struct sockaddr_in6 *) grp)->sin6_addr, sizeof(struct in6_addr));
+ mreq6.ipv6mr_interface = 0;
+ return (setsockopt(sockfd, IPPROTO_IPV6, IPV6_JOIN_GROUP, &mreq6, sizeof(mreq6)));
+ }
+ #endif
+ default:
+ errno = EAFNOSUPPORT;
+ return -1;
+ }
+#endif
+};
+
+int main(int argc, char **argv){
+
+ int fd = socket(AF_INET, SOCK_DGRAM, 0);
+ struct sockaddr_in grp;
+ bzero(&grp, sizeof(grp));
+ grp.sin_family = AF_INET;
+ grp.sin_addr.s_addr = inet_addr("224.0.0.1");;
+ if (mcast_join(fd, (struct sockaddr*)(&grp), sizeof(grp)))
+ perror("Join multicast group failed");
+}
+
+*/
+
+
+void kernelModuleOnvifObserver::m_fThreadProc(){
+ int socketFD;
+ int RetVal;
+ struct sockaddr_in r_address;
+ bool bOptVal;
+ int bOptLen;
+ int iOptLen;
+ uint16_t bCounterTO = 600; // 3 second
+ char rBuffer[MAX_BUFF_SIZE];
+#ifdef DEBUG_EXTRA
+ char tB[128];
+ LOG("Module Started!");
+#endif
+ m_bDetached = false;
+ m_bThreadStatus = TH_WORKING;
+ while( m_bThreadStatus < TH_ENDED ) {
+ if ( m_bEnabled ) {
+ if ( m_bProbeIsActive ) {
+ if( socketFD > -1 ){
+ if( bCounterTO-- ){
+ memset( rBuffer, 0, MAX_BUFF_SIZE );
+#ifdef DEBUG_EXTRA
+ struct sockaddr src_addr;
+ socklen_t addrlen = sizeof( src_addr );
+ RetVal = recvfrom( socketFD, rBuffer, MAX_BUFF_SIZE, 0, &src_addr, &addrlen );
+ if ( RetVal > -1 ) {
+ sprintf(tB, "(%d){%d}MSG[%d] from %s", bCounterTO, socketFD, RetVal, inet_ntoa(((struct sockaddr_in *)&src_addr)->sin_addr));
+ LOG( tB );
+ LOG( rBuffer );
+ };
+#else //http://192.168.200.127/axis-cgi/com/ptz.cgi?info=1&camera=1
+ RetVal = recvfrom( socketFD, rBuffer, MAX_BUFF_SIZE, 0, NULL, NULL );
+#endif
+ if ((RetVal == -1) && /*(errno != EAGAIN) &&*/ (errno != EINTR) && (errno != EWOULDBLOCK)) {
+ LOG_ERROR("Error acures while reading UDP package");
+ close( socketFD );
+ m_bProbeIsActive = false;
+ continue; // Error ocured but continue to next address
+ };
+ if( RetVal < 1 ){
+ //LOG("SLEEP");
+ SLEEP(DEFAULT_THREAD_SLEEP_TIME);
+ continue; // No Data - wait to next time
+ };
+ OBSERVER_RESULT *tResult = parseXML( rBuffer );
+ if ( tResult ) {
+ m_mResultProtector.lock();
+ m_vResultPool.push_back( tResult );
+ m_mResultProtector.unlock();
+#ifdef DEBUG_EXTRA
+ LOG("Probe Finished!");
+#endif
+ } else {
+#ifdef DEBUG_EXTRA
+ LOG("Probe Finished with unrecognized data!");
+#endif
+ };
+ continue; //To Fetch Another responces
+#ifdef DEBUG_EXTRA
+ } else {
+ LOG("Probe Finished By Timeout!");
+#endif
+ };
+#ifdef __linux__
+ close(socketFD);
+#else
+ closesocket(socketFD);
+#endif
+ };
+ m_bProbeIsActive = false;
+ //Sleep 5 minutes if done all scans
+ if ( m_bCurrentNIF == 0 ){
+ for( int i=12000; i, m_bThreadStatus < TH_ENDED; i-- ) SLEEP( DEFAULT_THREAD_SLEEP_TIME );
+ };
+ } else {
+ // start new probe;
+ m_mNIFMUTEX.lock();
+ if ( m_vNIFIPS.size() ) {
+#ifdef DEBUG_EXTRA
+ sprintf( tB, "Starting probe on %s address", m_vNIFIPS.at(m_bCurrentNIF) );
+ LOG( tB );
+#endif
+ socketFD = socket( AF_INET, SOCK_DGRAM, IPPROTO_UDP );
+ if( socketFD > -1 ){
+ CSTR send_buff = (CSTR)SEARCH_REQUEST_STRING;
+ r_address.sin_family = AF_INET;
+ r_address.sin_port = htons(HTTPMU_HOST_PORT);
+ r_address.sin_addr.s_addr = inet_addr(m_vNIFIPS.at(m_bCurrentNIF));
+ bOptVal = true;
+#ifdef DEBUG_EXTRA
+ LOG("Set Broadcast Flag");
+#endif
+ RetVal = setsockopt( socketFD, SOL_SOCKET, SO_BROADCAST, (char*)&bOptVal, bOptLen );
+ struct group_req req;
+ req.gr_interface = 0;
+ memcpy( &req.gr_group, &r_address, sizeof(r_address));
+#ifdef DEBUG_EXTRA
+ LOG("Join Broadcast Group");
+#endif
+ RetVal = setsockopt( socketFD, IPPROTO_IP, MCAST_JOIN_GROUP, (char*)&req, sizeof(req) );
+ //The broadcast address to be used may be determined by issuing an ioctl() with the SIOCGIFBRDADDR request.
+
+ if ( RetVal > -1 ) {
+ LOG_ERROR("Setting Socked as Broadcasted Error!");
+ };
+
+ //
+ struct sockaddr_in tServerAddr;
+ memset( &tServerAddr, 0, sizeof(tServerAddr) );
+ tServerAddr.sin_family = AF_INET; // IPv4
+ tServerAddr.sin_addr.s_addr = inet_addr( "0.0.0.0" ); //INADDR_ANY;
+ tServerAddr.sin_port = htons(rand( 20000, 40000));
+
+ // Bind the socket with the server address
+ RetVal = bind( socketFD, (const struct sockaddr *)&tServerAddr, sizeof(tServerAddr));
+ if ( RetVal > -1 ) {
+ LOG_ERROR("Bind Socked Error!");
+ };
+#ifdef DEBUG_EXTRA
+ LOG("Sending Probe Request");
+#endif
+ RetVal = sendto( socketFD, send_buff, strlen(send_buff), 0, (struct sockaddr*)&r_address, sizeof(struct sockaddr_in));
+ if ( RetVal > -1 ) {
+#ifdef DEBUG_EXTRA
+ sprintf( tB, "Sent %d Bytes of %d", RetVal, strlen(send_buff) );
+ LOG( tB );
+#endif
+
+#ifdef __linux__
+ fcntl( socketFD, F_SETFL, fcntl( socketFD, F_GETFL, 0) | O_NONBLOCK );
+#else
+ u_long val = 1;
+ ioctlsocket( socketFD, FIONBIO, &val );//none block
+#endif
+ bCounterTO = 600;
+ m_bProbeIsActive = true;
+ } else {
+#ifdef DEBUG_EXTRA
+ // Failure to send probe package
+ LOG_ERROR("Error in sending Probe Request");
+#endif
+#ifdef __linux__
+ close(socketFD);
+#else
+ closesocket(socketFD);
+#endif
+ };
+ };
+ m_bCurrentNIF++;
+ if ( m_bCurrentNIF == m_vNIFIPS.size() ) m_bCurrentNIF = 0;
+ };
+ m_mNIFMUTEX.unlock();
+ };
+ } else {
+ //Sleep 3 Sec.
+ for( int i=300; i, m_bThreadStatus < TH_ENDED; i-- ) SLEEP( DEFAULT_THREAD_SLEEP_TIME );
+ };
+ };
+ m_bDetached = true;
+};
+
+bool kernelModuleOnvifObserver::dispatchEvent(EVENT_CONTAINER *Evt){
+ if(!m_bEnabled) {
+#ifdef DEBUG_EXTRA
+ LOG("Module Disabled!");
+#endif
+ return true;
+ }
+ if( Evt == NULL ) return false;
+
return true;
-};
-
-bool kernelModuleOnvifObserver::reloadSettings(){
- m_mNIFMUTEX.lock();
- if( m_vNIFIPS.size() ) {
- for ( vectorCSTR::iterator idx=m_vNIFIPS.begin(); idx < m_vNIFIPS.end(); idx++ ) free(*idx);
- m_vNIFIPS.clear();
- };
- m_mNIFMUTEX.unlock();
-
-#ifdef DEBUG
- LOG("Check IPS");
-#endif
- hardwareManager *tHWM = hardwareManager::getInstance();
- if( tHWM != NULL ) {
-#ifdef DEBUG
- LOG("Check IPS 11");
-#endif
- DBC_INT_LIST *rIDS = tHWM->requestResourcesByType( HARDWARE_PROVIDER_NETWORK );
- if( rIDS != NULL ) {
-#ifdef DEBUG
- LOG("Check IPS 22");
-#endif
- for( DBC_INT_LIST::iterator idx = rIDS->begin(); idx < rIDS->end(); idx++ ){
-#ifdef DEBUG
- LOG("Check IPS 33");
-#endif
- hardwareResourceNetwork *tRES = ( hardwareResourceNetwork *) tHWM->requestResource( HARDWARE_PROVIDER_NETWORK, *idx );
- if( tRES != NULL ) {
-#ifdef DEBUG
- LOG("Have NIF Resource");
-#endif
- CSTR BC = tRES->getBroadcast();
- if( BC!= NULL ) {
-#ifdef DEBUG
- LOG("Have BC Address");
- LOG(BC);
-#endif
- m_mNIFMUTEX.lock();
- m_vNIFIPS.push_back( BC );
- m_mNIFMUTEX.unlock();
-#ifdef DEBUG
- LOG("NIF defined");
-#endif
- }
-#ifdef DEBUG
- else {
- LOG("NO BC Address");
- }
-#endif
- ;
- } else {
- LOG_ERROR("Cannot Get Resource!");
- };
- };
- delete( rIDS );
- } else {
- LOG("No Networks Detected!");
- m_bEnabled = false;
- };
- } else {
- LOG_ERROR("No HW Manager");
- };
-#ifdef DEBUG
- LOG("Default Probe");
- LOG( HTTPMU_HOST_ADDRESS );
-#endif
- CSTR tBC = (CSTR) malloc(16);
- if ( tBC ) {
- sprintf(tBC, HTTPMU_HOST_ADDRESS );
- m_mNIFMUTEX.lock();
- m_vNIFIPS.push_back( tBC );
- m_mNIFMUTEX.unlock();
- } else {
- LOG_ERROR("Malloc Error!");
- };
- return true;
-};
-
-OBSERVER_RESULT *kernelModuleOnvifObserver::parseXML( CSTR data ){
- OBSERVER_RESULT *retVal = NULL;
- if( data!=NULL ){
- XMLResults tParseResults;
- XMLNode response = XMLNode::parseString( data, "root", &tParseResults );
- if( tParseResults.error ){
- char tBuffer[CTEXT];
- sprintf( tBuffer, "XML Parse Error %d at %d:%d", tParseResults.error, tParseResults.nLine, tParseResults.nColumn );
- LOG_ERROR( tBuffer );
- } else {
- if( response.isEmpty() ){
- LOG_ERROR("The device descripe XML file is not a valid XML file. Cann't find root element.");
- } else {
-#ifdef DEBUG_EXTRA
- LOG("Probe XML parsed");
-#endif
- XMLNode Body = response.getChildNode( "Body", 0 );
- if(!Body.isEmpty()){
-#ifdef DEBUG_EXTRA
- LOG("Have Body elm");
-#endif
- XMLNode ProbeMatches = Body.getChildNode("ProbeMatches", 0);//EndpointReference
- if(!ProbeMatches.isEmpty()) {
-#ifdef DEBUG_EXTRA
- LOG("Have ProbeMathes elm");
-#endif
- int matches = ProbeMatches.nChildNode();
- for(int index=0;indexsize(); j++) {
- if( strlen(tArr->at(j)) > 10 ) {
- sprintf(retVal->RefID,"%s",tArr->at(j));
- break;
- };
- };
- tArr->clear();
- delete(tArr);
-
- };
- };
- }
- {
- XMLNode node = ProbeMatch.getChildNode("Types", 0);
- if( !node.isEmpty() ){
- char tBuf[CLOG];
- sprintf(tBuf,"%s", node.getText(0));
- CArray *tArr;
- tArr = explode(' ',tBuf);
- sprintf(retVal->Type,"%s",tArr->at(0));
- tArr->clear();
- delete(tArr);
- }
- }
- {
- XMLNode node = ProbeMatch.getChildNode("Scopes", 0);
- char tBuf[CLOG];
- sprintf( tBuf,"%s", node.getText(0) );
- CArray *tArr = explode(' ',tBuf);
- if( tArr->size() > 0 ) {
- for( int index = 0; index < tArr->size(); index++){
- char *tPtr;
- if( tPtr = strstr( tArr->at(index), "mac/" ) ){
- sprintf(retVal->MAC,"%s",tPtr+4);
- };
- if( tPtr = strstr( tArr->at(index), "hardware/" ) ){
- sprintf(retVal->Hardware,"%s",tPtr+9);
- };
- if( tPtr = strstr( tArr->at(index), "name/" ) ){
- sprintf(retVal->Name,"%s",tPtr+5);
- };
- if (tPtr = strstr(tArr->at(index), "MAC/")) {
- sprintf(retVal->MAC, "%s", tPtr + 4);
- };
- if (tPtr = strstr(tArr->at(index), "HARDWARE/")) {
- sprintf(retVal->Hardware, "%s", tPtr + 9);
- };
- if (tPtr = strstr(tArr->at(index), "NAME/")) {
- sprintf(retVal->Name, "%s", tPtr + 5);
- };
- };
- tArr->clear();
- };
- delete(tArr);
- }
- {
- XMLNode node = ProbeMatch.getChildNode("XAddrs", 0);
- char tBuf[CLOG];
- sprintf(tBuf,"%s", node.getText(0));
-#ifdef DEBUG
- LOG("Before Explode");
- LOG(tBuf);
-#endif
- CArray *tArr;
- tArr = explode(' ',tBuf);
- if( tArr->size() > 0 ) {
- for( int index=0; index < tArr->size(); index++ ){
- if( strstr( tArr->at(index), "[" ) != NULL ){
- // IPv6
- } else {
- // IPv4
- sprintf( retVal->XAddrs,"%s",tArr->at(0));
- };
- };
- tArr->clear();
- };
- delete(tArr);
- }
- };
- };
- };
- };
- };
- };
- };
- };
- return retVal;
-};
-
-
-bool kernelModuleOnvifObserver::validate(){
- m_mResultProtector.lock();
- if( m_vResultPool.size() ){ // Clear structures
- for( vectorOBSERVER_RESULT::iterator index = m_vResultPool.begin(); index < m_vResultPool.end(); index++){
-#ifdef DEBUG
- char tBuffer[256];
- sprintf( tBuffer, "Found Camwera [%s] %s", (*index)->XAddrs, (*index)->RefID );
- LOG( tBuffer );
-#endif
- uint32_t cid = m_pDBC->getCamId( (*index)->RefID ); //isCameraListed( DiscoverResults->at(index)->RefID );
- if( cid ) {
-#ifdef DEBUG
- sprintf( tBuffer, "Camera is Listed as %d", cid );
- LOG( tBuffer );
-#endif
- m_pDBC->updateIPCam( cid, (*index)->XAddrs );// DiscoverResults->at(index));
- } else {
- // Uncknown camera - no checking
-#ifdef DEBUG
- LOG("Camera is Not Listed");
-#endif
- m_pDBC->addIPCam( (*index) );
- };
- free(*index);
- }
- m_vResultPool.clear();
-#ifdef DEBUG_EXTRA
- LOG("Clear Structs Done!");
-#endif
- } else {
-#ifdef DEBUG_EXTRA
- LOG("No Online IP Cameras in Network");
-#endif
- };
- m_mResultProtector.unlock();
- return true;
-};
-
-
-
-#undef LOG
-#undef LOG_ERROR
-
+};
+
+bool kernelModuleOnvifObserver::reloadSettings(){
+ m_mNIFMUTEX.lock();
+ if( m_vNIFIPS.size() ) {
+ for ( vectorCSTR::iterator idx=m_vNIFIPS.begin(); idx < m_vNIFIPS.end(); idx++ ) free(*idx);
+ m_vNIFIPS.clear();
+ };
+ m_mNIFMUTEX.unlock();
+
+#ifdef DEBUG_EXTRA
+ LOG("Check IPS");
+#endif
+ hardwareManager *tHWM = hardwareManager::getInstance();
+ if( tHWM != NULL ) {
+#ifdef DEBUG_EXTRA
+ LOG("Check IPS 11");
+#endif
+ DBC_INT_LIST *rIDS = tHWM->requestResourcesByType( HARDWARE_PROVIDER_NETWORK );
+ if( rIDS != NULL ) {
+#ifdef DEBUG_EXTRA
+ LOG("Check IPS 22");
+#endif
+ for( DBC_INT_LIST::iterator idx = rIDS->begin(); idx < rIDS->end(); idx++ ){
+#ifdef DEBUG_EXTRA
+ LOG("Check IPS 33");
+#endif
+ hardwareResourceNetwork *tRES = ( hardwareResourceNetwork *) tHWM->requestResource( HARDWARE_PROVIDER_NETWORK, *idx );
+ if( tRES != NULL ) {
+#ifdef DEBUG_EXTRA
+ LOG("Have NIF Resource");
+#endif
+ CSTR BC = tRES->getBroadcast();
+ if( BC!= NULL ) {
+#ifdef DEBUG_EXTRA
+ LOG("Have BC Address");
+ LOG(BC);
+#endif
+ m_mNIFMUTEX.lock();
+ m_vNIFIPS.push_back( BC );
+ m_mNIFMUTEX.unlock();
+#ifdef DEBUG_EXTRA
+ LOG("NIF defined");
+#endif
+ }
+#ifdef DEBUG_EXTRA
+ else {
+ LOG("NO BC Address");
+ }
+#endif
+ ;
+ } else {
+ LOG_ERROR("Cannot Get Resource!");
+ };
+ };
+ delete( rIDS );
+ } else {
+ LOG_ERROR("No Networks Detected!");
+ m_bEnabled = false;
+ };
+ } else {
+ LOG_ERROR("No HW Manager");
+ };
+#ifdef DEBUG_EXTRA
+ LOG("Default Probe");
+ LOG( HTTPMU_HOST_ADDRESS );
+#endif
+ CSTR tBC = (CSTR) malloc(16);
+ if ( tBC ) {
+ sprintf(tBC, HTTPMU_HOST_ADDRESS );
+ m_mNIFMUTEX.lock();
+ m_vNIFIPS.push_back( tBC );
+ m_mNIFMUTEX.unlock();
+ } else {
+ LOG_ERROR("Malloc Error!");
+ };
+ return true;
+};
+
+OBSERVER_RESULT *kernelModuleOnvifObserver::parseXML( CSTR data ){
+ OBSERVER_RESULT *retVal = NULL;
+ if( data!=NULL ){
+ XMLResults tParseResults;
+ XMLNode response = XMLNode::parseString( data, "root", &tParseResults );
+ if( tParseResults.error ){
+ char tBuffer[CTEXT];
+ sprintf( tBuffer, "XML Parse Error %d at %d:%d", tParseResults.error, tParseResults.nLine, tParseResults.nColumn );
+ LOG_ERROR( tBuffer );
+ } else {
+ if( response.isEmpty() ){
+ LOG_ERROR("The device descripe XML file is not a valid XML file. Cann't find root element.");
+ } else {
+#ifdef DEBUG_EXTRA
+ LOG("Probe XML parsed");
+#endif
+ XMLNode Body = response.getChildNode( "Body", 0 );
+ if(!Body.isEmpty()){
+#ifdef DEBUG_EXTRA
+ LOG("Have Body elm");
+#endif
+ XMLNode ProbeMatches = Body.getChildNode("ProbeMatches", 0);//EndpointReference
+ if(!ProbeMatches.isEmpty()) {
+#ifdef DEBUG_EXTRA
+ LOG("Have ProbeMathes elm");
+#endif
+ int matches = ProbeMatches.nChildNode();
+ for(int index=0;indexsize(); j++) {
+ if( strlen(tArr->at(j)) > 10 ) {
+ sprintf(retVal->RefID,"%s",tArr->at(j));
+ break;
+ };
+ };
+ tArr->clear();
+ delete(tArr);
+
+ };
+ };
+ }
+ {
+ XMLNode node = ProbeMatch.getChildNode("Types", 0);
+ if( !node.isEmpty() ){
+ char tBuf[CLOG];
+ sprintf(tBuf,"%s", node.getText(0));
+ CArray *tArr;
+ tArr = explode(' ',tBuf);
+ sprintf(retVal->Type,"%s",tArr->at(0));
+ tArr->clear();
+ delete(tArr);
+ }
+ }
+ {
+ XMLNode node = ProbeMatch.getChildNode("Scopes", 0);
+ char tBuf[CLOG];
+ sprintf( tBuf,"%s", node.getText(0) );
+ CArray *tArr = explode(' ',tBuf);
+ if( tArr->size() > 0 ) {
+ for( int index = 0; index < tArr->size(); index++){
+ char *tPtr;
+ if( tPtr = strstr( tArr->at(index), "mac/" ) ){
+ sprintf(retVal->MAC,"%s",tPtr+4);
+ };
+ if( tPtr = strstr( tArr->at(index), "hardware/" ) ){
+ sprintf(retVal->Hardware,"%s",tPtr+9);
+ };
+ if( tPtr = strstr( tArr->at(index), "name/" ) ){
+ sprintf(retVal->Name,"%s",tPtr+5);
+ };
+ if (tPtr = strstr(tArr->at(index), "MAC/")) {
+ sprintf(retVal->MAC, "%s", tPtr + 4);
+ };
+ if (tPtr = strstr(tArr->at(index), "HARDWARE/")) {
+ sprintf(retVal->Hardware, "%s", tPtr + 9);
+ };
+ if (tPtr = strstr(tArr->at(index), "NAME/")) {
+ sprintf(retVal->Name, "%s", tPtr + 5);
+ };
+ };
+ tArr->clear();
+ };
+ delete(tArr);
+ }
+ {
+ XMLNode node = ProbeMatch.getChildNode("XAddrs", 0);
+ char tBuf[1024];
+ sprintf(tBuf,"%s", node.getText(0));
+#ifdef DEBUG_EXTRA
+ LOG("Before Explode");
+ LOG(tBuf);
+#endif
+ CArray *tArr;
+ tArr = explode(' ',tBuf);
+ if( tArr->size() > 0 ) {
+ for( int index=0; index < tArr->size(); index++ ){
+ if( strstr( tArr->at(index), "[" ) != NULL ){
+ // IPv6
+ } else {
+ // IPv4
+ sprintf( retVal->XAddrs,"%s",tArr->at(0));
+ };
+ };
+ tArr->clear();
+ };
+ delete(tArr);
+ }
+ };
+ };
+ };
+ };
+ };
+ };
+ };
+ };
+ return retVal;
+};
+
+
+bool kernelModuleOnvifObserver::validate(){
+ m_mResultProtector.lock();
+ if( m_vResultPool.size() ){ // Clear structures
+ for( vectorOBSERVER_RESULT::iterator index = m_vResultPool.begin(); index < m_vResultPool.end(); index++){
+#ifdef DEBUG_EXTRA
+ char tBuffer[256];
+ sprintf( tBuffer, "Found Camwera [%s] %s", (*index)->XAddrs, (*index)->RefID );
+ LOG( tBuffer );
+#endif
+ uint32_t cid = m_pDBC->getCamId( (*index)->RefID ); //isCameraListed( DiscoverResults->at(index)->RefID );
+ if( cid ) {
+#ifdef DEBUG_EXTRA
+ sprintf( tBuffer, "Camera is Listed as %d", cid );
+ LOG( tBuffer );
+#endif
+ m_pDBC->updateIPCam( cid, (*index)->XAddrs );// DiscoverResults->at(index));
+ } else {
+ // Uncknown camera - no checking
+#ifdef DEBUG_EXTRA
+ LOG("Camera is Not Listed");
+#endif
+ m_pDBC->addIPCam( (*index) );
+ };
+ free(*index);
+ }
+ m_vResultPool.clear();
+#ifdef DEBUG_EXTRA
+ LOG("Clear Structs Done!");
+#endif
+ } else {
+#ifdef DEBUG_EXTRA
+ LOG("No Online IP Cameras in Network");
+#endif
+ };
+ m_mResultProtector.unlock();
+ return true;
+};
+
+
+
+#undef LOG
+#undef LOG_ERROR
+
diff --git a/lib/App/common/serverMySQL_dataBinder.cpp b/lib/App/common/serverMySQL_dataBinder.cpp
index eb55ac15..314ce39e 100644
--- a/lib/App/common/serverMySQL_dataBinder.cpp
+++ b/lib/App/common/serverMySQL_dataBinder.cpp
@@ -49,7 +49,7 @@ uint64_t servaMySQLDBC::addMediaQueueRecord( CSTR uuid, uint64_t module_id, uint
sprintf( tQBuf, "INSERT INTO `media_queue` SET `module_id`=%" PRIu64 ", `session_id`=%" PRIu64 ", `ts`=%d, `tsms`=%d, `uuid`='%s', `width`=%d, `height`=%d, `fps`=%d, `fmt`='%s', `status`=0, `process`=0",
module_id, session_id, ts, tsms, uuid, width, height, fps, fmt
);
-#ifdef DEBUG
+#ifdef DEBUG_ALL
LOG(tQBuf);
#endif
RetVal = m_pDatabase->QueryID( tQBuf );
@@ -201,6 +201,9 @@ uint64_t servaMySQLDBC::getBottomLRF( uint64_t id ){
char tQBuf[MAX_PATH_LEN];
AAssoc *result;
sprintf( tQBuf, "SELECT `id` FROM `lrf_sensors` WHERE `role`='B' AND `mojo_id`=%d", id );
+#ifdef DEBUG_ALL
+ LOG(tQBuf);
+#endif
result = m_pDatabase->Query( tQBuf );
if( result!= NULL ) {
if( result->size() > 0 ) {
@@ -224,7 +227,9 @@ uint32_t servaMySQLDBC::getCloudLTS( uint8_t Obj, uint64_t id ){
char tQBuf[MAX_PATH_LEN];
AAssoc *result;
sprintf( tQBuf, "SELECT `ts` FROM `mem_online_cloud` WHERE `object_id`=%" PRIu64 " AND `object_type`=%d", id, Obj );
- LOG( tQBuf );
+#ifdef DEBUG_ALL
+ LOG(tQBuf);
+#endif
result = m_pDatabase->Query( tQBuf );
if( result!= NULL ) {
if( result->size() > 0 ) {
@@ -248,6 +253,9 @@ uint8_t servaMySQLDBC::getCloudStatus( uint8_t Obj, uint64_t id ){
char tQBuf[MAX_PATH_LEN];
AAssoc *result;
sprintf( tQBuf, "SELECT `status` FROM `mem_online_cloud` WHERE `object_id`=%" PRIu64 " AND `object_type`=%d", id, Obj );
+#ifdef DEBUG_ALL
+ LOG(tQBuf);
+#endif
result = m_pDatabase->Query( tQBuf );
if( result!= NULL ) {
if( result->size() > 0 ) {
@@ -271,6 +279,9 @@ uint64_t servaMySQLDBC::getRecentMediaId(){
char tQBuf[MAX_PATH_LEN];
AAssoc *result;
sprintf( tQBuf, "SELECT `id` FROM `media_queue` WHERE `status`=1 LIMIT 1" );
+#ifdef DEBUG_ALL
+ LOG(tQBuf);
+#endif
result = m_pDatabase->Query( tQBuf );
if( result!= NULL ) {
if( result->size() > 0 ) {
@@ -294,6 +305,9 @@ DBC_RPC_MEDIA_INFO *servaMySQLDBC::getRemoteMediaInfo( uint64_t id ){
char tQBuf[MAX_PATH_LEN];
AAssoc *result;
sprintf( tQBuf, "SELECT * FROM `media_queue` WHERE `id`=%" PRIu64, id );
+#ifdef DEBUG_ALL
+ LOG(tQBuf);
+#endif
result = m_pDatabase->Query( tQBuf );
if( result!= NULL ) {
if (result->size() > 0) {
@@ -346,6 +360,9 @@ DBC_RPC_MEDIA_INFO_EX *servaMySQLDBC::getRemoteMediaInfoEx( uint64_t id ){
char tQBuf[MAX_PATH_LEN];
AAssoc *result;
sprintf( tQBuf, "SELECT * FROM `media_queue` WHERE `id`=%" PRIu64, id );
+#ifdef DEBUG_ALL
+ LOG(tQBuf);
+#endif
result = m_pDatabase->Query( tQBuf );
if( result!= NULL ) {
if (result->size() > 0) {
@@ -406,6 +423,9 @@ uint64_t servaMySQLDBC::getTrackIdByMojo( uint64_t id ){
char tQBuf[MAX_PATH_LEN];
AAssoc *result;
sprintf( tQBuf, "SELECT `track_id` FROM `metro_modules` WHERE `id`=%" PRIu64, id );
+#ifdef DEBUG_ALL
+ LOG(tQBuf);
+#endif
result = m_pDatabase->Query( tQBuf );
if( result!= NULL ) {
if( result->size() > 0 ) {
@@ -429,6 +449,9 @@ uint64_t servaMySQLDBC::getUpperLRF( uint64_t id ){
char tQBuf[MAX_PATH_LEN];
AAssoc *result;
sprintf( tQBuf, "SELECT `id` FROM `lrf_sensors` WHERE `role`='U' AND `mojo_id`=%d", id );
+#ifdef DEBUG_ALL
+ LOG(tQBuf);
+#endif
result = m_pDatabase->Query( tQBuf );
if( result!= NULL ) {
if( result->size() > 0 ) {
@@ -450,6 +473,9 @@ bool servaMySQLDBC::putIntoLog( CSTR A, CSTR B, CSTR C ){
if( m_bIsConnected ){
char tQBuf[MAX_PATH_LEN];
sprintf( tQBuf, "INSERT INTO `server_log_messages` SET lvl = '%s', `ts`='%s', `msg`='%s'", A, B, C );
+#ifdef DEBUG_ALL
+ LOG(tQBuf);
+#endif
m_pDatabase->SilentQuery( tQBuf );
} else LOG("Not Connected!");
};
@@ -460,6 +486,9 @@ uint64_t servaMySQLDBC::registerMojo( CSTR A, CSTR B ){
if( m_bIsConnected ){
AAssoc *result;
sprintf( tQBuf, "SELECT `id` FROM `metro_modules` WHERE `IP4`='%s' AND `identity`='%s'", A, B );
+#ifdef DEBUG_ALL
+ LOG(tQBuf);
+#endif
result = m_pDatabase->Query( tQBuf );
if( result!= NULL ) {
if( result->size() > 0 ) {
@@ -542,6 +571,9 @@ uint32_t servaMySQLDBC::registerVideoTransfer( uint32_t srcNode, CSTR uuid, uint
char tQBuf[MAX_PATH_LEN];
sprintf( tQBuf, "INSERT INTO `media_queue` SET `src`=%d, `uuid`='%s', `size`=%d, `fmt`='%s', `ts`=%d",
srcNode, uuid, dataSize, fmt, ts );
+#ifdef DEBUG_ALL
+ LOG(tQBuf);
+#endif
return ( uint32_t ) m_pDatabase->QueryID( tQBuf );
};
return 0;
diff --git a/lib/App/serva/servaKernel.cpp b/lib/App/serva/servaKernel.cpp
index a2259ab9..3db84116 100644
--- a/lib/App/serva/servaKernel.cpp
+++ b/lib/App/serva/servaKernel.cpp
@@ -227,6 +227,9 @@ void servaKernel::m_fThreadProc( void ){
if ( uint64_t new_id = m_pDBC->getRecentMediaId() ) {
if ( processVideoFile( new_id ) ) updateEncodeStatus( new_id, MEDIA_ENCODE_PROGRESS, 0 );
};
+
+ if ( m_pSM ) m_pSM->validate();
+
//m_pHardwareManager->updateSysInfo( &m_sSysInfo );
DBC_RPC_WEB_CMD * tCMD = m_pDBC->fetchWebCmd( 0 ); //Kernel
if( tCMD != NULL ) {
diff --git a/lib/App/serva/servaSessionManager.cpp b/lib/App/serva/servaSessionManager.cpp
index 1cd0350d..999c2228 100644
--- a/lib/App/serva/servaSessionManager.cpp
+++ b/lib/App/serva/servaSessionManager.cpp
@@ -199,7 +199,7 @@ bool servaSessionManager::addEvent( SESSION_DATA *sp, ARGUS_DATA_EVENT *ptr ){
case EVT_TARGET_2D_BLACK:{
updateSessionStat( sp->db_id );
sprintf( tQBuf, "INSERT INTO `events`(`module_id`,`ts`,`ts_ms`,`evt_type`,`azimuth`,`range`,`area`)" \
- " VALUES(%d,%d,%d,%d,%0.2f,%0.2f,%0.2f,%0.2f)",
+ " VALUES(%d,%d,%d,%d,%0.2f,%0.2f,%0.2f)",
ptr->MODULE_ID,
ptr->TS,
ptr->MS,
@@ -357,25 +357,46 @@ SESSION_DATA *servaSessionManager::updateSession( uint32_t tack_id, uint32_t mod
};
bool servaSessionManager::updateSessionStat( uint64_t session_id, bool evt ){
- if ( evt ) {
- m_pDBC->sessionStatAddEvt( session_id );
- } else {
- m_pDBC->sessionStatAddVid( session_id );
+ if( SESSION_DATA *tD = validateSession( session_id ) ){
+ tD->lts = time( NULL );
+ if ( evt ) {
+ m_pDBC->sessionStatAddEvt( session_id );
+ } else {
+ m_pDBC->sessionStatAddVid( session_id );
+ };
+ return true;
};
- return true;
+ return false;
};
bool servaSessionManager::validate(){
- uint32_t cts = time(NULL);
+ uint32_t cts = time( NULL );
+ M_SESSIONS::iterator dE;
+ bool bMustDelete = false;
for( M_SESSIONS::iterator idx = m_mSessions.begin(); idx != m_mSessions.end(); idx++ ){
- if( cts - (*idx).second->lts > m_nSessionTO ){
- // Close Session
- m_pDBC->updateSessionStatus( (*idx).second->db_id, 1 );
- // remove session
-
- };
+ if ( (*idx).second ) {
+#ifdef DEBUG_EXTRA
+ char tB[128];
+ sprintf( tB, "Validation %d %d %d", cts, (*idx).second->lts, m_nSessionTO );
+ LOG( tB );
+#endif
+ if( cts - (*idx).second->lts > m_nSessionTO ){
+ // Expire Session
+ m_pDBC->updateSessionStatus( (*idx).second->db_id, 1 );
+ // Set Session to remove
+ dE = idx;
+ bMustDelete = true;
+ };
+ };
};
- return true;
+ if ( bMustDelete ) {
+ // Remove Session
+ delete( (*dE).second->m_pDataReport );
+ free( (*dE).second );
+ (*dE).second = NULL;
+ m_mSessions.erase( dE );
+ };
+ return true;
};
SESSION_DATA *servaSessionManager::validateSession( uint64_t sid ){