diff --git a/.gitignore b/.gitignore index 22b76dcc..60159b56 100644 --- a/.gitignore +++ b/.gitignore @@ -98,4 +98,5 @@ /Projects/MEKOROT/.vs/* /Projects/MEKOROT/x64/* /Projects/MEKOROT/storage/* -Projects/img_mill/Debug/* \ No newline at end of file +Projects/img_mill/Debug/* +Projects/img_mill/Release/* \ No newline at end of file diff --git a/Projects/3dClientGui/makefile b/Projects/3dClientGui/makefile index 5674c7e6..da9536e7 100644 --- a/Projects/3dClientGui/makefile +++ b/Projects/3dClientGui/makefile @@ -19,132 +19,83 @@ endif # ifeq "$(CFG)" "Debug" OUTDIR=Debug -OUTFILE=$(OUTDIR)/pathfinder -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 -lwiringPi -lwiringPiDev -lgphoto2 \ - -lgphoto2_port +OUTFILE=$(OUTDIR)/img_mill +CFG_INC=-I/usr/local/include/opencv4 -I/dr_frucht/lib/include +CFG_LIB=-lmysqlclient -lssl -lcrypto -lpthread `pkg-config --libs \ + libavcodec libavdevice libavfilter libavformat libavresample \ + libavutil libswresample libswscale libconfig++ libcurl opencv4` -lGL \ + -lGLU -lc -lm -lz CFG_OBJ= -COMMON_OBJ=$(OUTDIR)/base64.o $(OUTDIR)/basicDualThread.o \ - $(OUTDIR)/basicEngine.o $(OUTDIR)/basicEvent.o \ - $(OUTDIR)/basicEventHandler.o $(OUTDIR)/basicEventHeap.o \ - $(OUTDIR)/basicFunctionality.o $(OUTDIR)/basicLogCollection.o \ - $(OUTDIR)/basicLoggingService.o $(OUTDIR)/basicMutex.o \ - $(OUTDIR)/basicObject.o $(OUTDIR)/basicPosition.o \ +COMMON_OBJ=$(OUTDIR)/basicDualThread.o $(OUTDIR)/basicEngine.o \ + $(OUTDIR)/basicEvent.o $(OUTDIR)/basicEventHandler.o \ + $(OUTDIR)/basicEventHeap.o $(OUTDIR)/basicFunctionality.o \ + $(OUTDIR)/basicLogCollection.o $(OUTDIR)/basicLoggingService.o \ + $(OUTDIR)/basicMediaDestination.o $(OUTDIR)/basicMediaSource.o \ + $(OUTDIR)/basicMediaViewer.o $(OUTDIR)/basicMutex.o \ $(OUTDIR)/basicRing.o $(OUTDIR)/basicSettings.o \ $(OUTDIR)/basicSettingsProvider.o $(OUTDIR)/basicThread.o \ - $(OUTDIR)/basicTimeStamp.o $(OUTDIR)/basicTransport.o \ - $(OUTDIR)/basicTypes.o $(OUTDIR)/BNO055.o $(OUTDIR)/clientPort.o \ - $(OUTDIR)/curlRequest.o $(OUTDIR)/curlRequestsManager.o \ - $(OUTDIR)/database_class.o $(OUTDIR)/gPhotoCamera.o \ - $(OUTDIR)/heapDebug.o $(OUTDIR)/i2cPort.o $(OUTDIR)/json_reader.o \ - $(OUTDIR)/json_value.o $(OUTDIR)/json_writer.o $(OUTDIR)/libzip.o \ - $(OUTDIR)/lrfScanner.o $(OUTDIR)/mask.o $(OUTDIR)/md5.o \ - $(OUTDIR)/objectConsoleLoggingService.o \ - $(OUTDIR)/objectFileLoggingService.o \ - $(OUTDIR)/objectPathfinderBinaryLog.o $(OUTDIR)/objectSystemAnchor.o \ - $(OUTDIR)/Pathfinder_Kernel.o $(OUTDIR)/PathfinderBackend.o \ - $(OUTDIR)/pathfinderDBConnector.o $(OUTDIR)/ponvif.o \ - $(OUTDIR)/protocol.o $(OUTDIR)/protocolHTTP.o $(OUTDIR)/serialPort.o \ - $(OUTDIR)/ssdpAnnouncer.o $(OUTDIR)/Transform.o \ - $(OUTDIR)/transportBus.o $(OUTDIR)/transportSerial.o \ - $(OUTDIR)/transportSocket.o $(OUTDIR)/UBLOX_I2C.o $(OUTDIR)/utm.o \ + $(OUTDIR)/basicTransport.o $(OUTDIR)/basicVideoAnalyzer.o \ + $(OUTDIR)/database_class.o $(OUTDIR)/IM_Backend.o \ + $(OUTDIR)/IM_ClientHandler.o $(OUTDIR)/IM_ClientProtocol.o \ + $(OUTDIR)/IM_DataBaseAdapter.o $(OUTDIR)/IM_DnnWorker.o \ + $(OUTDIR)/IM_Kernel.o $(OUTDIR)/json_reader.o $(OUTDIR)/json_value.o \ + $(OUTDIR)/json_writer.o $(OUTDIR)/md5.o $(OUTDIR)/netClientHandler.o \ + $(OUTDIR)/netServer.o $(OUTDIR)/objectConsoleLoggingService.o \ + $(OUTDIR)/objectFileLoggingService.o $(OUTDIR)/protocol.o \ + $(OUTDIR)/serverPort.o $(OUTDIR)/transportSocket.o \ $(OUTDIR)/xmlParser.o OBJ=$(COMMON_OBJ) $(CFG_OBJ) -ALL_OBJ=$(OUTDIR)/base64.o $(OUTDIR)/basicDualThread.o \ - $(OUTDIR)/basicEngine.o $(OUTDIR)/basicEvent.o \ - $(OUTDIR)/basicEventHandler.o $(OUTDIR)/basicEventHeap.o \ - $(OUTDIR)/basicFunctionality.o $(OUTDIR)/basicLogCollection.o \ - $(OUTDIR)/basicLoggingService.o $(OUTDIR)/basicMutex.o \ - $(OUTDIR)/basicObject.o $(OUTDIR)/basicPosition.o \ +ALL_OBJ=$(OUTDIR)/basicDualThread.o $(OUTDIR)/basicEngine.o \ + $(OUTDIR)/basicEvent.o $(OUTDIR)/basicEventHandler.o \ + $(OUTDIR)/basicEventHeap.o $(OUTDIR)/basicFunctionality.o \ + $(OUTDIR)/basicLogCollection.o $(OUTDIR)/basicLoggingService.o \ + $(OUTDIR)/basicMediaDestination.o $(OUTDIR)/basicMediaSource.o \ + $(OUTDIR)/basicMediaViewer.o $(OUTDIR)/basicMutex.o \ $(OUTDIR)/basicRing.o $(OUTDIR)/basicSettings.o \ $(OUTDIR)/basicSettingsProvider.o $(OUTDIR)/basicThread.o \ - $(OUTDIR)/basicTimeStamp.o $(OUTDIR)/basicTransport.o \ - $(OUTDIR)/basicTypes.o $(OUTDIR)/BNO055.o $(OUTDIR)/clientPort.o \ - $(OUTDIR)/curlRequest.o $(OUTDIR)/curlRequestsManager.o \ - $(OUTDIR)/database_class.o $(OUTDIR)/gPhotoCamera.o \ - $(OUTDIR)/heapDebug.o $(OUTDIR)/i2cPort.o $(OUTDIR)/json_reader.o \ - $(OUTDIR)/json_value.o $(OUTDIR)/json_writer.o $(OUTDIR)/libzip.o \ - $(OUTDIR)/lrfScanner.o $(OUTDIR)/mask.o $(OUTDIR)/md5.o \ - $(OUTDIR)/objectConsoleLoggingService.o \ - $(OUTDIR)/objectFileLoggingService.o \ - $(OUTDIR)/objectPathfinderBinaryLog.o $(OUTDIR)/objectSystemAnchor.o \ - $(OUTDIR)/Pathfinder_Kernel.o $(OUTDIR)/PathfinderBackend.o \ - $(OUTDIR)/pathfinderDBConnector.o $(OUTDIR)/ponvif.o \ - $(OUTDIR)/protocol.o $(OUTDIR)/protocolHTTP.o $(OUTDIR)/serialPort.o \ - $(OUTDIR)/ssdpAnnouncer.o $(OUTDIR)/Transform.o \ - $(OUTDIR)/transportBus.o $(OUTDIR)/transportSerial.o \ - $(OUTDIR)/transportSocket.o $(OUTDIR)/UBLOX_I2C.o $(OUTDIR)/utm.o \ - $(OUTDIR)/xmlParser.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 -lwiringPi -lwiringPiDev \ - -lgphoto2 -lgphoto2_port - -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) $< + $(OUTDIR)/basicTransport.o $(OUTDIR)/basicVideoAnalyzer.o \ + $(OUTDIR)/database_class.o $(OUTDIR)/IM_Backend.o \ + $(OUTDIR)/IM_ClientHandler.o $(OUTDIR)/IM_ClientProtocol.o \ + $(OUTDIR)/IM_DataBaseAdapter.o $(OUTDIR)/IM_DnnWorker.o \ + $(OUTDIR)/IM_Kernel.o $(OUTDIR)/json_reader.o $(OUTDIR)/json_value.o \ + $(OUTDIR)/json_writer.o $(OUTDIR)/md5.o $(OUTDIR)/netClientHandler.o \ + $(OUTDIR)/netServer.o $(OUTDIR)/objectConsoleLoggingService.o \ + $(OUTDIR)/objectFileLoggingService.o $(OUTDIR)/protocol.o \ + $(OUTDIR)/serverPort.o $(OUTDIR)/transportSocket.o \ + $(OUTDIR)/xmlParser.o -lmysqlclient -lssl -lcrypto -lpthread \ + `pkg-config --libs libavcodec libavdevice libavfilter libavformat \ + libavresample libavutil libswresample libswscale libconfig++ libcurl \ + opencv4` -lGL -lGLU -lc -lm -lz + +COMPILE=g++ -c -x c++ "-D_OPENCV_" "-DDEBUG" -g -ggdb `pkg-config --cflags opencv4` -o "$(OUTDIR)/$(*F).o" $(CFG_INC) $< LINK=g++ -g -ggdb -o "$(OUTFILE)" $(ALL_OBJ) # Pattern rules -$(OUTDIR)/%.o : ../../lib/hardware/sensors/gps/%.cpp - $(COMPILE) - -$(OUTDIR)/%.o : ../../lib/data/transport/%.cpp - $(COMPILE) - -$(OUTDIR)/%.o : ../../lib/data/protocol/%.cpp - $(COMPILE) - -$(OUTDIR)/%.o : ../../lib/hardware/sensors/9dof/%.cpp - $(COMPILE) - -$(OUTDIR)/%.o : ../../lib/alg/lgs/%.cpp - $(COMPILE) - -$(OUTDIR)/%.o : ../../lib/data/ssdp/%.cpp - $(COMPILE) - -$(OUTDIR)/%.o : ../../lib/pathfinder/%.cpp - $(COMPILE) - -$(OUTDIR)/%.o : ../../lib/App/Pathfinder/%.cpp - $(COMPILE) - -$(OUTDIR)/%.o : ../../lib/data/ponvif/%.cpp - $(COMPILE) - $(OUTDIR)/%.o : ../../lib/alg/generic/%.cpp $(COMPILE) -$(OUTDIR)/%.o : ../../lib/components/base/%.cpp - $(COMPILE) - -$(OUTDIR)/%.o : ../../lib/hardware/i2c/%.cpp - $(COMPILE) - -$(OUTDIR)/%.o : ../../lib/hardware/uart/%.cpp +$(OUTDIR)/%.o : %.cpp $(COMPILE) -$(OUTDIR)/%.o : ../../lib/components/object/%.cpp +$(OUTDIR)/%.o : ../../lib/components/base/%.cpp $(COMPILE) -$(OUTDIR)/%.o : ../../lib/hardware/sensors/gphoto/%.cpp +$(OUTDIR)/%.o : ../../lib/data/transport/%.cpp $(COMPILE) -$(OUTDIR)/%.o : ../../lib/hardware/sensors/lrf/%.cpp +$(OUTDIR)/%.o : ../../lib/data/protocol/%.cpp $(COMPILE) $(OUTDIR)/%.o : ../../lib/data/net/%.cpp $(COMPILE) -$(OUTDIR)/%.o : ../../lib/data/curl/%.cpp +$(OUTDIR)/%.o : ../../lib/data/json/%.cpp $(COMPILE) $(OUTDIR)/%.o : ../../lib/data/mysql/%.cpp $(COMPILE) -$(OUTDIR)/%.o : ../../lib/data/json/%.cpp +$(OUTDIR)/%.o : ../../lib/components/object/%.cpp $(COMPILE) # Build rules @@ -173,132 +124,83 @@ endif # ifeq "$(CFG)" "Release" OUTDIR=Release -OUTFILE=$(OUTDIR)/pathfinder -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 -lwiringPi -lwiringPiDev -lgphoto2 \ - -lgphoto2_port +OUTFILE=$(OUTDIR)/img_mill +CFG_INC=-I/usr/local/include/opencv4 -I/dr_frucht/lib/include +CFG_LIB=-lmysqlclient -lssl -lcrypto -lpthread `pkg-config --libs \ + libavcodec libavdevice libavfilter libavformat libavresample \ + libavutil libswresample libswscale libconfig++ libcurl opencv4` -lGL \ + -lGLU -lc -lm -lz CFG_OBJ= -COMMON_OBJ=$(OUTDIR)/base64.o $(OUTDIR)/basicDualThread.o \ - $(OUTDIR)/basicEngine.o $(OUTDIR)/basicEvent.o \ - $(OUTDIR)/basicEventHandler.o $(OUTDIR)/basicEventHeap.o \ - $(OUTDIR)/basicFunctionality.o $(OUTDIR)/basicLogCollection.o \ - $(OUTDIR)/basicLoggingService.o $(OUTDIR)/basicMutex.o \ - $(OUTDIR)/basicObject.o $(OUTDIR)/basicPosition.o \ +COMMON_OBJ=$(OUTDIR)/basicDualThread.o $(OUTDIR)/basicEngine.o \ + $(OUTDIR)/basicEvent.o $(OUTDIR)/basicEventHandler.o \ + $(OUTDIR)/basicEventHeap.o $(OUTDIR)/basicFunctionality.o \ + $(OUTDIR)/basicLogCollection.o $(OUTDIR)/basicLoggingService.o \ + $(OUTDIR)/basicMediaDestination.o $(OUTDIR)/basicMediaSource.o \ + $(OUTDIR)/basicMediaViewer.o $(OUTDIR)/basicMutex.o \ $(OUTDIR)/basicRing.o $(OUTDIR)/basicSettings.o \ $(OUTDIR)/basicSettingsProvider.o $(OUTDIR)/basicThread.o \ - $(OUTDIR)/basicTimeStamp.o $(OUTDIR)/basicTransport.o \ - $(OUTDIR)/basicTypes.o $(OUTDIR)/BNO055.o $(OUTDIR)/clientPort.o \ - $(OUTDIR)/curlRequest.o $(OUTDIR)/curlRequestsManager.o \ - $(OUTDIR)/database_class.o $(OUTDIR)/gPhotoCamera.o \ - $(OUTDIR)/heapDebug.o $(OUTDIR)/i2cPort.o $(OUTDIR)/json_reader.o \ - $(OUTDIR)/json_value.o $(OUTDIR)/json_writer.o $(OUTDIR)/libzip.o \ - $(OUTDIR)/lrfScanner.o $(OUTDIR)/mask.o $(OUTDIR)/md5.o \ - $(OUTDIR)/objectConsoleLoggingService.o \ - $(OUTDIR)/objectFileLoggingService.o \ - $(OUTDIR)/objectPathfinderBinaryLog.o $(OUTDIR)/objectSystemAnchor.o \ - $(OUTDIR)/Pathfinder_Kernel.o $(OUTDIR)/PathfinderBackend.o \ - $(OUTDIR)/pathfinderDBConnector.o $(OUTDIR)/ponvif.o \ - $(OUTDIR)/protocol.o $(OUTDIR)/protocolHTTP.o $(OUTDIR)/serialPort.o \ - $(OUTDIR)/ssdpAnnouncer.o $(OUTDIR)/Transform.o \ - $(OUTDIR)/transportBus.o $(OUTDIR)/transportSerial.o \ - $(OUTDIR)/transportSocket.o $(OUTDIR)/UBLOX_I2C.o $(OUTDIR)/utm.o \ + $(OUTDIR)/basicTransport.o $(OUTDIR)/basicVideoAnalyzer.o \ + $(OUTDIR)/database_class.o $(OUTDIR)/IM_Backend.o \ + $(OUTDIR)/IM_ClientHandler.o $(OUTDIR)/IM_ClientProtocol.o \ + $(OUTDIR)/IM_DataBaseAdapter.o $(OUTDIR)/IM_DnnWorker.o \ + $(OUTDIR)/IM_Kernel.o $(OUTDIR)/json_reader.o $(OUTDIR)/json_value.o \ + $(OUTDIR)/json_writer.o $(OUTDIR)/md5.o $(OUTDIR)/netClientHandler.o \ + $(OUTDIR)/netServer.o $(OUTDIR)/objectConsoleLoggingService.o \ + $(OUTDIR)/objectFileLoggingService.o $(OUTDIR)/protocol.o \ + $(OUTDIR)/serverPort.o $(OUTDIR)/transportSocket.o \ $(OUTDIR)/xmlParser.o OBJ=$(COMMON_OBJ) $(CFG_OBJ) -ALL_OBJ=$(OUTDIR)/base64.o $(OUTDIR)/basicDualThread.o \ - $(OUTDIR)/basicEngine.o $(OUTDIR)/basicEvent.o \ - $(OUTDIR)/basicEventHandler.o $(OUTDIR)/basicEventHeap.o \ - $(OUTDIR)/basicFunctionality.o $(OUTDIR)/basicLogCollection.o \ - $(OUTDIR)/basicLoggingService.o $(OUTDIR)/basicMutex.o \ - $(OUTDIR)/basicObject.o $(OUTDIR)/basicPosition.o \ +ALL_OBJ=$(OUTDIR)/basicDualThread.o $(OUTDIR)/basicEngine.o \ + $(OUTDIR)/basicEvent.o $(OUTDIR)/basicEventHandler.o \ + $(OUTDIR)/basicEventHeap.o $(OUTDIR)/basicFunctionality.o \ + $(OUTDIR)/basicLogCollection.o $(OUTDIR)/basicLoggingService.o \ + $(OUTDIR)/basicMediaDestination.o $(OUTDIR)/basicMediaSource.o \ + $(OUTDIR)/basicMediaViewer.o $(OUTDIR)/basicMutex.o \ $(OUTDIR)/basicRing.o $(OUTDIR)/basicSettings.o \ $(OUTDIR)/basicSettingsProvider.o $(OUTDIR)/basicThread.o \ - $(OUTDIR)/basicTimeStamp.o $(OUTDIR)/basicTransport.o \ - $(OUTDIR)/basicTypes.o $(OUTDIR)/BNO055.o $(OUTDIR)/clientPort.o \ - $(OUTDIR)/curlRequest.o $(OUTDIR)/curlRequestsManager.o \ - $(OUTDIR)/database_class.o $(OUTDIR)/gPhotoCamera.o \ - $(OUTDIR)/heapDebug.o $(OUTDIR)/i2cPort.o $(OUTDIR)/json_reader.o \ - $(OUTDIR)/json_value.o $(OUTDIR)/json_writer.o $(OUTDIR)/libzip.o \ - $(OUTDIR)/lrfScanner.o $(OUTDIR)/mask.o $(OUTDIR)/md5.o \ - $(OUTDIR)/objectConsoleLoggingService.o \ - $(OUTDIR)/objectFileLoggingService.o \ - $(OUTDIR)/objectPathfinderBinaryLog.o $(OUTDIR)/objectSystemAnchor.o \ - $(OUTDIR)/Pathfinder_Kernel.o $(OUTDIR)/PathfinderBackend.o \ - $(OUTDIR)/pathfinderDBConnector.o $(OUTDIR)/ponvif.o \ - $(OUTDIR)/protocol.o $(OUTDIR)/protocolHTTP.o $(OUTDIR)/serialPort.o \ - $(OUTDIR)/ssdpAnnouncer.o $(OUTDIR)/Transform.o \ - $(OUTDIR)/transportBus.o $(OUTDIR)/transportSerial.o \ - $(OUTDIR)/transportSocket.o $(OUTDIR)/UBLOX_I2C.o $(OUTDIR)/utm.o \ - $(OUTDIR)/xmlParser.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 -lwiringPi -lwiringPiDev \ - -lgphoto2 -lgphoto2_port - -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) $< + $(OUTDIR)/basicTransport.o $(OUTDIR)/basicVideoAnalyzer.o \ + $(OUTDIR)/database_class.o $(OUTDIR)/IM_Backend.o \ + $(OUTDIR)/IM_ClientHandler.o $(OUTDIR)/IM_ClientProtocol.o \ + $(OUTDIR)/IM_DataBaseAdapter.o $(OUTDIR)/IM_DnnWorker.o \ + $(OUTDIR)/IM_Kernel.o $(OUTDIR)/json_reader.o $(OUTDIR)/json_value.o \ + $(OUTDIR)/json_writer.o $(OUTDIR)/md5.o $(OUTDIR)/netClientHandler.o \ + $(OUTDIR)/netServer.o $(OUTDIR)/objectConsoleLoggingService.o \ + $(OUTDIR)/objectFileLoggingService.o $(OUTDIR)/protocol.o \ + $(OUTDIR)/serverPort.o $(OUTDIR)/transportSocket.o \ + $(OUTDIR)/xmlParser.o -lmysqlclient -lssl -lcrypto -lpthread \ + `pkg-config --libs libavcodec libavdevice libavfilter libavformat \ + libavresample libavutil libswresample libswscale libconfig++ libcurl \ + opencv4` -lGL -lGLU -lc -lm -lz + +COMPILE=g++ -c -x c++ "-D_OPENCV_" "-DDEBUG" -ggdb `pkg-config --cflags opencv4` -o "$(OUTDIR)/$(*F).o" $(CFG_INC) $< LINK=g++ -ggdb -o "$(OUTFILE)" $(ALL_OBJ) # Pattern rules -$(OUTDIR)/%.o : ../../lib/hardware/sensors/gps/%.cpp - $(COMPILE) - -$(OUTDIR)/%.o : ../../lib/data/transport/%.cpp - $(COMPILE) - -$(OUTDIR)/%.o : ../../lib/data/protocol/%.cpp - $(COMPILE) - -$(OUTDIR)/%.o : ../../lib/hardware/sensors/9dof/%.cpp - $(COMPILE) - -$(OUTDIR)/%.o : ../../lib/alg/lgs/%.cpp - $(COMPILE) - -$(OUTDIR)/%.o : ../../lib/data/ssdp/%.cpp - $(COMPILE) - -$(OUTDIR)/%.o : ../../lib/pathfinder/%.cpp - $(COMPILE) - -$(OUTDIR)/%.o : ../../lib/App/Pathfinder/%.cpp - $(COMPILE) - -$(OUTDIR)/%.o : ../../lib/data/ponvif/%.cpp - $(COMPILE) - $(OUTDIR)/%.o : ../../lib/alg/generic/%.cpp $(COMPILE) -$(OUTDIR)/%.o : ../../lib/components/base/%.cpp - $(COMPILE) - -$(OUTDIR)/%.o : ../../lib/hardware/i2c/%.cpp - $(COMPILE) - -$(OUTDIR)/%.o : ../../lib/hardware/uart/%.cpp +$(OUTDIR)/%.o : %.cpp $(COMPILE) -$(OUTDIR)/%.o : ../../lib/components/object/%.cpp +$(OUTDIR)/%.o : ../../lib/components/base/%.cpp $(COMPILE) -$(OUTDIR)/%.o : ../../lib/hardware/sensors/gphoto/%.cpp +$(OUTDIR)/%.o : ../../lib/data/transport/%.cpp $(COMPILE) -$(OUTDIR)/%.o : ../../lib/hardware/sensors/lrf/%.cpp +$(OUTDIR)/%.o : ../../lib/data/protocol/%.cpp $(COMPILE) $(OUTDIR)/%.o : ../../lib/data/net/%.cpp $(COMPILE) -$(OUTDIR)/%.o : ../../lib/data/curl/%.cpp +$(OUTDIR)/%.o : ../../lib/data/json/%.cpp $(COMPILE) $(OUTDIR)/%.o : ../../lib/data/mysql/%.cpp $(COMPILE) -$(OUTDIR)/%.o : ../../lib/data/json/%.cpp +$(OUTDIR)/%.o : ../../lib/components/object/%.cpp $(COMPILE) # Build rules diff --git a/Projects/LRF_Server/build b/Projects/LRF_Server/build old mode 100644 new mode 100755 diff --git a/Projects/img_mill/IM_Backend.cpp b/Projects/img_mill/IM_Backend.cpp index 68952f71..6c8ffd9c 100644 --- a/Projects/img_mill/IM_Backend.cpp +++ b/Projects/img_mill/IM_Backend.cpp @@ -22,7 +22,6 @@ bool gSignal_Handler_Enabled = true; #define LOG_ERROR( X ) m_pLog->Log( "main", 0, _LOG_ERROR, X ) IM_Kernel * Kernel = NULL; -//LRF_HardwareManager * HWManager = NULL; basicLogCollection * m_pLog = NULL; networkServer * NetworkManager = NULL; @@ -49,7 +48,6 @@ void signal_SIGKILL_handler( int SIG ){ //#include int main (int argc, char *argv[]){ - //MySQL_Connector * DBC = NULL; basicSettingsProvider * SETTINGS = NULL; bool WBG; // Working Background bool SSE; // Server Statistics Engine @@ -148,7 +146,7 @@ int main (int argc, char *argv[]){ if( FLE != NULL ) { m_pLog->addHandler( FLE ); }; - LOG("Starting Log Engne!"); + LOG("Starting Log Engine!"); if ( fileExist( DCF_NAME ) ){ SETTINGS = basicSettingsProvider::getInstance(DCF_NAME); } else { @@ -206,6 +204,15 @@ int main (int argc, char *argv[]){ uint8_t m_bKernelExitCode = 0; + NetworkManager = new networkServer(); + if( NetworkManager != NULL ) { + if( NetworkManager->BootUp() ){ + LOG("Net Service is UP"); + } else { + delete(NetworkManager); + NetworkManager = NULL; + }; + }; do{ //Loop till some Restart action Kernel = IM_Kernel::getInstance(); @@ -217,10 +224,13 @@ int main (int argc, char *argv[]){ delete( m_pLog ); return -1; } else { - LOG( "++++ Server Started ++++" ); if ( Kernel->start() == false ){ LOG_ERROR("Kernel create failure!"); } else { + LOG( "++++ Server Started ++++" ); + if( NetworkManager!= NULL ) { + NetworkManager->attachEngine( Kernel ); + }; //Install Signal Listeners old_kill_handler_15 = signal( 15, signal_SIGKILL_handler ); old_kill_handler_9 = signal( 9, signal_SIGKILL_handler ); @@ -230,12 +240,13 @@ int main (int argc, char *argv[]){ signal( 9, old_kill_handler_9 ); signal( 15, old_kill_handler_15 ); }; + //Since Kernel is Singletone Object no need to delete delete( Kernel ); LOG( "++++ Server Ended ++++" ); }; } while( m_bKernelExitCode > 0 ); - delete( NetworkManager ); + if( NetworkManager ) delete( NetworkManager ); //LOG( "++++ CDC DEL ++++" ); unlink( gsCFG_PID_FILE ); LOG( "PID File Deleted" ); diff --git a/Projects/img_mill/IM_ClientHandler.cpp b/Projects/img_mill/IM_ClientHandler.cpp index 96665efa..eca4a323 100644 --- a/Projects/img_mill/IM_ClientHandler.cpp +++ b/Projects/img_mill/IM_ClientHandler.cpp @@ -1,6 +1,15 @@ #include "IM_ClientHandler.h" -#include "../../lib/alg/generic/md5.h" +#include "IM_Kernel.h" + +#include "../../lib/components/base/basicFunctionality.h" #include "../../lib/data/json/json_tool.h" +#include "../../lib/data/protocol/xmlParser.h" + +#include +#include +#include +#include + #define LOG( X ) m_pLog->Log( "NCH", this, X ) @@ -17,21 +26,25 @@ // Constructor implementation IM_ClientHandler::IM_ClientHandler( int SOCKET ) : networkClientHandler( SOCKET ), IM_ClientProtocol(){ m_pLog = basicLogCollection::getInstance(); - if( m_pPort != NULL ){ - //LOG("server port is OK"); + m_pDBA = IM_DataBaseAdapter::getInstance(); + m_pMyCurrentJob = NULL; + //if( m_pPort != NULL ){ if( create() ){ - setTransport( m_pPort ); - setConnectionStatus( CS_INIT ); - m_pPort->addRecipient(( protocolParser *)this ); - } else { - LOG_ERROR( "Protocol Parser Creation Failed!"); - }; - }; + m_pPort = new serverPort( SOCKET ); + if( m_pPort ) { +#ifdef DEBUG + LOG("Client Port Created OK!"); +#endif + setTransport( m_pPort ); + }else LOG_ERROR("Port Not Created!"); + } else LOG_ERROR( "Protocol Parser Creation Failed!"); + //} else LOG_ERROR("Port Not Created!"); }; // Destructor implementation -inline IM_ClientHandler::~IM_ClientHandler(){ - +IM_ClientHandler::~IM_ClientHandler(){ + if( m_pPort != NULL ) delete( m_pPort ); + //if( m_pMyCurrentJob ) free( (IM_JOB *)m_pMyCurrentJob ); }; bool IM_ClientHandler::getStatus( void ){ @@ -41,6 +54,124 @@ bool IM_ClientHandler::getStatus( void ){ return false; }; +bool IM_ClientHandler::handleItem( IM_ITEM_DATA *ptr ){ + if( ptr ) { + if( m_pEngine != NULL ) { + IM_Kernel *tKernel = (IM_Kernel *)m_pEngine; + IM_JOB *tJOB; + tJOB = (IM_JOB*)malloc(sizeof(IM_JOB)); + if( tJOB ) { + m_pMyCurrentJob = (void*) tJOB; + memset( tJOB, 0 , sizeof(IM_JOB)); + tJOB->dbID = ptr->item_id; + tJOB->type = ptr->type; + tJOB->width = ptr->width; + tJOB->height = ptr->height; + memcpy( tJOB->md5, ptr->md5, 32 ); + tKernel->enqueueJob( tJOB ); + }; + }; + free( ptr ); + }; + return true; +}; + +bool IM_ClientHandler::packetHandler( protocolPackage *Package ){ + if( Package ) { + if( Package->m_pData ) { + if (Package->m_nSize > 3 ) { + if( Package->m_pData[Package->m_nSize-4] == 13 ) Package->m_pData[Package->m_nSize-4] = 0; + if( Package->m_pData[Package->m_nSize-3] == 10 ) Package->m_pData[Package->m_nSize-3] = 0; + } + Package->m_pData[Package->m_nSize-2] = 0; + Package->m_pData[Package->m_nSize-1] = 0; + //LOG( (CSTR) Package->m_pData ); + try{ + XMLNode node1 = XMLNode::parseString( (const char *)Package->m_pData, "root"); + if( !node1.isEmpty() ){ + LOG( node1.getName() ); + if( strstr(node1.getName(),"ClockSync")!=NULL ){ +#ifdef __linux__ + unsigned long long t0, t1, t2, t3; +#else + unsigned __int64 t0, t1, t2, t3; +#endif + XMLNode node3 = node1.getChildNode("t0", 0); + XMLNode node4 = node1.getChildNode("t1", 0); + XMLNode node5 = node1.getChildNode("t2", 0); +/* + t3 = getSHDTimeValue(); +#ifdef __linux__ + t0 = atoll(node3.getText(0)); + t1 = atoll(node4.getText(0)); + t2 = atoll(node5.getText(0)); +#else + t0 = _atoi64(node3.getText(0)); + t1 = _atoi64(node4.getText(0)); + t2 = _atoi64(node5.getText(0)); +#endif + int offset = ((t1-t0)+(t2-t3))/2; + int latency = (t3-t0)-(t2-t1); + int jagajaga = offset+latency; + //if( 0 & correctSHTime( jagajaga ) ){ + // LOG("Time is Synced"); + // g_iTimeDiff = 0; + //} else { + // LOG_ERROR("Time Sync Unucessfull - Will use DIFF!"); + g_iTimeDiff = jagajaga; + //}; +*/ + }; + }; + } catch( exception e ){ + }; + try{ + Json::Value root; + Json::Reader reader; + if( !reader.parse( (char *)Package->m_pData, root ) ){ + LOG_ERROR( "The package data is nor a valid JSON data nor valid XML data" ); + return true; + }; + if( root.size() ){ + Json::Value tVal; + tVal = root["item_id"]; + if( tVal != NULL ){ + int itemID = atoi( tVal.asString().c_str() ) ; + if( itemID > 0 ) { + IM_ITEM_DATA *tData = m_pDBA->getItemDataById( itemID ); + if( tData ) return handleItem( tData ); + }; + }; + tVal = root["item_md5"]; + if( tVal != NULL ){ + if( strlen( tVal.asString().c_str())== 32 ){ + IM_ITEM_DATA *tData = m_pDBA->getItemDataByMd5( (CSTR) tVal.asString().c_str() ); + if( tData ) return handleItem( tData ); + }; + }; + }; + } catch ( exception e ){ + }; + }; + }; + return true; +}; + +void IM_ClientHandler::dispatchEvent( basicEvent *Evt ){ + if( Evt!= NULL ) { + if( Evt->m_eClass == EVT_CLASS_IMAGE ){ + if( Evt->m_eType == EVT_READY ){ + IM_RESULT *tData = (IM_RESULT*) Evt->m_pEvtData; + if( tData!= NULL ) { + if( tData->pJOB == m_pMyCurrentJob ) { + //handle finished Job + }; + }; + }; + }; + }; +}; + #undef LOG #undef LOG_ERROR diff --git a/Projects/img_mill/IM_ClientHandler.h b/Projects/img_mill/IM_ClientHandler.h index 01bfc02f..fd03f1fb 100644 --- a/Projects/img_mill/IM_ClientHandler.h +++ b/Projects/img_mill/IM_ClientHandler.h @@ -3,6 +3,9 @@ #include "../../lib/data/net/netClientHandler.h" #include "IM_ClientProtocol.h" +#include "IM_DataBaseAdapter.h" + + /** * TODO: Add class description * @@ -11,6 +14,10 @@ class IM_ClientHandler : public networkClientHandler, public IM_ClientProtocol{ private: basicLogCollection * m_pLog; + void * m_pMyCurrentJob; + IM_DataBaseAdapter * m_pDBA; + protected: + virtual bool packetHandler( protocolPackage *Package ); public: // Constructor explicit IM_ClientHandler( int SOCKET ); @@ -18,6 +25,8 @@ class IM_ClientHandler : public networkClientHandler, public IM_ClientProtocol{ // Destructor virtual ~IM_ClientHandler(); virtual bool getStatus( void ); + bool handleItem( IM_ITEM_DATA *ptr ); + virtual void dispatchEvent( basicEvent *Evt ); }; diff --git a/Projects/img_mill/IM_ClientProtocol.cpp b/Projects/img_mill/IM_ClientProtocol.cpp index f6f9f2d1..48a1e802 100644 --- a/Projects/img_mill/IM_ClientProtocol.cpp +++ b/Projects/img_mill/IM_ClientProtocol.cpp @@ -1,16 +1,55 @@ #include "IM_ClientProtocol.h" -#define LOG( X ) m_pLog->Log( "KRNL", this, X ) +#define LOG( X ) m_pLog->Log( "NCP", this, X ) #ifdef DEBUG #define LOG_ERROR( X ) {\ char _tBfrErrMSG234[256];\ sprintf( _tBfrErrMSG234, "In file %s[%d] in func:%s %s",__FILE__, __LINE__, __func__, X );\ - m_pLog->Log( "KRNL", this, _LOG_ERROR, _tBfrErrMSG234 );\ + m_pLog->Log( "NCP", this, _LOG_ERROR, _tBfrErrMSG234 );\ } #else - #define LOG_ERROR( X ) m_pLog->Log( "KRNL", this, _LOG_ERROR, X ); + #define LOG_ERROR( X ) m_pLog->Log( "NCP", this, _LOG_ERROR, X ); #endif +// Constructor implementation +IM_ClientProtocol::IM_ClientProtocol() : protocolParser(){ + +}; + +// Destructor implementation +IM_ClientProtocol::~IM_ClientProtocol(){ + +}; + +int IM_ClientProtocol::packetChecker(U8 *Buffer, size_t BufferSize){ + // double enter -> finish package + if( BufferSize > 2 ){ + if( ( Buffer[BufferSize-2] == 13 ) && ( Buffer[BufferSize-1] == 13 ) ) return 0; + }; + if( BufferSize > 3 ){ + if( ( Buffer[BufferSize-4] == 13 ) && ( Buffer[BufferSize-3] == 10 ) && ( Buffer[BufferSize-2] == 13 ) && ( Buffer[BufferSize-1] == 10 ) ) return 0; + }; + return 1; +}; + +protocolPackage *IM_ClientProtocol::packetExtractor(U8 *Buffer, size_t BufferSize){ + protocolPackage *tVal = NULL; + tVal = (protocolPackage *) malloc( sizeof(protocolPackage)); + if(tVal) { + tVal->m_pData = (U8*)malloc( BufferSize+1 ); + if( tVal->m_pData ) { + tVal->m_nCode = 200; + tVal->m_nSize = BufferSize; + memcpy( tVal->m_pData, Buffer, BufferSize ); + tVal->m_pData[BufferSize]=0; + } else { + free( tVal ); + tVal = NULL; + }; + }; + return tVal; +}; + #undef LOG diff --git a/Projects/img_mill/IM_ClientProtocol.h b/Projects/img_mill/IM_ClientProtocol.h index 93cac0bd..41a88538 100644 --- a/Projects/img_mill/IM_ClientProtocol.h +++ b/Projects/img_mill/IM_ClientProtocol.h @@ -9,48 +9,16 @@ * @author Gagua */ class IM_ClientProtocol : public protocolParser { + protected: + virtual int packetChecker(U8 *Buffer, size_t BufferSize); + virtual protocolPackage *packetExtractor(U8 *Buffer, size_t BufferSize); + virtual bool packetHandler( protocolPackage *Package ){ return false; }; public: // Constructor IM_ClientProtocol(); // Destructor virtual ~IM_ClientProtocol(); - - // Copy constructor - // TODO: Uncomment the copy constructor when you need it. - //IM_ClientProtocol(const IM_ClientProtocol& src); - - // Assignment operator - // TODO: Uncomment the assignment operator when you need it. - //IM_ClientProtocol& operator=(const IM_ClientProtocol& src); }; -// Constructor implementation -inline IM_ClientProtocol::IM_ClientProtocol() : protocolParser() -{ -} - -// Destructor implementation -inline IM_ClientProtocol::~IM_ClientProtocol() -{ -} - -// TODO: Uncomment the copy constructor when you need it. -//inline IM_ClientProtocol::IM_ClientProtocol(const IM_ClientProtocol& src) -//{ -// // TODO: copy -//} - -// TODO: Uncomment the assignment operator when you need it. -//inline IM_ClientProtocol& IM_ClientProtocol::operator=(const IM_ClientProtocol& rhs) -//{ -// if (this == &rhs) { -// return *this; -// } -// -// // TODO: assignment -// -// return *this; -//} - #endif // __IM_CLIENTPROTOCOL_H_INCL__ diff --git a/Projects/img_mill/IM_DataBaseAdapter.cpp b/Projects/img_mill/IM_DataBaseAdapter.cpp index 684038e7..652ef45d 100644 --- a/Projects/img_mill/IM_DataBaseAdapter.cpp +++ b/Projects/img_mill/IM_DataBaseAdapter.cpp @@ -1,15 +1,15 @@ #include "IM_DataBaseAdapter.h" #include "../../lib/alg/generic/md5.h" -#define LOG( X ) m_pLog->Log( "KRNL", this, X ) +#define LOG( X ) m_pLog->Log( "IMDBA", this, X ) #ifdef DEBUG #define LOG_ERROR( X ) {\ char _tBfrErrMSG234[256];\ sprintf( _tBfrErrMSG234, "In file %s[%d] in func:%s %s",__FILE__, __LINE__, __func__, X );\ - m_pLog->Log( "KRNL", this, _LOG_ERROR, _tBfrErrMSG234 );\ + m_pLog->Log( "IMDBA", this, _LOG_ERROR, _tBfrErrMSG234 );\ } #else - #define LOG_ERROR( X ) m_pLog->Log( "KRNL", this, _LOG_ERROR, X ); + #define LOG_ERROR( X ) m_pLog->Log( "IMDBA", this, _LOG_ERROR, X ); #endif IM_DataBaseAdapter* IM_DataBaseAdapter::_instance = NULL; @@ -89,6 +89,120 @@ inline IM_DataBaseAdapter::IM_DataBaseAdapter( config_setting_t * Settings ){ // Destructor implementation inline IM_DataBaseAdapter::~IM_DataBaseAdapter(){ + if( m_pConnectorClass ) delete( m_pConnectorClass ); +}; + +IM_ITEM_DATA *IM_DataBaseAdapter::getItemDataById( uint32_t itemID ){ + IM_ITEM_DATA *tVal = NULL; + if( m_pConnectorClass ) { + char tQBuf[CTEXT]; + AAssoc *result; + sprintf(tQBuf, "SELECT `id`, `md5`, `width`, `height`, `4cc` FROM `items` WHERE `id`=%d", itemID ); +#ifdef DEBUG + LOG(tQBuf); +#endif + result = m_pConnectorClass->Query( tQBuf ); + if( result!= NULL ) { + if( result->size() > 0 ) { + Assoc *cArr; + tVal = (IM_ITEM_DATA*) malloc(sizeof(IM_ITEM_DATA)); + if( tVal != NULL ) { + Assoc::iterator it; + + memset( tVal, 0, sizeof(IM_ITEM_DATA) ); + cArr = result->at(0); + it = cArr->find("id"); + if( it != cArr->end() ){ + tVal->item_id = atoi( it->second.c_str() ); + }; + it = cArr->find("md5"); + if( it != cArr->end() ){ + strncpy( tVal->md5, it->second.c_str(), 32 ); + }; + it = cArr->find("width"); + if( it != cArr->end() ){ + tVal->width = atoi( it->second.c_str() ); + }; + it = cArr->find("height"); + if( it != cArr->end() ){ + tVal->height = atoi( it->second.c_str() ); + }; + it = cArr->find("4cc"); + if( it != cArr->end() ){ + if( strstr( it->second.c_str(),"JPEG" ) ) tVal->type = IM_ITEM_TYPE_JPEG; + if( strstr( it->second.c_str(),"PNG" ) ) tVal->type = IM_ITEM_TYPE_PNG; + if( strstr( it->second.c_str(),"GIF" ) ) tVal->type = IM_ITEM_TYPE_GIF; + if( strstr( it->second.c_str(),"TIFF" ) ) tVal->type = IM_ITEM_TYPE_TIFF; + if( strstr( it->second.c_str(),"AGIF" ) ) tVal->type = IM_ITEM_TYPE_AGIF; + }; + }; + }; + }; + deleteResult( result ); + }; + return tVal; +}; + +IM_ITEM_DATA *IM_DataBaseAdapter::getItemDataByMd5( CSTR md5 ){ + IM_ITEM_DATA *tVal = NULL; + if( m_pConnectorClass ) { + char tQBuf[CTEXT]; + AAssoc *result; + sprintf(tQBuf, "SELECT `id`, `md5`, `width`, `height`, `4cc` FROM `items` WHERE `md5`='%s'", md5 ); +#ifdef DEBUG + LOG(tQBuf); +#endif + result = m_pConnectorClass->Query( tQBuf ); + if( result!= NULL ) { + if( result->size() > 0 ) { + Assoc *cArr; + tVal = (IM_ITEM_DATA*) malloc(sizeof(IM_ITEM_DATA)); + if( tVal != NULL ) { + Assoc::iterator it; + + memset( tVal, 0, sizeof(IM_ITEM_DATA) ); + cArr = result->at(0); + it = cArr->find("id"); + if( it != cArr->end() ){ + tVal->item_id = atoi( it->second.c_str() ); + }; + it = cArr->find("md5"); + if( it != cArr->end() ){ + strncpy( tVal->md5, it->second.c_str(), 32 ); + }; + it = cArr->find("width"); + if( it != cArr->end() ){ + tVal->width = atoi( it->second.c_str() ); + }; + it = cArr->find("height"); + if( it != cArr->end() ){ + tVal->height = atoi( it->second.c_str() ); + }; + it = cArr->find("4cc"); + if( it != cArr->end() ){ + if( strstr( it->second.c_str(),"JPEG" ) ) tVal->type = IM_ITEM_TYPE_JPEG; + if( strstr( it->second.c_str(),"PNG" ) ) tVal->type = IM_ITEM_TYPE_PNG; + if( strstr( it->second.c_str(),"GIF" ) ) tVal->type = IM_ITEM_TYPE_GIF; + if( strstr( it->second.c_str(),"TIFF" ) ) tVal->type = IM_ITEM_TYPE_TIFF; + if( strstr( it->second.c_str(),"AGIF" ) ) tVal->type = IM_ITEM_TYPE_AGIF; + }; + }; + }; + }; + deleteResult( result ); + }; + return tVal; +}; + +void IM_DataBaseAdapter::updateItemROI( uint32_t itemID, uint32_t classID, uint32_t x, uint32_t y, uint32_t w, uint32_t h ){ + if( m_pConnectorClass ) { + char tQBuf[CTEXT]; + sprintf(tQBuf, "INSERT INTO `item_rois` SET `item_id`=%d, `class_id`=%d, `x`=%d, `y`=%d, `width`=%d, `height`=%d", itemID, classID, x, y, w, h ); +#ifdef DEBUG + LOG(tQBuf); +#endif + m_pConnectorClass->SilentQuery( tQBuf ); + }; }; #undef LOG diff --git a/Projects/img_mill/IM_DataBaseAdapter.h b/Projects/img_mill/IM_DataBaseAdapter.h index d8fea53d..0ee05b05 100644 --- a/Projects/img_mill/IM_DataBaseAdapter.h +++ b/Projects/img_mill/IM_DataBaseAdapter.h @@ -3,6 +3,7 @@ #include "../../lib/data/mysql/database_class.h" #include "../../lib/components/base/basicSettingsProvider.h" +#include "IM_DataStructs.h" /** * TODO: Add class description @@ -22,6 +23,10 @@ class IM_DataBaseAdapter { // Destructor virtual ~IM_DataBaseAdapter(); + IM_ITEM_DATA * getItemDataById( uint32_t itemID ); + IM_ITEM_DATA * getItemDataByMd5( CSTR md5 ); + void updateItemROI( uint32_t itemID, uint32_t classID, uint32_t x, uint32_t y, uint32_t w, uint32_t h ); + protected: // Constructor - protected so users cannot call it. explicit IM_DataBaseAdapter( config_setting_t * Settings ); diff --git a/Projects/img_mill/IM_DataStructs.h b/Projects/img_mill/IM_DataStructs.h new file mode 100644 index 00000000..ec6fc7a4 --- /dev/null +++ b/Projects/img_mill/IM_DataStructs.h @@ -0,0 +1,50 @@ +#ifndef __IMAGE_MILL_DATA_STRUCTURES_HEADER__ +#define __IMAGE_MILL_DATA_STRUCTURES_HEADER__ + +#include + +typedef struct S_IM_ITEM_DATA{ + uint32_t item_id; + char md5[33]; + uint32_t width; + uint32_t height; + uint8_t type; +}IM_ITEM_DATA; + +typedef enum E_IM_ITEM_TYPES{ + IM_ITEM_TYPE_JPEG = 0, + IM_ITEM_TYPE_PNG = 1, + IM_ITEM_TYPE_GIF = 2, + IM_ITEM_TYPE_AGIF = 3, + IM_ITEM_TYPE_TIFF = 4 +}IM_ITEM_TYPES; + +typedef struct S_IM_JOB{ + uint32_t dbID; + uint8_t type; + uint32_t width; + uint32_t height; + uint32_t depth; + char md5[33]; +}IM_JOB; + +typedef struct S_IM_CLASS_BOUNDARY_BOX{ + uint32_t classID; + uint32_t x; + uint32_t y; + uint32_t width; + uint32_t height; + uint32_t depth; +}IM_CLASS_BOUNDARY_BOX; + +typedef struct S_IM_RESULT{ + IM_JOB * pJOB; + uint32_t nBoxCount; + IM_CLASS_BOUNDARY_BOX * boxes; +}IM_RESULT; + +typedef std::queue IM_JOB_QUEUE; + + + +#endif diff --git a/Projects/img_mill/IM_DnnWorker.cpp b/Projects/img_mill/IM_DnnWorker.cpp index b1986296..5e919c7f 100644 --- a/Projects/img_mill/IM_DnnWorker.cpp +++ b/Projects/img_mill/IM_DnnWorker.cpp @@ -13,29 +13,38 @@ #endif // Constructor implementation -IM_DnnWorker::IM_DnnWorker( config_setting_t * Settings ) : basicVideoAnalyzer(){ +IM_DnnWorker::IM_DnnWorker( config_setting_t * Settings ) : basicThread(), m_mBufferProtectorMutex(){ m_pLog = basicLogCollection::getInstance(); m_pSettings = basicSettingsProvider::getInstance()->getSubNode( Settings, "DNN" ); - - type = VA_DNN_ANAL; - m_bDataIsActive = false; - m_bDetectionStatus = false; - + m_pEvtHeap = basicEventHeap::getInstance(); m_eBackendEngine = cv::dnn::DNN_BACKEND_DEFAULT; m_eTargetDevice = cv::dnn::DNN_TARGET_CPU; - -} + m_pActiveJob = NULL; -// Destructor implementation -inline IM_DnnWorker::~IM_DnnWorker(){ +#ifdef DARKNET + m_pDarknetDetector = NULL; +#endif -} + m_bDataIsActive = false; +}; + +// Destructor implementation +IM_DnnWorker::~IM_DnnWorker(){}; bool IM_DnnWorker::create( void ){ + char tBuff[256]; if( m_pSettings == NULL ){ return false; } else { config_setting_t * tSetting; + tSetting = config_setting_get_member( m_pSettings, "PICTURES_BASE" ); + if( tSetting == NULL ){ + tSetting = config_setting_add(m_pSettings, "PICTURES_BASE", CONFIG_TYPE_STRING ); + config_setting_set_string( tSetting, "/srv/vault" ); + basicSettingsProvider::getInstance()->compromise(); + LOG("No Pictures Base Path! Using default!"); + }; + sprintf( m_pPicturesBase, "%s", config_setting_get_string(tSetting)); tSetting = config_setting_get_member( m_pSettings, "NET_CONFIG_FILE" ); if( tSetting == NULL ){ tSetting = config_setting_add(m_pSettings, "NET_CONFIG_FILE", CONFIG_TYPE_STRING ); @@ -74,6 +83,8 @@ bool IM_DnnWorker::create( void ){ if( strstr( config_setting_get_string(tSetting), "CUDA" )!=NULL ) m_eTargetDevice = cv::dnn::DNN_TARGET_CUDA; }; if( strstr( config_setting_get_string(tSetting), "HDDL" )!=NULL ) m_eTargetDevice = cv::dnn::DNN_TARGET_HDDL; + sprintf( tBuff, "Device: %s", config_setting_get_string(tSetting) ); + LOG( tBuff ); tSetting = config_setting_get_member( m_pSettings, "NET_BACKEND_ENGINE" ); if( tSetting == NULL ){ @@ -88,9 +99,12 @@ bool IM_DnnWorker::create( void ){ if( strstr( config_setting_get_string(tSetting), "OPENCV" )!=NULL ) m_eBackendEngine = cv::dnn::DNN_BACKEND_OPENCV; if( strstr( config_setting_get_string(tSetting), "VKCOM" )!=NULL ) m_eBackendEngine = cv::dnn::DNN_BACKEND_VKCOM; if( strstr( config_setting_get_string(tSetting), "CUDA" )!=NULL ) m_eBackendEngine = cv::dnn::DNN_BACKEND_CUDA; + sprintf( tBuff, "Engine: %s", config_setting_get_string(tSetting) ); + LOG( tBuff ); basicSettingsProvider::getInstance()->validate(); }; - LOG( "[INFO] loading YOLO from disk..." ); + sprintf( tBuff, "loading DNN from disk... CONF: %s WEIGHT: %s", m_pConfigPath, m_pWeightsPath ); + LOG( tBuff ); if(!fileExist( m_pConfigPath )) { LOG_ERROR("No Config file exists!"); return false; @@ -99,57 +113,126 @@ bool IM_DnnWorker::create( void ){ LOG_ERROR("No Weight file exists!"); return false; }; +#ifdef DARKNET + try { + m_pDarknetDetector = new Detector( m_pConfigPath, m_pWeightsPath ); + if( m_pDarknetDetector ) { + LOG("DarkNet Detector Created"); + } else { + LOG_ERROR("Failure during DarkNet Detector Creation!"); + }; + } catch ( exception e ) { + LOG_ERROR( e.what() ); + }; +#else m_net = cv::dnn::readNetFromDarknet( m_pConfigPath, m_pWeightsPath ); m_net.setPreferableBackend( m_eBackendEngine ); m_net.setPreferableTarget( m_eTargetDevice ); - return false; + std::vector outNames = m_net.getUnconnectedOutLayersNames(); + LOG("OutNames"); + for( std::vector::iterator idx = outNames.begin(); idx < outNames.end(); idx++ ) { + LOG( (*idx).c_str() ); + }; +#endif + return init(); }; bool IM_DnnWorker::m_fImageAnalyzer( Mat &Picture ){ - static Mat blob; - Size inpSize; - bool swapRB = true; - float scale = 1.f; - const Scalar mean; - - // Create a 4D blob from a frame. + Size inpSize; + bool swapRB = true; //BGR->RGB + double scale = 1.0;///255.0; + Scalar mean; inpSize.width = Picture.cols; inpSize.height = Picture.rows; - cv::dnn::blobFromImage( Picture, blob, 1 / 255.0, Size(416, 416), mean, swapRB, false, CV_8U ); - - // construct a blob from the input frame and then perform a forward - // pass of the YOLO object detector, giving us our bounding boxes - // and associated probabilities - //blob = cv2.dnn.blobFromImage(frame, 1 / 255.0, (416, 416), swapRB=True, crop=False ) - //net.setInput(blob) - //layerOutputs = net.forward(ln) + try { + LOG("Create a 4D blob from a frame"); + Mat blob = cv::dnn::blobFromImage( Picture, scale, Size(416, 416), mean, swapRB, false, CV_8U ); - // Run a model. - m_net.setInput( blob, "", scale, mean ); - if( m_net.getLayer(0)->outputNameToIndex("im_info") != -1 ){ - // Faster-RCNN or R-FCN - resize( Picture, Picture, inpSize); - Mat imInfo = (Mat_(1, 3) << inpSize.height, inpSize.width, 1.6f); - m_net.setInput(imInfo, "im_info"); + if( blob.empty() ) { + LOG_ERROR("Failure Creating Blob!"); + return false; + }; + // construct a blob from the input frame and then perform a forward + // pass of the YOLO object detector, giving us our bounding boxes + // and associated probabilities + //blob = cv2.dnn.blobFromImage(frame, 1 / 255.0, (416, 416), swapRB=True, crop=False ) + //net.setInput(blob) + //layerOutputs = net.forward(ln) + // Run a model. + LOG("Set BLOB to NET"); + m_net.setInput( blob ); + //std::vector outs; + //std::vector outNames = m_net.getUnconnectedOutLayersNames(); + Mat outMat = m_net.forward( String( "detection_out" )); + LOG("DONE!"); + /* + if( m_net.getLayer(0)->outputNameToIndex("im_info") != -1 ){ + // Faster-RCNN or R-FCN + //resize( Picture, Picture, inpSize ); + cv::resize( Picture, Picture, cv::Size(416, 416)); + Mat imInfo = ( Mat_(1, 3) << inpSize.height, inpSize.width, 1.6f); + m_net.setInput( imInfo, "im_info" ); + }; + */ + } catch ( cv::Exception& e ) { + LOG_ERROR("Catched Exception"); + LOG_ERROR( e.what() ); }; return false; }; -/* void IM_DnnWorker::m_fThreadProc( void ){ m_bThreadStatus = TH_WORKING; while( m_bThreadStatus < TH_ENDED ) { - while (!m_bDataIsActive && m_bThreadStatus < TH_ENDED ) SLEEP(1); - if (m_bThreadStatus < TH_ENDED){ - m_mBufferProtectorMutex.lock(); - m_bDetectionStatus = m_fImageAnalyzer( m_oWorkingMat ); - m_bDataIsActive = false; - m_mBufferProtectorMutex.unlock(); - }; + while (!m_bDataIsActive && m_bThreadStatus < TH_ENDED ) SLEEP( 20 ); + if( m_mBufferProtectorMutex.try_lock() ){ + if( m_bDataIsActive ){ + LOG( "Pushing Picure to DNN" ); + m_fImageAnalyzer( m_oWorkingMat ); + m_bDataIsActive = false; + }; + m_mBufferProtectorMutex.unlock(); + }; + // Create Finish EVT; + //basicEvent *tEvt; + //tEvt = createVAEvent(true);// EVT_CLASS_VIDEO, EVT_ALARM, "Motion Detected"); + //if (tEvt!=NULL)m_pEventHeap->broadcast(tEvt);^M }; }; -*/ + +bool IM_DnnWorker::enqueueJob( IM_JOB *ptr ){ + if( ptr ) { + if( m_mBufferProtectorMutex.try_lock() ) { + char tPath[1024]; + char p1[3]; + char p2[3]; + char p3[3]; + LOG( ptr->md5 ); + memcpy( p1, ptr->md5 , 2); p1[2]=(char)0; + memcpy( p2, ptr->md5+2, 2); p2[2]=(char)0; + memcpy( p3, ptr->md5+4, 2); p3[2]=(char)0; + switch( ptr->type ) { + case IM_ITEM_TYPE_JPEG: sprintf( tPath, "%s/%s/%s/%s/%s.jpg", m_pPicturesBase, p1, p2, p3, ptr->md5 ); break; + case IM_ITEM_TYPE_PNG: sprintf( tPath, "%s/%s/%s/%s/%s.png", m_pPicturesBase, p1, p2, p3, ptr->md5 ); break; + case IM_ITEM_TYPE_GIF: sprintf( tPath, "%s/%s/%s/%s/%s.gif", m_pPicturesBase, p1, p2, p3, ptr->md5 ); break; + case IM_ITEM_TYPE_AGIF: sprintf( tPath, "%s/%s/%s/%s/%s.gif", m_pPicturesBase, p1, p2, p3, ptr->md5 ); break; + case IM_ITEM_TYPE_TIFF: sprintf( tPath, "%s/%s/%s/%s/%s.tiff", m_pPicturesBase, p1, p2, p3, ptr->md5 ); break; + }; + LOG( tPath ); + Mat Frame = cv::imread( tPath, IMREAD_COLOR ); + if( !Frame.empty() ){ + Frame.copyTo( m_oWorkingMat ); + cv::resize( m_oWorkingMat, m_oWorkingMat, cv::Size(416, 416)); + cv::imwrite("cur-test-img.jpg", m_oWorkingMat ); + m_bDataIsActive = true; + m_mBufferProtectorMutex.unlock(); + } else LOG_ERROR( "Failure during Image Read!" ); + return true; + }; + }; + return false; +}; #undef LOG #undef LOG_ERROR diff --git a/Projects/img_mill/IM_DnnWorker.h b/Projects/img_mill/IM_DnnWorker.h index bfd98244..2d7a7361 100644 --- a/Projects/img_mill/IM_DnnWorker.h +++ b/Projects/img_mill/IM_DnnWorker.h @@ -1,32 +1,62 @@ #ifndef __IM_DNNWORKER_H_INCL__ #define __IM_DNNWORKER_H_INCL__ -#include "../../lib/components/base/basicVideoAnalyzer.h" +#include "../../lib/components/base/basicThread.h" +#include "../../lib/components/base/basicMutex.h" #include "../../lib/components/base/basicSettingsProvider.h" +#include "../../lib/components/base/basicEventHeap.h" +#include "IM_DataStructs.h" + +//#define DARKNET + +#ifdef DARKNET + #define GPU + //#include + #include + #undef GPU +#endif + +#include +#include +#include +#include #include + +using namespace cv; /** * TODO: Add class description * * @author Gagua */ -class IM_DnnWorker : public basicVideoAnalyzer { +class IM_DnnWorker : public basicThread { private: +#ifdef DARKNET + Detector * m_pDarknetDetector; +#else +#endif basicLogCollection * m_pLog; config_setting_t * m_pSettings; cv::dnn::Backend m_eBackendEngine; cv::dnn::Target m_eTargetDevice; cv::dnn::Net m_net; + cv::Mat m_oWorkingMat; + basicEventHeap * m_pEvtHeap; + char m_pPicturesBase[1024]; char m_pConfigPath[1024]; char m_pWeightsPath[1024]; - protected: - //virtual void m_fThreadProc( void ); + basicMutex m_mBufferProtectorMutex; + IM_JOB * m_pActiveJob; + bool m_bDataIsActive; virtual bool m_fImageAnalyzer( Mat &Picture ); + protected: + virtual void m_fThreadProc( void );//getLayerNames() public: // Constructor explicit IM_DnnWorker( config_setting_t * Settings = NULL ); // Destructor virtual ~IM_DnnWorker(); - bool create( void ); + bool create( void ); + bool enqueueJob( IM_JOB *ptr ); }; diff --git a/Projects/img_mill/IM_Kernel.cpp b/Projects/img_mill/IM_Kernel.cpp index 618ad64d..2394a638 100644 --- a/Projects/img_mill/IM_Kernel.cpp +++ b/Projects/img_mill/IM_Kernel.cpp @@ -25,27 +25,36 @@ IM_Kernel *IM_Kernel::getInstance(){ inline IM_Kernel::IM_Kernel( config_setting_t *Settings ) : basicEngine(), basicThread(){ m_pLog = basicLogCollection::getInstance(); m_pSettings = basicSettingsProvider::getInstance()->getSubNode( Settings, "KERNEL" ); + m_bExitCause = 0; m_pWorker = NULL; + m_pDBA = NULL; + m_pActiveJob = NULL; }; // Destructor implementation inline IM_Kernel::~IM_Kernel(){ waitThreadEnd( true ); + if( m_pWorker ) delete( m_pWorker ); + if( m_pDBA ) delete( m_pDBA ); + _instance = NULL; }; bool IM_Kernel::start(){ + m_pDBA = IM_DataBaseAdapter::getInstance( m_pSettings ); + if( m_pDBA ==NULL ) { + LOG_ERROR("Error Creating DataBase Adapter!"); + return false; + }; m_pWorker = new IM_DnnWorker( m_pSettings ); if( m_pWorker ) { if( m_pWorker->create() ){ return init(); - } else LOG_ERROR( "DNN Worker Create Failure!" ); - }; + } else LOG_ERROR( "DNN Worker INIT Failure!" ); + } else LOG_ERROR( "DNN Worker Create Failure!" ); return false; }; bool IM_Kernel::stop( bool Force ){ - delete( m_pWorker ); - m_pWorker = NULL; waitThreadEnd( Force ); return true; }; @@ -68,10 +77,28 @@ bool IM_Kernel::detachClient( networkClientHandler *ptr ){ void IM_Kernel::m_fThreadProc( void ){ m_bThreadStatus = TH_WORKING; while( m_bThreadStatus < TH_ENDED ) { + if( m_qJOBS.size() ) { + if( m_pWorker ){ + m_pActiveJob = m_qJOBS.front(); + if( m_pWorker->enqueueJob( m_pActiveJob ) ) m_qJOBS.pop(); + } else LOG_ERROR( "DNN Worker Not Created!" ); + }; SLEEP( DEFAULT_THREAD_SLEEP_TIME ); }; }; +bool IM_Kernel::enqueueJob( IM_JOB *ptr ){ + if( m_pWorker ) { + if( ptr!= NULL ) { +#ifdef DEBUG + LOG( "New Job Enqueued" ); +#endif + m_qJOBS.push( ptr ); + }; + } else LOG_ERROR( "DNN Worker Not Created!" ); + return false; +}; + #undef LOG #undef LOG_ERROR diff --git a/Projects/img_mill/IM_Kernel.h b/Projects/img_mill/IM_Kernel.h index d9353866..2f50bbdd 100644 --- a/Projects/img_mill/IM_Kernel.h +++ b/Projects/img_mill/IM_Kernel.h @@ -4,10 +4,12 @@ #include "../../lib/components/base/basicEngine.h" #include "../../lib/components/base/basicThread.h" #include "../../lib/components/base/basicSettingsProvider.h" +#include "IM_DataStructs.h" #include "IM_DnnWorker.h" - +#include "IM_DataBaseAdapter.h" class networkClientHandler; + /** * TODO: Add class description * @@ -17,8 +19,11 @@ class IM_Kernel : public basicEngine, public basicThread { private: basicLogCollection * m_pLog; config_setting_t * m_pSettings; + IM_DataBaseAdapter * m_pDBA; uint8_t m_bExitCause; IM_DnnWorker * m_pWorker; + IM_JOB_QUEUE m_qJOBS; + IM_JOB * m_pActiveJob; protected: virtual void m_fThreadProc( void ); public: @@ -32,6 +37,8 @@ class IM_Kernel : public basicEngine, public basicThread { uint8_t getExitCause( void ){ return m_bExitCause;}; virtual networkClientHandler * attachNewClient( int SocketID ); virtual bool detachClient( networkClientHandler *ptr ); + bool enqueueJob( IM_JOB *ptr ); + //IM_RESULT * getResult( IM_JOB *ptr ); private: static IM_Kernel * _instance; // Constructor diff --git a/Projects/img_mill/build b/Projects/img_mill/build new file mode 100755 index 00000000..3ba2f682 --- /dev/null +++ b/Projects/img_mill/build @@ -0,0 +1,9 @@ +#! /bin/sh + + +make clean -e "CFG=Debug" +make -j16 -e "CFG=Debug" + + +make clean -e "CFG=Release" +make -j16 -e "CFG=Release" diff --git a/Projects/img_mill/img_mill.vpj b/Projects/img_mill/img_mill.vpj index f1e2300f..a7541f2c 100644 --- a/Projects/img_mill/img_mill.vpj +++ b/Projects/img_mill/img_mill.vpj @@ -128,6 +128,7 @@ + + Defines='"/D_OPENCV_"'> + CmdLine='g++ -c %xup -x c++ %defd -O3 %~other -o "%bd%n%oe" %i %f' + OtherOptions="`pkg-config --cflags opencv4` -s"/> - + - @@ -283,6 +285,9 @@ + + + @@ -291,6 +296,7 @@ + + diff --git a/Projects/img_mill/makefile b/Projects/img_mill/makefile index 40ea2429..9b76bf77 100644 --- a/Projects/img_mill/makefile +++ b/Projects/img_mill/makefile @@ -24,7 +24,7 @@ CFG_INC=-I/usr/local/include/opencv4 -I../../lib/include CFG_LIB=-lmysqlclient -lssl -lcrypto -lpthread `pkg-config --libs \ libavcodec libavdevice libavfilter libavformat libavresample \ libavutil libswresample libswscale libconfig++ libcurl opencv4` -lGL \ - -lGLU -lc -lm -lz + -lGLU -lc -lm -lz -ldarknet CFG_OBJ= COMMON_OBJ=$(OUTDIR)/basicDualThread.o $(OUTDIR)/basicEngine.o \ $(OUTDIR)/basicEvent.o $(OUTDIR)/basicEventHandler.o \ @@ -34,14 +34,16 @@ COMMON_OBJ=$(OUTDIR)/basicDualThread.o $(OUTDIR)/basicEngine.o \ $(OUTDIR)/basicMediaViewer.o $(OUTDIR)/basicMutex.o \ $(OUTDIR)/basicRing.o $(OUTDIR)/basicSettings.o \ $(OUTDIR)/basicSettingsProvider.o $(OUTDIR)/basicThread.o \ - $(OUTDIR)/basicTransport.o $(OUTDIR)/basicVideoAnalyzer.o \ - $(OUTDIR)/database_class.o $(OUTDIR)/IM_Backend.o \ - $(OUTDIR)/IM_ClientHandler.o $(OUTDIR)/IM_ClientProtocol.o \ - $(OUTDIR)/IM_DataBaseAdapter.o $(OUTDIR)/IM_DnnWorker.o \ - $(OUTDIR)/IM_Kernel.o $(OUTDIR)/md5.o $(OUTDIR)/netClientHandler.o \ + $(OUTDIR)/basicTransport.o $(OUTDIR)/database_class.o \ + $(OUTDIR)/IM_Backend.o $(OUTDIR)/IM_ClientHandler.o \ + $(OUTDIR)/IM_ClientProtocol.o $(OUTDIR)/IM_DataBaseAdapter.o \ + $(OUTDIR)/IM_DnnWorker.o $(OUTDIR)/IM_Kernel.o \ + $(OUTDIR)/json_reader.o $(OUTDIR)/json_value.o \ + $(OUTDIR)/json_writer.o $(OUTDIR)/md5.o $(OUTDIR)/netClientHandler.o \ $(OUTDIR)/netServer.o $(OUTDIR)/objectConsoleLoggingService.o \ $(OUTDIR)/objectFileLoggingService.o $(OUTDIR)/protocol.o \ - $(OUTDIR)/serverPort.o $(OUTDIR)/transportSocket.o + $(OUTDIR)/serverPort.o $(OUTDIR)/transportSocket.o \ + $(OUTDIR)/xmlParser.o OBJ=$(COMMON_OBJ) $(CFG_OBJ) ALL_OBJ=$(OUTDIR)/basicDualThread.o $(OUTDIR)/basicEngine.o \ $(OUTDIR)/basicEvent.o $(OUTDIR)/basicEventHandler.o \ @@ -51,17 +53,19 @@ ALL_OBJ=$(OUTDIR)/basicDualThread.o $(OUTDIR)/basicEngine.o \ $(OUTDIR)/basicMediaViewer.o $(OUTDIR)/basicMutex.o \ $(OUTDIR)/basicRing.o $(OUTDIR)/basicSettings.o \ $(OUTDIR)/basicSettingsProvider.o $(OUTDIR)/basicThread.o \ - $(OUTDIR)/basicTransport.o $(OUTDIR)/basicVideoAnalyzer.o \ - $(OUTDIR)/database_class.o $(OUTDIR)/IM_Backend.o \ - $(OUTDIR)/IM_ClientHandler.o $(OUTDIR)/IM_ClientProtocol.o \ - $(OUTDIR)/IM_DataBaseAdapter.o $(OUTDIR)/IM_DnnWorker.o \ - $(OUTDIR)/IM_Kernel.o $(OUTDIR)/md5.o $(OUTDIR)/netClientHandler.o \ + $(OUTDIR)/basicTransport.o $(OUTDIR)/database_class.o \ + $(OUTDIR)/IM_Backend.o $(OUTDIR)/IM_ClientHandler.o \ + $(OUTDIR)/IM_ClientProtocol.o $(OUTDIR)/IM_DataBaseAdapter.o \ + $(OUTDIR)/IM_DnnWorker.o $(OUTDIR)/IM_Kernel.o \ + $(OUTDIR)/json_reader.o $(OUTDIR)/json_value.o \ + $(OUTDIR)/json_writer.o $(OUTDIR)/md5.o $(OUTDIR)/netClientHandler.o \ $(OUTDIR)/netServer.o $(OUTDIR)/objectConsoleLoggingService.o \ $(OUTDIR)/objectFileLoggingService.o $(OUTDIR)/protocol.o \ - $(OUTDIR)/serverPort.o $(OUTDIR)/transportSocket.o -lmysqlclient \ - -lssl -lcrypto -lpthread `pkg-config --libs libavcodec libavdevice \ - libavfilter libavformat libavresample libavutil libswresample \ - libswscale libconfig++ libcurl opencv4` -lGL -lGLU -lc -lm -lz + $(OUTDIR)/serverPort.o $(OUTDIR)/transportSocket.o \ + $(OUTDIR)/xmlParser.o -lmysqlclient -lssl -lcrypto -lpthread \ + `pkg-config --libs libavcodec libavdevice libavfilter libavformat \ + libavresample libavutil libswresample libswscale libconfig++ libcurl \ + opencv4` -lGL -lGLU -lc -lm -lz -ldarknet COMPILE=g++ -c -x c++ "-D_OPENCV_" "-DDEBUG" -g -ggdb `pkg-config --cflags opencv4` -o "$(OUTDIR)/$(*F).o" $(CFG_INC) $< LINK=g++ -g -ggdb -o "$(OUTFILE)" $(ALL_OBJ) @@ -85,6 +89,9 @@ $(OUTDIR)/%.o : ../../lib/data/protocol/%.cpp $(OUTDIR)/%.o : ../../lib/data/net/%.cpp $(COMPILE) +$(OUTDIR)/%.o : ../../lib/data/json/%.cpp + $(COMPILE) + $(OUTDIR)/%.o : ../../lib/data/mysql/%.cpp $(COMPILE) @@ -118,7 +125,7 @@ endif ifeq "$(CFG)" "Release" OUTDIR=Release OUTFILE=$(OUTDIR)/img_mill -CFG_INC=-I/usr/local/include/opencv4 -I/dr_frucht/lib/include +CFG_INC=-I/usr/local/include/opencv4 -I../../lib/include CFG_LIB=-lmysqlclient -lssl -lcrypto -lpthread `pkg-config --libs \ libavcodec libavdevice libavfilter libavformat libavresample \ libavutil libswresample libswscale libconfig++ libcurl opencv4` -lGL \ @@ -132,14 +139,16 @@ COMMON_OBJ=$(OUTDIR)/basicDualThread.o $(OUTDIR)/basicEngine.o \ $(OUTDIR)/basicMediaViewer.o $(OUTDIR)/basicMutex.o \ $(OUTDIR)/basicRing.o $(OUTDIR)/basicSettings.o \ $(OUTDIR)/basicSettingsProvider.o $(OUTDIR)/basicThread.o \ - $(OUTDIR)/basicTransport.o $(OUTDIR)/basicVideoAnalyzer.o \ - $(OUTDIR)/database_class.o $(OUTDIR)/IM_Backend.o \ - $(OUTDIR)/IM_ClientHandler.o $(OUTDIR)/IM_ClientProtocol.o \ - $(OUTDIR)/IM_DataBaseAdapter.o $(OUTDIR)/IM_DnnWorker.o \ - $(OUTDIR)/IM_Kernel.o $(OUTDIR)/md5.o $(OUTDIR)/netClientHandler.o \ + $(OUTDIR)/basicTransport.o $(OUTDIR)/database_class.o \ + $(OUTDIR)/IM_Backend.o $(OUTDIR)/IM_ClientHandler.o \ + $(OUTDIR)/IM_ClientProtocol.o $(OUTDIR)/IM_DataBaseAdapter.o \ + $(OUTDIR)/IM_DnnWorker.o $(OUTDIR)/IM_Kernel.o \ + $(OUTDIR)/json_reader.o $(OUTDIR)/json_value.o \ + $(OUTDIR)/json_writer.o $(OUTDIR)/md5.o $(OUTDIR)/netClientHandler.o \ $(OUTDIR)/netServer.o $(OUTDIR)/objectConsoleLoggingService.o \ $(OUTDIR)/objectFileLoggingService.o $(OUTDIR)/protocol.o \ - $(OUTDIR)/serverPort.o $(OUTDIR)/transportSocket.o + $(OUTDIR)/serverPort.o $(OUTDIR)/transportSocket.o \ + $(OUTDIR)/xmlParser.o OBJ=$(COMMON_OBJ) $(CFG_OBJ) ALL_OBJ=$(OUTDIR)/basicDualThread.o $(OUTDIR)/basicEngine.o \ $(OUTDIR)/basicEvent.o $(OUTDIR)/basicEventHandler.o \ @@ -149,20 +158,22 @@ ALL_OBJ=$(OUTDIR)/basicDualThread.o $(OUTDIR)/basicEngine.o \ $(OUTDIR)/basicMediaViewer.o $(OUTDIR)/basicMutex.o \ $(OUTDIR)/basicRing.o $(OUTDIR)/basicSettings.o \ $(OUTDIR)/basicSettingsProvider.o $(OUTDIR)/basicThread.o \ - $(OUTDIR)/basicTransport.o $(OUTDIR)/basicVideoAnalyzer.o \ - $(OUTDIR)/database_class.o $(OUTDIR)/IM_Backend.o \ - $(OUTDIR)/IM_ClientHandler.o $(OUTDIR)/IM_ClientProtocol.o \ - $(OUTDIR)/IM_DataBaseAdapter.o $(OUTDIR)/IM_DnnWorker.o \ - $(OUTDIR)/IM_Kernel.o $(OUTDIR)/md5.o $(OUTDIR)/netClientHandler.o \ + $(OUTDIR)/basicTransport.o $(OUTDIR)/database_class.o \ + $(OUTDIR)/IM_Backend.o $(OUTDIR)/IM_ClientHandler.o \ + $(OUTDIR)/IM_ClientProtocol.o $(OUTDIR)/IM_DataBaseAdapter.o \ + $(OUTDIR)/IM_DnnWorker.o $(OUTDIR)/IM_Kernel.o \ + $(OUTDIR)/json_reader.o $(OUTDIR)/json_value.o \ + $(OUTDIR)/json_writer.o $(OUTDIR)/md5.o $(OUTDIR)/netClientHandler.o \ $(OUTDIR)/netServer.o $(OUTDIR)/objectConsoleLoggingService.o \ $(OUTDIR)/objectFileLoggingService.o $(OUTDIR)/protocol.o \ - $(OUTDIR)/serverPort.o $(OUTDIR)/transportSocket.o -lmysqlclient \ - -lssl -lcrypto -lpthread `pkg-config --libs libavcodec libavdevice \ - libavfilter libavformat libavresample libavutil libswresample \ - libswscale libconfig++ libcurl opencv4` -lGL -lGLU -lc -lm -lz + $(OUTDIR)/serverPort.o $(OUTDIR)/transportSocket.o \ + $(OUTDIR)/xmlParser.o -lmysqlclient -lssl -lcrypto -lpthread \ + `pkg-config --libs libavcodec libavdevice libavfilter libavformat \ + libavresample libavutil libswresample libswscale libconfig++ libcurl \ + opencv4` -lGL -lGLU -lc -lm -lz -COMPILE=g++ -c -x c++ "-D_OPENCV_" "-DDEBUG" -ggdb `pkg-config --cflags opencv4` -o "$(OUTDIR)/$(*F).o" $(CFG_INC) $< -LINK=g++ -ggdb -o "$(OUTFILE)" $(ALL_OBJ) +COMPILE=g++ -c -x c++ "-D_OPENCV_" -O3 `pkg-config --cflags opencv4` -s -o "$(OUTDIR)/$(*F).o" $(CFG_INC) $< +LINK=g++ -O3 -s -o "$(OUTFILE)" $(ALL_OBJ) # Pattern rules $(OUTDIR)/%.o : ../../lib/alg/generic/%.cpp @@ -183,6 +194,9 @@ $(OUTDIR)/%.o : ../../lib/data/protocol/%.cpp $(OUTDIR)/%.o : ../../lib/data/net/%.cpp $(COMPILE) +$(OUTDIR)/%.o : ../../lib/data/json/%.cpp + $(COMPILE) + $(OUTDIR)/%.o : ../../lib/data/mysql/%.cpp $(COMPILE) diff --git a/lib/components/base/basicDualThread.cpp b/lib/components/base/basicDualThread.cpp index 9e3f0efa..f8021eff 100644 --- a/lib/components/base/basicDualThread.cpp +++ b/lib/components/base/basicDualThread.cpp @@ -75,7 +75,9 @@ void basicDualThread::m_fThreadBProc( void ){ mThis->m_fThreadAProc(); mThis->m_bThreadAStatus = TH_EXIT; }; +#ifdef DEBUG mThis->SLOG("ThreadAEntryPoint Exit."); +#endif #if defined( __linux__ ) || defined(WIN_PTHREAD) pthread_exit( NULL ); return NULL; @@ -95,7 +97,9 @@ void basicDualThread::m_fThreadBProc( void ){ mThis->m_fThreadBProc(); mThis->m_bThreadBStatus = TH_EXIT; }; +#ifdef DEBUG mThis->SLOG("ThreadBEntryPoint Exit."); +#endif #if defined( __linux__ ) || defined(WIN_PTHREAD) pthread_exit( NULL ); return NULL; @@ -106,14 +110,20 @@ void basicDualThread::m_fThreadBProc( void ){ void basicDualThread::waitThreadAEnd( bool Force ){ if( m_bThreadAStatus > TH_WORKING || m_bThreadAStatus < TH_ARMED ) { +#ifdef DEBUG LOG("Thread A already Dead!"); +#endif return; }; if( Force ){ +#ifdef DEBUG LOG("Thread A Requested Exit."); +#endif m_bThreadAStatus = TH_ENDED; } else { +#ifdef DEBUG LOG("Thread A Wait Exit."); +#endif }; while( m_bThreadAStatus != TH_EXIT ) SLEEP(DEFAULT_THREAD_SLEEP_TIME); #if defined( __linux__ ) || defined(WIN_PTHREAD) @@ -122,19 +132,27 @@ void basicDualThread::waitThreadAEnd( bool Force ){ WaitForSingleObject(m_hThreadAHandle, 2000); CloseHandle(m_hThreadAHandle); #endif +#ifdef DEBUG LOG("Thread A Ended."); +#endif }; void basicDualThread::waitThreadBEnd( bool Force ){ if( m_bThreadBStatus > TH_WORKING || m_bThreadBStatus < TH_ARMED ){ +#ifdef DEBUG LOG("Thread B already Dead!"); +#endif return; }; if( Force ){ +#ifdef DEBUG LOG("Thread B Requested Exit."); +#endif m_bThreadBStatus = TH_ENDED; } else { +#ifdef DEBUG LOG("Thread B Wait Exit."); +#endif }; while( m_bThreadBStatus != TH_EXIT ) SLEEP(DEFAULT_THREAD_SLEEP_TIME); #if defined( __linux__ ) || defined(WIN_PTHREAD) @@ -143,7 +161,9 @@ void basicDualThread::waitThreadBEnd( bool Force ){ WaitForSingleObject(m_hThreadBHandle, 2000); CloseHandle(m_hThreadBHandle); #endif +#ifdef DEBUG LOG("Thread B Ended."); +#endif }; #undef LOG diff --git a/lib/components/base/basicDualThread.h b/lib/components/base/basicDualThread.h index 7bf60995..ad2f9716 100644 --- a/lib/components/base/basicDualThread.h +++ b/lib/components/base/basicDualThread.h @@ -56,33 +56,9 @@ inline basicDualThread::basicDualThread(){ // Destructor implementation inline basicDualThread::~basicDualThread(){ - if( m_bThreadAStatus > TH_ARMED ) { - waitThreadAEnd(); - // Threads are detached inside Wait - //pthread_detach( m_sThreadAHandler ); - }; - if( m_bThreadBStatus > TH_ARMED ) { - waitThreadBEnd(); - //pthread_detach( m_sThreadBHandler ); - }; + waitThreadAEnd( true ); + waitThreadBEnd( true ); }; -// TODO: Uncomment the copy constructor when you need it. -//inline basicThread::basicThread(const basicThread& src) -//{ -// // TODO: copy -//} - -// TODO: Uncomment the assignment operator when you need it. -//inline basicThread& basicThread::operator=(const basicThread& rhs) -//{ -// if (this == &rhs) { -// return *this; -// } -// -// // TODO: assignment -// -// return *this; -//} #endif // __BASICTHREAD_H_INCL__ diff --git a/lib/components/base/basicFunctionality.cpp b/lib/components/base/basicFunctionality.cpp index 986a313e..4fcaed81 100644 --- a/lib/components/base/basicFunctionality.cpp +++ b/lib/components/base/basicFunctionality.cpp @@ -336,7 +336,9 @@ long long getMilliseconds( void ){ tTZ.tz_dsttime = 0; if( gettimeofday( &tData, &tTZ ) == -1 ){ tMilliseconds = (long long) 0; +#ifdef DEBUG URGENT_LOG( "EbioMat'!"); +#endif } else { tMilliseconds = (long long) tData.tv_sec; tMilliseconds = ( tMilliseconds * 1000 ); diff --git a/lib/components/base/basicFunctionality.h b/lib/components/base/basicFunctionality.h index 32e7ea83..c7625212 100644 --- a/lib/components/base/basicFunctionality.h +++ b/lib/components/base/basicFunctionality.h @@ -48,7 +48,7 @@ CSTR strReplace( CSTR orig, CSTR rep, CSTR with ); unsigned __int64 getSHTimeValue( void ); #endif -CSTR getSHDTimeStamp(void); +CSTR getSHDTimeStamp(void); #ifdef __linux__ inline PF_TIMESTAMP * getPFTS( PF_TIMESTAMP * ptr = NULL ){ diff --git a/lib/components/base/basicThread.cpp b/lib/components/base/basicThread.cpp index 8bb40137..334bbf78 100644 --- a/lib/components/base/basicThread.cpp +++ b/lib/components/base/basicThread.cpp @@ -6,25 +6,6 @@ #define SLOG( X ) mThis->m_pLog->Log( "BasicThreadS", mThis, X ) #define SLOG_ERROR( X ) mThis->m_pLog->Log( "BasicThreadS", mThis, _LOG_ERROR, X ) - - -// Constructor implementation -basicThread::basicThread(){ - m_pLog = basicLogCollection::getInstance(); - m_bThreadStatus = TH_PRE_INIT; -}; - -// Destructor implementation -basicThread::~basicThread(){ - if (m_bThreadStatus > TH_ARMED ) { - waitThreadEnd( true ); - // JOIN in Wait function!! - //pthread_detach(m_sThreadHandler); - //pthread_join(m_sThreadHandler, NULL); - }; -}; - - bool basicThread::init( void ){ if (m_bThreadStatus == TH_PRE_INIT) { m_bThreadStatus = TH_ARMED; diff --git a/lib/components/base/basicThread.h b/lib/components/base/basicThread.h index 3b7c04ea..94777292 100644 --- a/lib/components/base/basicThread.h +++ b/lib/components/base/basicThread.h @@ -74,22 +74,15 @@ class basicThread { // TODO: Uncomment the assignment operator when you need it. //basicThread& operator=(const basicThread& src); }; -// TODO: Uncomment the copy constructor when you need it. -//inline basicThread::basicThread(const basicThread& src) -//{ -// // TODO: copy -//} +// Constructor implementation +inline basicThread::basicThread(){ + m_pLog = basicLogCollection::getInstance(); + m_bThreadStatus = TH_PRE_INIT; +}; -// TODO: Uncomment the assignment operator when you need it. -//inline basicThread& basicThread::operator=(const basicThread& rhs) -//{ -// if (this == &rhs) { -// return *this; -// } -// -// // TODO: assignment -// -// return *this; -//} +// Destructor implementation +inline basicThread::~basicThread(){ + waitThreadEnd( true ); +}; #endif // __BASICTHREAD_H_INCL__ diff --git a/lib/data/mysql/database_class.cpp b/lib/data/mysql/database_class.cpp index 10400879..45b62fb3 100644 --- a/lib/data/mysql/database_class.cpp +++ b/lib/data/mysql/database_class.cpp @@ -37,6 +37,8 @@ MySQL_Connector::MySQL_Connector( CSTR DBHost, CSTR DBUser, CSTR DBPassword, uin MySQL_Connector::MySQL_Connector( CSTR DBName, CSTR DBHost, CSTR DBUser, CSTR DBPassword, uint16_t Port ):m_mAccessMutex(){ m_pLog = basicLogCollection::getInstance(); m_pDBLink = mysql_init(NULL); + m_pDBName = (CSTR) malloc( strlen( ( const char * ) DBName ) + 1 ); + strcpy( m_pDBName, DBName ); m_pDBHost = (CSTR) malloc( strlen( ( const char * ) DBHost ) + 1 ); strcpy( m_pDBHost, DBHost ); m_pDBUser = (CSTR) malloc( strlen( ( const char * ) DBUser ) + 1 ); @@ -52,7 +54,7 @@ MySQL_Connector::MySQL_Connector( CSTR DBName, CSTR DBHost, CSTR DBUser, CSTR DB if( mysql_select_db( m_pDBLink, m_pDBName ) == 0 ){ m_bIsConnected = true; #ifdef DEBUG - char temp[256]; + char temp[256]; sprintf( temp, "Connected to %s@%s:%d", m_pDBName, m_pDBHost, m_nPort ); LOG( temp ); #endif diff --git a/lib/data/net/netClientHandler.cpp b/lib/data/net/netClientHandler.cpp index 82f0dff6..7a2106cc 100644 --- a/lib/data/net/netClientHandler.cpp +++ b/lib/data/net/netClientHandler.cpp @@ -14,7 +14,7 @@ networkClientHandler::networkClientHandler( int SocketFD, basicEngine *ptr ): basicEventHandler(){ m_pEngine = ptr; m_pLog = basicLogCollection::getInstance(); - m_pPort = new serverPort( SocketFD ); + m_pPort = NULL;//new serverPort( SocketFD ); #ifdef DEBUG if( m_pPort ) { LOG("Client Port Created OK!"); @@ -27,6 +27,7 @@ networkClientHandler::~networkClientHandler(){ LOG("Destructor Start"); # endif m_pEngine = NULL; +/* if( m_pPort != NULL ){ # ifdef DEBUG LOG("Destruct Server Port"); @@ -36,6 +37,7 @@ networkClientHandler::~networkClientHandler(){ LOG("Destruct Server Port Done"); # endif }; +*/ # ifdef DEBUG LOG("Destructor Finished"); # endif diff --git a/lib/data/net/serverPort.cpp b/lib/data/net/serverPort.cpp index f25c6a88..ce939dcf 100644 --- a/lib/data/net/serverPort.cpp +++ b/lib/data/net/serverPort.cpp @@ -17,8 +17,6 @@ serverPort::serverPort( SOCKET AcceptedSocket ):transportSocket(){ serverPort::~serverPort(){ - //m_bThreadBStatus = TH_ENDED; - //m_bThreadAStatus = TH_ENDED; }; int serverPort::sendBlock(unsigned char *Data, int DataSize){ @@ -41,7 +39,7 @@ int serverPort::sendBlock(unsigned char *Data, int DataSize){ close( m_nSocketFD ); m_nSocketFD = -1; m_bConnected = false; - setConnectionStatus( CS_DISCONNECTED ); + //setConnectionStatus( CS_DISCONNECTED ); return -1; }; if( RetVal < 0 ) RetVal = 0; @@ -52,7 +50,7 @@ int serverPort::sendBlock(unsigned char *Data, int DataSize){ } else { LOG_ERROR("Not Connected!"); m_bConnected = false; - setConnectionStatus( CS_DISCONNECTED ); + //setConnectionStatus( CS_DISCONNECTED ); return -1; }; #else @@ -67,7 +65,7 @@ int serverPort::sendBlock(unsigned char *Data, int DataSize){ closesocket(m_nSocketFD); WSACleanup(); m_bConnected = false; - setConnectionStatus( CS_DISCONNECTED ); + //setConnectionStatus( CS_DISCONNECTED ); return -1; }; #ifdef DUBUG_COMMUNICATION @@ -79,11 +77,11 @@ int serverPort::sendBlock(unsigned char *Data, int DataSize){ WSACleanup(); m_bConnected = false; m_nSocketFD = INVALID_SOCKET; - setConnectionStatus( CS_DISCONNECTED ); + //setConnectionStatus( CS_DISCONNECTED ); }; } else { m_bConnected = false; - setConnectionStatus( CS_DISCONNECTED ); + //setConnectionStatus( CS_DISCONNECTED ); return -1; }; #endif @@ -96,7 +94,7 @@ int serverPort::recptBlock(unsigned char *Buffer, int *BufferLength){ LOG_ERROR("Not Connected!"); m_bInitComplete = false; m_bConnected = false; - setConnectionStatus( CS_DISCONNECTED ); + //setConnectionStatus( CS_DISCONNECTED ); return -1; // Exit after unsuccess reconnect } @@ -116,7 +114,7 @@ int serverPort::recptBlock(unsigned char *Buffer, int *BufferLength){ *BufferLength = 0; m_bConnected = false; m_nSocketFD = -1; - setConnectionStatus( CS_DISCONNECTED ); + //setConnectionStatus( CS_DISCONNECTED ); return -1; }; }; @@ -131,7 +129,7 @@ int serverPort::recptBlock(unsigned char *Buffer, int *BufferLength){ LOG_ERROR("Not Connected!"); *BufferLength = 0; m_bConnected = false; - setConnectionStatus( CS_DISCONNECTED ); + //setConnectionStatus( CS_DISCONNECTED ); return -1; }; #else @@ -160,7 +158,7 @@ int serverPort::recptBlock(unsigned char *Buffer, int *BufferLength){ LOG_ERROR("Not Connected!"); *BufferLength = 0; m_bConnected = false; - setConnectionStatus( CS_DISCONNECTED ); + //setConnectionStatus( CS_DISCONNECTED ); return -1; }; #endif diff --git a/lib/data/protocol/protocol.cpp b/lib/data/protocol/protocol.cpp index f7a62689..0065e66d 100644 --- a/lib/data/protocol/protocol.cpp +++ b/lib/data/protocol/protocol.cpp @@ -9,7 +9,12 @@ protocolParser::protocolParser() : m_mBufferProtectorMutex(){ m_pLog = basicLogCollection::getInstance(); m_eConnectionStatus = CS_UNKNOWN; + m_oDataTransport = NULL; m_pParserBuffer = (U8*) malloc(PROTOCOL_PARSER_BUFFER_SIZE); + if( m_pParserBuffer ) { + memset( m_pParserBuffer, 0, PROTOCOL_PARSER_BUFFER_SIZE ); + } else LOG_ERROR("Cannot allocate Parser Buffer!"); + LOG("C0"); m_nParserDataCount = 0; m_bStatus = 0; m_pCustomHandler = NULL; @@ -25,6 +30,7 @@ protocolParser::~protocolParser(){ LOG("Destructor Begin"); # endif m_mBufferProtectorMutex.unlock(); +/* #ifdef PROTOCOL_PARSER_IN_THREAD if (m_bParserThreadStatus > TH_ARMED ) { waitParserThreadEnd( true ); @@ -33,6 +39,7 @@ protocolParser::~protocolParser(){ waitParserThreadEnd(true); }; #endif +*/ if( m_pParserBuffer != NULL ) { free( m_pParserBuffer ); }; @@ -72,8 +79,10 @@ bool protocolParser::create(void){ }; void protocolParser::setConnectionStatus( CONNECTION_STATUS cStatus ){ +#ifdef DEBUG if (cStatus == CS_CONNECTED)LOG("Connection Status Changed - Connected!"); if (cStatus == CS_DISCONNECTED)LOG("Connection Status Changed - Disconnected!"); +#endif m_eConnectionStatus = cStatus; }; @@ -95,39 +104,49 @@ bool protocolParser::setTransport( basicTransport* Transport, bool check_if_all bool protocolParser::parse( U8 *Buffer, size_t BufferSize ){ bool rv = false; if( m_pParserBuffer != NULL ) { +#ifdef DUBUG_COMMUNICATION + char ttZZ[256]; + sprintf( ttZZ, "New %d bytes to Parse (allredy have in buffer: %d)", BufferSize, m_nParserDataCount ); + LOG(ttZZ); +#endif m_mBufferProtectorMutex.lock(); if( ( m_nParserDataCount + BufferSize ) < PROTOCOL_PARSER_BUFFER_SIZE ) { memcpy( m_pParserBuffer+m_nParserDataCount, Buffer, BufferSize ); m_nParserDataCount+=BufferSize; rv = m_bBufferAltered = true; #ifndef PROTOCOL_PARSER_IN_THREAD - m_mBufferProtectorMutex.lock(); while ( m_nParserDataCount > 0 ){ int RetVal; -#ifdef DUBUG_COMMUNICATION + #ifdef DUBUG_COMMUNICATION LOG("Check Pack"); -#endif + #endif RetVal = packetChecker(m_pParserBuffer, m_nParserDataCount); -#ifdef DUBUG_COMMUNICATION + #ifdef DUBUG_COMMUNICATION LOG("Check Pack Done"); -#endif + #endif if (RetVal < 0) { // Note: RetVal is NEGATIVE!!?? m_nParserDataCount += RetVal; memcpy(m_pParserBuffer, m_pParserBuffer - RetVal, m_nParserDataCount); } else if (RetVal == 0) { protocolPackage* tVal = NULL; - tVal = packetExtractor(m_pParserBuffer, m_nParserDataCount); + tVal = packetExtractor( m_pParserBuffer, m_nParserDataCount ); if (tVal != NULL) { -#ifdef DUBUG_COMMUNICATION + #ifdef DUBUG_COMMUNICATION LOG("Package Handling"); char tBuf[256]; sprintf(tBuf, "Pack Size: %d from %d bytes", tVal->m_nSize, m_nParserDataCount); LOG(tBuf); -#endif + #endif //Move unused data toward buffer's begin to parse at next parse attempt m_nParserDataCount -= tVal->m_nSize; - memcpy(m_pParserBuffer, m_pParserBuffer + tVal->m_nSize, m_nParserDataCount); + if( m_nParserDataCount > 0 ) { + memcpy(m_pParserBuffer, m_pParserBuffer + tVal->m_nSize, m_nParserDataCount); + } else { + // Clean Buff; + memset( m_pParserBuffer, 0, PROTOCOL_PARSER_BUFFER_SIZE); + m_nParserDataCount = 0; + }; // In Case implementation of packetHandler - handler must return !true! if (!packetHandler(tVal)) { m_vPackagePool.push_back(tVal); @@ -150,7 +169,7 @@ bool protocolParser::parse( U8 *Buffer, size_t BufferSize ){ }; }; m_bBufferAltered = false; - m_mBufferProtectorMutex.unlock(); + //m_mBufferProtectorMutex.unlock(); #endif }; m_mBufferProtectorMutex.unlock(); diff --git a/lib/data/protocol/protocolDefender.cpp b/lib/data/protocol/protocolDefender.cpp index 612fdaaf..290bf40b 100644 --- a/lib/data/protocol/protocolDefender.cpp +++ b/lib/data/protocol/protocolDefender.cpp @@ -625,7 +625,7 @@ bool protocolDefender::packetHandler( protocolPackage *Package ){ Json::Reader reader; if( !reader.parse( (char *)Package->m_pData, root ) ){ LOG_ERROR( "Error parsing the string" ); - return false; + return true; }; if (root.size()) { Json::Value tVal; @@ -649,7 +649,6 @@ bool protocolDefender::packetHandler( protocolPackage *Package ){ }; }; }catch( exception e ){ - return false; }; return true; }; diff --git a/lib/data/protocol/protocolSafeShore.cpp b/lib/data/protocol/protocolSafeShore.cpp index db6377f6..695fd16b 100644 --- a/lib/data/protocol/protocolSafeShore.cpp +++ b/lib/data/protocol/protocolSafeShore.cpp @@ -493,7 +493,6 @@ bool protocolSafeShore::packetHandler( protocolPackage *Package ){ }; }; }catch( exception e ){ - return false; }; return true; }; diff --git a/lib/data/transport/transportSocket.cpp b/lib/data/transport/transportSocket.cpp index 52e8dfc8..5b0e2440 100644 --- a/lib/data/transport/transportSocket.cpp +++ b/lib/data/transport/transportSocket.cpp @@ -18,6 +18,7 @@ transportSocket::transportSocket() : basicTransport(), basicDualThread(){ #ifdef DEBUG LOG("Init IO Threads Done"); #endif + setConnectionStatus( CS_CONNECTED ); } else { LOG_ERROR("Init IO Threads ERROR!"); }; @@ -29,20 +30,7 @@ transportSocket::~transportSocket(){ LOG("Destruct: START"); # endif m_mBufferProtectorMutex.unlock(); - if( m_bThreadAStatus > TH_ARMED ) { - waitThreadAEnd(); -# ifdef DEBUG - LOG("DONE"); -# endif - }; - m_mQueueProtectorMutex.unlock(); - if( m_bThreadBStatus > TH_ARMED ) { - waitThreadBEnd(); -# ifdef DEBUG - LOG("DONE"); -# endif - }; -# ifdef DEBUG +#ifdef DEBUG LOG("Destruct: DONE"); # endif }; @@ -51,7 +39,9 @@ void transportSocket::m_fThreadAProc(void){ int index; int RetVal; m_bThreadAStatus = TH_WORKING; +#ifdef DEBUG LOG("Sender Thread Started!"); +#endif while (m_bThreadAStatus < TH_ENDED) { m_mBufferProtectorMutex.lock(); if( m_nOutputBufferSize > 0 ){ @@ -60,11 +50,11 @@ void transportSocket::m_fThreadAProc(void){ RetVal = sendBlock(m_pOutputBuffer + index, m_nOutputBufferSize - index); if( RetVal > 0 ) index += RetVal; if( RetVal == -1 ){ + setConnectionStatus( CS_DISCONNECTED ); + m_nOutputBufferSize = 0; m_bThreadBStatus = TH_ENDED; m_bThreadAStatus = TH_ENDED; LOG_ERROR("Connection Error[send]"); - setConnectionStatus( CS_DISCONNECTED ); - m_nOutputBufferSize = 0; }; }; m_nOutputBufferSize = 0; @@ -79,42 +69,36 @@ void transportSocket::m_fThreadAProc(void){ void transportSocket::m_fThreadBProc(void){ m_bThreadBStatus = TH_WORKING; int RetVal; +#ifdef DEBUG LOG("Recipient Thread Started!"); +#endif while( m_bThreadBStatus < TH_ENDED ){ RetVal = recptBlock( m_pInputBuffer, &m_nInputBufferSize); if( RetVal == -1 ){ - LOG_ERROR("Connection Error[rcpt]"); + setConnectionStatus(CS_DISCONNECTED); m_nInputBufferSize = 0; - if(!getStatus()) { - setConnectionStatus(CS_DISCONNECTED); - m_bThreadBStatus = TH_ENDED; - m_bThreadAStatus = TH_ENDED; - } else SLEEP(100); + //if(!getStatus()) { + m_bThreadBStatus = TH_ENDED; + m_bThreadAStatus = TH_ENDED; + //} else SLEEP(100); + LOG_ERROR("Connection Error[rcpt]"); } else if( m_nInputBufferSize > 0 ){ - LOG("Try Parse Data!"); - if (m_vParsers.size()) { - m_mQueueProtectorMutex.lock(); - for (parseQueue::iterator index = m_vParsers.begin(); index != m_vParsers.end(); index++) { -#ifdef DEBUG - LOG("Parse Enter!"); - if( -#endif - (*index)->parse(m_pInputBuffer, m_nInputBufferSize) -#ifdef DEBUG - ){ - LOG("Data Consumed by Parser!"); - } - LOG("Parse Done!") -#endif - ; - }; - m_nInputBufferSize = 0; - m_mQueueProtectorMutex.unlock(); - } else { - LOG_ERROR("Try to parse data but No Parsers Assigned!"); - }; + do{ + if (m_vParsers.size()) { + m_mQueueProtectorMutex.lock(); + //char tB[65]; + //sprintf( tB, "Parsers Cnt: %d",m_vParsers.size() ); + //LOG( tB ); + for (parseQueue::iterator index = m_vParsers.begin(); index != m_vParsers.end(); index++) (*index)->parse(m_pInputBuffer, m_nInputBufferSize); + m_nInputBufferSize = 0; + m_mQueueProtectorMutex.unlock(); + } else { + LOG_ERROR("Try to parse data but No Parsers Assigned!"); + SLEEP(2); + }; + } while( ( m_vParsers.size() == 0 ) && ( m_bThreadBStatus < TH_ENDED ) && ( m_bThreadBStatus < TH_ENDED ) ); } else { - SLEEP(5); + SLEEP(2); }; }; };