diff --git a/Projects/argus/Debug/default.conf b/Projects/argus/Debug/default.conf index de85ae6c..67edd92e 100644 --- a/Projects/argus/Debug/default.conf +++ b/Projects/argus/Debug/default.conf @@ -10,7 +10,7 @@ KERNEL : SSDP : { DEVICE_TYPE = "urn:schemas-upnp-org:device:InternetGatewayDevice:1"; - SERVER_STRING = "Atom Argus App Server"; + SERVER_STRING = "RaspberryPi Argus App Server"; DEVICE_FRIENDLY_NAME = "Argus Application Server"; DEVICE_UUID = "47035424-731b-4d83-98c5-c4310993bbb3"; MANUFACTURER = "Dr.Frucht Systems"; diff --git a/Projects/argus/argus.vpj b/Projects/argus/argus.vpj index 09f3bc10..9c5119e5 100644 --- a/Projects/argus/argus.vpj +++ b/Projects/argus/argus.vpj @@ -25,7 +25,7 @@ SaveOption="SaveCurrent" RunFromDir="%rw"> - + + @@ -150,7 +151,7 @@ SaveOption="SaveCurrent" RunFromDir="%rw"> - + + @@ -307,11 +309,16 @@ - + + + + + + @@ -359,13 +366,22 @@ - + + + + + + + + + + diff --git a/Projects/argus/makefile b/Projects/argus/makefile index b1db8524..c39cfed4 100644 --- a/Projects/argus/makefile +++ b/Projects/argus/makefile @@ -24,7 +24,7 @@ CFG_INC= CFG_LIB=-lpthread -lmysqlclient -lssl -lcurl -lm -lcrypto -lconfig \ -lz -lv4l1 -lv4l2 -lhidapi-libusb `pkg-config libavcodec libavdevice \ libavfilter libavformat libavutil libpostproc libswresample \ - libswscale --libs` -lssl `pkg-config --libs rdkafka++` + libswscale --libs` -lssl -latomic `pkg-config --libs rdkafka++` CFG_OBJ= COMMON_OBJ=$(OUTDIR)/ArgusBackend.o $(OUTDIR)/base64.o \ $(OUTDIR)/basicDualThread.o $(OUTDIR)/basicEngine.o \ @@ -49,14 +49,18 @@ COMMON_OBJ=$(OUTDIR)/ArgusBackend.o $(OUTDIR)/base64.o \ $(OUTDIR)/protocolKAFKA.o $(OUTDIR)/protocolLGS.o \ $(OUTDIR)/protocolLGS2D.o $(OUTDIR)/protocolLGSm.o \ $(OUTDIR)/protocolSafeShore.o $(OUTDIR)/protocolZLMEDIA.o \ - $(OUTDIR)/RGoose_Kernel.o $(OUTDIR)/rgooseCamera.o \ - $(OUTDIR)/rgooseDBConnector.o $(OUTDIR)/rgooseIPCamera.o \ - $(OUTDIR)/rgooseKafkaModule.o $(OUTDIR)/rgooseModule.o \ - $(OUTDIR)/rgooseModuleFactory.o $(OUTDIR)/rgooseNode.o \ - $(OUTDIR)/rgooseNode2D.o $(OUTDIR)/rgooseNode3D.o \ - $(OUTDIR)/rgooseNodeFactory.o $(OUTDIR)/rgooseServerModule.o \ - $(OUTDIR)/rgooseUSBRelayModule.o $(OUTDIR)/rgooseZLMediaModule.o \ - $(OUTDIR)/serialPort.o $(OUTDIR)/serialSOL.o $(OUTDIR)/serverPort.o \ + $(OUTDIR)/rgooseCamera.o $(OUTDIR)/rgooseDBConnector.o \ + $(OUTDIR)/rgooseHardwareManager.o $(OUTDIR)/rgooseHardwareResource.o \ + $(OUTDIR)/rgooseHardwareResourceNetwork.o \ + $(OUTDIR)/rgooseHardwareResourceUART.o \ + $(OUTDIR)/rgooseHardwareUART.o $(OUTDIR)/rgooseIPCamera.o \ + $(OUTDIR)/rgooseKafkaModule.o $(OUTDIR)/rgooseKernel.o \ + $(OUTDIR)/rgooseModule.o $(OUTDIR)/rgooseModuleFactory.o \ + $(OUTDIR)/rgooseNode.o $(OUTDIR)/rgooseNode2D.o \ + $(OUTDIR)/rgooseNode3D.o $(OUTDIR)/rgooseNodeFactory.o \ + $(OUTDIR)/rgooseServerModule.o $(OUTDIR)/rgooseUSBRelayModule.o \ + $(OUTDIR)/rgooseZLMediaModule.o $(OUTDIR)/serialPort.o \ + $(OUTDIR)/serialSOL.o $(OUTDIR)/serverPort.o \ $(OUTDIR)/servletChannelWS.o $(OUTDIR)/servletClientHandlerWS.o \ $(OUTDIR)/servletWS.o $(OUTDIR)/ssdpAnnouncer.o \ $(OUTDIR)/Transform.o $(OUTDIR)/transportSerial.o \ @@ -85,14 +89,18 @@ ALL_OBJ=$(OUTDIR)/ArgusBackend.o $(OUTDIR)/base64.o \ $(OUTDIR)/protocolKAFKA.o $(OUTDIR)/protocolLGS.o \ $(OUTDIR)/protocolLGS2D.o $(OUTDIR)/protocolLGSm.o \ $(OUTDIR)/protocolSafeShore.o $(OUTDIR)/protocolZLMEDIA.o \ - $(OUTDIR)/RGoose_Kernel.o $(OUTDIR)/rgooseCamera.o \ - $(OUTDIR)/rgooseDBConnector.o $(OUTDIR)/rgooseIPCamera.o \ - $(OUTDIR)/rgooseKafkaModule.o $(OUTDIR)/rgooseModule.o \ - $(OUTDIR)/rgooseModuleFactory.o $(OUTDIR)/rgooseNode.o \ - $(OUTDIR)/rgooseNode2D.o $(OUTDIR)/rgooseNode3D.o \ - $(OUTDIR)/rgooseNodeFactory.o $(OUTDIR)/rgooseServerModule.o \ - $(OUTDIR)/rgooseUSBRelayModule.o $(OUTDIR)/rgooseZLMediaModule.o \ - $(OUTDIR)/serialPort.o $(OUTDIR)/serialSOL.o $(OUTDIR)/serverPort.o \ + $(OUTDIR)/rgooseCamera.o $(OUTDIR)/rgooseDBConnector.o \ + $(OUTDIR)/rgooseHardwareManager.o $(OUTDIR)/rgooseHardwareResource.o \ + $(OUTDIR)/rgooseHardwareResourceNetwork.o \ + $(OUTDIR)/rgooseHardwareResourceUART.o \ + $(OUTDIR)/rgooseHardwareUART.o $(OUTDIR)/rgooseIPCamera.o \ + $(OUTDIR)/rgooseKafkaModule.o $(OUTDIR)/rgooseKernel.o \ + $(OUTDIR)/rgooseModule.o $(OUTDIR)/rgooseModuleFactory.o \ + $(OUTDIR)/rgooseNode.o $(OUTDIR)/rgooseNode2D.o \ + $(OUTDIR)/rgooseNode3D.o $(OUTDIR)/rgooseNodeFactory.o \ + $(OUTDIR)/rgooseServerModule.o $(OUTDIR)/rgooseUSBRelayModule.o \ + $(OUTDIR)/rgooseZLMediaModule.o $(OUTDIR)/serialPort.o \ + $(OUTDIR)/serialSOL.o $(OUTDIR)/serverPort.o \ $(OUTDIR)/servletChannelWS.o $(OUTDIR)/servletClientHandlerWS.o \ $(OUTDIR)/servletWS.o $(OUTDIR)/ssdpAnnouncer.o \ $(OUTDIR)/Transform.o $(OUTDIR)/transportSerial.o \ @@ -100,10 +108,10 @@ ALL_OBJ=$(OUTDIR)/ArgusBackend.o $(OUTDIR)/base64.o \ -lpthread -lmysqlclient -lssl -lcurl -lm -lcrypto -lconfig -lz \ -lv4l1 -lv4l2 -lhidapi-libusb `pkg-config libavcodec libavdevice \ libavfilter libavformat libavutil libpostproc libswresample \ - libswscale --libs` -lssl `pkg-config --libs rdkafka++` + libswscale --libs` -lssl -latomic `pkg-config --libs rdkafka++` -COMPILE=g++ -c -x c++ "-DDEBUG" "-D__STDC_CONSTANT_MACROS" -g -std=c++11 -Wno-write-strings -I../../lib/include `pkg-config libavcodec libavdevice libavfilter libavformat libavutil libpostproc libswresample libswscale --cflags` -o "$(OUTDIR)/$(*F).o" $(CFG_INC) $< -LINK=g++ -g -o "$(OUTFILE)" $(ALL_OBJ) +COMPILE=g++ -c -x c++ "-DDEBUG" "-D__STDC_CONSTANT_MACROS" -g -ggdb -std=c++11 -Wno-write-strings -I../../lib/include `pkg-config libavcodec libavdevice libavfilter libavformat libavutil libpostproc libswresample libswscale --cflags` -o "$(OUTDIR)/$(*F).o" $(CFG_INC) $< +LINK=g++ -g -ggdb -o "$(OUTFILE)" $(ALL_OBJ) # Pattern rules $(OUTDIR)/%.o : ../../lib/data/transport/%.cpp @@ -188,7 +196,7 @@ CFG_INC= CFG_LIB=-lpthread -lmysqlclient -lssl -lcurl -lm -lcrypto -lconfig \ -lz -lv4l1 -lv4l2 -lhidapi-libusb `pkg-config libavcodec libavdevice \ libavfilter libavformat libavutil libpostproc libswresample \ - libswscale --libs` -lssl `pkg-config --libs rdkafka++` + libswscale --libs` -lssl -latomic `pkg-config --libs rdkafka++` CFG_OBJ= COMMON_OBJ=$(OUTDIR)/ArgusBackend.o $(OUTDIR)/base64.o \ $(OUTDIR)/basicDualThread.o $(OUTDIR)/basicEngine.o \ @@ -213,14 +221,18 @@ COMMON_OBJ=$(OUTDIR)/ArgusBackend.o $(OUTDIR)/base64.o \ $(OUTDIR)/protocolKAFKA.o $(OUTDIR)/protocolLGS.o \ $(OUTDIR)/protocolLGS2D.o $(OUTDIR)/protocolLGSm.o \ $(OUTDIR)/protocolSafeShore.o $(OUTDIR)/protocolZLMEDIA.o \ - $(OUTDIR)/RGoose_Kernel.o $(OUTDIR)/rgooseCamera.o \ - $(OUTDIR)/rgooseDBConnector.o $(OUTDIR)/rgooseIPCamera.o \ - $(OUTDIR)/rgooseKafkaModule.o $(OUTDIR)/rgooseModule.o \ - $(OUTDIR)/rgooseModuleFactory.o $(OUTDIR)/rgooseNode.o \ - $(OUTDIR)/rgooseNode2D.o $(OUTDIR)/rgooseNode3D.o \ - $(OUTDIR)/rgooseNodeFactory.o $(OUTDIR)/rgooseServerModule.o \ - $(OUTDIR)/rgooseUSBRelayModule.o $(OUTDIR)/rgooseZLMediaModule.o \ - $(OUTDIR)/serialPort.o $(OUTDIR)/serialSOL.o $(OUTDIR)/serverPort.o \ + $(OUTDIR)/rgooseCamera.o $(OUTDIR)/rgooseDBConnector.o \ + $(OUTDIR)/rgooseHardwareManager.o $(OUTDIR)/rgooseHardwareResource.o \ + $(OUTDIR)/rgooseHardwareResourceNetwork.o \ + $(OUTDIR)/rgooseHardwareResourceUART.o \ + $(OUTDIR)/rgooseHardwareUART.o $(OUTDIR)/rgooseIPCamera.o \ + $(OUTDIR)/rgooseKafkaModule.o $(OUTDIR)/rgooseKernel.o \ + $(OUTDIR)/rgooseModule.o $(OUTDIR)/rgooseModuleFactory.o \ + $(OUTDIR)/rgooseNode.o $(OUTDIR)/rgooseNode2D.o \ + $(OUTDIR)/rgooseNode3D.o $(OUTDIR)/rgooseNodeFactory.o \ + $(OUTDIR)/rgooseServerModule.o $(OUTDIR)/rgooseUSBRelayModule.o \ + $(OUTDIR)/rgooseZLMediaModule.o $(OUTDIR)/serialPort.o \ + $(OUTDIR)/serialSOL.o $(OUTDIR)/serverPort.o \ $(OUTDIR)/servletChannelWS.o $(OUTDIR)/servletClientHandlerWS.o \ $(OUTDIR)/servletWS.o $(OUTDIR)/ssdpAnnouncer.o \ $(OUTDIR)/Transform.o $(OUTDIR)/transportSerial.o \ @@ -249,14 +261,18 @@ ALL_OBJ=$(OUTDIR)/ArgusBackend.o $(OUTDIR)/base64.o \ $(OUTDIR)/protocolKAFKA.o $(OUTDIR)/protocolLGS.o \ $(OUTDIR)/protocolLGS2D.o $(OUTDIR)/protocolLGSm.o \ $(OUTDIR)/protocolSafeShore.o $(OUTDIR)/protocolZLMEDIA.o \ - $(OUTDIR)/RGoose_Kernel.o $(OUTDIR)/rgooseCamera.o \ - $(OUTDIR)/rgooseDBConnector.o $(OUTDIR)/rgooseIPCamera.o \ - $(OUTDIR)/rgooseKafkaModule.o $(OUTDIR)/rgooseModule.o \ - $(OUTDIR)/rgooseModuleFactory.o $(OUTDIR)/rgooseNode.o \ - $(OUTDIR)/rgooseNode2D.o $(OUTDIR)/rgooseNode3D.o \ - $(OUTDIR)/rgooseNodeFactory.o $(OUTDIR)/rgooseServerModule.o \ - $(OUTDIR)/rgooseUSBRelayModule.o $(OUTDIR)/rgooseZLMediaModule.o \ - $(OUTDIR)/serialPort.o $(OUTDIR)/serialSOL.o $(OUTDIR)/serverPort.o \ + $(OUTDIR)/rgooseCamera.o $(OUTDIR)/rgooseDBConnector.o \ + $(OUTDIR)/rgooseHardwareManager.o $(OUTDIR)/rgooseHardwareResource.o \ + $(OUTDIR)/rgooseHardwareResourceNetwork.o \ + $(OUTDIR)/rgooseHardwareResourceUART.o \ + $(OUTDIR)/rgooseHardwareUART.o $(OUTDIR)/rgooseIPCamera.o \ + $(OUTDIR)/rgooseKafkaModule.o $(OUTDIR)/rgooseKernel.o \ + $(OUTDIR)/rgooseModule.o $(OUTDIR)/rgooseModuleFactory.o \ + $(OUTDIR)/rgooseNode.o $(OUTDIR)/rgooseNode2D.o \ + $(OUTDIR)/rgooseNode3D.o $(OUTDIR)/rgooseNodeFactory.o \ + $(OUTDIR)/rgooseServerModule.o $(OUTDIR)/rgooseUSBRelayModule.o \ + $(OUTDIR)/rgooseZLMediaModule.o $(OUTDIR)/serialPort.o \ + $(OUTDIR)/serialSOL.o $(OUTDIR)/serverPort.o \ $(OUTDIR)/servletChannelWS.o $(OUTDIR)/servletClientHandlerWS.o \ $(OUTDIR)/servletWS.o $(OUTDIR)/ssdpAnnouncer.o \ $(OUTDIR)/Transform.o $(OUTDIR)/transportSerial.o \ @@ -264,10 +280,10 @@ ALL_OBJ=$(OUTDIR)/ArgusBackend.o $(OUTDIR)/base64.o \ -lpthread -lmysqlclient -lssl -lcurl -lm -lcrypto -lconfig -lz \ -lv4l1 -lv4l2 -lhidapi-libusb `pkg-config libavcodec libavdevice \ libavfilter libavformat libavutil libpostproc libswresample \ - libswscale --libs` -lssl `pkg-config --libs rdkafka++` + libswscale --libs` -lssl -latomic `pkg-config --libs rdkafka++` -COMPILE=g++ -c -x c++ "-DDEBUG" "-D__STDC_CONSTANT_MACROS" -std=c++11 -Wno-write-strings -I../../lib/include `pkg-config libavcodec libavdevice libavfilter libavformat libavutil libpostproc libswresample libswscale --cflags` -o "$(OUTDIR)/$(*F).o" $(CFG_INC) $< -LINK=g++ -o "$(OUTFILE)" $(ALL_OBJ) +COMPILE=g++ -c -x c++ "-DDEBUG" "-D__STDC_CONSTANT_MACROS" -ggdb -std=c++11 -Wno-write-strings -I../../lib/include `pkg-config libavcodec libavdevice libavfilter libavformat libavutil libpostproc libswresample libswscale --cflags` -o "$(OUTDIR)/$(*F).o" $(CFG_INC) $< +LINK=g++ -ggdb -o "$(OUTFILE)" $(ALL_OBJ) # Pattern rules $(OUTDIR)/%.o : ../../lib/data/transport/%.cpp diff --git a/Projects/argus/test_sha.php b/Projects/argus/test_sha.php index 97cadabf..ff267255 100644 --- a/Projects/argus/test_sha.php +++ b/Projects/argus/test_sha.php @@ -1,4 +1,6 @@ \ No newline at end of file diff --git a/lib/App/argus/ArgusBackend.cpp b/lib/App/argus/ArgusBackend.cpp index 1403b29d..2d8c9cfa 100644 --- a/lib/App/argus/ArgusBackend.cpp +++ b/lib/App/argus/ArgusBackend.cpp @@ -21,7 +21,7 @@ bool gSignal_Handler_Enabled = true; #define LOG( X ) m_pLog->Log( "main", 0, X ) #define LOG_ERROR( X ) m_pLog->Log( "main", 0, _LOG_ERROR, X ) -ARGUS_Kernel * Kernel = NULL; +argusKernel * Kernel = NULL; //LRF_HardwareManager * HWManager = NULL; basicLogCollection * m_pLog = NULL; networkServer * NetworkManager = NULL; @@ -46,7 +46,29 @@ void signal_SIGKILL_handler( int SIG ){ }; }; +//#include + int main (int argc, char *argv[]){ + /* + const rlim_t kStackSize = 16 * 1024 * 1024; // min stack size = 16 MB + struct rlimit rl; + int result; + + result = getrlimit(RLIMIT_STACK, &rl); + if (result == 0){ + printf( "Stack Size: %d\n", rl.rlim_cur ); + if ( rl.rlim_cur < kStackSize ){ + printf( "Resize Stack to: %d\n", kStackSize ); + rl.rlim_cur = kStackSize; + result = setrlimit(RLIMIT_STACK, &rl); + if (result != 0){ + fprintf(stderr, "setrlimit returned result = %d\n", result); + return -1; + }; + }; + }; + */ + MySQL_Connector * DBC = NULL; basicSettingsProvider * SETTINGS = NULL; bool WBG; // Working Background @@ -66,7 +88,7 @@ int main (int argc, char *argv[]){ SSP_NAME = (CSTR) DEFAULT_SERVER_SOCKET_PATH; gsSOFT_INFO.SW_BUILD_DATE = UNIX_TIMESTAMP; gsSOFT_INFO.DATA_VALID = false; - m_pLog = basicLogCollection::getInstance(); + m_pLog = basicLogCollection::getInstance( _LOG_TIME ); gsSOFT_INFO.SW_MODE_FLAGS = 0 #ifdef SKIP_TARGET_LOG | SW_INFO_NO_TARGET_LOG @@ -205,7 +227,7 @@ int main (int argc, char *argv[]){ uint8_t m_bKernelExitCode = 0; do{ - Kernel = new ARGUS_Kernel(); + Kernel = argusKernel::getInstance(); if( Kernel == NULL ) { // Aborting Work LOG_ERROR( "++++ Kernel failed to born ++++" ); diff --git a/lib/App/argus/ArgusBackend.h b/lib/App/argus/ArgusBackend.h index 19beec5a..bc874426 100644 --- a/lib/App/argus/ArgusBackend.h +++ b/lib/App/argus/ArgusBackend.h @@ -27,7 +27,7 @@ #include "../../data/ponvif/ponvif.h" #include "../../data/protocol/onvifMediaObserver.h" #include "../../data/mysql/database_class.h" -#include "RGoose_Kernel.h" +#include "../../rgoose/rgooseKernel.h" /** local definitions **/ //http://xmsecu.com:8080/ocx/NewActive.exe diff --git a/lib/App/argus/RGoose_Kernel.cpp b/lib/App/argus/RGoose_Kernel.cpp index 2dc3a425..4340d877 100644 --- a/lib/App/argus/RGoose_Kernel.cpp +++ b/lib/App/argus/RGoose_Kernel.cpp @@ -496,13 +496,15 @@ void ARGUS_Kernel::m_fThreadProc( void ){ m_bDiscoveryStarted = true; }; } else { + /* if((m_tTimeTSeconds%ONVIF_DISCOVERY_INTERVAL)==ONVIF_DISCOVERY_RESULT_TIME){ #ifdef DEBUG LOG("Validate IP Cameras"); #endif validateCameras(); m_bDiscoveryStarted = false; - }; + }; + */ }; }; //*/ @@ -515,9 +517,11 @@ void ARGUS_Kernel::m_fThreadProc( void ){ continue; }; - if( m_vEvtRecords.size() > 0 ){ +/* if( m_vEvtRecords.size() > 0 ){ validateEvents( lastTSS, lastTMS ); - }; + }; + */ + //*/ if( m_tTimeTSeconds != tTimeTSeconds ){ // Each Second Process tTimeTSeconds = m_tTimeTSeconds; @@ -532,6 +536,7 @@ void ARGUS_Kernel::m_fThreadProc( void ){ }; }; +/* int ARGUS_Kernel::isCameraListed( CSTR uid ){ if( m_vCamRecords.size() ) for( int index = 0; index < m_vCamRecords.size(); index++ ) @@ -591,11 +596,7 @@ void ARGUS_Kernel::validateEvents( int &lastTSS, int &lastTMS ){ #endif }; }; - -bool ARGUS_Kernel::setStatus( int A ){ - m_bThreadStatus = (thredStatus)A; - return true; -}; +*/ bool ARGUS_Kernel::signalEvent( void ){ if( m_pDBC->getLastEvents( m_vEvtRecords, 0,0 ) ){ diff --git a/lib/App/argus/RGoose_Kernel.h b/lib/App/argus/RGoose_Kernel.h index f6c0b416..ced6fc1b 100644 --- a/lib/App/argus/RGoose_Kernel.h +++ b/lib/App/argus/RGoose_Kernel.h @@ -108,9 +108,9 @@ class ARGUS_Kernel: public basicThread { argusModuleFactory * m_pModuleFactory; mediaNginxManager * m_pStreamManager; //servletWS * m_pServletWS; - int isCameraListed( CSTR uid ); - void validateCameras( void ); - void validateEvents( int &lastTSS, int &lastTMS ); + //int isCameraListed( CSTR uid ); + //void validateCameras( void ); + //void validateEvents( int &lastTSS, int &lastTMS ); void enumerateHardware( void ); protected: void m_fThreadProc( void ); @@ -122,7 +122,6 @@ class ARGUS_Kernel: public basicThread { bool create( void ); bool signalEvent( void ); void WaitFinish( bool Force = false ); - bool setStatus( int ); uint8_t getExitCause( void ){ return m_bExitCause;}; int getNetNodes( ARGUS_NODE_TYPE type, argusNetNode **&RA ); argusNetNode * getNetNode( int id ); diff --git a/lib/alg/generic/md5.cpp b/lib/alg/generic/md5.cpp index fb2fb0a3..6dc68225 100644 --- a/lib/alg/generic/md5.cpp +++ b/lib/alg/generic/md5.cpp @@ -37,6 +37,7 @@ #include #include #include +#include #include "md5.h" @@ -68,18 +69,17 @@ static unsigned char PADDING[64] = // PrintMD5: Converts a completed md5 digest into a char* string. char* PrintMD5(u_char md5Digest[16]) { - char chBuffer[256]; - char chEach[10]; + char chBuffer[33]; + char chEach[3]; int nCount; - memset(chBuffer,0,256); - memset(chEach, 0, 10); + memset(chBuffer,0,33); + memset(chEach, 0, 3); - for (nCount = 0; nCount < 16; nCount++) - { + for (nCount = 0; nCount < 16; nCount++){ sprintf(chEach, "%02x", md5Digest[nCount]); strncat(chBuffer, chEach, sizeof(chEach)); - } + }; #ifdef __linux__ return strdup(chBuffer); #else diff --git a/lib/components/base/basicLogCollection.cpp b/lib/components/base/basicLogCollection.cpp index 7ec86fb6..090d0043 100644 --- a/lib/components/base/basicLogCollection.cpp +++ b/lib/components/base/basicLogCollection.cpp @@ -5,11 +5,11 @@ basicLogCollection* basicLogCollection::_instance = 0; /** * Returns the single instance of the object. */ -basicLogCollection* basicLogCollection::getInstance() { +basicLogCollection* basicLogCollection::getInstance( _LOG_SETTINGS val ) { // check if the instance has been created yet if( 0 == _instance ){ // if not, then create it - _instance = new basicLogCollection; + _instance = new basicLogCollection( val ); }; // return the single instance return _instance; @@ -45,19 +45,54 @@ void basicLogCollection::Log( const char *Mod, void *ptr, const char *Msg ){ }; void basicLogCollection::Log( const char *Mod, void *ptr, _LOG_LEVEL Level, CSTR Msg ){ - if( Level <= m_bMaxLevel ){ - - char temp[CLOG]; - sprintf( temp, " %p %s: %s", ptr, Mod, Msg ); - broadcast( (CSTR) temp ); + if( Level <= m_bMaxLevel ){ + char temp[CLOG]; + if( strlen( Msg ) < ( CLOG >> 1 ) ) { + switch( m_bLogSettings ) { + case _LOG_SIMPLE: sprintf( temp, "%s: %s\n", Mod, Msg ); break; + case _LOG_TIME:{ + time_t LocalTime; + tm *gmt_time; + time( &LocalTime ); + gmt_time = gmtime( &LocalTime ); + sprintf( temp, "%04d-%02d-%02d %02d:%02d:%02d %s: %s\n", 1900+gmt_time->tm_year, 1+gmt_time->tm_mon, gmt_time->tm_mday, gmt_time->tm_hour, gmt_time->tm_min, gmt_time->tm_sec, Mod, Msg ); + break; + }; + case _LOG_PTR: sprintf( temp, "%p %s: %s\n", ptr, Mod, Msg ); break; + case _LOG_TIME_PTR: { + time_t LocalTime; + tm *gmt_time; + time( &LocalTime ); + gmt_time = gmtime( &LocalTime ); + sprintf( temp, "%04d-%02d-%02d %02d:%02d:%02d %p %s: %s\n", 1900+gmt_time->tm_year, 1+gmt_time->tm_mon, gmt_time->tm_mday, gmt_time->tm_hour, gmt_time->tm_min, gmt_time->tm_sec, ptr, Mod, Msg ); + break; + }; + case _LOG_LVL: sprintf( temp, "%02X %s: %s\n", Level, Mod, Msg ); break; + case _LOG_TIME_LVL:{ + time_t LocalTime; + tm *gmt_time; + time( &LocalTime ); + gmt_time = gmtime( &LocalTime ); + sprintf( temp, "%04d-%02d-%02d %02d:%02d:%02d %02X %s: %s\n", 1900+gmt_time->tm_year, 1+gmt_time->tm_mon, gmt_time->tm_mday, gmt_time->tm_hour, gmt_time->tm_min, gmt_time->tm_sec, Level, Mod, Msg ); + break; + }; + case _LOG_LVL_PTR: sprintf( temp, "%02X %p %s: %s\n", Level, ptr, Mod, Msg ); break; + case _LOG_TIME_LVL_PTR:{ + time_t LocalTime; + tm *gmt_time; + time( &LocalTime ); + gmt_time = gmtime( &LocalTime ); + sprintf( temp, "%04d-%02d-%02d %02d:%02d:%02d %02X %p %s: %s\n", 1900+gmt_time->tm_year, 1+gmt_time->tm_mon, gmt_time->tm_mday, gmt_time->tm_hour, gmt_time->tm_min, gmt_time->tm_sec, Level, ptr, Mod, Msg ); + break; + }; + }; + } else { + sprintf( temp, "Log Message Too Long Buffer is Overflowed" ); + }; + broadcast( (CSTR) temp ); }; }; void basicLogCollection::Log( const char *Mod, void *ptr, _LOG_LEVEL Level, const char *Msg ){ - if( Level <= m_bMaxLevel ){ - - char temp[CLOG]; - sprintf( temp, " %p %s: %s", ptr, Mod, Msg ); - broadcast( (CSTR) temp ); - }; + Log( Mod, ptr, Level,(CSTR) Msg ); }; diff --git a/lib/components/base/basicLogCollection.h b/lib/components/base/basicLogCollection.h index a5779cc9..1f134e61 100644 --- a/lib/components/base/basicLogCollection.h +++ b/lib/components/base/basicLogCollection.h @@ -13,8 +13,20 @@ typedef enum EE_LOG_LEVEL{ _LOG_ALL } _LOG_LEVEL; +typedef enum EE_LOG_SETTINGS{ + _LOG_SIMPLE = 0, + _LOG_TIME = 1, + _LOG_PTR = 2, + _LOG_TIME_PTR = 3, + _LOG_LVL = 4, + _LOG_TIME_LVL = 5, + _LOG_LVL_PTR = 6, + _LOG_TIME_LVL_PTR = 7 +} _LOG_SETTINGS; + #define _DEFAULT_LOG_LEVEL_ _LOG_DEBUG #define _WORKING_LOG_LEVEL_ _LOG_ALL +#define _DEFAULT_LOG_SETTINGS _LOG_TIME_PTR /** * @Description Singleton class to handle logging @@ -26,10 +38,11 @@ class basicLogCollection { basicMutex *m_pLogMutex; LoggersRing *m_pRing; _LOG_LEVEL m_bMaxLevel; + _LOG_SETTINGS m_bLogSettings; void broadcast( CSTR Msg ); public: // Method to fetch singleton instance. - static basicLogCollection* getInstance(); + static basicLogCollection* getInstance( _LOG_SETTINGS val = _DEFAULT_LOG_SETTINGS ); // Destructor virtual ~basicLogCollection(); @@ -43,7 +56,7 @@ class basicLogCollection { void Log( const char *Mod, void *ptr, _LOG_LEVEL Level, const char *Msg ); protected: // Constructor - protected so users cannot call it. - basicLogCollection(); + explicit basicLogCollection( _LOG_SETTINGS val ); private: // private static member referencing the single instance of the object @@ -64,8 +77,9 @@ class basicLogCollection { }; // Constructor implementation -inline basicLogCollection::basicLogCollection(){ +inline basicLogCollection::basicLogCollection( _LOG_SETTINGS val ){ m_pRing = NULL; + m_bLogSettings = val; m_pRing = new LoggersRing();//4); // Maximum 4 Logginig Engines; m_bMaxLevel = _DEFAULT_LOG_LEVEL_; m_pLogMutex = new basicMutex(); diff --git a/lib/components/base/basicObject.h b/lib/components/base/basicObject.h index ce69c485..c52c1a4f 100644 --- a/lib/components/base/basicObject.h +++ b/lib/components/base/basicObject.h @@ -28,10 +28,10 @@ class basicObject{ public: basicObject(); ~basicObject(); - virtual objectStatus getStatus( void ){ return m_eStatus; }; - virtual CSTR getUID( void ){ return m_sUID; }; - virtual int getID( void ){ return m_nID; }; - virtual objectCaps getCaps( void ){ return m_eCaps; }; + virtual objectStatus getStatus( void ){ return m_eStatus; }; + virtual CSTR getObjectUID( void ){ return m_sUID; }; + virtual int getObjectId( void ){ return m_nID; }; + virtual objectCaps getCaps( void ){ return m_eCaps; }; }; diff --git a/lib/components/base/basicTypes.h b/lib/components/base/basicTypes.h index 74423122..5e3ff799 100644 --- a/lib/components/base/basicTypes.h +++ b/lib/components/base/basicTypes.h @@ -97,18 +97,18 @@ typedef enum{ } MediaStateStatus; typedef struct _S_SOURCE_INFO{ - int type; - int subtype; - int deviceId; - bool frameIsWide; - int sizeId; + int type; + int subtype; + int deviceId; + bool frameIsWide; + int sizeId; int width; int height; - int framerate; - int capturePin; + int framerate; + int capturePin; char deviceName[CTEXT]; char devicePath[CTEXT]; - float lat, + float lat, lon, alt, h_lat, @@ -137,7 +137,7 @@ typedef struct _S_SOURCE_INFO{ fPanTotalRad, fTiltTotalDeg, fTiltTotalRad; - bool bAutoFocus, + bool bAutoFocus, bAutoIris, bAutoWB, bAutoExposure, @@ -156,11 +156,11 @@ typedef struct _S_SOURCE_INFO{ bZoomEna, bDZoomEna, bOptixEna; - int protocolId; - int protocolParameter; - int comTransportPort; + int protocolId; + int protocolParameter; + int comTransportPort; char comTransportPath[CTEXT]; - int comTransportSpeed; + int comTransportSpeed; char onvifDeviceURI[CTEXT]; char onvifVideoMRL[CTEXT]; char onvifPictureMRL[CTEXT]; @@ -513,5 +513,71 @@ typedef vector localIpAddresses; #define SLEEP(X) Sleep(X) #endif +typedef struct S_LRF_SETTINGS{ + uint32_t filterWidth; + uint32_t filterSST; + uint32_t filterOffset; + uint32_t filterOrder; +}LRF_SETTINGS; + +typedef struct S_LGS_SETTINGS{ + LRF_SETTINGS *pLRF; + uint8_t lrfCount; + uint32_t nSunMask; + uint32_t nLrfMask; + int32_t zShift; + bool bAutoReset; + bool bAlarmDC; + bool bAlarmOutputNC; + bool bCameraEna; + bool bAutoCameraCtrl; + uint8_t bCameraProtoID; + uint8_t bCameraID; + uint32_t bCameraPortSpeed; + + uint16_t nMaxAngle; + float fMaxAngle; + float fMaxDistance; + float fLat; + float fLon; + float fRoll; + float fPitch; + float fYaw; +}LGS_SETTINGS; + +typedef struct S_LOCAL_PORT_SETTINGS{ + CSTR pDeviceName; + uint32_t nSpeed; + uint8_t nDataBit; + uint8_t nStopBit; + uint8_t nParity; + uint8_t nFlowCtrl; +}LOCAL_PORT_SETTINGS; + +typedef enum E_SOL_TYPE{ + SOL_UDP_CLIENT = 0, + SOL_TCP_CLIENT = 1, + SOL_UDP_SERVER = 2, + SOL_TCP_SERVER = 3 +}SOL_TYPE; + +typedef struct S_SOL_PORT_SETTINGS{ + char pDeviceAddr[64]; + uint16_t nPort; + SOL_TYPE eConnectionType; + CSTR pUser; + CSTR pPassword; + bool bRFC2217; + uint32_t nSpeed; + uint8_t nDataBit; + uint8_t nStopBit; + uint8_t nParity; + uint8_t nFlowCtrl; +}SOL_PORT_SETTINGS; + +typedef struct S_KAFKA_SETTINGS{ + char brocker_addr[128]; + uint16_t brocker_port; +}KAFKA_SETTINGS; #endif diff --git a/lib/components/object/objectFileLoggingService.cpp b/lib/components/object/objectFileLoggingService.cpp index e57f8593..487e7fb7 100644 --- a/lib/components/object/objectFileLoggingService.cpp +++ b/lib/components/object/objectFileLoggingService.cpp @@ -17,17 +17,11 @@ void objectFileLoggingService::logMessage( CSTR Msg ){ }; void objectFileLoggingService::logMessage( const char *Msg ){ - FILE *FD; - char temp[CLOG]; if ( m_bLogging ){ - time_t LocalTime; - tm *gmt_time; - time( &LocalTime ); - gmt_time = gmtime( &LocalTime ); + FILE *FD; FD = fopen( m_pFileName , "a+"); if( FD != NULL ) { - sprintf( temp, "%04d-%02d-%02d %02d:%02d:%02d %s\n", 1900+gmt_time->tm_year, 1+gmt_time->tm_mon, gmt_time->tm_mday, gmt_time->tm_hour, gmt_time->tm_min, gmt_time->tm_sec, Msg ); - fwrite( temp, strlen(temp), 1, FD ); + fwrite( Msg, strlen(Msg), 1, FD ); fclose(FD); } else { printf( "Totally Lost\n" ); diff --git a/lib/data/NginxMediaServer/mediaNginxStreamingProxyManager.cpp b/lib/data/NginxMediaServer/mediaNginxStreamingProxyManager.cpp index dba26336..325d516f 100644 --- a/lib/data/NginxMediaServer/mediaNginxStreamingProxyManager.cpp +++ b/lib/data/NginxMediaServer/mediaNginxStreamingProxyManager.cpp @@ -176,8 +176,10 @@ void mediaNginxManager::m_fThreadProc( void ){ if( RetVal == 0 ){ pthread_detach( (*index)->m_sThreadHandler ); }; - LOG("Restarting Stream Channel"); - restartStream( *index ); + //LOG("Restarting Stream Channel"); + //restartStream( *index ); + LOG("Removing Stream Channel"); + m_vStreams.erase( index ); }; }; }; diff --git a/lib/data/mysql/database_class.cpp b/lib/data/mysql/database_class.cpp index 02102bc9..10400879 100644 --- a/lib/data/mysql/database_class.cpp +++ b/lib/data/mysql/database_class.cpp @@ -207,17 +207,21 @@ AAssoc *MySQL_Connector::Query( CSTR QS, bool useCache ){ Key = NULL; Val = NULL; Key = new string( Fields[ i ].name ); - if( Row[ i ] != NULL ){ - Val = new string( Row[ i ] ); - } else { - Val = new string( "0" );//Row[ i ] ); - }; - if( Key != NULL && Val != NULL ){ - //(*tElement).insert( pair< string, string > ( *Key, *Val ) ); - (*tElement)[*Key]=*Val; - } else { - LOG_ERROR( "Alloc Error" ); - }; + if( Key!= NULL ) { + if( Row[ i ] != NULL ){ + Val = new string( Row[ i ] ); + } else { + Val = new string( "0" ); + }; + if( Val != NULL ){ + //(*tElement).insert( pair< string, string > ( *Key, *Val ) ); + (*tElement)[*Key]=*Val; + } else { + LOG_ERROR( "Val Alloc Error" ); + }; + } else { + LOG_ERROR( "Key Alloc Error" ); + }; }; /*for (map::iterator p = (*tElement).begin( ); p != (*tElement).end( ); ++p ) { cout << "Field: " << p->first<< ", #: " << p->second << endl; @@ -252,40 +256,28 @@ CSTR MySQL_Connector::escapeString( CSTR str ){ }; uint64_t MySQL_Connector::QueryID( CSTR QS ){ - MYSQL_RES * Result; uint64_t RetVal = 0; m_mAccessMutex.lock(); #ifdef DEBUG_MYSQL_QUERIES LOG( QS ); #endif - if ( mysql_query( m_pDBLink, QS ) ) { + while ( mysql_query( m_pDBLink, QS ) ) { LOG_ERROR( mysql_error( m_pDBLink )); - char temp[256]; sprintf( temp, "Error Code: %d", mysql_errno( m_pDBLink )); LOG_ERROR( temp ); - - switch( mysql_errno( m_pDBLink ) ){ - case 2006:{// Server Gone - if( ReConnect() ){ - if ( !mysql_query( m_pDBLink, QS ) ){ - Result = mysql_store_result( m_pDBLink ); - } else { - Result = NULL; - }; - } else { - Result = NULL; - }; - break; - }; - }; - RetVal = 0; - } else { - RetVal = ( uint64_t ) mysql_insert_id( m_pDBLink ); + if( mysql_errno( m_pDBLink ) == 2013 || mysql_errno( m_pDBLink ) == 2006 ) { + ReConnect(); + } else break; }; + LOG("Query Issued"); + RetVal = ( uint64_t ) 0;//mysql_insert_id( m_pDBLink ); + LOG("ID Receved"); m_mAccessMutex.unlock(); + LOG("Mutex Unlocked"); return RetVal; }; + void MySQL_Connector::SilentQuery( CSTR QS ){ m_mAccessMutex.lock(); #ifdef DEBUG_MYSQL_QUERIES @@ -300,7 +292,6 @@ void MySQL_Connector::SilentQuery( CSTR QS ){ ReConnect(); } else break; }; - //Result = NULL; m_mAccessMutex.unlock(); }; diff --git a/lib/data/protocol/onvifMediaObserver.h b/lib/data/protocol/onvifMediaObserver.h index e44f6fca..281f3b89 100644 --- a/lib/data/protocol/onvifMediaObserver.h +++ b/lib/data/protocol/onvifMediaObserver.h @@ -28,7 +28,7 @@ #define HTTPMU_HOST_ADDRESS "239.255.255.250" #define HTTPMU_HOST_PORT 3702 -//#define DEBUG_ONVIF_PRINTOUT_MESSAGES +#define DEBUG_ONVIF_PRINTOUT_MESSAGES /* #define SEARCH_REQUEST_STRING "M-SEARCH * HTTP/1.1\r\nST:ssdp:all\r\nMX: 3\r\nMAN:\"ssdp:discover\"\r\nHOST: 239.255.255.250:1900\r\n\r\n" diff --git a/lib/data/protocol/protocolKAFKA.cpp b/lib/data/protocol/protocolKAFKA.cpp index 5dc9d9a9..a4c7c4b4 100644 --- a/lib/data/protocol/protocolKAFKA.cpp +++ b/lib/data/protocol/protocolKAFKA.cpp @@ -140,6 +140,38 @@ protocolKAFKA::protocolKAFKA( config_setting_t *Settings ){ }; }; +protocolKAFKA::protocolKAFKA( KAFKA_SETTINGS *Settings ){ + m_pLog = basicLogCollection::getInstance(); + m_pSettings = NULL; + m_pKafka = NULL; + m_pKafkaBrokerSTR = (CSTR)malloc(CLOG); + if( m_pKafkaBrokerSTR == NULL ) return; + memset( m_pKafkaBrokerSTR, 0 , CLOG); + m_pKafkaTopicSTR= (CSTR)malloc(CLOG); + if( m_pKafkaTopicSTR == NULL ) return; + memset( m_pKafkaTopicSTR, 0 , CLOG); + m_pKafkaTopic = NULL; + + m_pScannerName = (CSTR)malloc(OS_SCANNER_NAME_SIZE); + if( m_pScannerName == NULL ) return; + memset( m_pScannerName, 0 , OS_SCANNER_NAME_SIZE); + m_pServerIP = (CSTR)malloc(OS_CEP_ADDRESS_SIZE); + if( m_pServerIP == NULL ) return; + memset( m_pServerIP, 0 , OS_CEP_ADDRESS_SIZE); + m_pAccessURL = (CSTR)malloc(CTEXT); + if (m_pAccessURL == NULL) return; + memset(m_pAccessURL, 0, CTEXT); + + m_bCurrentStatus = false; + m_bMitigationStatus = false; + m_bEnabled = false; + m_bEnableStatus = false; + if( Settings!= NULL ) { + strncpy( m_pServerIP, Settings->brocker_addr, 16 ); + m_nServerPort = Settings->brocker_port; + }; +}; + /** * @brief Message delivery report callback. * diff --git a/lib/data/protocol/protocolKAFKA.h b/lib/data/protocol/protocolKAFKA.h index 45bf38b9..9ede1f24 100644 --- a/lib/data/protocol/protocolKAFKA.h +++ b/lib/data/protocol/protocolKAFKA.h @@ -18,84 +18,79 @@ #include "../../components/base/basicLogCollection.h" #include "../../components/base/basicSettingsProvider.h" -typedef struct S_KAFKA_SETTINGS{ - char brocker_addr[128]; - uint16_t brocker_port; -}KAFKA_SETTINGS; - /** * TODO: Add class description * * @author gagua */ class protocolKAFKA:public RdKafka::DeliveryReportCb { -private: - basicLogCollection * m_pLog; - config_setting_t * m_pSettings; - //rd_kafka_t * m_pKafka; /* Producer instance handle */ - RdKafka::Producer * m_pKafka; /* Producer instance handle */ - //rd_kafka_conf_t * m_pKafkaConf; /* Temporary configuration object */ - //RdKafka::Conf * m_pKafkaConf; /* Temporary configuration object */ - CSTR m_pKafkaBrokerSTR; - CSTR m_pKafkaTopicSTR; - RdKafka::Topic * m_pKafkaTopic; - bool m_bUseCompression; - bool m_bEnableStatus; - //uint8_t m_bKafkaBrokersCount; + private: + basicLogCollection * m_pLog; + config_setting_t * m_pSettings; + //rd_kafka_t * m_pKafka; /* Producer instance handle */ + RdKafka::Producer * m_pKafka; /* Producer instance handle */ + //rd_kafka_conf_t * m_pKafkaConf; /* Temporary configuration object */ + //RdKafka::Conf * m_pKafkaConf; /* Temporary configuration object */ + CSTR m_pKafkaBrokerSTR; + CSTR m_pKafkaTopicSTR; + RdKafka::Topic * m_pKafkaTopic; + bool m_bUseCompression; + bool m_bEnableStatus; + //uint8_t m_bKafkaBrokersCount; - int m_nScannerDimentions; - CSTR m_pScannerName; - CSTR m_pServerIP; - CSTR m_pAccessURL; - bool m_bEnabled; - bool m_bUseSSL; - bool m_bMitigationStatus; - float m_fLon; - float m_fLat; - int m_nServerPort; - bool m_bCurrentStatus; - //CSTR buildURL( CSTR templ, int dim, CSTR devID ); - CSTR buildUniqID( void ); - bool buildClockSyncPackage( unsigned char *Buffer, int &BufferSize ); - bool buildCallBackPackage( unsigned char *Buffer, int &BufferSize, CSTR CallBackPath ); - bool buildStatusPackage( unsigned char *Buffer, int &BufferSize, bool Status ); - bool buildFaultPackage( unsigned char *Buffer, int &BufferSize, unsigned char Type, CSTR Description ); - bool buildEvent2DPackage( unsigned char *Buffer, int &BufferSize, CSTR msgUID, int targetID, float Angle, float Range, float Width ); - bool buildEvent3DPackage( unsigned char *Buffer, int &BufferSize, CSTR msgUID, int targetID, float Angle1, float Angle2, float Range ); + int m_nScannerDimentions; + CSTR m_pScannerName; + CSTR m_pServerIP; + CSTR m_pAccessURL; + bool m_bEnabled; + bool m_bUseSSL; + bool m_bMitigationStatus; + float m_fLon; + float m_fLat; + int m_nServerPort; + bool m_bCurrentStatus; + //CSTR buildURL( CSTR templ, int dim, CSTR devID ); + CSTR buildUniqID( void ); + bool buildClockSyncPackage( unsigned char *Buffer, int &BufferSize ); + bool buildCallBackPackage( unsigned char *Buffer, int &BufferSize, CSTR CallBackPath ); + bool buildStatusPackage( unsigned char *Buffer, int &BufferSize, bool Status ); + bool buildFaultPackage( unsigned char *Buffer, int &BufferSize, unsigned char Type, CSTR Description ); + bool buildEvent2DPackage( unsigned char *Buffer, int &BufferSize, CSTR msgUID, int targetID, float Angle, float Range, float Width ); + bool buildEvent3DPackage( unsigned char *Buffer, int &BufferSize, CSTR msgUID, int targetID, float Angle1, float Angle2, float Range ); - CSTR assembleStatusData( bool StatusOK ); - CSTR assembleFaultData( uint8_t Code, CSTR Desc ); - CSTR assembleTargetData( bool is3D, int targetID, int Range, int Width, int Azimuth, int Elevation = 0 ); - size_t assembleDefenderJSON( CSTR Buffer, defenderCategoryTypes Type, uint8_t Severity, CSTR Location, CSTR Data ); - bool issuePost( CSTR Buffer, int BufferSize ); -public: - // Constructor - explicit protocolKAFKA( config_setting_t *Settings ); - explicit protocolKAFKA( KAFKA_SETTINGS *Settings ); - //ToDo: change Serial to BaseClass of some kind of socket - //protocolSafeShore( clientPort *SocketTransport, config_setting_t *Settings = NULL ); - // Destructor - virtual ~protocolKAFKA(); - bool init(); - bool Alarm2D( float Angle, float Range, float Width, int ID=0 ); - bool Alarm3D( float Angle1, float Angle2, float Range, int ID=0 ); - bool VisibilityChanged( bool Worsened ); - bool StatusUpdate( void ); - void SetStatus( bool A ){ m_bCurrentStatus = A; }; - bool ErrorReporting( int lvl, CSTR Descr ); - bool StartTimeSynch( void ); - /* Implementation of RdKafka::DeliveryReportCb */ - virtual void dr_cb( RdKafka::Message &message ); -#ifdef __linux__ - //bool FinishTimeSynch( unsigned long long *tVals ); -#else - //bool FinishTimeSynch( unsigned __int64 *tVals ); -#endif - bool SetupCallBack( CSTR CallBackPath ); - void setProtocolType( bool DeviceIs3D ); - void setScannerName( CSTR Name ); - void setScannerPosition( float Lat, float Lon ){ m_fLon = Lon; m_fLat = Lat; }; - bool getMitigationStatus(void) { return m_bMitigationStatus; }; + CSTR assembleStatusData( bool StatusOK ); + CSTR assembleFaultData( uint8_t Code, CSTR Desc ); + CSTR assembleTargetData( bool is3D, int targetID, int Range, int Width, int Azimuth, int Elevation = 0 ); + size_t assembleDefenderJSON( CSTR Buffer, defenderCategoryTypes Type, uint8_t Severity, CSTR Location, CSTR Data ); + bool issuePost( CSTR Buffer, int BufferSize ); + public: + // Constructor + explicit protocolKAFKA( config_setting_t *Settings ); + explicit protocolKAFKA( KAFKA_SETTINGS *Settings ); + //ToDo: change Serial to BaseClass of some kind of socket + //protocolSafeShore( clientPort *SocketTransport, config_setting_t *Settings = NULL ); + // Destructor + virtual ~protocolKAFKA(); + bool init(); + bool Alarm2D( float Angle, float Range, float Width, int ID=0 ); + bool Alarm3D( float Angle1, float Angle2, float Range, int ID=0 ); + bool VisibilityChanged( bool Worsened ); + bool StatusUpdate( void ); + void SetStatus( bool A ){ m_bCurrentStatus = A; }; + bool ErrorReporting( int lvl, CSTR Descr ); + bool StartTimeSynch( void ); + /* Implementation of RdKafka::DeliveryReportCb */ + virtual void dr_cb( RdKafka::Message &message ); + #ifdef __linux__ + //bool FinishTimeSynch( unsigned long long *tVals ); + #else + //bool FinishTimeSynch( unsigned __int64 *tVals ); + #endif + bool SetupCallBack( CSTR CallBackPath ); + void setProtocolType( bool DeviceIs3D ); + void setScannerName( CSTR Name ); + void setScannerPosition( float Lat, float Lon ){ m_fLon = Lon; m_fLat = Lat; }; + bool getMitigationStatus(void) { return m_bMitigationStatus; }; }; #ifdef __linux__ diff --git a/lib/data/protocol/protocolZLMEDIA.cpp b/lib/data/protocol/protocolZLMEDIA.cpp index 07b1896d..707fd841 100644 --- a/lib/data/protocol/protocolZLMEDIA.cpp +++ b/lib/data/protocol/protocolZLMEDIA.cpp @@ -50,11 +50,9 @@ protocolZLMEDIA::protocolZLMEDIA( config_setting_t *Settings ): protocolHTTP( ba protocolZLMEDIA::protocolZLMEDIA( CSTR key, CSTR host, CSTR ip, uint32_t port ): protocolHTTP( NULL ){ m_pLog = basicLogCollection::getInstance(); m_pSettings = NULL; - LOG("Param1"); strncpy( m_pSecret, key, 255 ); - LOG("Param2"); + strncpy( m_pVHost, host, 255 ); strncpy( m_pAccessPoint, key, 255 ); - LOG("Param3"); strncpy( m_pIP, ip, 16 ); LOG("Done!"); m_bSessionOnGo = false; @@ -70,22 +68,22 @@ protocolZLMEDIA::~protocolZLMEDIA(){ }; bool protocolZLMEDIA::packetHandler( protocolPackage *Package ){ - LOG("Pack Handler!!"); + //LOG("Pack Handler!!"); if( Package == NULL ){ m_bSessionOnGo = false; return false; }; - LOG("Pack not NULL"); + //LOG("Pack not NULL"); if( Package->m_nSize == 0 ) { m_bSessionOnGo = false; return false; }; - LOG("Size not NULL"); + //LOG("Size not NULL"); if( Package->m_pData == NULL ){ m_bSessionOnGo = false; return false; }; - LOG("Data not NULL"); + //LOG("Data not NULL"); if( Package->m_nCode != 200 ){ m_bSessionOnGo = false; return false; @@ -105,6 +103,10 @@ bool protocolZLMEDIA::packetHandler( protocolPackage *Package ){ char tBuffer[256]; sprintf( tBuffer,"Data: %s: %s ", inner.key().asString().c_str(), (*inner).asString().c_str() ); LOG( tBuffer ); + if( strstr( inner.key().asString().c_str(), "key" ) != NULL ) { + LOG("New Key Arived"); + strncpy( m_pLastValue, (*inner).asString().c_str(), 255 ); + }; }; }; } catch (exception e ){ @@ -141,7 +143,7 @@ bool protocolZLMEDIA::isOnline(){ LOG("Server is Onffline"); }; #endif - } + }; return m_bServerIsPresent; }; bool protocolZLMEDIA::restartServer(){ @@ -150,18 +152,191 @@ bool protocolZLMEDIA::restartServer(){ bool protocolZLMEDIA::getConfig(){ return false; }; -CSTR protocolZLMEDIA::addStreamProxy(){ + + + +/* Converts a hex character to its integer value */ +char from_hex(char ch) { + return isdigit(ch) ? ch - '0' : tolower(ch) - 'a' + 10; +} + +/* Converts an integer value to its hex character*/ +char to_hex(char code) { + static char hex[] = "0123456789abcdef"; + return hex[code & 15]; +} + +/* Returns a url-encoded version of str */ +/* IMPORTANT: be sure to free() the returned string after use */ +char *url_encode(char *str) { + char *pstr = str, *buf = (char *) malloc(strlen(str) * 3 + 1), *pbuf = buf; + while (*pstr) { + if (isalnum(*pstr) || *pstr == '-' || *pstr == '_' || *pstr == '.' || *pstr == '~') + *pbuf++ = *pstr; + else if (*pstr == ' ') + *pbuf++ = '+'; + else + *pbuf++ = '%', *pbuf++ = to_hex(*pstr >> 4), *pbuf++ = to_hex(*pstr & 15); + pstr++; + } + *pbuf = '\0'; + return buf; +} + +/* Returns a url-decoded version of str */ +/* IMPORTANT: be sure to free() the returned string after use */ +char *url_decode(char *str) { + char *pstr = str, *buf = (char *)malloc(strlen(str) + 1), *pbuf = buf; + while (*pstr) { + if (*pstr == '%') { + if (pstr[1] && pstr[2]) { + *pbuf++ = from_hex(pstr[1]) << 4 | from_hex(pstr[2]); + pstr += 2; + } + } else if (*pstr == '+') { + *pbuf++ = ' '; + } else { + *pbuf++ = *pstr; + } + pstr++; + } + *pbuf = '\0'; + return buf; +} + + + +#include +#include +#include + +using namespace std; + +string urlEncode( const string &value ){ + ostringstream escaped; + escaped.fill('0'); + escaped << hex; + for( string::const_iterator i = value.begin(), n = value.end(); i != n; ++i ){ + string::value_type c = (*i); + // Keep alphanumeric and other accepted characters intact + if (isalnum(c) || c == '-' || c == '_' || c == '.' || c == '~') { + escaped << c; + continue; + }; + // Any other characters are percent-encoded + escaped << uppercase; + escaped << '%' << setw(2) << int((unsigned char) c); + escaped << nouppercase; + }; + return escaped.str(); +}; + +string urlDecode( string text ){ + string escaped; + for( auto i = text.begin(), nd = text.end(); i < nd; ++i ){ + auto c = ( *i ); + switch( c ){ + case '%': if( i[1] && i[2] ){ + char hs[]{ i[1], i[2] }; + escaped += static_cast(strtol(hs, nullptr, 16)); + i += 2; + }; + break; + case '+': escaped += ' '; break; + default: escaped += c; + }; + }; + return escaped; +}; + +CSTR protocolZLMEDIA::buildURL( CSTR base, uint32_t streamId, CSTR host, CSTR app, CSTR src ){ + char tBuffer[2048]; + char *a = url_encode( app ); + char *s = url_encode( src ); + char *h = url_encode( host ); + if( a == NULL || h == NULL || s == NULL ) { + if( a != NULL ) free( a ); + if( s != NULL ) free ( s ); + if( h != NULL ) free( h ); + return NULL; + }; + if( m_bUseSSL ) { //__defaultVhost__ + sprintf( tBuffer,"https://%s:%d/%s?&vhost=%s&app=%s&stream=%d&url=%s&enable_hls=1&rtp_type=0&secret=%s", m_pIP, m_nPort, base, h, a, streamId, s, m_pSecret ); + } else { + sprintf( tBuffer, "http://%s:%d/%s?&vhost=%s&app=%s&stream=%d&url=%s&enable_hls=1&rtp_type=0&secret=%s", m_pIP, m_nPort, base, h, a, streamId, s, m_pSecret ); + }; + free(a); free(s); free(h); + return strdup(tBuffer); +}; + +CSTR protocolZLMEDIA::addStreamProxy( uint32_t streamId, CSTR app, CSTR mrl ){ + if( m_bServerIsPresent ) { // Just First Time to set initial flag + uint8_t timeout = 100; // 1 sec. + while( m_bSessionOnGo && timeout-- ) SLEEP(10); + if( !m_bSessionOnGo ){ + char *URL; + LOG("Add Stream Proxy"); + m_bSessionOnGo = true; + URL = buildURL( ZL_ADD_STREAM_PROXY, streamId, m_pVHost, app, mrl ); + LOG( URL ); + //ToDo: Check if OK to send nothing for checking Onlines + //int len = 0; + //issuePost( URL, NULL, len ); + issueGet( URL ); + free( URL ); + while( m_bSessionOnGo && timeout-- ) SLEEP(10); + if( ! m_bSessionOnGo ) { + ZL_STREAM_INFO *tVal; + tVal = (ZL_STREAM_INFO*) malloc(sizeof(ZL_STREAM_INFO)); + if( tVal != NULL ) { + tVal->streamId = streamId; + strncpy( tVal->key, m_pLastValue, 128 ); + m_vCurrentStreams.push_back( tVal ); + LOG("Stream Added Successfully"); + LOG( m_pLastValue ); + return tVal->key; + }; + return NULL; + }; + return NULL; + } else LOG("LIST MEDIA - SESSION BUSY!"); + }; return NULL; }; + bool protocolZLMEDIA::delStreamProxy(CSTR key){ return false; }; + +bool protocolZLMEDIA::delAllStreamProxys( void ){ + if( m_bServerIsPresent ) { // Just First Time to set initial flag + uint8_t timeout = 100; // 1 sec. + while( m_bSessionOnGo && timeout-- ) SLEEP(10); + if( !m_bSessionOnGo ){ + char URL[256]; + LOG("Restart Server"); + m_bSessionOnGo = true; + if( m_bUseSSL ) { + sprintf(URL,"https://%s:%d/%s?secret=%s", m_pIP, m_nPort, ZL_RESTART_SERVER, m_pSecret ); + } else { + sprintf(URL,"http://%s:%d/%s?secret=%s", m_pIP, m_nPort, ZL_RESTART_SERVER, m_pSecret ); + }; + LOG( URL ); + issueGet( URL ); + while( m_bSessionOnGo && timeout-- ) SLEEP(10); + return ( timeout > 0 ); + } else LOG("LIST MEDIA - SESSION BUSY!"); + }; + return false; +}; + bool protocolZLMEDIA::listMedia(){ if( m_bServerIsPresent ) { // Just First Time to set initial flag - LOG("LIST MEDIA"); + uint8_t timeout = 100; // 1 sec. + while( m_bSessionOnGo && timeout-- ) SLEEP(10); if( !m_bSessionOnGo ) { char URL[256]; - uint8_t timeout = 100; // 1 sec. + LOG("List Media"); m_bSessionOnGo = true; if( m_bUseSSL ) { sprintf(URL,"https://%s:%d/%s?secret=%s", m_pIP, m_nPort, ZL_LIST_MEDIA, m_pSecret ); @@ -173,6 +348,7 @@ bool protocolZLMEDIA::listMedia(){ //int len = 0; //issuePost( URL, NULL, len ); issueGet( URL ); + timeout = 100; while( m_bSessionOnGo && timeout-- ) SLEEP(10); return ( timeout > 0 ); } else LOG("LIST MEDIA - SESSION BUSY!"); diff --git a/lib/data/protocol/protocolZLMEDIA.h b/lib/data/protocol/protocolZLMEDIA.h index 7eee0708..0d18aa11 100644 --- a/lib/data/protocol/protocolZLMEDIA.h +++ b/lib/data/protocol/protocolZLMEDIA.h @@ -13,11 +13,14 @@ #include #include #include +#include #include "../../components/base/basicFunctionality.h" #include "../../components/base/basicLogCollection.h" #include "../../components/base/basicSettingsProvider.h" +//https://github.com/xia-chu/ZLMediaKit/wiki + #define ZL_ADD_ENCODER_SOURCE ((CSTR) "index/api/addFFmpegSource" ) #define ZL_ADD_STREAM_PROXY ((CSTR) "index/api/addStreamProxy" ) #define ZL_CLOSE_STREAM ((CSTR) "index/api/close_stream" ) @@ -32,31 +35,44 @@ #define ZL_KICK_SESSION ((CSTR) "index/api/kick_session" ) #define ZL_RESTART_SERVER ((CSTR) "index/api/restartServer" ) #define ZL_SET_SERVER_CONFIG ((CSTR) "index/api/setServerConfig" ) +#define ZL_IS_MEDIA_ONLINE ((CSTR) "index/api/isMediaOnline" ) + +typedef struct S_ZL_STREAM_INFO{ + uint32_t streamId; + char key[129]; +}ZL_STREAM_INFO; +typedef std::vector V_ZL_STREAM_INFO; class protocolZLMEDIA : public protocolHTTP { private: basicLogCollection * m_pLog; config_setting_t * m_pSettings; char m_pSecret[256]; char m_pAccessPoint[256]; + char m_pVHost[256]; char m_pIP[16]; bool m_bSessionOnGo; bool m_bServerIsPresent; bool m_bUseSSL; uint16_t m_nPort; + V_ZL_STREAM_INFO m_vCurrentStreams; + char m_pLastValue[256]; + CSTR buildURL( CSTR base, uint32_t streamId, CSTR host, CSTR app, CSTR src ); protected: virtual bool packetHandler( protocolPackage *Package ); public: - explicit protocolZLMEDIA( config_setting_t *Settings = NULL ); - explicit protocolZLMEDIA( CSTR key, CSTR host, CSTR ip, uint32_t port ); - ~protocolZLMEDIA(); - bool isOnline(); - bool restartServer(); - bool getConfig(); - CSTR addStreamProxy(); - bool delStreamProxy(CSTR key); - bool listMedia(); - bool requestIsFinished(); + explicit protocolZLMEDIA( config_setting_t *Settings = NULL ); + explicit protocolZLMEDIA( CSTR key, CSTR host, CSTR ip, uint32_t port ); + ~protocolZLMEDIA(); + bool isOnline(); + bool restartServer(); + bool getConfig(); + CSTR addStreamProxy( uint32_t streamId, CSTR app, CSTR mrl ); + bool delStreamProxy( CSTR key ); + bool delAllStreamProxys( void ); + bool listMedia(); + V_ZL_STREAM_INFO *getStreams(){ return &m_vCurrentStreams;}; + bool requestIsFinished(); }; diff --git a/lib/hardware/uart/serialPort.cpp b/lib/hardware/uart/serialPort.cpp index 00c17100..39cb4dae 100644 --- a/lib/hardware/uart/serialPort.cpp +++ b/lib/hardware/uart/serialPort.cpp @@ -1,9 +1,18 @@ #include "serialPort.h" #define LOG( X ) m_pLog->Log( "UART", this, X ) -#define LOG_ERROR( X ) m_pLog->Log( "UART", this, _LOG_ERROR, X ) -/* +#ifdef DEBUG + #define LOG_ERROR( X ) {\ + char _tBfrErrMSG2w34[256];\ + sprintf( _tBfrErrMSG2w34, "In file %s[%d] in func:%s %s",__FILE__, __LINE__, __func__, X );\ + m_pLog->Log( "UART", this, _LOG_ERROR, _tBfrErrMSG2w34 );\ + } +#else + #define LOG_ERROR( X ) m_pLog->Log( "UART", this, _LOG_ERROR, X ); +#endif + + serialPort::serialPort():transportSerial(){ #ifdef __linux__ memset( &m_sTTY, 0, sizeof( m_sTTY ) ); @@ -19,7 +28,6 @@ serialPort::serialPort():transportSerial(){ m_sDevicePath = NULL; m_iLineSpeed = 9600; }; -*/ serialPort::serialPort( CSTR DevicePath, int Speed ): transportSerial() { @@ -43,8 +51,32 @@ serialPort::serialPort( CSTR DevicePath, int Speed ): transportSerial() { sprintf( MsgBuffer,"Init %s [%d] OK", m_sDevicePath, m_iLineSpeed ); LOG( MsgBuffer ); #endif - init(); + m_bInitComplete = init(); + }; +}; + +bool serialPort::create( CSTR DevicePath, int Speed ){ + if( m_bConnected ){ + LOG_ERROR( "TRYING TO CONNECT ON OPENED PORT!" ); + return false; + }; + if( m_bInitComplete ) { + LOG_ERROR( "TRYING TO CREATE CREATED PORT!" ); + return false; + }; + m_iLineSpeed = Speed; + m_sDevicePath = (CSTR) malloc( strlen(DevicePath)+1); + strcpy( m_sDevicePath, DevicePath ); + m_bInitComplete = HW_init( m_sDevicePath, m_iLineSpeed ); + if( m_bInitComplete ) { +#ifdef DEBUG + char MsgBuffer[CLOG]; + sprintf( MsgBuffer,"Init %s [%d] OK", m_sDevicePath, m_iLineSpeed ); + LOG( MsgBuffer ); +#endif + return m_bInitComplete = init(); }; + return false; }; // Destructor implementation diff --git a/lib/hardware/uart/serialPort.h b/lib/hardware/uart/serialPort.h index ded4ae39..d20b5333 100644 --- a/lib/hardware/uart/serialPort.h +++ b/lib/hardware/uart/serialPort.h @@ -45,9 +45,10 @@ class serialPort: public transportSerial { int sendBlock( unsigned char *Data, int DataSize ); int recptBlock( unsigned char *Buffer, int *BufferLength ); public: - //serialPort(); - explicit serialPort( CSTR DevicePath, int Speed ); + serialPort(); + serialPort( CSTR DevicePath, int Speed ); virtual ~serialPort(); + bool create( CSTR DevicePath, int Speed ); }; #endif // __SERIALPORT_H_INCL__ diff --git a/lib/hardware/uart/serialSOL.cpp b/lib/hardware/uart/serialSOL.cpp index ca137dd2..1340f140 100644 --- a/lib/hardware/uart/serialSOL.cpp +++ b/lib/hardware/uart/serialSOL.cpp @@ -5,7 +5,8 @@ serialSOL::serialSOL( SOL_TYPE t ): transportSocket(){ m_pLog = m_pLog = basicLogCollection::getInstance(); - m_eSolType = t; + memset( &m_sPortSettings, 0, sizeof( SOL_PORT_SETTINGS )); + m_sPortSettings.eConnectionType = t; m_bInitComplete = false; #ifdef __linux__ m_nSocketFD = -1; @@ -18,7 +19,7 @@ serialSOL::serialSOL( SOL_TYPE t ): transportSocket(){ serialSOL::~serialSOL(){ char tBuff[128]; - switch (m_eSolType) { + switch (m_sPortSettings.eConnectionType) { case SOL_UDP_CLIENT: case SOL_UDP_SERVER: { #ifdef __linux__ @@ -46,24 +47,28 @@ serialSOL::~serialSOL(){ }; }; -int recvfromTimeOutUDP(SOCKET socket, long sec, long usec) { - // Setup timeval variable - struct timeval timeout; - struct fd_set fds; - timeout.tv_sec = sec; - timeout.tv_usec = usec; - // Setup fd_set structure - FD_ZERO(&fds); - FD_SET(socket, &fds); - // Return value: - // -1: error occurred - // 0: timed out - // > 0: data ready to be read - return select(0, &fds, 0, 0, &timeout); -}; - +#ifndef __linux__ + int recvfromTimeOutUDP(SOCKET socket, long sec, long usec) { + // Setup timeval variable + struct timeval timeout; + struct fd_set fds; + timeout.tv_sec = sec; + timeout.tv_usec = usec; + // Setup fd_set structure + FD_ZERO(&fds); + FD_SET(socket, &fds); + // Return value: + // -1: error occurred + // 0: timed out + // > 0: data ready to be read + return select(0, &fds, 0, 0, &timeout); + }; +#endif bool serialSOL::create( CSTR address, uint16_t port, int Speed ){ - switch( m_eSolType ) { + m_sPortSettings.nPort = port; + m_sPortSettings.nSpeed = Speed; + strncpy( m_sPortSettings.pDeviceAddr, address, 64 ); + switch( m_sPortSettings.eConnectionType ) { case SOL_TCP_CLIENT:{ break; }; @@ -158,7 +163,7 @@ bool serialSOL::create( CSTR address, uint16_t port, int Speed ){ int serialSOL::sendBlock(unsigned char* Data, int DataSize) { int RetVal = 0; if (!m_bInitComplete || !m_bConnected) return -1; // Exit after unsuccess reconnect - switch (m_eSolType) { + switch ( m_sPortSettings.eConnectionType ) { case SOL_UDP_CLIENT: case SOL_UDP_SERVER: { @@ -221,7 +226,7 @@ int serialSOL::recptBlock( unsigned char *Buffer, int *BufferLength ){ }; if( !m_bConnected ){ //make prep for connection - if(m_eSolType == SOL_TCP_SERVER){ + if( m_sPortSettings.eConnectionType == SOL_TCP_SERVER){ //Listen }; }; @@ -251,7 +256,7 @@ int serialSOL::recptBlock( unsigned char *Buffer, int *BufferLength ){ return -1; }; #else - switch (m_eSolType) { + switch ( m_sPortSettings.eConnectionType ) { case SOL_UDP_CLIENT: case SOL_UDP_SERVER: { SOCKADDR_IN tAddr; diff --git a/lib/hardware/uart/serialSOL.h b/lib/hardware/uart/serialSOL.h index 6a8da1a5..50249ddb 100644 --- a/lib/hardware/uart/serialSOL.h +++ b/lib/hardware/uart/serialSOL.h @@ -39,13 +39,6 @@ #include "../../data/transport/transportSocket.h" -typedef enum E_SOL_TYPE{ - SOL_UDP_CLIENT = 0, - SOL_TCP_CLIENT = 1, - SOL_UDP_SERVER = 2, - SOL_TCP_SERVER = 3 -}SOL_TYPE; - /** * TODO: Add class description * @@ -54,7 +47,7 @@ typedef enum E_SOL_TYPE{ class serialSOL: public transportSocket { private: basicLogCollection *m_pLog; - SOL_TYPE m_eSolType; + SOL_PORT_SETTINGS m_sPortSettings; bool m_bInitComplete; #ifdef __linux__ int m_nSocketFD; @@ -71,6 +64,7 @@ class serialSOL: public transportSocket { int recptBlock( unsigned char *Buffer, int *BufferLength ); public: explicit serialSOL( SOL_TYPE t ); + explicit serialSOL( SOL_PORT_SETTINGS *PortSettings ); virtual ~serialSOL(); bool create( CSTR address, uint16_t port, int Speed ); }; diff --git a/lib/rgoose/rgooseCamera.cpp b/lib/rgoose/rgooseCamera.cpp index 031d3f06..ba7a6eab 100644 --- a/lib/rgoose/rgooseCamera.cpp +++ b/lib/rgoose/rgooseCamera.cpp @@ -1,5 +1,5 @@ #include "rgooseCamera.h" -ARGUS_Camera::ARGUS_Camera( ARGUS_DBC *DBC, DBC_NODE_DATA *Data ): argusNetNode( DBC, Data ), basicEventHandler() { +ARGUS_Camera::ARGUS_Camera( DBC_NODE_DATA *Data ): argusNetNode( Data ), basicEventHandler() { m_tTimeTSeconds = 0; if( m_pDBC != NULL ) { DBC_CAM_DATA * tData = NULL; @@ -9,7 +9,7 @@ ARGUS_Camera::ARGUS_Camera( ARGUS_DBC *DBC, DBC_NODE_DATA *Data ): argusNetNode( }; }; -ARGUS_Camera::ARGUS_Camera( ARGUS_DBC *DBC, int id, DBC_CAM_DATA *Data ): argusNetNode( DBC, id ), basicEventHandler() { +ARGUS_Camera::ARGUS_Camera( uint32_t id, DBC_CAM_DATA *Data ): argusNetNode( id ), basicEventHandler() { m_tTimeTSeconds = 0; if( Data != NULL ) { memcpy( &m_sCamData, Data, sizeof(DBC_CAM_DATA) ); diff --git a/lib/rgoose/rgooseCamera.h b/lib/rgoose/rgooseCamera.h index 3a28bd49..4b447871 100644 --- a/lib/rgoose/rgooseCamera.h +++ b/lib/rgoose/rgooseCamera.h @@ -32,8 +32,8 @@ class ARGUS_Camera: public argusNetNode, public basicEventHandler { time_t m_tTimeTSeconds; DBC_CAM_DATA m_sCamData; public: - explicit ARGUS_Camera( ARGUS_DBC *DBC, DBC_NODE_DATA *Data ); - explicit ARGUS_Camera( ARGUS_DBC *DBC, int id, DBC_CAM_DATA *Data = NULL ); + explicit ARGUS_Camera( DBC_NODE_DATA *Data ); + explicit ARGUS_Camera( uint32_t id, DBC_CAM_DATA *Data = NULL ); virtual ~ARGUS_Camera(); virtual void dispatchEvent( basicEvent *Evt ){}; diff --git a/lib/rgoose/rgooseDBConnector.cpp b/lib/rgoose/rgooseDBConnector.cpp index 68f845dd..179069bd 100644 --- a/lib/rgoose/rgooseDBConnector.cpp +++ b/lib/rgoose/rgooseDBConnector.cpp @@ -1,19 +1,44 @@ #include "rgooseDBConnector.h" -#define LOG( X ) m_pLog->Log( "ADBC", this, X ) -#define LOG_ERROR( X ) m_pLog->Log( "ADBC", this, _LOG_ERROR, X ) +#define LOG( X ) m_pLog->Log( "ADBC", this, X ) -ARGUS_DBC::ARGUS_DBC( config_setting_t * Settings ){ +#ifdef DEBUG + #define LOG_ERROR( X ) {\ + char _tBfrErrMSG2w34[256];\ + sprintf( _tBfrErrMSG2w34, "In file %s[%d] in func:%s %s",__FILE__, __LINE__, __func__, X );\ + m_pLog->Log( "ADBC", this, _LOG_ERROR, _tBfrErrMSG2w34 );\ + } +#else + #define LOG_ERROR( X ) m_pLog->Log( "ADBC", this, _LOG_ERROR, X ); +#endif + +argusDBC *argusDBC::_instance = NULL; + +/** + * Returns the single instance of the object. + */ +argusDBC* argusDBC::getInstance( config_setting_t * Settings ) { + // check if the instance has been created yet + if( 0 == _instance ){ + // if not, then create it + _instance = new argusDBC( Settings ); + }; + // return the single instance + return _instance; +}; + + +argusDBC::argusDBC( config_setting_t * Settings ){ m_pLog = basicLogCollection::getInstance(); m_pSettings = basicSettingsProvider::getInstance()->getSubNode( Settings, "DBC" ); m_bIsConnected = false; m_pDatabase = NULL; }; -ARGUS_DBC::~ARGUS_DBC(){ +argusDBC::~argusDBC(){ }; -bool ARGUS_DBC::connect( void ){ +bool argusDBC::connect( void ){ config_setting_t * tSetting; m_bIsConnected = false; if( m_pSettings!= NULL ) { @@ -59,13 +84,15 @@ bool ARGUS_DBC::connect( void ){ return m_bIsConnected; }; -bool ARGUS_DBC::updateIPCam( uint32_t SiteID, CSTR uuid, CSTR Addr ){ +bool argusDBC::updateIPCam( uint32_t SiteID, CSTR uuid, CSTR Addr ){ if(m_bIsConnected) { char tQBuf[MAX_PATH_LEN]; char tIpBuf[CTEXT]; char *tPos; char *tPos2; +#ifdef DEBUG LOG("Cam Update"); +#endif tPos = strstr(Addr,"//"); if( tPos != NULL ) { tPos2 = strstr( tPos + 2,"/"); @@ -75,36 +102,38 @@ bool ARGUS_DBC::updateIPCam( uint32_t SiteID, CSTR uuid, CSTR Addr ){ strncpy(tIpBuf,tPos + 2,len); tIpBuf[len] = (char)0; } else { - LOG("Pos 2 - err"); + LOG_ERROR("Pos 2 - err"); tIpBuf[0] = (char)0; }; } else { - LOG("Pos 0 - err"); + LOG_ERROR("Pos 0 - err"); tIpBuf[0] = (char)0; }; - sprintf(tQBuf,"INSERT INTO cameras SET `uuid`='%s', `onvif_ctrl`='%s', `ip`='%s', `type`=2, `status`=0, `site_id`=%d ON DUPLICATE KEY UPDATE `onvif_ctrl`='%s', `ip`='%s'", - uuid, + sprintf(tQBuf,"UPDATE cameras SET `online`=1,`onvif_ctrl`='%s', `ip`='%s' WHERE `uuid`='%s' AND `site_id`=%d", Addr, tIpBuf, - SiteID, - Addr, - tIpBuf + uuid, + SiteID ); +#ifdef DEBUG LOG(tQBuf); +#endif m_pDatabase->SilentQuery( tQBuf ); return true; }; return false; }; -bool ARGUS_DBC::updateIPCam( uint32_t SiteID, resultWoWo *tPtr ){ +bool argusDBC::updateIPCam( uint32_t SiteID, uint32_t CamID, CSTR Addr ){ if(m_bIsConnected) { char tQBuf[MAX_PATH_LEN]; char tIpBuf[CTEXT]; char *tPos; char *tPos2; - LOG("Cam Update WoWo"); - tPos = strstr(tPtr->XAddrs,"//"); +#ifdef DEBUG + LOG("Cam Update"); +#endif + tPos = strstr(Addr,"//"); if( tPos != NULL ) { tPos2 = strstr( tPos + 2,"/"); if( tPos2 != NULL ) { @@ -113,32 +142,88 @@ bool ARGUS_DBC::updateIPCam( uint32_t SiteID, resultWoWo *tPtr ){ strncpy(tIpBuf,tPos + 2,len); tIpBuf[len] = (char)0; } else { - LOG("Pos 2 - err"); + LOG_ERROR("Pos 2 - err"); + tIpBuf[0] = (char)0; + }; + } else { + LOG_ERROR("Pos 0 - err"); + tIpBuf[0] = (char)0; + }; + sprintf(tQBuf,"UPDATE cameras SET `online`=1, `onvif_ctrl`='%s', `ip`='%s' WHERE id=%d AND `site_id`=%d", + Addr, + tIpBuf, + CamID, + SiteID + ); +#ifdef DEBUG + LOG(tQBuf); +#endif + m_pDatabase->SilentQuery( tQBuf ); + sprintf(tQBuf,"UPDATE media_streams SET `valid`=1 WHERE source_id=%d AND source_type='D'", CamID ); +#ifdef DEBUG + LOG(tQBuf); +#endif + m_pDatabase->SilentQuery( tQBuf ); + return true; + }; + return false; +}; + +bool argusDBC::addIPCam( uint32_t SiteID, resultWoWo *tPtr ){ + if(m_bIsConnected) { + char tQBuf[1024]; + char tIpBuf[32]; + char tProto[32]; + char tPath[CTEXT]; + char *tPos; + char *tPos2; +#ifdef DEBUG + LOG("Add New Camera Record"); +#endif + memcpy( tProto, tPtr->XAddrs, 5 ); + tProto[5] = (char)0; + if( tProto[4] == ':') tProto[4] = (char)0; + memset( tPath, 0, CTEXT ); + tPos = strstr(tPtr->XAddrs,"//"); + if( tPos != NULL ) { + tPos2 = strstr( tPos + 2,"/"); + if( tPos2 != NULL ) { + int len,len2,len3; + len = tPos2 - tPos - 2; + strncpy( tIpBuf, tPos + 2, len); + tIpBuf[len] = (char)0; + strncpy( tPath, tPos + 2 + len, CTEXT ); + } else { + LOG_ERROR("Pos 2 - err"); tIpBuf[0] = (char)0; }; } else { - LOG("Pos 0 - err"); + LOG_ERROR("Pos 0 - err"); tIpBuf[0] = (char)0; }; - sprintf(tQBuf,"INSERT INTO cameras SET `uuid`='%s', `onvif_ctrl`='%s', `ip`='%s', `type`=2, `status`=0, `site_id`=%d, `mac`='%s', `hardware`='%s', `name`='%s' ON DUPLICATE KEY UPDATE `onvif_ctrl`='%s', `ip`='%s'", + sprintf(tQBuf,"INSERT INTO cameras SET `online`=1, `uuid`='%s', `onvif_ctrl`='%s', `ip`='%s', `type`=2, `status`=0, `site_id`=%d, `mac`='%s', `hardware`='%s', `name`='%s', `onvif_access`='%s' ON DUPLICATE KEY UPDATE `online`=1, `ip`='%s'", tPtr->RefID, - tPtr->XAddrs, + //tPtr->XAddrs, + tPath, tIpBuf, SiteID, tPtr->MAC, tPtr->Hardware, tPtr->Name, - tPtr->XAddrs, + tProto, + //tPtr->XAddrs, tIpBuf ); +#ifdef DEBUG LOG(tQBuf); +#endif m_pDatabase->SilentQuery( tQBuf ); return true; }; return false; }; -bool ARGUS_DBC::transferEvtToArchive( uint32_t SECONDS ){ +bool argusDBC::transferEvtToArchive( uint32_t SECONDS ){ if(m_bIsConnected) { if( SECONDS > 0 ) { char tQBuf[CTEXT]; @@ -149,7 +234,7 @@ bool ARGUS_DBC::transferEvtToArchive( uint32_t SECONDS ){ }; return false; } -bool ARGUS_DBC::getLastEvents( vectorEventRecords &VR, uint32_t tss, uint32_t tsms ){ +bool argusDBC::getLastEvents( vectorEventRecords &VR, uint32_t tss, uint32_t tsms ){ if(m_bIsConnected){ char tQBuf[CTEXT]; AAssoc *result; @@ -181,10 +266,9 @@ bool ARGUS_DBC::getLastEvents( vectorEventRecords &VR, uint32_t tss, uint32_t ts LOG(tBuf); VR.push_back(tPtr); }; - delete(cArr); + //?? + //delete(cArr); }; - //result->clear(); - //delete(result); }; deleteResult( result ); if( m_pDatabase->isConnected()) return true; @@ -192,7 +276,7 @@ bool ARGUS_DBC::getLastEvents( vectorEventRecords &VR, uint32_t tss, uint32_t ts return false; }; -bool ARGUS_DBC::getAllCamRecords( uint32_t SiteID, vectorCamRecords &VR ){ +bool argusDBC::getAllCamRecords( uint32_t SiteID, vectorCamRecords &VR ){ if(m_bIsConnected){ char tQBuf[CTEXT]; AAssoc *result; @@ -211,13 +295,18 @@ bool ARGUS_DBC::getAllCamRecords( uint32_t SiteID, vectorCamRecords &VR ){ if( tVal!= NULL ) { Assoc::iterator it; memset(tVal,0,sizeof(DBC_CAM_DATA)); + it = cArr->find("id"); if( it != cArr->end() ){ tVal->id = atoi( it->second.c_str() ); }; - it = cArr->find("enabled"); + it = cArr->find("site_id"); if( it != cArr->end() ){ - tVal->enabled = (bool) atoi( it->second.c_str() ); + tVal->site_id = atoi( it->second.c_str() ); + }; + it = cArr->find("node_id"); + if( it != cArr->end() ){ + tVal->node_id = atoi( it->second.c_str() ); }; it = cArr->find("online"); if( it != cArr->end() ){ @@ -227,18 +316,30 @@ bool ARGUS_DBC::getAllCamRecords( uint32_t SiteID, vectorCamRecords &VR ){ if( it != cArr->end() ){ tVal->type = atoi( it->second.c_str() ); }; - it = cArr->find("caps"); + it = cArr->find("name"); + if( it != cArr->end() ){ + strncpy( tVal->name, it->second.c_str(), 64 ); + }; + it = cArr->find("hardware"); if( it != cArr->end() ){ - tVal->caps = atoi( it->second.c_str() ); + strncpy( tVal->hardware, it->second.c_str(), 32 ); }; it = cArr->find("status"); if( it != cArr->end() ){ tVal->status = atoi( it->second.c_str() ); }; + it = cArr->find("session"); + if( it != cArr->end() ){ + strncpy( tVal->session, it->second.c_str(), 32 ); + }; it = cArr->find("protocol"); if( it != cArr->end() ){ tVal->protocol = atoi( it->second.c_str() ); }; + it = cArr->find("protocol_aux"); + if( it != cArr->end() ){ + strncpy( tVal->protocol_aux, it->second.c_str(), 64 ); + }; it = cArr->find("lat"); if( it != cArr->end() ){ tVal->lat = atof( it->second.c_str() ); @@ -263,6 +364,14 @@ bool ARGUS_DBC::getAllCamRecords( uint32_t SiteID, vectorCamRecords &VR ){ if( it != cArr->end() ){ tVal->yaw = atof( it->second.c_str() ); }; + it = cArr->find("imager_size"); + if( it != cArr->end() ){ + tVal->imager_size = atof( it->second.c_str() ); + }; + it = cArr->find("imager_ratio"); + if( it != cArr->end() ){ + tVal->imager_ratio = atof( it->second.c_str() ); + }; it = cArr->find("min_f"); if( it != cArr->end() ){ tVal->min_f = atof( it->second.c_str() ); @@ -271,67 +380,60 @@ bool ARGUS_DBC::getAllCamRecords( uint32_t SiteID, vectorCamRecords &VR ){ if( it != cArr->end() ){ tVal->max_f = atof( it->second.c_str() ); }; - it = cArr->find("imager_size"); + it = cArr->find("access_login"); if( it != cArr->end() ){ - tVal->imager_size = atof( it->second.c_str() ); + strncpy( tVal->username, it->second.c_str(), 16 ); }; - it = cArr->find("imager_ratio"); + it = cArr->find("access_pass"); if( it != cArr->end() ){ - tVal->imager_ratio = atof( it->second.c_str() ); + strncpy( tVal->password, it->second.c_str(), 16 ); }; it = cArr->find("uuid"); if( it != cArr->end() ){ strncpy( tVal->uuid, it->second.c_str(), CLOG ); }; - it = cArr->find("port"); + it = cArr->find("mac"); if( it != cArr->end() ){ - strncpy( tVal->port, it->second.c_str(), 5 ); + strncpy( tVal->mac, it->second.c_str(), 16 ); }; it = cArr->find("ip"); if( it != cArr->end() ){ strncpy( tVal->ip, it->second.c_str(), 16 ); }; - it = cArr->find("hardware"); - if( it != cArr->end() ){ - strncpy( tVal->hardware, it->second.c_str(), 16 ); - }; - it = cArr->find("session"); + it = cArr->find("port"); if( it != cArr->end() ){ - strncpy( tVal->session, it->second.c_str(), 16 ); + tVal->port = atoi( it->second.c_str() ); }; - it = cArr->find("access_login"); + it = cArr->find("onvif_access"); if( it != cArr->end() ){ - strncpy( tVal->username, it->second.c_str(), 16 ); + strncpy( tVal->onvif_access, it->second.c_str(), 5); }; - it = cArr->find("access_pass"); - if( it != cArr->end() ){ - strncpy( tVal->password, it->second.c_str(), 16 ); - }; - it = cArr->find("name"); + it = cArr->find("onvif_ctrl"); if( it != cArr->end() ){ - strncpy( tVal->name, it->second.c_str(), 16 ); + strncpy( tVal->onvif_ctrl, it->second.c_str(), 250); }; - it = cArr->find("onvif_ctrl"); + it = cArr->find("ptz_token"); if( it != cArr->end() ){ - strncpy( tVal->onvif_ctrl, it->second.c_str(), 16 ); + strncpy( tVal->ptz_token, it->second.c_str(), 64); }; VR.push_back(tVal); }; - delete(cArr); + //?? + //delete(cArr); }; - //result->clear(); - //delete(result); }; deleteResult( result ); +#ifdef DEBUG sprintf( tQBuf,"Now %d Camera Records in System", VR.size()); LOG(tQBuf); +#endif if( m_pDatabase->isConnected()) return true; }; return false; }; -DBC_INT_LIST *ARGUS_DBC::listNodes( uint32_t SiteID ){ +DBC_INT_LIST *argusDBC::listNodes( uint32_t SiteID ){ DBC_INT_LIST * tVal = NULL; if(m_bIsConnected){ char tQBuf[CTEXT]; @@ -362,7 +464,7 @@ DBC_INT_LIST *ARGUS_DBC::listNodes( uint32_t SiteID ){ return tVal; }; -DBC_INT_LIST *ARGUS_DBC::listNewNodes( uint32_t SiteID, DBC_INT_LIST *old_ids ){ +DBC_INT_LIST *argusDBC::listNewNodes( uint32_t SiteID, DBC_INT_LIST *old_ids ){ DBC_INT_LIST * tVal = NULL; char tParam[CTEXT]; //memset( tParam, 0, CTEXT ); @@ -404,7 +506,7 @@ DBC_INT_LIST *ARGUS_DBC::listNewNodes( uint32_t SiteID, DBC_INT_LIST *old_ids ){ }; -DBC_NODE_DATA *ARGUS_DBC::getNodeData( uint32_t ID ){ +DBC_NODE_DATA *argusDBC::getNodeData( uint32_t ID ){ DBC_NODE_DATA * tVal = NULL; if(m_bIsConnected){ char tQBuf[CTEXT]; @@ -457,7 +559,7 @@ DBC_NODE_DATA *ARGUS_DBC::getNodeData( uint32_t ID ){ return tVal; }; -DBC_INT_LIST *ARGUS_DBC::listModules( uint32_t ServerID ){ +DBC_INT_LIST *argusDBC::listModules( uint32_t ServerID ){ DBC_INT_LIST * tVal = NULL; if(m_bIsConnected){ char tQBuf[CTEXT]; @@ -488,7 +590,73 @@ DBC_INT_LIST *ARGUS_DBC::listModules( uint32_t ServerID ){ return tVal; }; -DBC_INT_LIST *ARGUS_DBC::listNewModules( uint32_t ServerID, DBC_INT_LIST * old_ids ){ +DBC_INT_LIST *argusDBC::listMediaStreams( uint32_t SiteId, uint32_t MediaServerID, uint8_t listMode ){ + DBC_INT_LIST * tVal = NULL; + if(m_bIsConnected){ + char tQBuf[CTEXT]; + AAssoc *result; + switch( listMode ){ + case LIST_VALID_RECORDS: sprintf(tQBuf, "SELECT id FROM media_server_streams WHERE `valid`=1 AND `site_id`=%d AND `media_server_id`=%d", SiteId, MediaServerID ); break; + case LIST_INVALID_RECORDS: sprintf(tQBuf, "SELECT id FROM media_server_streams WHERE `valid`=0 AND `site_id`=%d AND `media_server_id`=%d", SiteId, MediaServerID ); break; + default: sprintf(tQBuf, "SELECT id FROM media_server_streams WHERE `site_id`=%d AND `media_server_id`=%d", SiteId, MediaServerID ); + }; +#ifdef DEBUG + //LOG(tQBuf); +#endif + result = m_pDatabase->Query( tQBuf ); + if( result!= NULL ) { + if( result->size() > 0 ) { + Assoc *cArr; + tVal = new DBC_INT_LIST(); + if( tVal != NULL ) { + Assoc::iterator it; + for(int i=0;isize();i++) { + cArr = result->at(i); + it = cArr->find("id"); + if( it != cArr->end() ){ + tVal->push_back( atoi( it->second.c_str() )); + }; + }; + }; + }; + }; + deleteResult( result ); + }; + return tVal; +}; + +DBC_INT_LIST *argusDBC::listSockets( uint32_t NodeID ){ + DBC_INT_LIST * tVal = NULL; + if(m_bIsConnected){ + char tQBuf[CTEXT]; + AAssoc *result; + sprintf(tQBuf, "SELECT id FROM sockets WHERE `node_id`=%d", NodeID ); +#ifdef DEBUG + LOG(tQBuf); +#endif + result = m_pDatabase->Query( tQBuf ); + if( result!= NULL ) { + if( result->size() > 0 ) { + Assoc *cArr; + tVal = new DBC_INT_LIST(); + if( tVal != NULL ) { + Assoc::iterator it; + for(int i=0;isize();i++) { + cArr = result->at(i); + it = cArr->find("id"); + if( it != cArr->end() ){ + tVal->push_back( atoi( it->second.c_str() )); + }; + }; + }; + }; + }; + deleteResult( result ); + }; + return tVal; +}; + +DBC_INT_LIST *argusDBC::listNewModules( uint32_t ServerID, DBC_INT_LIST * old_ids ){ DBC_INT_LIST * tVal = NULL; char tParam[CTEXT]; //memset( tParam, 0, CTEXT ); @@ -528,8 +696,33 @@ DBC_INT_LIST *ARGUS_DBC::listNewModules( uint32_t ServerID, DBC_INT_LIST * old_i }; return tVal; }; +uint32_t argusDBC::getCamId( CSTR UUID ){ + uint32_t RetVal = 0; + if(m_bIsConnected){ + char tQBuf[CTEXT]; + AAssoc *result; + sprintf(tQBuf, "SELECT id FROM cameras WHERE `uuid`='%s'", UUID ); +#ifdef DEBUG + LOG(tQBuf); +#endif + result = m_pDatabase->Query( tQBuf ); + if( result!= NULL ) { + if( result->size() > 0 ) { + Assoc *cArr; + Assoc::iterator it; + cArr = result->at(0); + it = cArr->find("id"); + if( it != cArr->end() ){ + RetVal = atoi( it->second.c_str() ); + }; + }; + }; + deleteResult( result ); + }; + return RetVal; +}; -DBC_CAM_DATA *ARGUS_DBC::getCamData( uint32_t ID ){ +DBC_CAM_DATA *argusDBC::getCamData( uint32_t ID ){ DBC_CAM_DATA *tVal = NULL; if(m_bIsConnected){ char tQBuf[CTEXT]; @@ -548,9 +741,13 @@ DBC_CAM_DATA *ARGUS_DBC::getCamData( uint32_t ID ){ tVal->id = ID; Assoc::iterator it; cArr = result->at(0); - it = cArr->find("enabled"); + it = cArr->find("site_id"); if( it != cArr->end() ){ - tVal->enabled = (bool) atoi( it->second.c_str() ); + tVal->site_id = atoi( it->second.c_str() ); + }; + it = cArr->find("node_id"); + if( it != cArr->end() ){ + tVal->node_id = atoi( it->second.c_str() ); }; it = cArr->find("online"); if( it != cArr->end() ){ @@ -560,18 +757,30 @@ DBC_CAM_DATA *ARGUS_DBC::getCamData( uint32_t ID ){ if( it != cArr->end() ){ tVal->type = atoi( it->second.c_str() ); }; - it = cArr->find("caps"); + it = cArr->find("name"); if( it != cArr->end() ){ - tVal->caps = atoi( it->second.c_str() ); + strncpy( tVal->name, it->second.c_str(), 64 ); + }; + it = cArr->find("hardware"); + if( it != cArr->end() ){ + strncpy( tVal->hardware, it->second.c_str(), 32 ); }; it = cArr->find("status"); if( it != cArr->end() ){ tVal->status = atoi( it->second.c_str() ); }; + it = cArr->find("session"); + if( it != cArr->end() ){ + strncpy( tVal->session, it->second.c_str(), 32 ); + }; it = cArr->find("protocol"); if( it != cArr->end() ){ tVal->protocol = atoi( it->second.c_str() ); }; + it = cArr->find("protocol_aux"); + if( it != cArr->end() ){ + strncpy( tVal->protocol_aux, it->second.c_str(), 64 ); + }; it = cArr->find("lat"); if( it != cArr->end() ){ tVal->lat = atof( it->second.c_str() ); @@ -596,6 +805,14 @@ DBC_CAM_DATA *ARGUS_DBC::getCamData( uint32_t ID ){ if( it != cArr->end() ){ tVal->yaw = atof( it->second.c_str() ); }; + it = cArr->find("imager_size"); + if( it != cArr->end() ){ + tVal->imager_size = atof( it->second.c_str() ); + }; + it = cArr->find("imager_ratio"); + if( it != cArr->end() ){ + tVal->imager_ratio = atof( it->second.c_str() ); + }; it = cArr->find("min_f"); if( it != cArr->end() ){ tVal->min_f = atof( it->second.c_str() ); @@ -604,49 +821,41 @@ DBC_CAM_DATA *ARGUS_DBC::getCamData( uint32_t ID ){ if( it != cArr->end() ){ tVal->max_f = atof( it->second.c_str() ); }; - it = cArr->find("imager_size"); + it = cArr->find("access_login"); if( it != cArr->end() ){ - tVal->imager_size = atof( it->second.c_str() ); + strncpy( tVal->username, it->second.c_str(), 16 ); }; - it = cArr->find("imager_ratio"); + it = cArr->find("access_pass"); if( it != cArr->end() ){ - tVal->imager_ratio = atof( it->second.c_str() ); + strncpy( tVal->password, it->second.c_str(), 16 ); }; it = cArr->find("uuid"); if( it != cArr->end() ){ - strncpy( tVal->uuid, it->second.c_str(), CLOG ); + strncpy( tVal->uuid, it->second.c_str(), 64 ); }; - it = cArr->find("port"); + it = cArr->find("mac"); if( it != cArr->end() ){ - strncpy( tVal->port, it->second.c_str(), 5 ); + strncpy( tVal->mac, it->second.c_str(), 16 ); }; it = cArr->find("ip"); if( it != cArr->end() ){ strncpy( tVal->ip, it->second.c_str(), 16 ); }; - it = cArr->find("hardware"); - if( it != cArr->end() ){ - strncpy( tVal->hardware, it->second.c_str(), 16 ); - }; - it = cArr->find("session"); - if( it != cArr->end() ){ - strncpy( tVal->session, it->second.c_str(), 16 ); - }; - it = cArr->find("access_login"); + it = cArr->find("port"); if( it != cArr->end() ){ - strncpy( tVal->username, it->second.c_str(), 16 ); + tVal->port = atoi( it->second.c_str() ); }; - it = cArr->find("access_pass"); + it = cArr->find("onvif_access"); if( it != cArr->end() ){ - strncpy( tVal->password, it->second.c_str(), 16 ); + strncpy( tVal->onvif_access, it->second.c_str(), 5); }; - it = cArr->find("name"); + it = cArr->find("onvif_ctrl"); if( it != cArr->end() ){ - strncpy( tVal->name, it->second.c_str(), 16 ); + strncpy( tVal->onvif_ctrl, it->second.c_str(), 250); }; - it = cArr->find("onvif_ctrl"); + it = cArr->find("ptz_token"); if( it != cArr->end() ){ - strncpy( tVal->onvif_ctrl, it->second.c_str(), 16 ); + strncpy( tVal->ptz_token, it->second.c_str(), 64); }; }; }; @@ -656,7 +865,7 @@ DBC_CAM_DATA *ARGUS_DBC::getCamData( uint32_t ID ){ return tVal; }; -DBC_MODULE_DATA *ARGUS_DBC::getModuleData( uint32_t ID ){ +DBC_MODULE_DATA *argusDBC::getModuleData( uint32_t ID ){ DBC_MODULE_DATA *tVal = NULL; if(m_bIsConnected){ char tQBuf[CTEXT]; @@ -690,21 +899,19 @@ DBC_MODULE_DATA *ARGUS_DBC::getModuleData( uint32_t ID ){ tVal->enabled = (bool)atoi( it->second.c_str() ); }; }; - //result->clear(); }; - //delete( result ); }; deleteResult( result ); }; return tVal; }; -DBC_MEDIA_SERVER_DATA *ARGUS_DBC::getMediaServerData( uint32_t ID ){ - DBC_MEDIA_SERVER_DATA *tVal = NULL; +DBC_SOCKET_DATA *argusDBC::getSocketData( uint32_t ID ){ + DBC_SOCKET_DATA *tVal = NULL; if(m_bIsConnected){ char tQBuf[CTEXT]; AAssoc *result; - sprintf(tQBuf, "SELECT * FROM media_servers WHERE `id`=%d", ID ); + sprintf(tQBuf, "SELECT * FROM sockets WHERE `id`=%d", ID ); #ifdef DEBUG LOG(tQBuf); #endif @@ -712,14 +919,110 @@ DBC_MEDIA_SERVER_DATA *ARGUS_DBC::getMediaServerData( uint32_t ID ){ if( result!= NULL ) { if( result->size() > 0 ) { Assoc *cArr; - tVal = (DBC_MEDIA_SERVER_DATA*) malloc(sizeof(DBC_MEDIA_SERVER_DATA)); + tVal = (DBC_SOCKET_DATA*) malloc(sizeof(DBC_SOCKET_DATA)); if( tVal != NULL ) { Assoc::iterator it; cArr = result->at(0); it = cArr->find("id"); if( it != cArr->end() ){ - tVal->id = atoi( it->second.c_str() ); + tVal->socket_id = atoi( it->second.c_str() ); }; + it = cArr->find("aux_id"); + if( it != cArr->end() ){ + tVal->aux_id = atoi( it->second.c_str() ); + }; + it = cArr->find("type"); + if( it != cArr->end() ){ + tVal->type = atoi( it->second.c_str() ); + }; + it = cArr->find("binded"); + if( it != cArr->end() ){ + tVal->binded = (bool)atoi( it->second.c_str() ); + }; + }; + }; + }; + deleteResult( result ); + }; + return tVal; +}; + +DBC_MEDIA_STREAM_DATA *argusDBC::getMediaStreamData( uint32_t ID ){ + DBC_MEDIA_STREAM_DATA *tVal = NULL; + if(m_bIsConnected){ + char tQBuf[CTEXT]; + AAssoc *result; + sprintf(tQBuf, "SELECT * FROM media_streams WHERE `id`=%d", ID ); +#ifdef DEBUG + //LOG(tQBuf); +#endif + result = m_pDatabase->Query( tQBuf ); + if( result!= NULL ) { + if( result->size() > 0 ) { + Assoc *cArr; + tVal = (DBC_MEDIA_STREAM_DATA*) malloc(sizeof(DBC_MEDIA_STREAM_DATA)); + if( tVal != NULL ) { + Assoc::iterator it; + cArr = result->at(0); + tVal->id = ID; + it = cArr->find("source_id"); + if( it != cArr->end() ){ + tVal->source_id = atoi( it->second.c_str() ); + }; + it = cArr->find("site_id"); + if( it != cArr->end() ){ + tVal->site_id = atoi( it->second.c_str() ); + }; + it = cArr->find("source_type"); + if( it != cArr->end() ){ + sprintf( tVal->source_type, it->second.c_str() ); + }; + it = cArr->find("valid"); + if( it != cArr->end() ){ + tVal->valid = (bool) atoi( it->second.c_str() ); + }; + it = cArr->find("token"); + if( it != cArr->end() ){ + sprintf( tVal->token, it->second.c_str() ); + }; + it = cArr->find("mrl_proto"); + if( it != cArr->end() ){ + sprintf( tVal->mrl_proto, it->second.c_str() ); + }; + it = cArr->find("mrl_port"); + if( it != cArr->end() ){ + tVal->mrl_port = atoi( it->second.c_str() ); + }; + it = cArr->find("mrl"); + if( it != cArr->end() ){ + sprintf( tVal->mrl, it->second.c_str() ); + }; + }; + }; + }; + deleteResult( result ); + }; + return tVal; +}; + +DBC_MEDIA_SERVER_DATA *argusDBC::getMediaServerData( uint32_t ID ){ + DBC_MEDIA_SERVER_DATA *tVal = NULL; + if(m_bIsConnected){ + char tQBuf[CTEXT]; + AAssoc *result; + sprintf(tQBuf, "SELECT * FROM media_servers WHERE `id`=%d", ID ); +#ifdef DEBUG + LOG(tQBuf); +#endif + result = m_pDatabase->Query( tQBuf ); + if( result!= NULL ) { + if( result->size() > 0 ) { + Assoc *cArr; + tVal = (DBC_MEDIA_SERVER_DATA*) malloc(sizeof(DBC_MEDIA_SERVER_DATA)); + if( tVal != NULL ) { + Assoc::iterator it; + cArr = result->at(0); + tVal->id = ID; it = cArr->find("secret_key"); if( it != cArr->end() ){ sprintf( tVal->key, it->second.c_str() ); @@ -742,16 +1045,56 @@ DBC_MEDIA_SERVER_DATA *ARGUS_DBC::getMediaServerData( uint32_t ID ){ }; sprintf( tVal->name,"ZLMedia_%d", tVal->id ); }; - //result->clear(); }; - //delete( result ); }; deleteResult( result ); }; return tVal; }; -void ARGUS_DBC::registerServer(uint32_t SiteID, CSTR identity ){ +DBC_MEDIA_SERVER_STREAM_DATA *argusDBC::getMediaServerStreamData( uint32_t ID ){ + DBC_MEDIA_SERVER_STREAM_DATA *tVal = NULL; + if(m_bIsConnected){ + char tQBuf[MAX_PATH_LEN]; + AAssoc *result; + sprintf(tQBuf, "SELECT `id`, `media_stream_id`, `online`, `key`, `mrl` FROM media_server_streams WHERE `id`=%d", ID ); +#ifdef DEBUG + //LOG(tQBuf); +#endif + result = m_pDatabase->Query( tQBuf ); + if( result!= NULL ) { + if( result->size() > 0 ) { + Assoc *cArr; + tVal = (DBC_MEDIA_SERVER_STREAM_DATA*) malloc(sizeof(DBC_MEDIA_SERVER_STREAM_DATA)); + if( tVal != NULL ) { + Assoc::iterator it; + cArr = result->at(0); + tVal->id = ID; + it = cArr->find("media_stream_id"); + if( it != cArr->end() ){ + tVal->media_stream_id = atoi( it->second.c_str() ); + }; + it = cArr->find("online"); + if( it != cArr->end() ){ + tVal->online = atoi( it->second.c_str() ); + }; + it = cArr->find("key"); + if( it != cArr->end() ){ + sprintf( tVal->key, it->second.c_str() ); + }; + it = cArr->find("mrl"); + if( it != cArr->end() ){ + sprintf( tVal->mrl, it->second.c_str() ); + }; + }; + }; + }; + deleteResult( result ); + }; + return tVal; +}; + +void argusDBC::registerServer(uint32_t SiteID, CSTR identity ){ if(m_bIsConnected){ char tQBuf[CTEXT]; sprintf(tQBuf,"INSERT INTO servers SET `site_id`=%d, `identity`='%s', `online`=1 ON DUPLICATE KEY UPDATE `online`=1", SiteID, identity ); @@ -760,6 +1103,31 @@ void ARGUS_DBC::registerServer(uint32_t SiteID, CSTR identity ){ #endif m_pDatabase->SilentQuery( tQBuf ); + + // Clenup Nodes and services ... + sprintf(tQBuf,"UPDATE nodes SET `online`=0 WHERE `site_id`=%d ", SiteID ); +#ifdef DEBUG + LOG(tQBuf); +#endif + m_pDatabase->SilentQuery( tQBuf ); + sprintf(tQBuf,"UPDATE cameras SET `online`=0 WHERE `site_id`=%d ", SiteID ); +#ifdef DEBUG + LOG(tQBuf); +#endif + m_pDatabase->SilentQuery( tQBuf ); + + sprintf(tQBuf,"UPDATE media_streams SET `valid`=0 WHERE `site_id`=%d ", SiteID ); +#ifdef DEBUG + LOG(tQBuf); +#endif + m_pDatabase->SilentQuery( tQBuf ); + + sprintf(tQBuf,"UPDATE media_server_streams SET `valid`=0, `online`=0 WHERE `site_id`=%d ", SiteID ); +#ifdef DEBUG + LOG(tQBuf); +#endif + m_pDatabase->SilentQuery( tQBuf ); + uint32_t sid = getServerID( identity ); if( sid ) { sprintf(tQBuf,"INSERT INTO nodes SET `site_id`=%d, `aux_id`='%d', `type`= 0, `online`=1, `name`='Server Node' ON DUPLICATE KEY UPDATE `online`=1", SiteID, sid ); @@ -767,11 +1135,11 @@ void ARGUS_DBC::registerServer(uint32_t SiteID, CSTR identity ){ LOG(tQBuf); #endif m_pDatabase->SilentQuery( tQBuf ); - }; + }; }; }; -void ARGUS_DBC::unregisterServer(uint32_t ServerID, uint32_t NodeID ){ +void argusDBC::unregisterServer(uint32_t ServerID, uint32_t NodeID ){ if(m_bIsConnected){ char tQBuf[CTEXT]; sprintf(tQBuf,"UPDATE servers SET `online`=0 WHERE `id` = %d", ServerID ); @@ -783,7 +1151,7 @@ void ARGUS_DBC::unregisterServer(uint32_t ServerID, uint32_t NodeID ){ }; }; -void ARGUS_DBC::setNodeOnline( uint32_t NodeID ){ +void argusDBC::setNodeOnline( uint32_t NodeID ){ if(m_bIsConnected){ char tQBuf[CTEXT]; if( NodeID ) { @@ -792,16 +1160,16 @@ void ARGUS_DBC::setNodeOnline( uint32_t NodeID ){ LOG(tQBuf); #endif m_pDatabase->SilentQuery( tQBuf ); - sprintf(tQBuf,"UPDATE sockets SET `state`=1 WHERE `node_id` = %d", NodeID ); + //sprintf(tQBuf,"UPDATE sockets SET `state`=1 WHERE `node_id` = %d", NodeID ); #ifdef DEBUG - LOG(tQBuf); + //LOG(tQBuf); #endif - m_pDatabase->SilentQuery( tQBuf ); + //m_pDatabase->SilentQuery( tQBuf ); }; }; }; -void ARGUS_DBC::setNodeOffline( uint32_t NodeID ){ +void argusDBC::setNodeOffline( uint32_t NodeID ){ if(m_bIsConnected){ char tQBuf[CTEXT]; if( NodeID ) { @@ -810,16 +1178,16 @@ void ARGUS_DBC::setNodeOffline( uint32_t NodeID ){ LOG(tQBuf); #endif m_pDatabase->SilentQuery( tQBuf ); - sprintf(tQBuf,"UPDATE sockets SET `state`=0 WHERE `node_id` = %d", NodeID ); + //sprintf(tQBuf,"UPDATE sockets SET `state`=0 WHERE `node_id` = %d", NodeID ); #ifdef DEBUG - LOG(tQBuf); + //LOG(tQBuf); #endif - m_pDatabase->SilentQuery( tQBuf ); + //m_pDatabase->SilentQuery( tQBuf ); }; }; }; -uint32_t ARGUS_DBC::getServerID( CSTR identity ){ +uint32_t argusDBC::getServerID( CSTR identity ){ uint32_t RetVal = 0; if(m_bIsConnected){ char tQBuf[CTEXT]; @@ -838,16 +1206,14 @@ uint32_t ARGUS_DBC::getServerID( CSTR identity ){ if( it != cArr->end() ){ RetVal = atoi( it->second.c_str() ); }; - //result->clear(); }; - //delete( result ); }; deleteResult( result ); }; return RetVal; }; -uint32_t ARGUS_DBC::getServerNode( uint32_t SID ){ +uint32_t argusDBC::getServerNode( uint32_t SID ){ uint32_t RetVal = 0; if(m_bIsConnected){ char tQBuf[CTEXT]; @@ -866,30 +1232,221 @@ uint32_t ARGUS_DBC::getServerNode( uint32_t SID ){ if( it != cArr->end() ){ RetVal = atoi( it->second.c_str() ); }; - //result->clear(); }; - //delete( result ); }; deleteResult( result ); }; return RetVal; }; -void ARGUS_DBC::addNodeSocket( uint32_t NodeID, uint8_t SocketType, CSTR path, CSTR name ){ +uint64_t argusDBC::addLocalMediaSource( uint32_t SiteID, CSTR path, uint32_t width, uint32_t height ){ + uint64_t RetVal = 0; + if(m_bIsConnected){ + char tQBuf[1024]; + char tM5[33]; + CSTR tMD5 = MD5String( path ); + if( tMD5 != NULL ) { + memcpy( tM5, tMD5, 33 ); + tM5[32]=(char)0; + free( tMD5 ); + sprintf( tQBuf, "INSERT INTO media_streams SET `site_id`=%d, `source_id`=0, source_type='A', `valid`=1, `name`='Local Frame Grabber', `token`='%s', `img_width`=%d, `img_height`=%d, `mrl_proto`='v4l2', `mrl_port`='', `picture_proto`='', mrl='%s' ON DUPLICATE KEY UPDATE id=id, `valid`=1, img_width=%d, img_height=%d", + SiteID, tM5, width, height, path, width, height ); +#ifdef DEBUG + LOG(tQBuf); +#endif + RetVal = m_pDatabase->QueryID( tQBuf ); + }; + + }; + LOG("Func Finished"); + return RetVal; +}; + +uint32_t argusDBC::addNodeSocket( uint32_t NodeID, uint32_t auxID, uint8_t SocketType, uint8_t SocketMode, bool multidrop, CSTR path, CSTR name ){ + uint32_t retVal = 0; + if(m_bIsConnected){ + char tQBuf[2048]; + char tM5[33]; + CSTR tMD5 = MD5String( path ); + if( tMD5 != NULL ) { + memcpy( tM5, tMD5, 33 ); + free( tMD5 ); + if( multidrop ) { + sprintf(tQBuf,"INSERT INTO `sockets` SET `node_id`=%d, `type`=%d, `mode`=%d, `multidrop`=1, `md5`='%s', `path`='%s', `name`='%s', `aux_id`=%d ON DUPLICATE KEY UPDATE `id`=`id`, `name`='%s'", + NodeID, SocketType, SocketMode, tM5, path, name, auxID, name ); + } else { + sprintf(tQBuf,"INSERT INTO `sockets` SET `node_id`=%d, `type`=%d, `mode`=%d, `multidrop`=0, `md5`='%s', `path`='%s', `name`='%s', `aux_id`=%d ON DUPLICATE KEY UPDATE `id`=`id`, `name`='%s'", + NodeID, SocketType, SocketMode, tM5, path, name, auxID, name ); + }; +#ifdef DEBUG + LOG(tQBuf); +#endif + //m_pDatabase->SilentQuery( tQBuf ); + retVal = (uint32_t) m_pDatabase->QueryID( tQBuf ); + }; + }; + return retVal; +}; + +uint32_t argusDBC::getNodeSocketID( uint32_t NodeID, uint32_t auxID, uint8_t SocketType, CSTR path ){ + uint32_t retVal = 0; + if(m_bIsConnected){ + char tQBuf[2048]; + char tM5[33]; + CSTR tMD5 = MD5String( path ); + if( tMD5 != NULL ) { + memcpy( tM5, tMD5, 33 ); + free( tMD5 ); + sprintf( tQBuf,"SELECT id FROM `sockets` WHERE `node_id`=%d AND `type`=%d AND `md5`='%s' AND `aux_id`=%d", NodeID, SocketType, tM5, auxID ); +#ifdef DEBUG + LOG(tQBuf); +#endif + AAssoc *result; + result = m_pDatabase->Query( tQBuf ); + if( result!= NULL ) { + if( result->size() > 0 ) { + Assoc * cArr; + Assoc::iterator it; + cArr = result->at(0); + it = cArr->find("id"); + if( it != cArr->end() ){ + retVal = atoi( it->second.c_str() ); + }; + }; + }; + deleteResult( result ); + }; + }; + return retVal; +}; + +CSTR argusDBC::getNodeIP4( uint32_t NodeID ){ + return getSocketName( NodeID, ARGUS_NODE_SOCK_TYPE_NETWORK_IPV4 ); +}; + +CSTR argusDBC::getNodeIP6( uint32_t NodeID ){ + return getSocketName( NodeID, ARGUS_NODE_SOCK_TYPE_NETWORK_IPV6 ); +}; + +CSTR argusDBC::getSocketPath( uint32_t NodeID, uint32_t Type ){ if(m_bIsConnected){ char tQBuf[CTEXT]; - CSTR tMD5; - tMD5 = MD5String( path ); - sprintf(tQBuf,"INSERT INTO sockets SET `node_id`=%d, `type`=%d, `md5`='%s', `path`='%s', `state`=1, `name`='%s' ON DUPLICATE KEY UPDATE `state`=1, `name`='%s'", - NodeID, SocketType, tMD5, path, name, name ); + sprintf( tQBuf, "SELECT `path` FROM `sockets` WHERE `node_id`=%d AND `type`=%d LIMIT 1", + NodeID, Type ); #ifdef DEBUG LOG(tQBuf); #endif - free( tMD5 ); - m_pDatabase->SilentQuery( tQBuf ); + AAssoc *result; + result = m_pDatabase->Query( tQBuf ); + if( result!= NULL ) { + if( result->size() > 0 ) { + Assoc * cArr; + Assoc::iterator it; + cArr = result->at(0); + it = cArr->find("path"); + if( it != cArr->end() ){ + strncpy( tQBuf, it->second.c_str(), CTEXT ); + }; + }; + }; + deleteResult( result ); + return strdup(tQBuf); + }; + return NULL; +}; + +CSTR argusDBC::getSocketName( uint32_t NodeID, uint32_t Type ){ + if(m_bIsConnected){ + char tQBuf[CTEXT]; + sprintf( tQBuf, "SELECT `name` FROM `sockets` WHERE `node_id`=%d AND `type`=%d LIMIT 1", + NodeID, Type ); +#ifdef DEBUG + LOG(tQBuf); +#endif + AAssoc *result; + result = m_pDatabase->Query( tQBuf ); + if( result!= NULL ) { + if( result->size() > 0 ) { + Assoc * cArr; + Assoc::iterator it; + cArr = result->at(0); + it = cArr->find("name"); + if( it != cArr->end() ){ + strncpy( tQBuf, it->second.c_str(), CTEXT ); + }; + }; + }; + deleteResult( result ); + return strdup(tQBuf); }; + return NULL; +}; + +KAFKA_SETTINGS *argusDBC::getSettingsKAFKA( uint32_t NodeID ){ + return NULL; }; +DBC_UART_DATA *argusDBC::getSettingsUART( uint32_t SocketID ){ + DBC_UART_DATA *tVal = NULL; + if( m_bIsConnected ) { + char tQBuf[MAX_PATH_LEN]; + AAssoc *result; + sprintf( tQBuf, "SELECT us.speed, so.path FROM uart_settings us LEFT JOIN sockets so ON ( so.id = us.socket_id ) WHERE us.socket_id = %d", SocketID ); +#ifdef DEBUG + LOG(tQBuf); +#endif + result = m_pDatabase->Query( tQBuf ); + if( result!= NULL ) { + if( result->size() > 0 ) { + Assoc *cArr; + tVal = (DBC_UART_DATA*) malloc(sizeof(DBC_UART_DATA)); + if( tVal != NULL ) { + Assoc::iterator it; + cArr = result->at(0); + //tVal->socket_id = SocketID; + it = cArr->find("speed"); + if( it != cArr->end() ){ + tVal->speed = atoi( it->second.c_str() ); + }; + it = cArr->find("path"); + if( it != cArr->end() ){ + strncpy( tVal->device, it->second.c_str(), 255 ); + }; + }; + }; + }; + deleteResult( result ); + }; + return tVal; +}; + +bool argusDBC::updateMediaServerStream( uint32_t id, CSTR mrl, CSTR key ){ + if( m_bIsConnected ) { + char tQBuf[MAX_PATH_LEN]; +#ifdef DEBUG + LOG("Stream Update"); +#endif + if( key == NULL ) { + if( mrl == NULL ) { + sprintf( tQBuf,"UPDATE media_server_streams SET `online`=0, `key`='', mrl='', `valid`=0 WHERE `id`=%d", id ); + } else { + sprintf( tQBuf,"UPDATE media_server_streams SET `online`=0, `key`='', `mrl`='%s', `valid`=1 WHERE `id`=%d", mrl, id ); + }; + } else { + sprintf( tQBuf,"UPDATE media_server_streams SET `online`=1, `key`='%s', `mrl`='%s', `valid`=1 WHERE `id`=%d", + key, + mrl, + id + ); + }; +#ifdef DEBUG + LOG(tQBuf); +#endif + m_pDatabase->SilentQuery( tQBuf ); + return true; + }; + return false; +}; #undef LOG #undef LOG_ERROR diff --git a/lib/rgoose/rgooseDBConnector.h b/lib/rgoose/rgooseDBConnector.h index 54ab8866..051684db 100644 --- a/lib/rgoose/rgooseDBConnector.h +++ b/lib/rgoose/rgooseDBConnector.h @@ -10,6 +10,23 @@ #define ONE_HOUR_HISTORY 3600 #define ONE_SECOND_HISTORY 1 +#define ARGUS_NODE_SOCK_MODE_IN 1 +#define ARGUS_NODE_SOCK_MODE_OUT 2 +#define ARGUS_NODE_SOCK_MODE_INOUT 3 + +#define ARGUS_NODE_SOCK_TYPE_SERIAL_PORT 1 +#define ARGUS_NODE_SOCK_TYPE_NETWORK_IPV4 2 +#define ARGUS_NODE_SOCK_TYPE_DC 3 +#define ARGUS_NODE_SOCK_TYPE_VIDEO_GRABBER 4 +#define ARGUS_NODE_SOCK_TYPE_AUDIO_GRABBER 5 +#define ARGUS_NODE_SOCK_TYPE_IPV_OUT 6 +#define ARGUS_NODE_SOCK_TYPE_DVR_IN 7 +#define ARGUS_NODE_SOCK_TYPE_NETWORK_IPV6 8 +#define ARGUS_NODE_SOCK_TYPE_MEDIA_AD_BRIDGE 9 +#define LIST_ALL_RECORDS 0 +#define LIST_VALID_RECORDS 1 +#define LIST_INVALID_RECORDS 2 + typedef enum E_ARGUS_NODE_TYPE{ ARGUS_SERVER = 0, ARGUS_ALS_SENSOR = 1, @@ -31,32 +48,36 @@ typedef enum E_ARGUS_NODE_TYPE{ }ARGUS_NODE_TYPE; typedef struct S_DBC_CAM_DATA{ - bool enabled; + uint32_t id; + uint32_t site_id; + uint32_t node_id; bool online; uint8_t type; - uint8_t caps; + char name[65]; + char hardware[33]; uint8_t status; + char session[33]; uint8_t protocol; - uint32_t id; + char protocol_aux[65]; float lat; float lon; float alt; float pitch; float roll; float yaw; - float min_f; - float max_f; float imager_size; float imager_ratio; - char uuid[CLOG]; - char port[5]; - char ip[16]; - char hardware[32]; - char session[32]; - char username[32]; - char password[32]; - char name[64]; - char onvif_ctrl[250]; + float min_f; + float max_f; + char username[33]; + char password[33]; + char uuid[65]; + char ip[18]; + uint16_t port; + char mac[18]; + char onvif_access[6]; + char onvif_ctrl[251]; + char ptz_token[65]; }DBC_CAM_DATA; typedef struct S_EventRecordDBC{ @@ -83,6 +104,30 @@ typedef struct S_DBC_MODULE_DATA{ char name[128]; }DBC_MODULE_DATA; +typedef struct S_DBC_SOCKET_DATA{ + uint32_t socket_id; + uint32_t node_id; + uint32_t aux_id; + uint32_t type; + uint32_t state; + uint32_t mode; + bool binded; + char path[128]; + char name[128]; +}DBC_SOCKET_DATA; + +typedef struct S_DBC_MEDIA_STREAM_DATA{ + uint32_t id; + uint32_t source_id; + uint32_t site_id; + char source_type[2]; + bool valid; + char token[65]; + char mrl_proto[6]; + uint16_t mrl_port; + char mrl[251]; +}DBC_MEDIA_STREAM_DATA; + typedef struct S_DBC_MEDIA_SERVER_DATA{ uint32_t id; char key[46]; @@ -93,14 +138,25 @@ typedef struct S_DBC_MEDIA_SERVER_DATA{ char name[128]; }DBC_MEDIA_SERVER_DATA; +typedef struct S_DBC_MEDIA_SERVER_STREAM_DATA{ + uint32_t id; + uint32_t media_stream_id; + bool online; + char key[64]; + char mrl[128]; +} DBC_MEDIA_SERVER_STREAM_DATA; -typedef std::vector DBC_INT_LIST; +typedef struct S_DBC_UART_DATA{ + char device[256]; + uint32_t speed; +}DBC_UART_DATA; -typedef std::vector vectorCamRecords; -typedef std::vector vectorEventRecords; +typedef std::vector DBC_INT_LIST; +typedef std::vector vectorCamRecords; +typedef std::vector vectorEventRecords; -class ARGUS_DBC{ +class argusDBC{ private: basicLogCollection * m_pLog; config_setting_t * m_pSettings; @@ -111,34 +167,56 @@ class ARGUS_DBC{ char m_pDbPassword[CLOG]; char m_pDbDatabase[CLOG]; public: - explicit ARGUS_DBC( config_setting_t * Settings ); - ~ARGUS_DBC(); + static argusDBC * getInstance( config_setting_t * Settings = NULL ); + virtual ~argusDBC(); /* Functionality */ bool connect( void ); bool getConnectionStatus(void){return m_bIsConnected;}; bool setOnlineStatus( bool Status ); int getIPCamCount( uint32_t SiteID ); bool getAllCamRecords( uint32_t SiteID, vectorCamRecords &VR ); - DBC_CAM_DATA * getCamData( uint32_t CamID ); + bool updateIPCam( uint32_t SiteID, CSTR uuid, CSTR Addr ); - bool updateIPCam( uint32_t SiteID, resultWoWo *tPtr ); + bool updateIPCam( uint32_t SiteID, uint32_t CamID, CSTR Addr ); + bool addIPCam( uint32_t SiteID, resultWoWo *tPtr ); + uint64_t addLocalMediaSource( uint32_t SiteID, CSTR path, uint32_t width, uint32_t height ); bool updateNetworkNode( bool OnlineStatus ); + bool updateMediaServerStream( uint32_t id, CSTR mrl=NULL, CSTR key = NULL ); bool getLastEvents( vectorEventRecords &VR, uint32_t tss, uint32_t tsms ); bool transferEvtToArchive( uint32_t SECONDS = ONE_DAY_HISTORY ); - DBC_INT_LIST * listNodes( uint32_t SiteID ); + DBC_INT_LIST * listMediaStreams( uint32_t SiteId, uint32_t MediaServerID, uint8_t listingType = LIST_ALL_RECORDS ); DBC_INT_LIST * listModules( uint32_t SiteID ); - DBC_INT_LIST * listNewNodes( uint32_t SiteID, DBC_INT_LIST * old_ids ); DBC_INT_LIST * listNewModules( uint32_t SiteID, DBC_INT_LIST * old_ids ); + DBC_INT_LIST * listNewNodes( uint32_t SiteID, DBC_INT_LIST * old_ids ); + DBC_INT_LIST * listNodes( uint32_t SiteID ); + DBC_INT_LIST * listSockets( uint32_t NodeID ); + + DBC_CAM_DATA * getCamData( uint32_t CamID ); + uint32_t getCamId( CSTR UUID ); DBC_NODE_DATA * getNodeData( uint32_t ID ); DBC_MODULE_DATA * getModuleData( uint32_t ID ); + DBC_SOCKET_DATA * getSocketData( uint32_t ID ); + DBC_MEDIA_STREAM_DATA * getMediaStreamData( uint32_t ID ); DBC_MEDIA_SERVER_DATA * getMediaServerData( uint32_t ID ); + DBC_MEDIA_SERVER_STREAM_DATA * getMediaServerStreamData( uint32_t ID ); + void registerServer(uint32_t SiteID, CSTR identity ); void unregisterServer(uint32_t ServerID, uint32_t NodeID ); uint32_t getServerID( CSTR identity ); uint32_t getServerNode( uint32_t SID ); - void addNodeSocket( uint32_t NodeID, uint8_t SocketType, CSTR path, CSTR name ); + CSTR getNodeIP4( uint32_t NodeID ); + CSTR getNodeIP6( uint32_t NodeID ); + CSTR getSocketPath( uint32_t NodeID, uint32_t Type ); + CSTR getSocketName( uint32_t NodeID, uint32_t Type ); + uint32_t addNodeSocket( uint32_t NodeID, uint32_t auxID, uint8_t SocketType, uint8_t SocketMode, bool multidrop, CSTR path, CSTR name ); + uint32_t getNodeSocketID( uint32_t NodeID, uint32_t auxID, uint8_t SocketType, CSTR path ); void setNodeOnline( uint32_t NodeID ); void setNodeOffline( uint32_t NodeID ); + KAFKA_SETTINGS * getSettingsKAFKA( uint32_t NodeID ); + DBC_UART_DATA * getSettingsUART( uint32_t SocketID ); + private: + static argusDBC * _instance; + explicit argusDBC( config_setting_t * Settings = NULL ); }; #endif diff --git a/lib/rgoose/rgooseHardwareManager.cpp b/lib/rgoose/rgooseHardwareManager.cpp new file mode 100644 index 00000000..3d3228e7 --- /dev/null +++ b/lib/rgoose/rgooseHardwareManager.cpp @@ -0,0 +1,348 @@ +#include "rgooseHardwareManager.h" +#include "rgooseKernel.h" +#include "rgooseDBConnector.h" +#include "rgooseHardwareUART.h" + +#define LOG( X ) m_pLog->Log( "HWM", 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 );\ + m_pLog->Log( "HWM", this, _LOG_ERROR, _tBfrErrMSG2w34 );\ + } +#else + #define LOG_ERROR( X ) m_pLog->Log( "HWM", this, _LOG_ERROR, X ); +#endif + +argusHardwareManager *argusHardwareManager::_instance = NULL; + +/** + * Returns the single instance of the object. + */ +argusHardwareManager* argusHardwareManager::getInstance() { + // check if the instance has been created yet + if( 0 == _instance ){ + // if not, then create it + _instance = new argusHardwareManager; + }; + // return the single instance + return _instance; +}; + +argusHardwareManager::argusHardwareManager(){ + m_pLog = basicLogCollection::getInstance(); + m_bHardwareEnumerated = false; + m_pKernel = argusKernel::getInstance(); + if( m_pKernel == NULL ) LOG_ERROR( "Failure to get Kernel Instance!" ); + m_pDBC = argusDBC::getInstance(); + if( m_pDBC == NULL ) LOG_ERROR( "Failure to get DBC Instance!" ); + loadResources(); +}; + +argusHardwareManager::~argusHardwareManager(){ + +}; + +void argusHardwareManager::loadResources( void ){ + if( m_pDBC == NULL ) return; + DBC_INT_LIST *tVal; + tVal = m_pDBC->listSockets( m_pKernel->getServerNodeId() ); + if( tVal!= NULL ) { + for( DBC_INT_LIST::iterator index = tVal->begin(); index < tVal->end(); index++ ) { + LOG("ADD RESOURCE!"); + argusHardwareResource *tPtr; + tPtr = new argusHardwareResource( *index ); + if( tPtr!= NULL ) { + m_vResources.push_back( tPtr ); + }; + }; + tVal->clear(); + delete( tVal ); + }; +}; + +void argusHardwareManager::validate( void ){ + if( !m_bHardwareEnumerated ){ + enumerateHardware(); + m_bHardwareEnumerated = true; + }; +}; + +int xioctl(int fh, int request, void *arg){ + int r; + do { + r = ioctl( fh, request, arg ); + } while (-1 == r && EINTR == errno); + return r; +}; + +#define CLEAR(x) memset(&(x), 0, sizeof(x)) + +#include +#include + +void argusHardwareManager::enumerateHardware( void ){ + DIR * dFD; + struct dirent * pDR = NULL; + char tBuffer[CTEXT]; + struct ifaddrs * ifaddr = NULL; + struct ifaddrs * ifa; + char addr[INET6_ADDRSTRLEN]; + + if( m_pKernel == NULL ) return; + + uint32_t m_nServerNodeID = m_pKernel->getServerNodeId(); + uint32_t m_nServerID = m_pKernel->getServerId(); + uint32_t m_nSiteID = m_pKernel->getSiteId(); + /* Add Network Interfaces */ + if( -1 == getifaddrs(&ifaddr)) { + } else { + for( ifa = ifaddr; ifa; ifa = ifa->ifa_next ){ + if( ifa->ifa_addr->sa_family != AF_INET && ifa->ifa_addr->sa_family != AF_INET6 ) continue; + // Filter Loopback if + if( strstr( ifa->ifa_name, "lo" ) != NULL ) continue; + if( ifa->ifa_addr->sa_family == AF_INET ){ + // create IPv4 string + struct sockaddr_in *in = (struct sockaddr_in*) ifa->ifa_addr; + inet_ntop(AF_INET, &in->sin_addr, addr, sizeof(addr)); + //sprintf( tBuffer, "NET4:%s", ifa->ifa_name ); + m_pDBC->addNodeSocket( m_nServerNodeID, m_nServerID, ARGUS_NODE_SOCK_TYPE_NETWORK_IPV4, ARGUS_NODE_SOCK_MODE_INOUT, true, ifa->ifa_name, addr ); + } else { // AF_INET6 + // create IPv6 string + struct sockaddr_in6 *in6 = (struct sockaddr_in6*) ifa->ifa_addr; + inet_ntop(AF_INET6, &in6->sin6_addr, addr, sizeof(addr)); + //sprintf( tBuffer, "NET6:%s", ifa->ifa_name ); + m_pDBC->addNodeSocket( m_nServerNodeID, m_nServerID, ARGUS_NODE_SOCK_TYPE_NETWORK_IPV6, ARGUS_NODE_SOCK_MODE_INOUT, true, ifa->ifa_name, addr ); + }; + sprintf( tBuffer, "Network Interface: %s [%s]", ifa->ifa_name, addr ); + LOG(tBuffer); + }; + freeifaddrs( ifaddr ); + }; + /* Add devices from DEV */ + dFD = opendir("/dev"); + if( dFD != NULL ) { + while( ( pDR = readdir( dFD ))!= NULL ){ + if( strcasestr( pDR->d_name, "video" ) == pDR->d_name ) { + /* Enumerate Video Capture */ + sprintf( tBuffer, "Video Source: %s", pDR->d_name ); + LOG( tBuffer ); + struct v4l2_capability cap; + //struct v4l2_cropcap cropcap; + //struct v4l2_crop crop; + struct v4l2_format fmt; + char dev_name[CTEXT]; + int fd = -1; + struct stat st; + + sprintf( dev_name, "/dev/%s", pDR->d_name ); + + if (-1 == stat( dev_name, &st )) { + sprintf( tBuffer, "Cannot identify '%s': %d, %s\\n", dev_name, errno, strerror(errno)); + LOG_ERROR( tBuffer ); + continue; + }; + if (!S_ISCHR(st.st_mode)) { + sprintf( tBuffer, "%s is no devicen", dev_name); + LOG_ERROR( tBuffer ); + continue; + }; + fd = open(dev_name, O_RDWR /* required */ | O_NONBLOCK, 0); + if (-1 == fd) { + sprintf( tBuffer, "Cannot open '%s': %d, %s\\n", dev_name, errno, strerror(errno)); + LOG_ERROR( tBuffer ); + continue; + } else { + if (-1 == xioctl(fd, VIDIOC_QUERYCAP, &cap)) { + if (EINVAL == errno) { + sprintf( tBuffer, "%s is no V4L2 device", dev_name ); + LOG_ERROR( tBuffer ); + } else { + LOG_ERROR( "VIDIOC_QUERYCAP" ); + }; + close(fd); + continue; + }; + if (!(cap.capabilities & V4L2_CAP_VIDEO_CAPTURE)) { + sprintf(tBuffer, "%s is no video capture device\\n", dev_name); + LOG_ERROR( tBuffer ); + close(fd); + continue; + }; + CLEAR(fmt); + fmt.type = V4L2_BUF_TYPE_VIDEO_CAPTURE; + /* Preserve original settings as set by v4l2-ctl for example */ + if (-1 == xioctl(fd, VIDIOC_G_FMT, &fmt)){ + LOG_ERROR("VIDIOC_G_FMT"); + } else { + sprintf( tBuffer, "Grabber[%dx%d]",fmt.fmt.pix.width,fmt.fmt.pix.height); + LOG( tBuffer ); + uint64_t mid = m_pDBC->addLocalMediaSource( m_nSiteID, dev_name, fmt.fmt.pix.width, fmt.fmt.pix.height ); + LOG("Stream Added!"); + m_pDBC->addNodeSocket( m_nServerNodeID, mid, ARGUS_NODE_SOCK_TYPE_VIDEO_GRABBER, ARGUS_NODE_SOCK_MODE_OUT, false, dev_name, tBuffer ); + }; + close(fd); + continue; + }; + }; + if( strcasestr( pDR->d_name, "ttyS" ) == pDR->d_name ){ + /* Enumerate BuiltIn Serial */ + sprintf( tBuffer, "Native Serial: %s", pDR->d_name ); + LOG( tBuffer ); + char dev_name[CTEXT]; + int fd = -1; + struct serial_struct ss; + sprintf( dev_name, "/dev/%s", pDR->d_name ); + fd = open( dev_name, O_RDWR | O_NOCTTY | O_NDELAY | O_NONBLOCK ); + if (-1 == fd) { + sprintf( tBuffer, "Cannot open '%s': %d, %s\\n", dev_name, errno, strerror(errno)); + LOG_ERROR( tBuffer ); + continue; + } else { + if (-1 == xioctl(fd, TIOCGSERIAL, &ss)){ + LOG_ERROR("TIOCGSERIAL"); + } else { + sprintf( tBuffer, "Serial Port[Port:0x%X IRQ:%d BB:%d Line:%d Type:%d Flags:%X]", + ss.port, + ss.irq, + ss.baud_base, + ss.line, + ss.type, + ss.flags + ); + LOG( tBuffer ); + char comName[16]; + int pn = atoi( pDR->d_name+4) + 1; + sprintf( comName,"COM%d", pn ); + uint32_t dbid = m_pDBC->addNodeSocket( m_nServerNodeID, m_nServerID, ARGUS_NODE_SOCK_TYPE_SERIAL_PORT, ARGUS_NODE_SOCK_MODE_INOUT, true, dev_name, comName ); + if( dbid == 0 ) { + // Socket Allredy in DB - was just updated + dbid = m_pDBC->getNodeSocketID( m_nServerNodeID, m_nServerID, ARGUS_NODE_SOCK_TYPE_SERIAL_PORT, dev_name ); + }; + if( dbid ) { + // Creating Ressource!! + argusHardwareUART *tResource; + tResource = new argusHardwareUART( dbid ); + if( tResource!= NULL ) { + if( tResource->create() ) { + m_vResources.push_back( (argusHardwareResource*) tResource ); + }; + }; + } else LOG_ERROR("Failure to fetch Socket ID!"); + }; + close(fd); + continue; + }; + continue; + }; + // RaspberyPI Hardware + if( strcasestr( pDR->d_name, "ttyAMA" ) == pDR->d_name ){ + /* Enumerate BuiltIn Serial */ + sprintf( tBuffer, "Native Serial: %s", pDR->d_name ); + LOG( tBuffer ); + char dev_name[CTEXT]; + int fd = -1; + struct serial_struct ss; + sprintf( dev_name, "/dev/%s", pDR->d_name ); + fd = open( dev_name, O_RDWR | O_NOCTTY | O_NDELAY | O_NONBLOCK ); + if (-1 == fd) { + sprintf( tBuffer, "Cannot open '%s': %d, %s\\n", dev_name, errno, strerror(errno)); + LOG_ERROR( tBuffer ); + continue; + } else { + if (-1 == xioctl(fd, TIOCGSERIAL, &ss)){ + LOG_ERROR("TIOCGSERIAL"); + } else { + sprintf( tBuffer, "Serial Port[Port:0x%X IRQ:%d BB:%d Line:%d Type:%d Flags:%X]", + ss.port, + ss.irq, + ss.baud_base, + ss.line, + ss.type, + ss.flags + ); + LOG( tBuffer ); + char comName[16]; + int pn = atoi( pDR->d_name+4) + 1; + sprintf( comName,"COM%d", pn ); + uint32_t dbid = m_pDBC->addNodeSocket( m_nServerNodeID, m_nServerID, ARGUS_NODE_SOCK_TYPE_SERIAL_PORT, ARGUS_NODE_SOCK_MODE_INOUT, true, dev_name, comName ); + if( dbid == 0 ) { + // Socket Allredy in DB - was just updated + dbid = m_pDBC->getNodeSocketID( m_nServerNodeID, m_nServerID, ARGUS_NODE_SOCK_TYPE_SERIAL_PORT, dev_name ); + }; + if( dbid ) { + // Creating Ressource!! + argusHardwareUART *tResource; + tResource = new argusHardwareUART( dbid ); + if( tResource!= NULL ) { + if( tResource->create() ) { + m_vResources.push_back( (argusHardwareResource*) tResource ); + }; + }; + } else LOG_ERROR("Failure to fetch Socket ID!"); + }; + close(fd); + continue; + }; + continue; + }; + //USB to Serial Converter + if( strcasestr( pDR->d_name, "ttyUSB" ) == pDR->d_name ){ + /* Enumerate USB Serial devices */ + sprintf( tBuffer, "USB Serial: %s", pDR->d_name ); + LOG( tBuffer ); + char dev_name[CTEXT]; + int fd = -1; + struct serial_struct ss; + sprintf( dev_name, "/dev/%s", pDR->d_name ); + fd = open( dev_name, O_RDWR | O_NOCTTY | O_NDELAY | O_NONBLOCK ); + if (-1 == fd) { + sprintf( tBuffer, "Cannot open '%s': %d, %s\\n", dev_name, errno, strerror(errno)); + LOG_ERROR( tBuffer ); + continue; + } else { + if (-1 == xioctl(fd, TIOCGSERIAL, &ss)){ + LOG_ERROR("TIOCGSERIAL"); + } else { + sprintf( tBuffer, "Serial Port[Port:0x%X IRQ:%d BB:%d Line:%d Type:%d Flags:%X]", + ss.port, + ss.irq, + ss.baud_base, + ss.line, + ss.type, + ss.flags + ); + LOG( tBuffer ); + char comName[16]; + int pn = atoi( pDR->d_name+4) + 1; + sprintf( comName,"USB-COM%d", pn ); + uint32_t dbid = m_pDBC->addNodeSocket( m_nServerNodeID, m_nServerID, ARGUS_NODE_SOCK_TYPE_SERIAL_PORT, ARGUS_NODE_SOCK_MODE_INOUT, true, dev_name, comName ); + if( dbid == 0 ) { + // Socket Allredy in DB - was just updated + dbid = m_pDBC->getNodeSocketID( m_nServerNodeID, m_nServerID, ARGUS_NODE_SOCK_TYPE_SERIAL_PORT, dev_name ); + }; + if( dbid ) { + // Creating Ressource!! + argusHardwareUART *tResource; + tResource = new argusHardwareUART( dbid ); + if( tResource!= NULL ) { + if( tResource->create() ) { + m_vResources.push_back( (argusHardwareResource*) tResource ); + }; + }; + } else LOG_ERROR("Failure to fetch Socket ID!"); + }; + close(fd); + continue; + }; + continue; + }; + }; + closedir( dFD ); + }; +}; + +#undef CLEAR +#undef LOG +#undef LOG_ERROR diff --git a/lib/rgoose/rgooseHardwareManager.h b/lib/rgoose/rgooseHardwareManager.h new file mode 100644 index 00000000..1c66f473 --- /dev/null +++ b/lib/rgoose/rgooseHardwareManager.h @@ -0,0 +1,33 @@ +#ifndef __ARGOOSE_HARDWARE_MANAGER_HEADER__ +#define __ARGOOSE_HARDWARE_MANAGER_HEADER__ + +#include "../components/base/basicLogCollection.h" +#include "rgooseHardwareResource.h" + +class argusKernel; +class argusDBC; + +class argusHardwareManager{ + private: + argusKernel * m_pKernel; + argusDBC * m_pDBC; + basicLogCollection * m_pLog; + VECTOR_HW_RESOURCES m_vResources; + bool m_bHardwareEnumerated; + void loadResources( void ); + void enumerateHardware( void ); + public: + virtual ~argusHardwareManager(); + static argusHardwareManager * getInstance( void ); + void validate( void ); + argusHardwareResource * getUart( uint32_t SocketId ); + private: + static argusHardwareManager * _instance; + argusHardwareManager(); + +}; + + + +#endif + diff --git a/lib/rgoose/rgooseHardwareResource.cpp b/lib/rgoose/rgooseHardwareResource.cpp new file mode 100644 index 00000000..cb1d9b1e --- /dev/null +++ b/lib/rgoose/rgooseHardwareResource.cpp @@ -0,0 +1,47 @@ +#include "rgooseHardwareResource.h" + +#define LOG( X ) m_pLog->Log( "HWR", 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 );\ + m_pLog->Log( "HWR", this, _LOG_ERROR, _tBfrErrMSG2w34 );\ + } +#else + #define LOG_ERROR( X ) m_pLog->Log( "HWR", this, _LOG_ERROR, X ); +#endif + +argusHardwareResource::argusHardwareResource( uint32_t id, ARGUS_HARDWARE_TYPE type ): basicObject(){ + m_pDBC = argusDBC::getInstance(); + m_pLog = basicLogCollection::getInstance(); + if( id > 0 ){ + if( m_pDBC!=NULL ){ + DBC_SOCKET_DATA *tData = m_pDBC->getSocketData( id ); + if( tData != NULL ) { + memcpy( &m_sSettings, tData, sizeof(DBC_SOCKET_DATA)); + free( tData ); + } else { + LOG_ERROR("Cannot Fetch Hardware Data from DB!"); + memset( &m_sSettings, 0, sizeof( DBC_SOCKET_DATA )); + m_sSettings.socket_id = id; + m_sSettings.type = type; + }; + } else { + memset( &m_sSettings, 0, sizeof( DBC_SOCKET_DATA )); + m_sSettings.socket_id = id; + m_sSettings.type = type; + }; + } else { + memset( &m_sSettings, 0, sizeof( DBC_SOCKET_DATA )); + m_sSettings.socket_id = id; + m_sSettings.type = type; + }; +}; + +argusHardwareResource::~argusHardwareResource(){ +}; + +#undef LOG +#undef LOG_ERROR + diff --git a/lib/rgoose/rgooseHardwareResource.h b/lib/rgoose/rgooseHardwareResource.h new file mode 100644 index 00000000..6a450f6b --- /dev/null +++ b/lib/rgoose/rgooseHardwareResource.h @@ -0,0 +1,36 @@ +#ifndef __ARGUS_HARDWARE_RESOURCE_HEADER__ +#define __ARGUS_HARDWARE_RESOURCE_HEADER__ + +#include "../components/base/basicObject.h" +#include "../components/base/basicLogCollection.h" +#include "rgooseDBConnector.h" +#include + +typedef enum E_ARGUS_HARDWARE_TYPE{ + HARDWARE_UNKNOWN = 0, + HARDWARE_UART = 1, + HARDWARE_NETWORK = 2, + HARDWARE_VIDEO_IN = 3, + HARDWARE_IP_UART = 4, + HARDWARE_IP_VIDEO = 5 +} ARGUS_HARDWARE_TYPE; + +class argusHardwareResource: public basicObject{ + private: + protected: + DBC_SOCKET_DATA m_sSettings; + basicLogCollection * m_pLog; + argusDBC * m_pDBC; + public: + explicit argusHardwareResource( uint32_t id, ARGUS_HARDWARE_TYPE type = HARDWARE_UNKNOWN ); + virtual ~argusHardwareResource(); + virtual bool create( void ){ return false; }; + uint32_t getDbId( void ){ return m_sSettings.socket_id; }; + ARGUS_HARDWARE_TYPE getType( void ){ return (ARGUS_HARDWARE_TYPE) m_sSettings.type; }; +}; + + +typedef std::vector VECTOR_HW_RESOURCES; + +#endif + diff --git a/lib/rgoose/rgooseHardwareResourceIpUART.h b/lib/rgoose/rgooseHardwareResourceIpUART.h new file mode 100644 index 00000000..e69de29b diff --git a/lib/rgoose/rgooseHardwareResourceIpVideoIn.h b/lib/rgoose/rgooseHardwareResourceIpVideoIn.h new file mode 100644 index 00000000..e69de29b diff --git a/lib/rgoose/rgooseHardwareResourceNetwork.cpp b/lib/rgoose/rgooseHardwareResourceNetwork.cpp new file mode 100644 index 00000000..ce1fee35 --- /dev/null +++ b/lib/rgoose/rgooseHardwareResourceNetwork.cpp @@ -0,0 +1,25 @@ +#include "rgooseHardwareResourceNetwork.h" + +#define LOG( X ) m_pLog->Log( "HW_NET", 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 );\ + m_pLog->Log( "HW_NET", this, _LOG_ERROR, _tBfrErrMSG2w34 );\ + } +#else + #define LOG_ERROR( X ) m_pLog->Log( "HW_NET", this, _LOG_ERROR, X ); +#endif + +argusHardwareResourceNetwork::argusHardwareResourceNetwork( uint32_t id ):argusHardwareResource( id, HARDWARE_NETWORK ){ + +}; + +argusHardwareResourceNetwork::~argusHardwareResourceNetwork(){ + +}; + +#undef LOG +#undef LOG_ERROR + diff --git a/lib/rgoose/rgooseHardwareResourceNetwork.h b/lib/rgoose/rgooseHardwareResourceNetwork.h new file mode 100644 index 00000000..f2a3c48e --- /dev/null +++ b/lib/rgoose/rgooseHardwareResourceNetwork.h @@ -0,0 +1,12 @@ +#ifndef __ARGUS_HARDWARE_RESOURCE_NETWORK_HEADER__ +#define __ARGUS_HARDWARE_RESOURCE_NETWORK_HEADER__ + +#include "rgooseHardwareResource.h" + +class argusHardwareResourceNetwork: public argusHardwareResource { + public: + explicit argusHardwareResourceNetwork( uint32_t id ); + virtual ~argusHardwareResourceNetwork(); +}; + +#endif diff --git a/lib/rgoose/rgooseHardwareResourceUART.cpp b/lib/rgoose/rgooseHardwareResourceUART.cpp new file mode 100644 index 00000000..b9129466 --- /dev/null +++ b/lib/rgoose/rgooseHardwareResourceUART.cpp @@ -0,0 +1,25 @@ +#include "rgooseHardwareResourceUART.h" + +#define LOG( X ) m_pLog->Log( "HW_UART", 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 );\ + m_pLog->Log( "HW_UART", this, _LOG_ERROR, _tBfrErrMSG2w34 );\ + } +#else + #define LOG_ERROR( X ) m_pLog->Log( "HW_UART", this, _LOG_ERROR, X ); +#endif + +argusHardwareResourceUART::argusHardwareResourceUART( uint32_t id ):argusHardwareResource(id, HARDWARE_UART ){ + +}; + +argusHardwareResourceUART::~argusHardwareResourceUART(){ + +}; + +#undef LOG +#undef LOG_ERROR + diff --git a/lib/rgoose/rgooseHardwareResourceUART.h b/lib/rgoose/rgooseHardwareResourceUART.h new file mode 100644 index 00000000..3f97e2f2 --- /dev/null +++ b/lib/rgoose/rgooseHardwareResourceUART.h @@ -0,0 +1,12 @@ +#ifndef __ARGUS_HARDWARE_RESOURCE_UART_HEADER__ +#define __ARGUS_HARDWARE_RESOURCE_UART_HEADER__ + +#include "rgooseHardwareResource.h" + +class argusHardwareResourceUART: public argusHardwareResource { + public: + explicit argusHardwareResourceUART( uint32_t id ); + virtual ~argusHardwareResourceUART(); +}; + +#endif diff --git a/lib/rgoose/rgooseHardwareResourceVideoIn.h b/lib/rgoose/rgooseHardwareResourceVideoIn.h new file mode 100644 index 00000000..e69de29b diff --git a/lib/rgoose/rgooseHardwareUART.cpp b/lib/rgoose/rgooseHardwareUART.cpp new file mode 100644 index 00000000..6654d89e --- /dev/null +++ b/lib/rgoose/rgooseHardwareUART.cpp @@ -0,0 +1,36 @@ +#include "rgooseHardwareUART.h" + +#define LOG( X ) argusHardwareResource::m_pLog->Log( "HUART", 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 );\ + argusHardwareResource::m_pLog->Log( "HUART", this, _LOG_ERROR, _tBfrErrMSG2w34 );\ + } +#else + #define LOG_ERROR( X ) argusHardwareResource::m_pLog->Log( "HUART", this, _LOG_ERROR, X ); +#endif + +argusHardwareUART::argusHardwareUART( uint32_t dbID ) : serialPort(), argusHardwareResource( dbID, HARDWARE_UART ){ + memset( &settingsUART, 0, sizeof(DBC_UART_DATA)); +}; + +argusHardwareUART::~argusHardwareUART(){ +}; + +bool argusHardwareUART::create( void ){ + DBC_UART_DATA *tDATA = NULL; + tDATA = m_pDBC->getSettingsUART( m_sSettings.socket_id ); + if( tDATA!= NULL ) { + memcpy( &settingsUART, tDATA, sizeof(DBC_UART_DATA)); + free( tDATA ); + LOG(settingsUART.device); + return serialPort::create( settingsUART.device, settingsUART.speed ); + }; + return false; +}; + +#undef LOG +#undef LOG_ERROR + diff --git a/lib/rgoose/rgooseHardwareUART.h b/lib/rgoose/rgooseHardwareUART.h new file mode 100644 index 00000000..d0055c91 --- /dev/null +++ b/lib/rgoose/rgooseHardwareUART.h @@ -0,0 +1,17 @@ +#ifndef __ARGUS_HARDWARE_UART_HEADER__ +#define __ARGUS_HARDWARE_UART_HEADER__ + +#include "../hardware/uart/serialPort.h" +#include "rgooseHardwareResource.h" + +class argusHardwareUART: public serialPort, argusHardwareResource { + private: + DBC_UART_DATA settingsUART; + public: + explicit argusHardwareUART( uint32_t dbID ); + virtual ~argusHardwareUART(); + virtual bool create( void ); +}; + +#endif + diff --git a/lib/rgoose/rgooseIPCamera.cpp b/lib/rgoose/rgooseIPCamera.cpp index 7e09d8c8..ff77cf76 100644 --- a/lib/rgoose/rgooseIPCamera.cpp +++ b/lib/rgoose/rgooseIPCamera.cpp @@ -3,7 +3,7 @@ #define LOG( X ) m_pLog->Log( "ARGUS_IPCAM", this, X ) #define LOG_ERROR( X ) m_pLog->Log( "ARGUS_IPCAM", this, _LOG_ERROR, X ) -ARGUS_IPCAM::ARGUS_IPCAM( ARGUS_DBC *DBC, int id ): ARGUS_Camera( DBC, id ), basicThread(){ +ARGUS_IPCAM::ARGUS_IPCAM( uint32_t id ): ARGUS_Camera( id ), basicThread(){ m_pLog = basicLogCollection::getInstance(); m_pOnVif = NULL; m_pPosition = NULL; diff --git a/lib/rgoose/rgooseIPCamera.h b/lib/rgoose/rgooseIPCamera.h index ef4f68c7..dde75e49 100644 --- a/lib/rgoose/rgooseIPCamera.h +++ b/lib/rgoose/rgooseIPCamera.h @@ -42,7 +42,7 @@ class ARGUS_IPCAM: public ARGUS_Camera, public basicThread{ protected: void m_fThreadProc( void ); public: - explicit ARGUS_IPCAM( ARGUS_DBC *DBC, int id ); + explicit ARGUS_IPCAM( uint32_t id ); ~ARGUS_IPCAM(); bool create( CSTR ip, CSTR username, CSTR password ); virtual void dispatchEvent( basicEvent *Evt ); diff --git a/lib/rgoose/rgooseKafkaModule.cpp b/lib/rgoose/rgooseKafkaModule.cpp index 09a74be6..d0bfb56a 100644 --- a/lib/rgoose/rgooseKafkaModule.cpp +++ b/lib/rgoose/rgooseKafkaModule.cpp @@ -1,18 +1,19 @@ #include "rgooseKafkaModule.h" +#include "../hardware/soc/general/3DLRF.h" -#define LOG( X ) argusKernelModule::m_pLog->Log( "AKM", this, X ) +#define LOG( X ) argusKernelModule::m_pLog->Log( "KM", 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 );\ - argusKernelModule::m_pLog->Log( "AKM", this, _LOG_ERROR, _tBfrErrMSG2w34 );\ + argusKernelModule::m_pLog->Log( "KM", this, _LOG_ERROR, _tBfrErrMSG2w34 );\ } #else - #define LOG_ERROR( X ) argusKernelModule::m_pLog->Log( "AKM", this, _LOG_ERROR, X ); + #define LOG_ERROR( X ) argusKernelModule::m_pLog->Log( "KM", this, _LOG_ERROR, X ); #endif -argusKafkaModule::argusKafkaModule( uint32_t ModuleID, ARGUS_DBC *DBC ): argusKernelModule( ModuleID, ARGUS_MODULE_KAFKA, DBC ){ +argusKafkaModule::argusKafkaModule( uint32_t ModuleID ): argusKernelModule( ModuleID, ARGUS_MODULE_KAFKA ){ m_pProtocol = NULL; /* if( DBC != NULL ) { @@ -41,7 +42,7 @@ void argusKafkaModule::m_fThreadProc( void ){ while( m_bThreadStatus < TH_ENDED ) { m_llTicks ++;//= getMilliseconds(); if( m_llTicks % 20 == 0 ) { // each 2 seconds - StatusUpdate(); + m_pProtocol->StatusUpdate(); //m_lCycleCounter == 0; }; /* No need for time Sync @@ -67,6 +68,7 @@ bool argusKafkaModule::startService(){ }; bool argusKafkaModule::stopService(){ + return true; }; bool argusKafkaModule::reloadSettings(){ @@ -96,10 +98,11 @@ void argusKafkaModule::dispatchEvent( basicEvent *Evt ){ if( !m_bEvtFlags[ Evt->m_eType ] ) return; // Hadle Event switch( Evt->m_eType ) { - case EVT_TARGET_WHITE: - case EVT_TARGET_BLACK: - case EVT_TARGET: - case EVT_ALARM:{ + case EVT_TARGET_1D: + case EVT_TARGET_2D_WHITE: + case EVT_TARGET_2D_BLACK: + case EVT_TARGET_3D_WHITE: + case EVT_TARGET_3D_BLACK:{ CLIENT_EVENT *tCEVT; tCEVT = (CLIENT_EVENT *) Evt->m_pEvtData; if( tCEVT != NULL ){ @@ -111,18 +114,18 @@ void argusKafkaModule::dispatchEvent( basicEvent *Evt ){ #else make3Ddeg( tCEVT->th_id, Az, El, true ); #endif - Alarm3D( (int)Az, (int)El, cRange , tCEVT->k_id ); + m_pProtocol->Alarm3D( (int)Az, (int)El, cRange , tCEVT->k_id ); }; }; break; case EVT_ERROR: - SetStatus( false ); + m_pProtocol->SetStatus( false ); break; case EVT_SCAN: //StatusUpdate(); //break; case EVT_FLIP: - SetStatus( true ); + m_pProtocol->SetStatus( true ); //StatusUpdate(); break; case EVT_COMMAND: diff --git a/lib/rgoose/rgooseKafkaModule.h b/lib/rgoose/rgooseKafkaModule.h index 9da07d9c..428cea77 100644 --- a/lib/rgoose/rgooseKafkaModule.h +++ b/lib/rgoose/rgooseKafkaModule.h @@ -10,10 +10,11 @@ class argusKafkaModule: public basicThread, argusKernelModule { private: KAFKA_SETTINGS *m_pSettings; protocolKAFKA *m_pProtocol; + unsigned long long m_llTicks; protected: virtual void m_fThreadProc( void ); public: - explicit argusKafkaModule( uint32_t ModuleID, ARGUS_DBC *DBC ); + explicit argusKafkaModule( uint32_t ModuleID ); virtual ~argusKafkaModule(); virtual bool reloadSettings(); diff --git a/lib/rgoose/rgooseKernel.cpp b/lib/rgoose/rgooseKernel.cpp new file mode 100644 index 00000000..ce1bc16a --- /dev/null +++ b/lib/rgoose/rgooseKernel.cpp @@ -0,0 +1,430 @@ +/******************************************************************* +* +* DESCRIPTION: ARGUS Kernel source +* +* AUTHOR: gagua +* +* HISTORY: +* +* DATE:5/29/2019 +* +*******************************************************************/ +#include "rgooseKernel.h" +#include + +#define LOG( X ) m_pLog->Log( "KRNL", 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 );\ + m_pLog->Log( "KRNL", this, _LOG_ERROR, _tBfrErrMSG2w34 );\ + } +#else + #define LOG_ERROR( X ) m_pLog->Log( "KRNL", this, _LOG_ERROR, X ); +#endif + +argusKernel *argusKernel::_instance = NULL; + +/** + * Returns the single instance of the object. + */ +argusKernel* argusKernel::getInstance( config_setting_t *Settings ) { + // check if the instance has been created yet + if( 0 == _instance ){ + // if not, then create it + _instance = new argusKernel( Settings ); + }; + // return the single instance + return _instance; +}; + +argusKernel::argusKernel( config_setting_t *Settings ):basicThread(){ + m_bExitCause = 0; + m_nServerID = 0; + m_nSiteID = 0; + m_pDBC = NULL; + m_tTimeTSeconds = time( NULL ); + m_pLog = basicLogCollection::getInstance(); + m_pSettings = basicSettingsProvider::getInstance()->getSubNode( Settings, "KERNEL" ); + m_pServiceAnnouncer = NULL; + m_pEventHeap = NULL; + m_pOnvifMediaObserver = NULL; + m_pNodeFactory = NULL; + m_pModuleFactory = NULL; +}; + +argusKernel::~argusKernel(){ +#ifdef DEBUG + LOG("Destructor"); +#endif + WaitFinish(true); + if( m_pDBC != NULL ) m_pDBC->unregisterServer( m_nSiteID, m_nServerNodeID ); +#ifdef DEBUG + LOG("Deleting Components"); +#endif + if( m_pStreamManager != NULL ) delete( m_pStreamManager ); + + //Last DBC + if( m_pDBC != NULL ) delete( m_pDBC ); +#ifdef DEBUG + LOG("Destructor Finished"); +#endif +}; + +bool argusKernel::create( void ){ + char tBuffer[256]; + if( m_pSettings != NULL ) { + config_setting_t * pSetting; + int tVal; + const char * tBuf; + //Connect( CSTR DBName, CSTR DBHost, CSTR DBUser, CSTR DBPassword, uint16_t Port = 3300 ); + LOG("Getting Settings ..."); + if( !config_setting_lookup_string( m_pSettings, ARGUS_KERNEL_TAG_SERVER_IDENTITY, &tBuf ) ){ + char * tVar; + char * tTS; + tTS = getTStr(NULL); + tVar = MD5String(tTS); + free(tTS); + sprintf( m_sIdentity, tVar ); + pSetting = config_setting_add( m_pSettings, ARGUS_KERNEL_TAG_SERVER_IDENTITY, CONFIG_TYPE_STRING ); + config_setting_set_string( pSetting, tVar ); + free( tVar ); + basicSettingsProvider::getInstance()->compromise(); + LOG("Server Identity not defined - generating new!"); + } else { + sprintf( m_sIdentity, tBuf ); + sprintf( tBuffer, "Server Identity Read From Settings: %s", tBuf ); + LOG( tBuffer ); + }; + if( !config_setting_lookup_int( m_pSettings, ARGUS_KERNEL_TAG_SITE_ID, &tVal ) ){ + tVal = m_nSiteID = 1; + pSetting = config_setting_add( m_pSettings, ARGUS_KERNEL_TAG_SITE_ID, CONFIG_TYPE_INT ); + config_setting_set_int( pSetting, tVal ); + basicSettingsProvider::getInstance()->compromise(); + LOG("Site ID not defined - using [1] as number!"); + } else { + m_nSiteID = tVal; + sprintf( tBuffer, "Site ID Read From Settings: %d", m_nSiteID ); + LOG( tBuffer ); + }; + } else { + LOG_ERROR("Failed Read Config Settings!"); + return false; + }; + + if( m_pDBC == NULL ) { + LOG("Explicitly Create DBC Object"); + m_pDBC = argusDBC::getInstance( m_pSettings ); + }; + if( m_pDBC == NULL ){ + LOG_ERROR("DBC Object Creation Failure!"); + return false; + }; + if(!m_pDBC->connect()){ + LOG_ERROR("DBC Connection Failure!"); + SLEEP(5000); + //ToDO: Set Restart Kernel! + return false; + }; +#ifdef DEBUG + LOG( "Settings Read Done" ); +#endif + m_pDBC->registerServer( m_nSiteID, m_sIdentity ); + m_nServerID = m_pDBC->getServerID( m_sIdentity ); + m_nServerNodeID = m_pDBC->getServerNode( m_nServerID ); + + //Init Subcomponents + m_pHardwareManager = argusHardwareManager::getInstance(); + if( m_pHardwareManager!= NULL ) { + m_pHardwareManager->validate(); + } else { + LOG_ERROR("Failure to get HardwareManager Instance!"); + return false; + }; + m_pServiceAnnouncer = new ssdpAnnouncer( m_pSettings ); + if( basicSettingsProvider::getInstance()->isCompromised() ) { + basicSettingsProvider::getInstance()->validate(); + }; + + m_pEventHeap = basicEventHeap::getInstance(); + + m_pOnvifMediaObserver = onvifMediaObserver::getInstance(); + + m_pNodeFactory = argusNodeFactory::getInstance(); + + m_pModuleFactory = argusModuleFactory::getInstance(); + + //enumerateHardware(); + + + //m_pNodeFactory->setDBC( m_pDBC ); + m_pNodeFactory->loadNodes( m_nSiteID ); + + //m_pModuleFactory->setDBC( m_pDBC ); //m_pDBC->getIPCamRecords( m_vCamRecords ); + m_pModuleFactory->loadModules( m_nSiteID ); + +#ifdef DEBUG + LOG( "Start SSDP Beacon" ); +#endif + + if( m_pServiceAnnouncer != NULL ) { + if( !m_pServiceAnnouncer->init() ){ + delete(m_pServiceAnnouncer); + m_pServiceAnnouncer = NULL; + }; + }; + + m_pStreamManager = NULL;//mediaNginxManager::getInstance(); + //if( m_pStreamManager != NULL ) { + // m_pStreamManager->attachStream("rtsp://gagua:4GetMyID@192.168.0.104:554/Streaming/Channels/101?transportmode=unicast&profile=Profile_1", true, 12, "12918" ); + //}; +/* +#ifdef DEBUG + LOG("Init IP Cameras"); +#endif + if( m_vCamRecords.size() ) { + ARGUS_Camera *tPtr = NULL; + for( int i=0; i < m_vCamRecords.size(); i++ ) { + tPtr = new ARGUS_Camera(); + if( tPtr != NULL ) { + if( tPtr->create( m_vCamRecords.at(i)->ip, m_vCamRecords.at(i)->username, m_vCamRecords.at(i)->password ) ){ +#ifdef DEBUG + LOG("Camera Created!"); +#endif + m_vCameras.push_back( tPtr ); + tPtr = NULL; + } else { + LOG_ERROR("Camera Creation Failure!"); + delete( tPtr ); + tPtr = NULL; + }; + }; + }; + }; + */ + +#ifdef DEBUG + LOG("Start OnVIF Discovery"); +#endif + if( m_pOnvifMediaObserver!= NULL ) { + m_pOnvifMediaObserver->startDiscovery(); + m_bDiscoveryStarted = true; + }; + +#ifdef DEBUG + LOG( "Kernel Trhead is about to be Created" ); +#endif + if( init() == false ){ + LOG_ERROR("Error in starting Kernel Thread!"); + return false; + }; +#ifdef DEBUG + LOG( "Kernel Thread Created" ); +#endif +/* + m_pServletWS = new servletWS(); + if( m_pServletWS != NULL ) { + LOG("ServletWS Created"); + if(m_pServletWS->create(8080)){ + LOG("ServletWS Started"); + //if( ! m_pServletWS->attachChannel("rtsp://gagua:4GetMyID@192.168.0.109:554/Streaming/Channels/101?transportmode=unicast&profile=Profile_1", false ) ){ + // LOG("Error Adding Channel!"); + //} else { + // LOG("Channel Attached"); + //}; + }; + }; + */ +#ifdef DEBUG + sprintf( tBuffer, "Server is registered as id[%d]", m_nServerID ); + LOG( tBuffer ); +#endif + return true; +}; + +void argusKernel::WaitFinish( bool Force ){ + if( Force ){ +#ifdef DEBUG + LOG( "Thread End Forced" ); +#endif + } else { + // 3 seconds sleep to settle down processes + SLEEP(3000); + }; + waitThreadEnd( Force ); +#ifdef DEBUG + LOG( "Thread is Detached" ); +#endif +}; + +/* Main Kernel Thread Procedure */ +void argusKernel::m_fThreadProc( void ){ + char Buffer[CTEXT]; + time_t tTimeTSeconds; + int lastTSS = 0; + int lastTMS = 0; + EventRecordDBC * tEvtPtr; + pid_t pid = gettid(); + char pidBuf[16]; + sprintf(pidBuf,"pid:%d", pid); + LOG(pidBuf); + m_bThreadStatus = TH_WORKING; + while( m_bThreadStatus < TH_ENDED ){ + m_tTimeTSeconds = time( NULL ); + + // Network IP OnVif Discovery +//* + if( m_pOnvifMediaObserver!= NULL ){ + if( !m_bDiscoveryStarted ) { + if((m_tTimeTSeconds%ONVIF_DISCOVERY_INTERVAL)==0){ +#ifdef DEBUG + LOG("Start OnVIF Discovery"); +#endif + m_pOnvifMediaObserver->startDiscovery(); + m_bDiscoveryStarted = true; + }; + } else { + //* + if((m_tTimeTSeconds%ONVIF_DISCOVERY_INTERVAL)==ONVIF_DISCOVERY_RESULT_TIME){ +#ifdef DEBUG + LOG("Validate IP Cameras"); +#endif + validateCameras(); + m_bDiscoveryStarted = false; + }; + //*/ + }; + }; +//*/ +//* + // Event Processing Loop + if( !m_pDBC->getLastEvents( m_vEvtRecords, lastTSS, lastTMS ) ){ + // Error In DB Access + m_bThreadStatus = TH_ENDED; + m_bExitCause = 1; + continue; + }; + +/* if( m_vEvtRecords.size() > 0 ){ + validateEvents( lastTSS, lastTMS ); + }; + */ + +//*/ + if( m_tTimeTSeconds != tTimeTSeconds ){ // Each Second Process + tTimeTSeconds = m_tTimeTSeconds; + if( m_pModuleFactory != NULL ) { + m_pModuleFactory->validate(); + }; + //if( m_pNodeFactory != NULL ) { + //m_pNodeFactory->validate(); + //}; + }; + SLEEP( SLEEP_KERNEL_INTERVAL ); + }; +}; + + +int argusKernel::isCameraListed( CSTR uid ){ + if( m_vCamRecords.size() ){ + for( int index = 0; index < m_vCamRecords.size(); index++ ){ + if(strstr(m_vCamRecords.at(index)->uuid,uid)!=NULL){ + m_vCamRecords.at(index)->online = true; + return index; + }; + }; + } else { + LOG("No Registered Cameras!"); + }; + return -1; +}; + +void argusKernel::validateCameras( void ){ + vectorWoWoResults *DiscoverResults = m_pOnvifMediaObserver->getResults(); + if( DiscoverResults->size() > 0 ) { + for (int index = 0; index < DiscoverResults->size(); index++) { + char tBuffer[256]; + sprintf( tBuffer,"Found Camwera [%s] %s", DiscoverResults->at(index)->XAddrs, DiscoverResults->at(index)->RefID ); + LOG( tBuffer ); + uint32_t cid = m_pDBC->getCamId( DiscoverResults->at(index)->RefID ); //isCameraListed( DiscoverResults->at(index)->RefID ); + if( cid ) { + sprintf( tBuffer, "Camera is Listed as %d", cid ); + LOG( tBuffer ); + //if( strstr(DiscoverResults->at(index)->XAddrs,m_vCamRecords.at(cid)->ip)==NULL ) { + // LOG( DiscoverResults->at(index)->XAddrs ); + m_pDBC->updateIPCam( m_nSiteID, cid, DiscoverResults->at(index)->XAddrs );// DiscoverResults->at(index)); + //}; + } else { + // Uncknown camera - no checking + LOG("Camera is Not Listed"); + m_pDBC->addIPCam( m_nSiteID, DiscoverResults->at(index) ); + }; + }; + } else { + LOG("No Online IP Cameras in Network"); + }; +}; +/* +void ARGUS_Kernel::validateEvents( int &lastTSS, int &lastTMS ){ + EventRecordDBC *tPtr = NULL; + basicEvent *tEvt = NULL; + if(m_vEvtRecords.size()) { + lastTSS = m_vEvtRecords.at(m_vEvtRecords.size()-1)->ts_s; + lastTMS = m_vEvtRecords.at(m_vEvtRecords.size()-1)->ts_ms; +#ifndef ONE_EVENT_PER_LOOP + while(m_vEvtRecords.size()) { +#endif + tPtr = *m_vEvtRecords.begin(); + if( tPtr != NULL ) { + if( tEvt != NULL ) { + m_pEventHeap->broadcast( tEvt ); + //free( tEvt ); + }; + free( tPtr ); + }; + m_vEvtRecords.erase(m_vEvtRecords.begin()); +#ifndef ONE_EVENT_PER_LOOP + }; +#endif + }; +}; +*/ + +bool argusKernel::signalEvent( void ){ + if( m_pDBC->getLastEvents( m_vEvtRecords, 0,0 ) ){ + + + + }; + return true; +}; + +int argusKernel::getNetNodes( ARGUS_NODE_TYPE type, argusNetNode **&RA ){ + RA = NULL; + int cnt = 0; + if( m_pNodeFactory != NULL ){ + cnt = m_pNodeFactory->getNodeCount( type ); + if( cnt ) { + RA = (argusNetNode **) calloc( cnt, sizeof( argusNetNode * ) ); + m_pNodeFactory->fetchNodes(type, RA ); + }; + }; + return cnt; +}; + +argusNetNode *argusKernel::getNetNode( int id ){ + return NULL; +}; + +int argusKernel::getModules( ARGUS_MODULE_TYPE type, argusKernelModule **&RA ){ + return 0; +}; + +argusKernelModule *argusKernel::getModule( int id ){ + return NULL; +}; + +#undef LOG +#undef LOG_ERROR + diff --git a/lib/rgoose/rgooseKernel.h b/lib/rgoose/rgooseKernel.h new file mode 100644 index 00000000..c6dc60a7 --- /dev/null +++ b/lib/rgoose/rgooseKernel.h @@ -0,0 +1,135 @@ +/******************************************************************* +* +* DESCRIPTION: ARGUS Kernel Header File +* +* AUTHOR: gagua +* +* HISTORY: +* +* DATE:5/29/2019 +* +*******************************************************************/ +#ifndef __ARGUS_KERNEL_HEADER__ +#define __ARGUS_KERNEL_HEADER__ + +#include +#include + +#include +#include +#include +#include + +#include /* getopt_long() */ + +#include /* low-level i/o */ +#include +#include +#include +#include +#include +#include +#include + +#include +#include + +struct serial_struct { + int type; + int line; + unsigned int port; + int irq; + int flags; + int xmit_fifo_size; + int custom_divisor; + int baud_base; + unsigned short close_delay; + char io_type; + char reserved_char[1]; + int hub6; + unsigned short closing_wait; /* time to wait before closing */ + unsigned short closing_wait2; /* no longer used... */ + unsigned char *iomem_base; + unsigned short iomem_reg_shift; + unsigned int port_high; + unsigned long iomap_base; /* cookie passed into ioremap */ +}; + +#include "../alg/generic/md5.h" +#include "../components/base/basicThread.h" +#include "../components/base/basicEngine.h" +#include "../components/base/basicSettingsProvider.h" +#include "../data/ponvif/ponvif.h" +#include "../data/protocol/onvifMediaObserver.h" +#include "../data/ssdp/ssdpAnnouncer.h" +#include "../data/NginxMediaServer/mediaNginxStreamingProxyManager.h" +#include "../components/base/basicEventHeap.h" +#include "rgooseDBConnector.h" +#include "rgooseIPCamera.h" +#include "rgooseNodeFactory.h" +#include "rgooseModuleFactory.h" +#include "rgooseHardwareManager.h" +#include "../data/net/netServer.h" +#include "../data/servletWS/servletWS.h" + +#define SLEEP_KERNEL_INTERVAL 10 +#define ONVIF_DISCOVERY_INTERVAL 300 // 5 min +#define ONVIF_DISCOVERY_RESULT_TIME 5 + +#define ARGUS_KERNEL_TAG_SITE_ID "SITE_ID" +#define ARGUS_KERNEL_TAG_SERVER_IDENTITY "IDENTITY" + +class argusKernel: public basicThread { + private: + uint32_t m_nSiteID; + uint32_t m_nServerID; + uint32_t m_nServerNodeID; + char m_sIdentity[33]; + time_t m_tTimeTSeconds; + basicLogCollection * m_pLog; + basicEventHeap * m_pEventHeap; + config_setting_t * m_pSettings; + ssdpAnnouncer * m_pServiceAnnouncer; + uint8_t m_bExitCause; + argusDBC * m_pDBC; + networkServer * m_pNetClientsServer; + onvifMediaObserver * m_pOnvifMediaObserver; + bool m_bDiscoveryStarted; + vectorARGUS_Cameras m_vCameras; + vectorCamRecords m_vCamRecords; + vectorEventRecords m_vEvtRecords; + argusNodeFactory * m_pNodeFactory; + argusModuleFactory * m_pModuleFactory; + mediaNginxManager * m_pStreamManager; + argusHardwareManager * m_pHardwareManager; + //servletWS * m_pServletWS; + int isCameraListed( CSTR uid ); + void validateCameras( void ); + //void validateEvents( int &lastTSS, int &lastTMS ); + //void enumerateHardware( void ); + protected: + void m_fThreadProc( void ); + public: + static argusKernel * getInstance( config_setting_t *Settings = NULL ); + // Destructor + virtual ~argusKernel(); + bool create( void ); + bool signalEvent( void ); + void WaitFinish( bool Force = false ); + uint8_t getExitCause( void ){ return m_bExitCause;}; + int getNetNodes( ARGUS_NODE_TYPE type, argusNetNode **&RA ); + argusNetNode * getNetNode( int id ); + int getModules( ARGUS_MODULE_TYPE type, argusKernelModule **&RA ); + argusKernelModule * getModule( int id ); + uint32_t getSiteId( void ){ return m_nSiteID; }; + uint32_t getServerId( void ){ return m_nServerID; }; + uint32_t getServerNodeId( void ){ return m_nServerNodeID; }; + CSTR getServerIdentity( void ){ return (CSTR)m_sIdentity; }; // NOTE: DON't FREE THIS MEMORY!!! + private: + static argusKernel * _instance; + // Constructor + explicit argusKernel( config_setting_t *Settings = NULL ); +}; + + +#endif diff --git a/lib/rgoose/rgooseModule.cpp b/lib/rgoose/rgooseModule.cpp index 98961a4e..e1ed0c50 100644 --- a/lib/rgoose/rgooseModule.cpp +++ b/lib/rgoose/rgooseModule.cpp @@ -1,8 +1,10 @@ #include "rgooseModule.h" +#include "rgooseKernel.h" -argusKernelModule( int id, ARGUS_MODULE_TYPE param, ARGUS_DBC *DBC):basicObject(){ +argusKernelModule::argusKernelModule( uint32_t id, ARGUS_MODULE_TYPE param ):basicObject(){ m_pLog = basicLogCollection::getInstance(); - m_pDBC = DBC; + m_pDBC = argusDBC::getInstance(); + m_pKernel = argusKernel::getInstance(); m_eType = param; m_nDBID = id; m_bDetached = false; @@ -10,7 +12,7 @@ argusKernelModule( int id, ARGUS_MODULE_TYPE param, ARGUS_DBC *DBC):basicObject( for( int i = 0; i < MAX_EVENT_ID; i++ ) m_bEvtFlags[i] = false; }; -~argusKernelModule(){ +argusKernelModule::~argusKernelModule(){ }; diff --git a/lib/rgoose/rgooseModule.h b/lib/rgoose/rgooseModule.h index e107f754..7fc5c250 100644 --- a/lib/rgoose/rgooseModule.h +++ b/lib/rgoose/rgooseModule.h @@ -12,19 +12,23 @@ typedef enum E_ARGUS_MODULE_TYPE{ ARGUS_MODULE_ZLMEDIA = 1, ARGUS_MODULE_DCBUSB = 2, ARGUS_MODULE_KAFKA = 3, - ARGUS_MODULE_NETWORK = 4 + ARGUS_MODULE_GPS = 4, + ARGUS_MODULE_NETWORK = 5 }ARGUS_MODULE_TYPE; +class argusKernel; + class argusKernelModule: public basicEventHandler, basicObject{ protected: basicLogCollection * m_pLog; - ARGUS_DBC * m_pDBC; + argusDBC * m_pDBC; uint32_t m_nDBID; + argusKernel * m_pKernel; bool m_bDetached; bool m_bEvtFlags[MAX_EVENT_ID]; public: ARGUS_MODULE_TYPE m_eType; - explicit argusKernelModule( int id, ARGUS_MODULE_TYPE param = ARGUS_MODULE_UNKNOWN, ARGUS_DBC *DBC = NULL); + explicit argusKernelModule( uint32_t id, ARGUS_MODULE_TYPE param = ARGUS_MODULE_UNKNOWN ); virtual ~argusKernelModule(); uint32_t getId() const { return m_nDBID;}; ARGUS_MODULE_TYPE getType() const { return m_eType; }; @@ -33,10 +37,10 @@ class argusKernelModule: public basicEventHandler, basicObject{ virtual bool reloadSettings(){ return false; }; void setAttached( bool b=true ){ m_bDetached = !b; }; void setDetached( bool b=true ){ m_bDetached = b; }; - void setDBC( ARGUS_DBC *tPtr ){ m_pDBC = tPtr; m_bDetached = ! reloadSettings(); }; virtual bool startService(){ return false; }; virtual bool stopService(){ return true; }; virtual bool validate(){ return false; }; + virtual void dispatchEvent( basicEvent *Evt ){}; }; diff --git a/lib/rgoose/rgooseModuleFactory.cpp b/lib/rgoose/rgooseModuleFactory.cpp index 3d218511..a576e6e2 100644 --- a/lib/rgoose/rgooseModuleFactory.cpp +++ b/lib/rgoose/rgooseModuleFactory.cpp @@ -25,8 +25,7 @@ argusModuleFactory* argusModuleFactory::getInstance() { }; argusModuleFactory::argusModuleFactory(){ m_pLog = basicLogCollection::getInstance(); - m_pDBC = NULL; - + m_pDBC = argusDBC::getInstance(); }; argusModuleFactory::~argusModuleFactory(){ @@ -41,27 +40,28 @@ argusModuleFactory::~argusModuleFactory(){ }; }; -void argusModuleFactory::setDBC(ARGUS_DBC * tPtr){ - if( (m_pDBC == NULL) && (tPtr != NULL) ) m_pDBC = tPtr; -}; - bool argusModuleFactory::loadModules( uint32_t SiteID ){ if(m_pDBC == NULL) return false; m_nSiteID = SiteID; DBC_INT_LIST *tList = NULL; - LOG("QRY Modules from DB"); + LOG("Query Modules from DB"); tList = m_pDBC->listModules( SiteID ); if( tList != NULL ) { - LOG("Modules Fetched from DB"); - for(int index=0; index< tList->size(); index++) { - createModule( tList->at(index) ); + if( tList->size()>0 ) { + LOG("Modules Fetched from DB"); + for( int index=0; index< tList->size(); index++) { + createModule( tList->at(index) ); + }; + tList->clear(); + LOG("Modules Loadded"); + } else { + LOG("No Modules Defined"); }; - tList->clear(); delete( tList ); - LOG("Modules Loadded"); return true; + } else { + LOG_ERROR("Cannot Fetch Modules from DB!"); }; - LOG("No Modules Defined"); return false; }; @@ -78,7 +78,7 @@ argusKernelModule *argusModuleFactory::createModule( int id ){ #ifdef DEBUG LOG("Creating ZLMedia Connector Module"); #endif - tVal = new ARGUS_ZLMedia( tData->aux_id, m_pDBC ); + tVal = new ARGUS_ZLMedia( tData->aux_id ); break; case ARGUS_MODULE_DCBUSB: #ifdef DEBUG diff --git a/lib/rgoose/rgooseModuleFactory.h b/lib/rgoose/rgooseModuleFactory.h index bffd5435..817a97ce 100644 --- a/lib/rgoose/rgooseModuleFactory.h +++ b/lib/rgoose/rgooseModuleFactory.h @@ -9,7 +9,7 @@ typedef std::vector vectorKernelModules; class argusModuleFactory{ private: basicLogCollection * m_pLog; - ARGUS_DBC * m_pDBC; + argusDBC * m_pDBC; uint32_t m_nSiteID; vectorKernelModules m_vKernelModules; public: @@ -19,7 +19,6 @@ class argusModuleFactory{ void deleteModule( argusKernelModule * ); void deleteModule( int id ); bool loadModules( uint32_t SiteID = 0 ); - void setDBC(ARGUS_DBC * tPtr); void validate( void ); protected: argusModuleFactory(); diff --git a/lib/rgoose/rgooseNetworkUART.h b/lib/rgoose/rgooseNetworkUART.h new file mode 100644 index 00000000..e69de29b diff --git a/lib/rgoose/rgooseNode.cpp b/lib/rgoose/rgooseNode.cpp index af0aa91b..c1dee9f8 100644 --- a/lib/rgoose/rgooseNode.cpp +++ b/lib/rgoose/rgooseNode.cpp @@ -1,8 +1,8 @@ #include "rgooseNode.h" -argusNetNode::argusNetNode( ARGUS_DBC *DBC, int id ):basicObject(){ +argusNetNode::argusNetNode( uint32_t id ):basicObject(){ m_nDBID = id; - m_pDBC = DBC; + m_pDBC = argusDBC::getInstance(); if( m_pDBC != NULL ) { DBC_NODE_DATA *tData = NULL; tData = m_pDBC->getNodeData( m_nDBID ); @@ -21,19 +21,12 @@ argusNetNode::argusNetNode( ARGUS_DBC *DBC, int id ):basicObject(){ }; }; -argusNetNode::argusNetNode( ARGUS_DBC *DBC, DBC_NODE_DATA *Data ):basicObject(){ +argusNetNode::argusNetNode( DBC_NODE_DATA *Data ):basicObject(){ m_nDBID = Data->node_id; - m_pDBC = DBC; + m_pDBC = argusDBC::getInstance(); memcpy( &m_sNodeData , Data, sizeof(DBC_NODE_DATA)); }; argusNetNode::~argusNetNode(){ if( m_pPosition != NULL ) delete(m_pPosition); }; - -void argusNetNode::setDBC( ARGUS_DBC *tPtr ){ - m_pDBC = tPtr; - if( m_pDBC!= NULL ) { - - }; -}; diff --git a/lib/rgoose/rgooseNode.h b/lib/rgoose/rgooseNode.h index e0bbcf10..f2b60686 100644 --- a/lib/rgoose/rgooseNode.h +++ b/lib/rgoose/rgooseNode.h @@ -7,20 +7,19 @@ class argusNetNode: public basicObject{ protected: - ARGUS_DBC * m_pDBC; + argusDBC * m_pDBC; uint32_t m_nDBID; DBC_NODE_DATA m_sNodeData; basicPosition * m_pPosition; public: - explicit argusNetNode( ARGUS_DBC *DBC, int id ); - explicit argusNetNode( ARGUS_DBC *DBC, DBC_NODE_DATA *Data ); + explicit argusNetNode( uint32_t id ); + explicit argusNetNode( DBC_NODE_DATA *Data ); virtual ~argusNetNode(); - uint32_t getId() const { return m_nDBID;}; + uint32_t getDbId() const { return m_nDBID;}; ARGUS_NODE_TYPE getType() const { return m_sNodeData.type; }; bool isOnline( void ) const { return m_sNodeData.online; }; virtual bool isDetached() { return true; }; virtual bool isAttached() { return false; }; - void setDBC( ARGUS_DBC *tPtr ); virtual bool startService(){ return false; }; virtual bool stopService(){ return true; }; virtual bool validate(){ return false; }; diff --git a/lib/rgoose/rgooseNode3D.cpp b/lib/rgoose/rgooseNode3D.cpp index 4664a4c5..77271979 100644 --- a/lib/rgoose/rgooseNode3D.cpp +++ b/lib/rgoose/rgooseNode3D.cpp @@ -3,23 +3,23 @@ #define LOG( X ) m_pLog->Log( (m_bIsMaster?"objectLGS[M]":"objectLGS[S]"), this, X ) #define LOG_ERROR( X ) m_pLog->Log( (m_bIsMaster?"objectLGS[M]":"objectLGS[S]"), this, _LOG_ERROR, X ) -ARGUS_3DSensor::ARGUS_3DSensor( ARGUS_DBC *DBC, int ID ): argusNetNode( DBC, ID ){ +argus3DLIDAR::argus3DLIDAR( uint32_t ID ): argusNetNode( ID ){ }; -ARGUS_3DSensor::~ARGUS_3DSensor(){ +argus3DLIDAR::~argus3DLIDAR(){ }; -bool ARGUS_3DSensor::startService(){ +bool argus3DLIDAR::startService(){ return false; }; -bool ARGUS_3DSensor::stopService(){ +bool argus3DLIDAR::stopService(){ return true; }; -bool ARGUS_3DSensor::validate(){ +bool argus3DLIDAR::validate(){ return false; }; @@ -285,7 +285,7 @@ void objectLGS::m_fThreadAProc(void){ m_mStatusMutex.unlock(); basicEvent *tEVT; - tEVT = createBasicEvent(getID(), EVT_CLASS_SENSOR, EVT_READY, "Device is connected"); + tEVT = createBasicEvent( getObjectId(), EVT_CLASS_SENSOR, EVT_READY, "Device is connected"); m_pEventHeap->broadcast(tEVT); } else { //handle no connection @@ -302,7 +302,7 @@ void objectLGS::m_fThreadAProc(void){ basicEvent *tEVT; //ToDo: Change Device Name! - tEVT = createBasicEvent( getID(), EVT_CLASS_SENSOR, EVT_ERROR, "Device is Not Connected"); + tEVT = createBasicEvent( getObjectId(), EVT_CLASS_SENSOR, EVT_ERROR, "Device is Not Connected"); m_pEventHeap->broadcast( tEVT ); }; } else { @@ -325,9 +325,9 @@ void objectLGS::m_fThreadAProc(void){ basicEvent *tEVT; if( m_bIsMaster ) { - tEVT = createBasicEvent(getID(), EVT_CLASS_SENSOR, EVT_READY, "Master Device is connected"); + tEVT = createBasicEvent( getObjectId(), EVT_CLASS_SENSOR, EVT_READY, "Master Device is connected"); }else{ - tEVT = createBasicEvent(getID(), EVT_CLASS_SENSOR, EVT_READY, "Slave Device is connected"); + tEVT = createBasicEvent( getObjectId(), EVT_CLASS_SENSOR, EVT_READY, "Slave Device is connected"); }; m_pEventHeap->broadcast(tEVT); } else { @@ -345,9 +345,9 @@ void objectLGS::m_fThreadAProc(void){ basicEvent *tEVT; if( m_bIsMaster ) { - tEVT = createBasicEvent( getID(), EVT_CLASS_SENSOR, EVT_ERROR, "Master Device is disconnected"); + tEVT = createBasicEvent( getObjectId(), EVT_CLASS_SENSOR, EVT_ERROR, "Master Device is disconnected"); }else{ - tEVT = createBasicEvent( getID(), EVT_CLASS_SENSOR, EVT_ERROR, "Slave Device is disconnected"); + tEVT = createBasicEvent( getObjectId(), EVT_CLASS_SENSOR, EVT_ERROR, "Slave Device is disconnected"); }; m_pEventHeap->broadcast( tEVT ); }; @@ -526,9 +526,9 @@ void objectLGS::m_fThreadAProc(void){ // Handle device's time out basicEvent *tEVT; if( m_bIsMaster ) { - tEVT = createBasicEvent( getID(), EVT_CLASS_SENSOR, EVT_ERROR, "Master Device communication Time Out"); + tEVT = createBasicEvent( getObjectId(), EVT_CLASS_SENSOR, EVT_ERROR, "Master Device communication Time Out"); } else { - tEVT = createBasicEvent( getID(), EVT_CLASS_SENSOR, EVT_ERROR, "Slave Device communication Time Out"); + tEVT = createBasicEvent( getObjectId(), EVT_CLASS_SENSOR, EVT_ERROR, "Slave Device communication Time Out"); }; m_pEventHeap->broadcast( tEVT ); //m_bComIsBusy = false; @@ -846,21 +846,21 @@ bool objectLGS::packetHandler(protocolPackage* Package) { case STG_STUDY: { m_mStatusMutex.unlock(); basicEvent* tEVT; - tEVT = createBasicEvent(getID(), EVT_CLASS_SENSOR, EVT_STUDY, "Device in STUDY mode"); + tEVT = createBasicEvent( getObjectId(), EVT_CLASS_SENSOR, EVT_STUDY, "Device in STUDY mode"); m_pEventHeap->broadcast(tEVT); break; }; case STG_REDY: { m_mStatusMutex.unlock(); basicEvent* tEVT; - tEVT = createBasicEvent(getID(), EVT_CLASS_SENSOR, EVT_READY, "Device in DETECTION mode"); + tEVT = createBasicEvent( getObjectId(), EVT_CLASS_SENSOR, EVT_READY, "Device in DETECTION mode"); m_pEventHeap->broadcast(tEVT); break; }; case STG_BUSY: { m_mStatusMutex.unlock(); basicEvent* tEVT; - tEVT = createBasicEvent(getID(), EVT_CLASS_SENSOR, EVT_ERROR, "Device in BUSY mode"); + tEVT = createBasicEvent( getObjectId(), EVT_CLASS_SENSOR, EVT_ERROR, "Device in BUSY mode"); m_pEventHeap->broadcast(tEVT); break; }; @@ -875,8 +875,8 @@ bool objectLGS::packetHandler(protocolPackage* Package) { tEVT = (CLIENT_EVENT*)& pReceivedPackage[DATA_BEGIN_IDX + 1]; for (uint8_t xindex = 0; xindex < tCount; xindex++) { switch (tEVT[xindex].type) { - case EVT_TARGET_BLACK: - case EVT_TARGET_WHITE: { + case EVT_TARGET_3D_BLACK: + case EVT_TARGET_3D_WHITE: { TARGET_DATA *tData; tData = prepareTargetData(tEVT+xindex); if(tData != NULL){ @@ -891,7 +891,7 @@ bool objectLGS::packetHandler(protocolPackage* Package) { sprintf(tBuffer, "%s[%d] %s target \tRange: %.2fm. \tAzimuth: %.2f \tElevation: %.2f \tTS: %d@%d W:%.2f", (bIsMaster ? "M" : "S"), bKernelID, - ((tEVT[xindex].type == EVT_TARGET_WHITE) ? "White" : "Black"), + ((tEVT[xindex].type == EVT_TARGET_3D_WHITE) ? "White" : "Black"), tData->local_target.r, tData->local_target.fi, tData->local_target.tetta, @@ -899,7 +899,7 @@ bool objectLGS::packetHandler(protocolPackage* Package) { tEVT[xindex].ums, tData->area ); - bEVT = createBasicEvent(getID(), EVT_CLASS_SENSOR, (basicEventTypeID)tEVT[xindex].type, tBuffer, tData); + bEVT = createBasicEvent( getObjectId(), EVT_CLASS_SENSOR, (basicEventTypeID)tEVT[xindex].type, tBuffer, tData); if (bEVT != NULL) { m_pEventHeap->broadcast(bEVT); } else { @@ -957,23 +957,23 @@ bool objectLGS::packetHandler(protocolPackage* Package) { case CMD_EVT: break; case CMD_FLIP_COMPLETE: { - tEVT = createBasicEvent(getID(), EVT_CLASS_SENSOR, EVT_FLIP, "Flip Complete"); + tEVT = createBasicEvent( getObjectId(), EVT_CLASS_SENSOR, EVT_FLIP, "Flip Complete"); m_pEventHeap->broadcast(tEVT); break; }; case CMD_SCAN_COMPLETE: { - tEVT = createBasicEvent(getID(), EVT_CLASS_SENSOR, EVT_SCAN, "Scan Complete"); + tEVT = createBasicEvent( getObjectId(), EVT_CLASS_SENSOR, EVT_SCAN, "Scan Complete"); m_pEventHeap->broadcast(tEVT); break; }; case CMD_TARGET: { - tEVT = createBasicEvent(getID(), EVT_CLASS_SENSOR, EVT_TARGET, "Target"); + tEVT = createBasicEvent( getObjectId(), EVT_CLASS_SENSOR, EVT_TARGET_3D_WHITE, "Target"); m_pEventHeap->broadcast(tEVT); break; }; case CMD_TARGET_WW: { - tEVT = createBasicEvent(getID(), EVT_CLASS_SENSOR, EVT_TARGET, "Target with Width"); + tEVT = createBasicEvent( getObjectId(), EVT_CLASS_SENSOR, EVT_TARGET_3D_WHITE, "Target with Width"); m_pEventHeap->broadcast(tEVT); break; }; @@ -987,7 +987,7 @@ bool objectLGS::packetHandler(protocolPackage* Package) { tData->mWidth = (pReceivedPackage[12] << 24) + (pReceivedPackage[13] << 16) + (pReceivedPackage[14] << 8) + pReceivedPackage[15]; //if( m_pMapWidget != NULL ) m_pMapWidget->addTarget(tData->mSampleID ); //if( m_pRadarWidget != NULL ) m_pRadarWidget->addTarget(tData->mSampleID, tData->mRange, m_bIsMaster ); - tEVT = createBasicEvent( getID(), EVT_CLASS_SENSOR, EVT_TARGET_WHITE, "White Intruder Detection", tData ); + tEVT = createBasicEvent( getID(), EVT_CLASS_SENSOR, EVT_TARGET_3D_WHITE, "White Intruder Detection", tData ); m_pEventHeap->broadcast( tEVT ); */ }; @@ -1003,7 +1003,7 @@ bool objectLGS::packetHandler(protocolPackage* Package) { tData->mWidth = (pReceivedPackage[12] << 24) + (pReceivedPackage[13] << 16) + (pReceivedPackage[14] << 8) + pReceivedPackage[15]; //if( m_pMapWidget != NULL ) m_pMapWidget->addTarget(tData->mSampleID, m_bIsMaster ); //if( m_pRadarWidget != NULL ) m_pRadarWidget->addTarget(tData->mSampleID, tData->mRange, m_bIsMaster ); - tEVT = createBasicEvent( getID(), EVT_CLASS_SENSOR, EVT_TARGET_BLACK, "Target Black", tData ); + tEVT = createBasicEvent( getID(), EVT_CLASS_SENSOR, EVT_TARGET_3D_BLACK, "Target Black", tData ); m_pEventHeap->broadcast( tEVT ); */ }; @@ -1037,7 +1037,7 @@ bool objectLGS::packetHandler(protocolPackage* Package) { fAzimuth, fElevation ); - tEVT = createBasicEvent( getID(), EVT_CLASS_SENSOR, EVT_TARGET_WHITE, tBuffer, tData ); + tEVT = createBasicEvent( getID(), EVT_CLASS_SENSOR, EVT_TARGET_3D_WHITE, tBuffer, tData ); } else { sprintf( tBuffer, "[%s]:%.2fm. Azimuth: %.2f Elevation: %.2f", (m_bIsMaster?"M":"S"), @@ -1045,7 +1045,7 @@ bool objectLGS::packetHandler(protocolPackage* Package) { fAzimuth, fElevation ); - tEVT = createBasicEvent( getID(), EVT_CLASS_SENSOR, EVT_TARGET_BLACK, tBuffer, tData ); + tEVT = createBasicEvent( getID(), EVT_CLASS_SENSOR, EVT_TARGET_3D_BLACK, tBuffer, tData ); }; m_pEventHeap->broadcast( tEVT ); */ diff --git a/lib/rgoose/rgooseNode3D.h b/lib/rgoose/rgooseNode3D.h index 31673156..1bfcf838 100644 --- a/lib/rgoose/rgooseNode3D.h +++ b/lib/rgoose/rgooseNode3D.h @@ -18,7 +18,10 @@ #include "../alg/lgs/mask.h" #include "../data/net/clientPort.h" -#include "../data/protocol/protocolLGS.h" + +#define PACKET_MULTIBYTE_SIZE + #include "../data/protocol/protocolLGS.h" +#undef PACKET_MULTIBYTE_SIZE #include "../hardware/soc/general/3DLRF.h" @@ -57,15 +60,15 @@ typedef struct S_DEVICE_STATUS{ class objectLGS; -class ARGUS_3DSensor: public argusNetNode{ +class argus3DLIDAR: public argusNetNode{ private: basicLogCollection * m_pLog; objectLGS * m_pMasterNode; objectLGS * m_pSlaveNode; basicEventHeap * m_pEventHeap; public: - explicit ARGUS_3DSensor( ARGUS_DBC *DBC, int ID ); - virtual ~ARGUS_3DSensor(); + explicit argus3DLIDAR( uint32_t dbID ); + virtual ~argus3DLIDAR(); virtual bool startService(); virtual bool stopService(); virtual bool validate(); diff --git a/lib/rgoose/rgooseNodeFactory.cpp b/lib/rgoose/rgooseNodeFactory.cpp index 6e61ad44..56ef09db 100644 --- a/lib/rgoose/rgooseNodeFactory.cpp +++ b/lib/rgoose/rgooseNodeFactory.cpp @@ -24,7 +24,7 @@ argusNodeFactory* argusNodeFactory::getInstance() { }; argusNodeFactory::argusNodeFactory(){ m_pLog = basicLogCollection::getInstance(); - m_pDBC = NULL; + m_pDBC = argusDBC::getInstance(); }; argusNodeFactory::~argusNodeFactory(){ @@ -36,20 +36,17 @@ argusNodeFactory::~argusNodeFactory(){ }; }; m_vNetNodes.clear(); + m_mNetNodesIDS.clear(); }; }; -void argusNodeFactory::setDBC(ARGUS_DBC * tPtr){ - if( (m_pDBC == NULL) && (tPtr != NULL) ) m_pDBC = tPtr; -}; - bool argusNodeFactory::loadNodes( uint32_t SiteID ){ if(m_pDBC == NULL) return false; m_nSiteID = SiteID; DBC_INT_LIST *tList = NULL; tList = m_pDBC->listNodes( SiteID ); if( tList != NULL ) { - for(int index=0; index< tList->size(); index++) { + for( int index=0; index< tList->size(); index++ ) { createNode( tList->at(index) ); }; tList->clear(); @@ -59,7 +56,7 @@ bool argusNodeFactory::loadNodes( uint32_t SiteID ){ return false; }; -argusNetNode *argusNodeFactory::createNode( int id ){ +argusNetNode *argusNodeFactory::createNode( uint32_t id ){ argusNetNode *tVal = NULL; if( m_pDBC != NULL ){ DBC_NODE_DATA *tData = NULL; @@ -81,7 +78,7 @@ argusNetNode *argusNodeFactory::createNode( int id ){ LOG("Creating Network Static Camera"); #endif ARGUS_IPCAM *tCamera; - tCamera = new ARGUS_IPCAM( m_pDBC, id ); + tCamera = new ARGUS_IPCAM( id ); if( tCamera ) { LOG("Success"); tVal = ( argusNetNode *) tCamera; @@ -147,95 +144,117 @@ argusNetNode *argusNodeFactory::createNode( int id ){ free(tData); }; }; - if( tVal != NULL ) m_vNetNodes.push_back( tVal ); + if( tVal != NULL ){ + m_vNetNodes.push_back( tVal ); + m_mNetNodesIDS[id] = tVal; + }; return tVal; }; -void argusNodeFactory::deleteNode( argusNetNode * N ){ - if( N ) { - switch( N->getType() ) { - case ARGUS_ANALOG_STATIC_CAMERA: +void argusNodeFactory::deleteNode( argusNetNode *ptr ){ + if( ptr == NULL ) return; + // if some troubles move this to an end of the function! + for( vectorNetNodes::iterator index = m_vNetNodes.begin() ; index < m_vNetNodes.end(); index++ ){ + if( (*index) == ptr ) { + m_mNetNodesIDS.erase( ptr->getDbId() ); + m_vNetNodes.erase( index ); + break; + }; + }; + switch( ptr->getType() ) { + case ARGUS_ANALOG_STATIC_CAMERA: #ifdef DEBUG - LOG("Destroying Analog Static Camera"); + LOG("Destroying Analog Static Camera"); #endif - break; - case ARGUS_ANALOG_PTZ_CAMERA: + break; + case ARGUS_ANALOG_PTZ_CAMERA: #ifdef DEBUG - LOG("Destroying Analog PTZ Camera"); + LOG("Destroying Analog PTZ Camera"); #endif - break; - case ARGUS_IP_STATIC_CAMERA: + break; + case ARGUS_IP_STATIC_CAMERA: #ifdef DEBUG - LOG("Destroying Network Static Camera"); + LOG("Destroying Network Static Camera"); #endif - delete((ARGUS_Camera *) N ); - break; - case ARGUS_IP_PTZ_CAMERA: + delete((ARGUS_Camera *) ptr ); + break; + case ARGUS_IP_PTZ_CAMERA: #ifdef DEBUG - LOG("Destroying Network PTZ Camera"); + LOG("Destroying Network PTZ Camera"); #endif - delete((ARGUS_Camera *) N ); - break; - case ARGUS_IP_UART_GATEWAY: + delete((ARGUS_Camera *) ptr ); + break; + case ARGUS_IP_UART_GATEWAY: #ifdef DEBUG - LOG("Destroying Ethernet to UART Gateway"); + LOG("Destroying Ethernet to UART Gateway"); #endif - break; - case ARGUS_IP_VIDEO_SERVER: + break; + case ARGUS_IP_VIDEO_SERVER: #ifdef DEBUG - LOG("Destroying Network Video Encoder"); + LOG("Destroying Network Video Encoder"); #endif - break; - case ARGUS_LFS_SENSOR: + break; + case ARGUS_LFS_SENSOR: #ifdef DEBUG - LOG("Destroying LFS Sensor"); + LOG("Destroying LFS Sensor"); #endif - break; - case ARGUS_ALS_SENSOR: + break; + case ARGUS_ALS_SENSOR: #ifdef DEBUG - LOG("Destroying ALS Sensor"); + LOG("Destroying ALS Sensor"); #endif - break; - case ARGUS_PLS_200_SENSOR: + break; + case ARGUS_PLS_200_SENSOR: #ifdef DEBUG - LOG("Destroying PLS200 Sensor"); + LOG("Destroying PLS200 Sensor"); #endif - break; - case ARGUS_PLS_360_SENSOR: + break; + case ARGUS_PLS_360_SENSOR: #ifdef DEBUG - LOG("Destroying PLS360 Sensor"); + LOG("Destroying PLS360 Sensor"); #endif - break; - case ARGUS_3D_SENSOR: + break; + case ARGUS_3D_SENSOR: #ifdef DEBUG - LOG("Destroying 3D Sensor"); + LOG("Destroying 3D Sensor"); #endif - break; - case ARGUS_JAMER: + break; + case ARGUS_JAMER: #ifdef DEBUG - LOG("Destroying RF Jamer"); + LOG("Destroying RF Jamer"); #endif - break; - case ARGUS_NET_PLS_200: + break; + case ARGUS_NET_PLS_200: #ifdef DEBUG - LOG("Destroying Network-PLS200 Sensor"); + LOG("Destroying Network-PLS200 Sensor"); #endif - break; - case ARGUS_DRONE_CONTROL: + break; + case ARGUS_DRONE_CONTROL: #ifdef DEBUG - LOG("Destroying Drone Controll"); + LOG("Destroying Drone Controll"); #endif - break; - }; + break; }; }; -void argusNodeFactory::deleteNode( int id ){ - if( m_vNetNodes.size() > id ) { - deleteNode( m_vNetNodes.at( id ) ); - m_vNetNodes.erase( m_vNetNodes.begin() + id ); - m_vNetNodes.shrink_to_fit(); +/* + @id Database ID of Node to be deleted +*/ +argusNetNode *argusNodeFactory::getNode( uint32_t id ){ + mapNode2Id::iterator it; + it = m_mNetNodesIDS.find( id ); + if( it != m_mNetNodesIDS.end() ) { + return m_mNetNodesIDS[id]; }; + return NULL; +}; + +/* + @id Database ID of Node to be deleted +*/ +void argusNodeFactory::deleteNode( uint32_t id ){ + argusNetNode *tNode = getNode( id ); + deleteNode( tNode ); }; void argusNodeFactory::validate( void ){ @@ -248,7 +267,7 @@ void argusNodeFactory::validate( void ){ #endif if( m_vNetNodes.size() ) { DBC_INT_LIST tL; - for( int cm = 0; cm < m_vNetNodes.size(); cm++ ) tL.push_back( m_vNetNodes.at(cm)->getId() ); + for( int cm = 0; cm < m_vNetNodes.size(); cm++ ) tL.push_back( m_vNetNodes.at(cm)->getDbId() ); tList = m_pDBC->listNewNodes( m_nSiteID, &tL ); tL.clear(); } else { @@ -275,7 +294,7 @@ void argusNodeFactory::validate( void ){ //check if module removed bool tRemoved = true; for( int lm = 0; lm < tList->size(); lm++ ) { - if( tList->at(lm) == m_vNetNodes.at(cm)->getId() ) { + if( tList->at(lm) == m_vNetNodes.at(cm)->getDbId() ) { tRemoved = false; break; }; @@ -292,7 +311,7 @@ void argusNodeFactory::validate( void ){ delete( tList ); } else { LOG("All Modules Must be Deleted!"); - while( m_vNetNodes.size() ) deleteNode( 0 ); + while( m_vNetNodes.size() ) deleteNode( (uint32_t) 0 ); }; }; #ifdef MEM_DEBUG @@ -337,6 +356,5 @@ uint32_t argusNodeFactory::fetchNodes( ARGUS_NODE_TYPE type, argusNetNode **&RA return RetVal; }; - #undef LOG #undef LOG_ERROR diff --git a/lib/rgoose/rgooseNodeFactory.h b/lib/rgoose/rgooseNodeFactory.h index cd79d2a1..a14422fc 100644 --- a/lib/rgoose/rgooseNodeFactory.h +++ b/lib/rgoose/rgooseNodeFactory.h @@ -2,27 +2,29 @@ #define __ARGUS_NODE_FACTORY_HEADER__ #include +#include #include "rgooseNode.h" -typedef std::vector vectorNetNodes; - +typedef std::vector vectorNetNodes; +typedef std::map mapNode2Id; class argusNodeFactory{ private: basicLogCollection * m_pLog; - ARGUS_DBC * m_pDBC; + argusDBC * m_pDBC; uint32_t m_nSiteID; vectorNetNodes m_vNetNodes; + mapNode2Id m_mNetNodesIDS; public: static argusNodeFactory * getInstance(); virtual ~argusNodeFactory(); - argusNetNode * createNode( int id ); - void deleteNode( argusNetNode * ); - void deleteNode( int id ); + argusNetNode * createNode( uint32_t id ); + void deleteNode( argusNetNode *ptr ); + void deleteNode( uint32_t id ); + uint32_t fetchNodes( ARGUS_NODE_TYPE type, argusNetNode **&RA ); + argusNetNode * getNode( uint32_t id ); + uint32_t getNodeCount( ARGUS_NODE_TYPE type ); bool loadNodes( uint32_t SiteID = 0 ); - void setDBC(ARGUS_DBC * tPtr); void validate( void ); - uint32_t getNodeCount( ARGUS_NODE_TYPE type ); - uint32_t fetchNodes( ARGUS_NODE_TYPE type, argusNetNode **&RA ); protected: argusNodeFactory(); private: diff --git a/lib/rgoose/rgooseServerModule.cpp b/lib/rgoose/rgooseServerModule.cpp index 4e9b5782..3e21e353 100644 --- a/lib/rgoose/rgooseServerModule.cpp +++ b/lib/rgoose/rgooseServerModule.cpp @@ -1,8 +1,8 @@ #include "rgooseServerModule.h" -argusServerModule::argusServerModule( uint32_t ModuleID, ARGUS_DBC * DBC ):argusKernelModule( ModuleID, ARGUS_MODULE_NETWORK, DBC){ +argusServerModule::argusServerModule( uint32_t ModuleID ):argusKernelModule( ModuleID, ARGUS_MODULE_NETWORK ){ }; argusServerModule::~argusServerModule(){}; -void dispatchEvent( basicEvent *Evt ){}; +void argusServerModule::dispatchEvent( basicEvent *Evt ){}; diff --git a/lib/rgoose/rgooseServerModule.h b/lib/rgoose/rgooseServerModule.h index 18b0a1de..157c6826 100644 --- a/lib/rgoose/rgooseServerModule.h +++ b/lib/rgoose/rgooseServerModule.h @@ -6,7 +6,7 @@ class argusServerModule: public argusKernelModule{ public: - explicit argusServerModule( uint32_t ModuleID, ARGUS_DBC * DBC ); + explicit argusServerModule( uint32_t ModuleID ); virtual ~argusServerModule(); virtual void dispatchEvent( basicEvent *Evt ); }; diff --git a/lib/rgoose/rgooseUSBRelayModule.cpp b/lib/rgoose/rgooseUSBRelayModule.cpp index f1853384..19184ea3 100644 --- a/lib/rgoose/rgooseUSBRelayModule.cpp +++ b/lib/rgoose/rgooseUSBRelayModule.cpp @@ -288,7 +288,8 @@ static int get_board_features(relay_board *board, hid_device *handle) } -argusUSBRelayModule::argusUSBRelayModule( uint32_t ModuleID, ARGUS_DBC *DBC ) : argusKernelModule( ModuleID, ARGUS_MODULE_DCBUSB, DBC ){}; +argusUSBRelayModule::argusUSBRelayModule( uint32_t ModuleID ) : argusKernelModule( ModuleID, ARGUS_MODULE_DCBUSB ){ +}; argusUSBRelayModule::~argusUSBRelayModule(){}; diff --git a/lib/rgoose/rgooseUSBRelayModule.h b/lib/rgoose/rgooseUSBRelayModule.h index 64b8f6df..ec27b01b 100644 --- a/lib/rgoose/rgooseUSBRelayModule.h +++ b/lib/rgoose/rgooseUSBRelayModule.h @@ -33,7 +33,7 @@ class argusUSBRelayModule: public argusKernelModule { uint32_t m_nCURRENT_STATE; uint32_t m_aCHANNEL_CONFIGS[32]; public: - explicit argusUSBRelayModule( uint32_t ModuleID, ARGUS_DBC *DBC ); + explicit argusUSBRelayModule( uint32_t ModuleID ); virtual ~argusUSBRelayModule(); virtual void dispatchEvent( basicEvent *Evt ); }; diff --git a/lib/rgoose/rgooseZLMediaModule.cpp b/lib/rgoose/rgooseZLMediaModule.cpp index 1eadcf23..da440d38 100644 --- a/lib/rgoose/rgooseZLMediaModule.cpp +++ b/lib/rgoose/rgooseZLMediaModule.cpp @@ -1,49 +1,153 @@ #include "rgooseZLMediaModule.h" +#include "rgooseKernel.h" #define LOG( X ) m_pLog->Log( "ZLMM", this, X ) #define LOG_ERROR( X ) m_pLog->Log( "ZLMM", this, _LOG_ERROR, X ) -ARGUS_ZLMedia::ARGUS_ZLMedia( int id, ARGUS_DBC *DBC ): argusKernelModule( id, ARGUS_MODULE_ZLMEDIA, DBC ){ +ARGUS_ZLMedia::ARGUS_ZLMedia( uint32_t id ): argusKernelModule( id, ARGUS_MODULE_ZLMEDIA ){ m_pLog = basicLogCollection::getInstance(); m_pProtocol = NULL; + //m_pDefinedStreams = NULL; m_bCStage = ZLMC_STAGE_INIT; + m_tTimeSeconds = 0; + memset( &m_sSettings,0,sizeof( DBC_MEDIA_SERVER_DATA )); if( m_pDBC!= NULL ) { DBC_MEDIA_SERVER_DATA * tDATA = NULL; tDATA = m_pDBC->getMediaServerData( m_nDBID ); if( tDATA != NULL ) { - LOG( tDATA->name ); - m_pProtocol = new protocolZLMEDIA( tDATA->key, tDATA->host, tDATA->ip, tDATA->port ); + memcpy( &m_sSettings, tDATA,sizeof( DBC_MEDIA_SERVER_DATA ) ); + free( tDATA ); + LOG( m_sSettings.name ); + m_pProtocol = new protocolZLMEDIA( m_sSettings.key, m_sSettings.host, m_sSettings.ip, m_sSettings.port ); + if( m_pProtocol!=NULL) { + //Add IP Video Socket to Server in DB + char tBuff[256]; + sprintf( tBuff,"%s_pxd", m_sSettings.key ); + m_pDBC->addNodeSocket( m_pKernel->getServerNodeId(), m_nDBID, ARGUS_NODE_SOCK_TYPE_DVR_IN, ARGUS_NODE_SOCK_MODE_IN, true, tBuff, "ZLMEDIA Digital" ); + sprintf( tBuff,"%s_pxa", m_sSettings.key ); + m_pDBC->addNodeSocket( m_pKernel->getServerNodeId(), m_nDBID, ARGUS_NODE_SOCK_TYPE_MEDIA_AD_BRIDGE, ARGUS_NODE_SOCK_MODE_IN, true, tBuff, "ZLMEDIA Analog" ); + }; }; + updateMRLs(); }; }; ARGUS_ZLMedia::~ARGUS_ZLMedia(){ if(m_pProtocol!= NULL) delete(m_pProtocol); + //if(m_pDefinedStreams!=NULL) { + // m_pDefinedStreams->clear(); + // delete(m_pDefinedStreams); + //}; + if( m_pVHostIP!= NULL ) free( m_pVHostIP ); +}; +void ARGUS_ZLMedia::updateMRLs( void ){ + if( strstr( m_sSettings.ip, "127.0.0.1" ) != NULL ){ + //Must Update MRL only for Local Media Server + LOG("Updating Local MRLs"); + m_pVHostIP = m_pDBC->getNodeIP4( m_pKernel->getServerNodeId() ); + if( m_pVHostIP!= NULL ){ + + }; + }; }; bool ARGUS_ZLMedia::validate(){ - LOG("VALIDATION"); + time_t tTimeSeconds; if( m_pProtocol != NULL ) { if( m_pProtocol->isOnline() ) { - char tBuff[256]; - sprintf( tBuff, "Stage: %d", m_bCStage ); - LOG( tBuff ); + //tTimeSeconds = time( NULL ); + //if( m_tTimeSeconds > tTimeSeconds ) return true; + //m_tTimeSeconds = tTimeSeconds + ZLM_SECONDS_VALIDATE; + +#ifdef DEBUG + //char tBuff[256]; + //sprintf( tBuff, "Stage: %d", m_bCStage ); + //LOG( tBuff ); +#endif + switch(m_bCStage) { // Request Current Media case ZLMC_STAGE_INIT: - LOG("Request Media"); - if( !m_pProtocol->listMedia() ) return false; - LOG("Request Sent!"); + if( !m_pProtocol->delAllStreamProxys() ) return false; break; // Validate Media List case ZLMC_STAGE_START: { // Stay on same stage till request is finished if( !m_pProtocol->requestIsFinished() ) return true; - LOG("Media Request Done!"); + + DBC_INT_LIST *tStreams; + tStreams = m_pDBC->listMediaStreams( m_pKernel->getSiteId(), m_sSettings.id, LIST_VALID_RECORDS ); + if( tStreams != NULL ){ + for( int index = 0; index < tStreams->size(); index++ ) { + DBC_MEDIA_SERVER_STREAM_DATA * tData; + tData = m_pDBC->getMediaServerStreamData( tStreams->at(index) ); + if( tData!= NULL ) { + if( ! tData->online ) { + char *tKey = NULL; + // Put Stream Offline at first + //m_pDBC->updateMediaServerStream( tData->id ); + LOG("Try to add MRL -> Server"); + LOG( tData->mrl ); + tKey = m_pProtocol->addStreamProxy( tData->id, m_pKernel->getServerIdentity(), tData->mrl ); + LOG( tKey ); + if( tKey!= NULL ) { + m_pDBC->updateMediaServerStream( tData->id, tData->mrl, tKey ); + }; + }; + free( tData ); + }; + }; + }; break; }; - case ZLM_STAGE_COLLECT_DATA: + case ZLM_STAGE_COLLECT_DATA:{ + // Validate Invalid Streams + DBC_INT_LIST *tStreams; + tStreams = m_pDBC->listMediaStreams( m_pKernel->getSiteId(), m_sSettings.id, LIST_INVALID_RECORDS ); + if( tStreams!= NULL ) { + DBC_MEDIA_SERVER_STREAM_DATA *tData; + for( int index = 0; index < tStreams->size(); index++ ) { + tData = m_pDBC->getMediaServerStreamData( tStreams->at(index) ); + if( tData!= NULL ){ + //update MRL + DBC_MEDIA_STREAM_DATA *tStream; + tStream = m_pDBC->getMediaStreamData( tData->media_stream_id ); + if( tStream != NULL ) { + if( tStream->valid ){ + if( tStream->source_type[0] == 'D' ) { + DBC_CAM_DATA *tCam; + tCam = m_pDBC->getCamData( tStream->source_id ); + if( tCam!= NULL ) { + if( tCam->online ) { + sprintf( tData->mrl, "%s://%s:%s@%s:%d%s", + tStream->mrl_proto, + tCam->username, + tCam->password, + tCam->ip, + tStream->mrl_port, + tStream->mrl + ); + LOG( tData->mrl ); + m_pDBC->updateMediaServerStream( tStreams->at(index), tData->mrl ); + }; + free( tCam ); + } else LOG("Error Fetching Cam Data From DB"); + } else { + // Grabber Stream Handling + }; + } else { + //LOG("Stream Not Valid"); + }; + free( tStream ); + } else LOG("Error Fetching Media Stream Data From DB"); + free( tData ); + } else LOG("Error Fetching Media Server Stream Data From DB"); + }; + tStreams->clear(); + delete( tStreams ); + }; break; + }; }; m_bCStage ++; if( m_bCStage >= ZLMC_STAGE_END ) m_bCStage = ZLMC_STAGE_START; diff --git a/lib/rgoose/rgooseZLMediaModule.h b/lib/rgoose/rgooseZLMediaModule.h index 2e0f5283..77ed4363 100644 --- a/lib/rgoose/rgooseZLMediaModule.h +++ b/lib/rgoose/rgooseZLMediaModule.h @@ -12,15 +12,20 @@ #define ZLMC_STAGE_START 1 #define ZLM_STAGE_COLLECT_DATA 2 #define ZLMC_STAGE_END 3 +#define ZLM_SECONDS_VALIDATE 5 class ARGUS_ZLMedia: public argusKernelModule{ private: uint8_t m_bCStage; basicLogCollection * m_pLog; - //config_setting_t * m_pSettings; + DBC_MEDIA_SERVER_DATA m_sSettings; protocolZLMEDIA * m_pProtocol; + //DBC_INT_LIST * m_pDefinedStreams; + CSTR m_pVHostIP; + time_t m_tTimeSeconds; + void updateMRLs( void ); public: - explicit ARGUS_ZLMedia( int id, ARGUS_DBC *DBC ); + explicit ARGUS_ZLMedia( uint32_t id ); ~ARGUS_ZLMedia(); virtual bool validate(); };