Browse Source

Added Darknet Lib to IMG MILL

AGP
Gitea 6 years ago
parent
commit
494f580c67
  1. 3
      .gitignore
  2. 290
      Projects/3dClientGui/makefile
  3. 0
      Projects/LRF_Server/build
  4. 21
      Projects/img_mill/IM_Backend.cpp
  5. 155
      Projects/img_mill/IM_ClientHandler.cpp
  6. 9
      Projects/img_mill/IM_ClientHandler.h
  7. 45
      Projects/img_mill/IM_ClientProtocol.cpp
  8. 40
      Projects/img_mill/IM_ClientProtocol.h
  9. 120
      Projects/img_mill/IM_DataBaseAdapter.cpp
  10. 5
      Projects/img_mill/IM_DataBaseAdapter.h
  11. 50
      Projects/img_mill/IM_DataStructs.h
  12. 171
      Projects/img_mill/IM_DnnWorker.cpp
  13. 40
      Projects/img_mill/IM_DnnWorker.h
  14. 35
      Projects/img_mill/IM_Kernel.cpp
  15. 9
      Projects/img_mill/IM_Kernel.h
  16. 9
      Projects/img_mill/build
  17. 17
      Projects/img_mill/img_mill.vpj
  18. 82
      Projects/img_mill/makefile
  19. 20
      lib/components/base/basicDualThread.cpp
  20. 28
      lib/components/base/basicDualThread.h
  21. 2
      lib/components/base/basicFunctionality.cpp
  22. 2
      lib/components/base/basicFunctionality.h
  23. 19
      lib/components/base/basicThread.cpp
  24. 25
      lib/components/base/basicThread.h
  25. 4
      lib/data/mysql/database_class.cpp
  26. 4
      lib/data/net/netClientHandler.cpp
  27. 20
      lib/data/net/serverPort.cpp
  28. 39
      lib/data/protocol/protocol.cpp
  29. 3
      lib/data/protocol/protocolDefender.cpp
  30. 1
      lib/data/protocol/protocolSafeShore.cpp
  31. 74
      lib/data/transport/transportSocket.cpp

3
.gitignore

@ -98,4 +98,5 @@
/Projects/MEKOROT/.vs/* /Projects/MEKOROT/.vs/*
/Projects/MEKOROT/x64/* /Projects/MEKOROT/x64/*
/Projects/MEKOROT/storage/* /Projects/MEKOROT/storage/*
Projects/img_mill/Debug/*
Projects/img_mill/Debug/*
Projects/img_mill/Release/*

290
Projects/3dClientGui/makefile

@ -19,132 +19,83 @@ endif
# #
ifeq "$(CFG)" "Debug" ifeq "$(CFG)" "Debug"
OUTDIR=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= 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)/basicRing.o $(OUTDIR)/basicSettings.o \
$(OUTDIR)/basicSettingsProvider.o $(OUTDIR)/basicThread.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 $(OUTDIR)/xmlParser.o
OBJ=$(COMMON_OBJ) $(CFG_OBJ) 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)/basicRing.o $(OUTDIR)/basicSettings.o \
$(OUTDIR)/basicSettingsProvider.o $(OUTDIR)/basicThread.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) LINK=g++ -g -ggdb -o "$(OUTFILE)" $(ALL_OBJ)
# Pattern rules # 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 $(OUTDIR)/%.o : ../../lib/alg/generic/%.cpp
$(COMPILE) $(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) $(COMPILE)
$(OUTDIR)/%.o : ../../lib/components/object/%.cpp
$(OUTDIR)/%.o : ../../lib/components/base/%.cpp
$(COMPILE) $(COMPILE)
$(OUTDIR)/%.o : ../../lib/hardware/sensors/gphoto/%.cpp
$(OUTDIR)/%.o : ../../lib/data/transport/%.cpp
$(COMPILE) $(COMPILE)
$(OUTDIR)/%.o : ../../lib/hardware/sensors/lrf/%.cpp
$(OUTDIR)/%.o : ../../lib/data/protocol/%.cpp
$(COMPILE) $(COMPILE)
$(OUTDIR)/%.o : ../../lib/data/net/%.cpp $(OUTDIR)/%.o : ../../lib/data/net/%.cpp
$(COMPILE) $(COMPILE)
$(OUTDIR)/%.o : ../../lib/data/curl/%.cpp
$(OUTDIR)/%.o : ../../lib/data/json/%.cpp
$(COMPILE) $(COMPILE)
$(OUTDIR)/%.o : ../../lib/data/mysql/%.cpp $(OUTDIR)/%.o : ../../lib/data/mysql/%.cpp
$(COMPILE) $(COMPILE)
$(OUTDIR)/%.o : ../../lib/data/json/%.cpp
$(OUTDIR)/%.o : ../../lib/components/object/%.cpp
$(COMPILE) $(COMPILE)
# Build rules # Build rules
@ -173,132 +124,83 @@ endif
# #
ifeq "$(CFG)" "Release" ifeq "$(CFG)" "Release"
OUTDIR=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= 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)/basicRing.o $(OUTDIR)/basicSettings.o \
$(OUTDIR)/basicSettingsProvider.o $(OUTDIR)/basicThread.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 $(OUTDIR)/xmlParser.o
OBJ=$(COMMON_OBJ) $(CFG_OBJ) 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)/basicRing.o $(OUTDIR)/basicSettings.o \
$(OUTDIR)/basicSettingsProvider.o $(OUTDIR)/basicThread.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) LINK=g++ -ggdb -o "$(OUTFILE)" $(ALL_OBJ)
# Pattern rules # 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 $(OUTDIR)/%.o : ../../lib/alg/generic/%.cpp
$(COMPILE) $(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) $(COMPILE)
$(OUTDIR)/%.o : ../../lib/components/object/%.cpp
$(OUTDIR)/%.o : ../../lib/components/base/%.cpp
$(COMPILE) $(COMPILE)
$(OUTDIR)/%.o : ../../lib/hardware/sensors/gphoto/%.cpp
$(OUTDIR)/%.o : ../../lib/data/transport/%.cpp
$(COMPILE) $(COMPILE)
$(OUTDIR)/%.o : ../../lib/hardware/sensors/lrf/%.cpp
$(OUTDIR)/%.o : ../../lib/data/protocol/%.cpp
$(COMPILE) $(COMPILE)
$(OUTDIR)/%.o : ../../lib/data/net/%.cpp $(OUTDIR)/%.o : ../../lib/data/net/%.cpp
$(COMPILE) $(COMPILE)
$(OUTDIR)/%.o : ../../lib/data/curl/%.cpp
$(OUTDIR)/%.o : ../../lib/data/json/%.cpp
$(COMPILE) $(COMPILE)
$(OUTDIR)/%.o : ../../lib/data/mysql/%.cpp $(OUTDIR)/%.o : ../../lib/data/mysql/%.cpp
$(COMPILE) $(COMPILE)
$(OUTDIR)/%.o : ../../lib/data/json/%.cpp
$(OUTDIR)/%.o : ../../lib/components/object/%.cpp
$(COMPILE) $(COMPILE)
# Build rules # Build rules

0
Projects/LRF_Server/build

21
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 ) #define LOG_ERROR( X ) m_pLog->Log( "main", 0, _LOG_ERROR, X )
IM_Kernel * Kernel = NULL; IM_Kernel * Kernel = NULL;
//LRF_HardwareManager * HWManager = NULL;
basicLogCollection * m_pLog = NULL; basicLogCollection * m_pLog = NULL;
networkServer * NetworkManager = NULL; networkServer * NetworkManager = NULL;
@ -49,7 +48,6 @@ void signal_SIGKILL_handler( int SIG ){
//#include <sys/resource.h> //#include <sys/resource.h>
int main (int argc, char *argv[]){ int main (int argc, char *argv[]){
//MySQL_Connector * DBC = NULL;
basicSettingsProvider * SETTINGS = NULL; basicSettingsProvider * SETTINGS = NULL;
bool WBG; // Working Background bool WBG; // Working Background
bool SSE; // Server Statistics Engine bool SSE; // Server Statistics Engine
@ -148,7 +146,7 @@ int main (int argc, char *argv[]){
if( FLE != NULL ) { if( FLE != NULL ) {
m_pLog->addHandler( FLE ); m_pLog->addHandler( FLE );
}; };
LOG("Starting Log Engne!");
LOG("Starting Log Engine!");
if ( fileExist( DCF_NAME ) ){ if ( fileExist( DCF_NAME ) ){
SETTINGS = basicSettingsProvider::getInstance(DCF_NAME); SETTINGS = basicSettingsProvider::getInstance(DCF_NAME);
} else { } else {
@ -206,6 +204,15 @@ int main (int argc, char *argv[]){
uint8_t m_bKernelExitCode = 0; 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{ do{
//Loop till some Restart action //Loop till some Restart action
Kernel = IM_Kernel::getInstance(); Kernel = IM_Kernel::getInstance();
@ -217,10 +224,13 @@ int main (int argc, char *argv[]){
delete( m_pLog ); delete( m_pLog );
return -1; return -1;
} else { } else {
LOG( "++++ Server Started ++++" );
if ( Kernel->start() == false ){ if ( Kernel->start() == false ){
LOG_ERROR("Kernel create failure!"); LOG_ERROR("Kernel create failure!");
} else { } else {
LOG( "++++ Server Started ++++" );
if( NetworkManager!= NULL ) {
NetworkManager->attachEngine( Kernel );
};
//Install Signal Listeners //Install Signal Listeners
old_kill_handler_15 = signal( 15, signal_SIGKILL_handler ); old_kill_handler_15 = signal( 15, signal_SIGKILL_handler );
old_kill_handler_9 = signal( 9, 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( 9, old_kill_handler_9 );
signal( 15, old_kill_handler_15 ); signal( 15, old_kill_handler_15 );
}; };
//Since Kernel is Singletone Object no need to delete
delete( Kernel ); delete( Kernel );
LOG( "++++ Server Ended ++++" ); LOG( "++++ Server Ended ++++" );
}; };
} while( m_bKernelExitCode > 0 ); } while( m_bKernelExitCode > 0 );
delete( NetworkManager );
if( NetworkManager ) delete( NetworkManager );
//LOG( "++++ CDC DEL ++++" ); //LOG( "++++ CDC DEL ++++" );
unlink( gsCFG_PID_FILE ); unlink( gsCFG_PID_FILE );
LOG( "PID File Deleted" ); LOG( "PID File Deleted" );

155
Projects/img_mill/IM_ClientHandler.cpp

@ -1,6 +1,15 @@
#include "IM_ClientHandler.h" #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/json/json_tool.h"
#include "../../lib/data/protocol/xmlParser.h"
#include <strings.h>
#include <json/value.h>
#include <json/writer.h>
#include <json/reader.h>
#define LOG( X ) m_pLog->Log( "NCH", this, X ) #define LOG( X ) m_pLog->Log( "NCH", this, X )
@ -17,21 +26,25 @@
// Constructor implementation // Constructor implementation
IM_ClientHandler::IM_ClientHandler( int SOCKET ) : networkClientHandler( SOCKET ), IM_ClientProtocol(){ IM_ClientHandler::IM_ClientHandler( int SOCKET ) : networkClientHandler( SOCKET ), IM_ClientProtocol(){
m_pLog = basicLogCollection::getInstance(); 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() ){ 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 // 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 ){ bool IM_ClientHandler::getStatus( void ){
@ -41,6 +54,124 @@ bool IM_ClientHandler::getStatus( void ){
return false; 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
#undef LOG_ERROR #undef LOG_ERROR

9
Projects/img_mill/IM_ClientHandler.h

@ -3,6 +3,9 @@
#include "../../lib/data/net/netClientHandler.h" #include "../../lib/data/net/netClientHandler.h"
#include "IM_ClientProtocol.h" #include "IM_ClientProtocol.h"
#include "IM_DataBaseAdapter.h"
/** /**
* TODO: Add class description * TODO: Add class description
* *
@ -11,6 +14,10 @@
class IM_ClientHandler : public networkClientHandler, public IM_ClientProtocol{ class IM_ClientHandler : public networkClientHandler, public IM_ClientProtocol{
private: private:
basicLogCollection * m_pLog; basicLogCollection * m_pLog;
void * m_pMyCurrentJob;
IM_DataBaseAdapter * m_pDBA;
protected:
virtual bool packetHandler( protocolPackage *Package );
public: public:
// Constructor // Constructor
explicit IM_ClientHandler( int SOCKET ); explicit IM_ClientHandler( int SOCKET );
@ -18,6 +25,8 @@ class IM_ClientHandler : public networkClientHandler, public IM_ClientProtocol{
// Destructor // Destructor
virtual ~IM_ClientHandler(); virtual ~IM_ClientHandler();
virtual bool getStatus( void ); virtual bool getStatus( void );
bool handleItem( IM_ITEM_DATA *ptr );
virtual void dispatchEvent( basicEvent *Evt );
}; };

45
Projects/img_mill/IM_ClientProtocol.cpp

@ -1,16 +1,55 @@
#include "IM_ClientProtocol.h" #include "IM_ClientProtocol.h"
#define LOG( X ) m_pLog->Log( "KRNL", this, X )
#define LOG( X ) m_pLog->Log( "NCP", this, X )
#ifdef DEBUG #ifdef DEBUG
#define LOG_ERROR( X ) {\ #define LOG_ERROR( X ) {\
char _tBfrErrMSG234[256];\ char _tBfrErrMSG234[256];\
sprintf( _tBfrErrMSG234, "In file %s[%d] in func:%s %s",__FILE__, __LINE__, __func__, X );\ 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 #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 #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 #undef LOG

40
Projects/img_mill/IM_ClientProtocol.h

@ -9,48 +9,16 @@
* @author Gagua * @author Gagua
*/ */
class IM_ClientProtocol : public protocolParser { 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: public:
// Constructor // Constructor
IM_ClientProtocol(); IM_ClientProtocol();
// Destructor // Destructor
virtual ~IM_ClientProtocol(); 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__ #endif // __IM_CLIENTPROTOCOL_H_INCL__

120
Projects/img_mill/IM_DataBaseAdapter.cpp

@ -1,15 +1,15 @@
#include "IM_DataBaseAdapter.h" #include "IM_DataBaseAdapter.h"
#include "../../lib/alg/generic/md5.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 #ifdef DEBUG
#define LOG_ERROR( X ) {\ #define LOG_ERROR( X ) {\
char _tBfrErrMSG234[256];\ char _tBfrErrMSG234[256];\
sprintf( _tBfrErrMSG234, "In file %s[%d] in func:%s %s",__FILE__, __LINE__, __func__, X );\ 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 #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 #endif
IM_DataBaseAdapter* IM_DataBaseAdapter::_instance = NULL; IM_DataBaseAdapter* IM_DataBaseAdapter::_instance = NULL;
@ -89,6 +89,120 @@ inline IM_DataBaseAdapter::IM_DataBaseAdapter( config_setting_t * Settings ){
// Destructor implementation // Destructor implementation
inline IM_DataBaseAdapter::~IM_DataBaseAdapter(){ 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 #undef LOG

5
Projects/img_mill/IM_DataBaseAdapter.h

@ -3,6 +3,7 @@
#include "../../lib/data/mysql/database_class.h" #include "../../lib/data/mysql/database_class.h"
#include "../../lib/components/base/basicSettingsProvider.h" #include "../../lib/components/base/basicSettingsProvider.h"
#include "IM_DataStructs.h"
/** /**
* TODO: Add class description * TODO: Add class description
@ -22,6 +23,10 @@ class IM_DataBaseAdapter {
// Destructor // Destructor
virtual ~IM_DataBaseAdapter(); 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: protected:
// Constructor - protected so users cannot call it. // Constructor - protected so users cannot call it.
explicit IM_DataBaseAdapter( config_setting_t * Settings ); explicit IM_DataBaseAdapter( config_setting_t * Settings );

50
Projects/img_mill/IM_DataStructs.h

@ -0,0 +1,50 @@
#ifndef __IMAGE_MILL_DATA_STRUCTURES_HEADER__
#define __IMAGE_MILL_DATA_STRUCTURES_HEADER__
#include <queue>
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 *> IM_JOB_QUEUE;
#endif

171
Projects/img_mill/IM_DnnWorker.cpp

@ -13,29 +13,38 @@
#endif #endif
// Constructor implementation // 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_pLog = basicLogCollection::getInstance();
m_pSettings = basicSettingsProvider::getInstance()->getSubNode( Settings, "DNN" ); 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_eBackendEngine = cv::dnn::DNN_BACKEND_DEFAULT;
m_eTargetDevice = cv::dnn::DNN_TARGET_CPU; 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 ){ bool IM_DnnWorker::create( void ){
char tBuff[256];
if( m_pSettings == NULL ){ if( m_pSettings == NULL ){
return false; return false;
} else { } else {
config_setting_t * tSetting; 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" ); tSetting = config_setting_get_member( m_pSettings, "NET_CONFIG_FILE" );
if( tSetting == NULL ){ if( tSetting == NULL ){
tSetting = config_setting_add(m_pSettings, "NET_CONFIG_FILE", CONFIG_TYPE_STRING ); 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), "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; 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" ); tSetting = config_setting_get_member( m_pSettings, "NET_BACKEND_ENGINE" );
if( tSetting == NULL ){ 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), "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), "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; 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(); 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 )) { if(!fileExist( m_pConfigPath )) {
LOG_ERROR("No Config file exists!"); LOG_ERROR("No Config file exists!");
return false; return false;
@ -99,57 +113,126 @@ bool IM_DnnWorker::create( void ){
LOG_ERROR("No Weight file exists!"); LOG_ERROR("No Weight file exists!");
return false; 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 = cv::dnn::readNetFromDarknet( m_pConfigPath, m_pWeightsPath );
m_net.setPreferableBackend( m_eBackendEngine ); m_net.setPreferableBackend( m_eBackendEngine );
m_net.setPreferableTarget( m_eTargetDevice ); m_net.setPreferableTarget( m_eTargetDevice );
return false;
std::vector<String> outNames = m_net.getUnconnectedOutLayersNames();
LOG("OutNames");
for( std::vector<String>::iterator idx = outNames.begin(); idx < outNames.end(); idx++ ) {
LOG( (*idx).c_str() );
};
#endif
return init();
}; };
bool IM_DnnWorker::m_fImageAnalyzer( Mat &Picture ){ 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.width = Picture.cols;
inpSize.height = Picture.rows; 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_<float>(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<Mat> outs;
//std::vector<String> 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_<float>(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; return false;
}; };
/*
void IM_DnnWorker::m_fThreadProc( void ){ void IM_DnnWorker::m_fThreadProc( void ){
m_bThreadStatus = TH_WORKING; m_bThreadStatus = TH_WORKING;
while( m_bThreadStatus < TH_ENDED ) { 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
#undef LOG_ERROR #undef LOG_ERROR

40
Projects/img_mill/IM_DnnWorker.h

@ -1,32 +1,62 @@
#ifndef __IM_DNNWORKER_H_INCL__ #ifndef __IM_DNNWORKER_H_INCL__
#define __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/basicSettingsProvider.h"
#include "../../lib/components/base/basicEventHeap.h"
#include "IM_DataStructs.h"
//#define DARKNET
#ifdef DARKNET
#define GPU
//#include <darknet/darknet.h>
#include <darknet/yolo_v2_class.hpp>
#undef GPU
#endif
#include <opencv2/opencv.hpp>
#include <opencv2/core.hpp>
#include <opencv2/imgcodecs.hpp>
#include <opencv2/highgui.hpp>
#include <opencv2/dnn/dnn.hpp> #include <opencv2/dnn/dnn.hpp>
using namespace cv;
/** /**
* TODO: Add class description * TODO: Add class description
* *
* @author Gagua * @author Gagua
*/ */
class IM_DnnWorker : public basicVideoAnalyzer {
class IM_DnnWorker : public basicThread {
private: private:
#ifdef DARKNET
Detector * m_pDarknetDetector;
#else
#endif
basicLogCollection * m_pLog; basicLogCollection * m_pLog;
config_setting_t * m_pSettings; config_setting_t * m_pSettings;
cv::dnn::Backend m_eBackendEngine; cv::dnn::Backend m_eBackendEngine;
cv::dnn::Target m_eTargetDevice; cv::dnn::Target m_eTargetDevice;
cv::dnn::Net m_net; cv::dnn::Net m_net;
cv::Mat m_oWorkingMat;
basicEventHeap * m_pEvtHeap;
char m_pPicturesBase[1024];
char m_pConfigPath[1024]; char m_pConfigPath[1024];
char m_pWeightsPath[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 ); virtual bool m_fImageAnalyzer( Mat &Picture );
protected:
virtual void m_fThreadProc( void );//getLayerNames()
public: public:
// Constructor // Constructor
explicit IM_DnnWorker( config_setting_t * Settings = NULL ); explicit IM_DnnWorker( config_setting_t * Settings = NULL );
// Destructor // Destructor
virtual ~IM_DnnWorker(); virtual ~IM_DnnWorker();
bool create( void );
bool create( void );
bool enqueueJob( IM_JOB *ptr );
}; };

35
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(){ inline IM_Kernel::IM_Kernel( config_setting_t *Settings ) : basicEngine(), basicThread(){
m_pLog = basicLogCollection::getInstance(); m_pLog = basicLogCollection::getInstance();
m_pSettings = basicSettingsProvider::getInstance()->getSubNode( Settings, "KERNEL" ); m_pSettings = basicSettingsProvider::getInstance()->getSubNode( Settings, "KERNEL" );
m_bExitCause = 0;
m_pWorker = NULL; m_pWorker = NULL;
m_pDBA = NULL;
m_pActiveJob = NULL;
}; };
// Destructor implementation // Destructor implementation
inline IM_Kernel::~IM_Kernel(){ inline IM_Kernel::~IM_Kernel(){
waitThreadEnd( true ); waitThreadEnd( true );
if( m_pWorker ) delete( m_pWorker );
if( m_pDBA ) delete( m_pDBA );
_instance = NULL;
}; };
bool IM_Kernel::start(){ 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 ); m_pWorker = new IM_DnnWorker( m_pSettings );
if( m_pWorker ) { if( m_pWorker ) {
if( m_pWorker->create() ){ if( m_pWorker->create() ){
return init(); 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; return false;
}; };
bool IM_Kernel::stop( bool Force ){ bool IM_Kernel::stop( bool Force ){
delete( m_pWorker );
m_pWorker = NULL;
waitThreadEnd( Force ); waitThreadEnd( Force );
return true; return true;
}; };
@ -68,10 +77,28 @@ bool IM_Kernel::detachClient( networkClientHandler *ptr ){
void IM_Kernel::m_fThreadProc( void ){ void IM_Kernel::m_fThreadProc( void ){
m_bThreadStatus = TH_WORKING; m_bThreadStatus = TH_WORKING;
while( m_bThreadStatus < TH_ENDED ) { 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 ); 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
#undef LOG_ERROR #undef LOG_ERROR

9
Projects/img_mill/IM_Kernel.h

@ -4,10 +4,12 @@
#include "../../lib/components/base/basicEngine.h" #include "../../lib/components/base/basicEngine.h"
#include "../../lib/components/base/basicThread.h" #include "../../lib/components/base/basicThread.h"
#include "../../lib/components/base/basicSettingsProvider.h" #include "../../lib/components/base/basicSettingsProvider.h"
#include "IM_DataStructs.h"
#include "IM_DnnWorker.h" #include "IM_DnnWorker.h"
#include "IM_DataBaseAdapter.h"
class networkClientHandler; class networkClientHandler;
/** /**
* TODO: Add class description * TODO: Add class description
* *
@ -17,8 +19,11 @@ class IM_Kernel : public basicEngine, public basicThread {
private: private:
basicLogCollection * m_pLog; basicLogCollection * m_pLog;
config_setting_t * m_pSettings; config_setting_t * m_pSettings;
IM_DataBaseAdapter * m_pDBA;
uint8_t m_bExitCause; uint8_t m_bExitCause;
IM_DnnWorker * m_pWorker; IM_DnnWorker * m_pWorker;
IM_JOB_QUEUE m_qJOBS;
IM_JOB * m_pActiveJob;
protected: protected:
virtual void m_fThreadProc( void ); virtual void m_fThreadProc( void );
public: public:
@ -32,6 +37,8 @@ class IM_Kernel : public basicEngine, public basicThread {
uint8_t getExitCause( void ){ return m_bExitCause;}; uint8_t getExitCause( void ){ return m_bExitCause;};
virtual networkClientHandler * attachNewClient( int SocketID ); virtual networkClientHandler * attachNewClient( int SocketID );
virtual bool detachClient( networkClientHandler *ptr ); virtual bool detachClient( networkClientHandler *ptr );
bool enqueueJob( IM_JOB *ptr );
//IM_RESULT * getResult( IM_JOB *ptr );
private: private:
static IM_Kernel * _instance; static IM_Kernel * _instance;
// Constructor // Constructor

9
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"

17
Projects/img_mill/img_mill.vpj

@ -128,6 +128,7 @@
<Lib File="-lc"/> <Lib File="-lc"/>
<Lib File="-lm"/> <Lib File="-lm"/>
<Lib File="-lz"/> <Lib File="-lz"/>
<Lib File="-ldarknet"/>
</Libs> </Libs>
</Config> </Config>
<Config <Config
@ -137,7 +138,7 @@
Version="1" Version="1"
OutputFile="%bdimg_mill" OutputFile="%bdimg_mill"
CompilerConfigName="Latest Version" CompilerConfigName="Latest Version"
Defines='"/D_OPENCV_" "/DDEBUG"'>
Defines='"/D_OPENCV_"'>
<Menu> <Menu>
<Target <Target
Name="Compile" Name="Compile"
@ -149,8 +150,8 @@
SaveOption="SaveCurrent" SaveOption="SaveCurrent"
RunFromDir="%rw"> RunFromDir="%rw">
<Exec <Exec
CmdLine='g++ -c %xup -x c++ %defd -ggdb %~other -o "%bd%n%oe" %i %f'
OtherOptions="`pkg-config --cflags opencv4`"/>
CmdLine='g++ -c %xup -x c++ %defd -O3 %~other -o "%bd%n%oe" %i %f'
OtherOptions="`pkg-config --cflags opencv4` -s"/>
</Target> </Target>
<Target <Target
Name="Link" Name="Link"
@ -161,7 +162,9 @@
Deletable="0" Deletable="0"
SaveOption="SaveCurrent" SaveOption="SaveCurrent"
RunFromDir="%rw"> RunFromDir="%rw">
<Exec CmdLine='g++ %xup -ggdb -o "%o" %objs'/>
<Exec
CmdLine='g++ %xup -O3 %~other -o "%o" %objs'
OtherOptions=" -s"/>
</Target> </Target>
<Target <Target
Name="Build" Name="Build"
@ -275,7 +278,6 @@
<F N="../../lib/components/base/basicSettingsProvider.cpp"/> <F N="../../lib/components/base/basicSettingsProvider.cpp"/>
<F N="../../lib/components/base/basicThread.cpp"/> <F N="../../lib/components/base/basicThread.cpp"/>
<F N="../../lib/components/base/basicTransport.cpp"/> <F N="../../lib/components/base/basicTransport.cpp"/>
<F N="../../lib/components/base/basicVideoAnalyzer.cpp"/>
<F N="../../lib/data/mysql/database_class.cpp"/> <F N="../../lib/data/mysql/database_class.cpp"/>
<F N="IM_Backend.cpp"/> <F N="IM_Backend.cpp"/>
<F N="IM_ClientHandler.cpp"/> <F N="IM_ClientHandler.cpp"/>
@ -283,6 +285,9 @@
<F N="IM_DataBaseAdapter.cpp"/> <F N="IM_DataBaseAdapter.cpp"/>
<F N="IM_DnnWorker.cpp"/> <F N="IM_DnnWorker.cpp"/>
<F N="IM_Kernel.cpp"/> <F N="IM_Kernel.cpp"/>
<F N="../../lib/data/json/json_reader.cpp"/>
<F N="../../lib/data/json/json_value.cpp"/>
<F N="../../lib/data/json/json_writer.cpp"/>
<F N="../../lib/alg/generic/md5.cpp"/> <F N="../../lib/alg/generic/md5.cpp"/>
<F N="../../lib/data/net/netClientHandler.cpp"/> <F N="../../lib/data/net/netClientHandler.cpp"/>
<F N="../../lib/data/net/netServer.cpp"/> <F N="../../lib/data/net/netServer.cpp"/>
@ -291,6 +296,7 @@
<F N="../../lib/data/protocol/protocol.cpp"/> <F N="../../lib/data/protocol/protocol.cpp"/>
<F N="../../lib/data/net/serverPort.cpp"/> <F N="../../lib/data/net/serverPort.cpp"/>
<F N="../../lib/data/transport/transportSocket.cpp"/> <F N="../../lib/data/transport/transportSocket.cpp"/>
<F N="../../lib/data/protocol/xmlParser.cpp"/>
</Folder> </Folder>
<Folder <Folder
Name="Header Files" Name="Header Files"
@ -300,6 +306,7 @@
<F N="IM_ClientHandler.h"/> <F N="IM_ClientHandler.h"/>
<F N="IM_ClientProtocol.h"/> <F N="IM_ClientProtocol.h"/>
<F N="IM_DataBaseAdapter.h"/> <F N="IM_DataBaseAdapter.h"/>
<F N="IM_DataStructs.h"/>
<F N="IM_DnnWorker.h"/> <F N="IM_DnnWorker.h"/>
<F N="IM_Kernel.h"/> <F N="IM_Kernel.h"/>
<F N="../../lib/data/net/netClientHandler.h"/> <F N="../../lib/data/net/netClientHandler.h"/>

82
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 \ CFG_LIB=-lmysqlclient -lssl -lcrypto -lpthread `pkg-config --libs \
libavcodec libavdevice libavfilter libavformat libavresample \ libavcodec libavdevice libavfilter libavformat libavresample \
libavutil libswresample libswscale libconfig++ libcurl opencv4` -lGL \ libavutil libswresample libswscale libconfig++ libcurl opencv4` -lGL \
-lGLU -lc -lm -lz
-lGLU -lc -lm -lz -ldarknet
CFG_OBJ= CFG_OBJ=
COMMON_OBJ=$(OUTDIR)/basicDualThread.o $(OUTDIR)/basicEngine.o \ COMMON_OBJ=$(OUTDIR)/basicDualThread.o $(OUTDIR)/basicEngine.o \
$(OUTDIR)/basicEvent.o $(OUTDIR)/basicEventHandler.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)/basicMediaViewer.o $(OUTDIR)/basicMutex.o \
$(OUTDIR)/basicRing.o $(OUTDIR)/basicSettings.o \ $(OUTDIR)/basicRing.o $(OUTDIR)/basicSettings.o \
$(OUTDIR)/basicSettingsProvider.o $(OUTDIR)/basicThread.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)/netServer.o $(OUTDIR)/objectConsoleLoggingService.o \
$(OUTDIR)/objectFileLoggingService.o $(OUTDIR)/protocol.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) OBJ=$(COMMON_OBJ) $(CFG_OBJ)
ALL_OBJ=$(OUTDIR)/basicDualThread.o $(OUTDIR)/basicEngine.o \ ALL_OBJ=$(OUTDIR)/basicDualThread.o $(OUTDIR)/basicEngine.o \
$(OUTDIR)/basicEvent.o $(OUTDIR)/basicEventHandler.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)/basicMediaViewer.o $(OUTDIR)/basicMutex.o \
$(OUTDIR)/basicRing.o $(OUTDIR)/basicSettings.o \ $(OUTDIR)/basicRing.o $(OUTDIR)/basicSettings.o \
$(OUTDIR)/basicSettingsProvider.o $(OUTDIR)/basicThread.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)/netServer.o $(OUTDIR)/objectConsoleLoggingService.o \
$(OUTDIR)/objectFileLoggingService.o $(OUTDIR)/protocol.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) $< 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) LINK=g++ -g -ggdb -o "$(OUTFILE)" $(ALL_OBJ)
@ -85,6 +89,9 @@ $(OUTDIR)/%.o : ../../lib/data/protocol/%.cpp
$(OUTDIR)/%.o : ../../lib/data/net/%.cpp $(OUTDIR)/%.o : ../../lib/data/net/%.cpp
$(COMPILE) $(COMPILE)
$(OUTDIR)/%.o : ../../lib/data/json/%.cpp
$(COMPILE)
$(OUTDIR)/%.o : ../../lib/data/mysql/%.cpp $(OUTDIR)/%.o : ../../lib/data/mysql/%.cpp
$(COMPILE) $(COMPILE)
@ -118,7 +125,7 @@ endif
ifeq "$(CFG)" "Release" ifeq "$(CFG)" "Release"
OUTDIR=Release OUTDIR=Release
OUTFILE=$(OUTDIR)/img_mill 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 \ CFG_LIB=-lmysqlclient -lssl -lcrypto -lpthread `pkg-config --libs \
libavcodec libavdevice libavfilter libavformat libavresample \ libavcodec libavdevice libavfilter libavformat libavresample \
libavutil libswresample libswscale libconfig++ libcurl opencv4` -lGL \ 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)/basicMediaViewer.o $(OUTDIR)/basicMutex.o \
$(OUTDIR)/basicRing.o $(OUTDIR)/basicSettings.o \ $(OUTDIR)/basicRing.o $(OUTDIR)/basicSettings.o \
$(OUTDIR)/basicSettingsProvider.o $(OUTDIR)/basicThread.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)/netServer.o $(OUTDIR)/objectConsoleLoggingService.o \
$(OUTDIR)/objectFileLoggingService.o $(OUTDIR)/protocol.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) OBJ=$(COMMON_OBJ) $(CFG_OBJ)
ALL_OBJ=$(OUTDIR)/basicDualThread.o $(OUTDIR)/basicEngine.o \ ALL_OBJ=$(OUTDIR)/basicDualThread.o $(OUTDIR)/basicEngine.o \
$(OUTDIR)/basicEvent.o $(OUTDIR)/basicEventHandler.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)/basicMediaViewer.o $(OUTDIR)/basicMutex.o \
$(OUTDIR)/basicRing.o $(OUTDIR)/basicSettings.o \ $(OUTDIR)/basicRing.o $(OUTDIR)/basicSettings.o \
$(OUTDIR)/basicSettingsProvider.o $(OUTDIR)/basicThread.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)/netServer.o $(OUTDIR)/objectConsoleLoggingService.o \
$(OUTDIR)/objectFileLoggingService.o $(OUTDIR)/protocol.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 # Pattern rules
$(OUTDIR)/%.o : ../../lib/alg/generic/%.cpp $(OUTDIR)/%.o : ../../lib/alg/generic/%.cpp
@ -183,6 +194,9 @@ $(OUTDIR)/%.o : ../../lib/data/protocol/%.cpp
$(OUTDIR)/%.o : ../../lib/data/net/%.cpp $(OUTDIR)/%.o : ../../lib/data/net/%.cpp
$(COMPILE) $(COMPILE)
$(OUTDIR)/%.o : ../../lib/data/json/%.cpp
$(COMPILE)
$(OUTDIR)/%.o : ../../lib/data/mysql/%.cpp $(OUTDIR)/%.o : ../../lib/data/mysql/%.cpp
$(COMPILE) $(COMPILE)

20
lib/components/base/basicDualThread.cpp

@ -75,7 +75,9 @@ void basicDualThread::m_fThreadBProc( void ){
mThis->m_fThreadAProc(); mThis->m_fThreadAProc();
mThis->m_bThreadAStatus = TH_EXIT; mThis->m_bThreadAStatus = TH_EXIT;
}; };
#ifdef DEBUG
mThis->SLOG("ThreadAEntryPoint Exit."); mThis->SLOG("ThreadAEntryPoint Exit.");
#endif
#if defined( __linux__ ) || defined(WIN_PTHREAD) #if defined( __linux__ ) || defined(WIN_PTHREAD)
pthread_exit( NULL ); pthread_exit( NULL );
return NULL; return NULL;
@ -95,7 +97,9 @@ void basicDualThread::m_fThreadBProc( void ){
mThis->m_fThreadBProc(); mThis->m_fThreadBProc();
mThis->m_bThreadBStatus = TH_EXIT; mThis->m_bThreadBStatus = TH_EXIT;
}; };
#ifdef DEBUG
mThis->SLOG("ThreadBEntryPoint Exit."); mThis->SLOG("ThreadBEntryPoint Exit.");
#endif
#if defined( __linux__ ) || defined(WIN_PTHREAD) #if defined( __linux__ ) || defined(WIN_PTHREAD)
pthread_exit( NULL ); pthread_exit( NULL );
return NULL; return NULL;
@ -106,14 +110,20 @@ void basicDualThread::m_fThreadBProc( void ){
void basicDualThread::waitThreadAEnd( bool Force ){ void basicDualThread::waitThreadAEnd( bool Force ){
if( m_bThreadAStatus > TH_WORKING || m_bThreadAStatus < TH_ARMED ) { if( m_bThreadAStatus > TH_WORKING || m_bThreadAStatus < TH_ARMED ) {
#ifdef DEBUG
LOG("Thread A already Dead!"); LOG("Thread A already Dead!");
#endif
return; return;
}; };
if( Force ){ if( Force ){
#ifdef DEBUG
LOG("Thread A Requested Exit."); LOG("Thread A Requested Exit.");
#endif
m_bThreadAStatus = TH_ENDED; m_bThreadAStatus = TH_ENDED;
} else { } else {
#ifdef DEBUG
LOG("Thread A Wait Exit."); LOG("Thread A Wait Exit.");
#endif
}; };
while( m_bThreadAStatus != TH_EXIT ) SLEEP(DEFAULT_THREAD_SLEEP_TIME); while( m_bThreadAStatus != TH_EXIT ) SLEEP(DEFAULT_THREAD_SLEEP_TIME);
#if defined( __linux__ ) || defined(WIN_PTHREAD) #if defined( __linux__ ) || defined(WIN_PTHREAD)
@ -122,19 +132,27 @@ void basicDualThread::waitThreadAEnd( bool Force ){
WaitForSingleObject(m_hThreadAHandle, 2000); WaitForSingleObject(m_hThreadAHandle, 2000);
CloseHandle(m_hThreadAHandle); CloseHandle(m_hThreadAHandle);
#endif #endif
#ifdef DEBUG
LOG("Thread A Ended."); LOG("Thread A Ended.");
#endif
}; };
void basicDualThread::waitThreadBEnd( bool Force ){ void basicDualThread::waitThreadBEnd( bool Force ){
if( m_bThreadBStatus > TH_WORKING || m_bThreadBStatus < TH_ARMED ){ if( m_bThreadBStatus > TH_WORKING || m_bThreadBStatus < TH_ARMED ){
#ifdef DEBUG
LOG("Thread B already Dead!"); LOG("Thread B already Dead!");
#endif
return; return;
}; };
if( Force ){ if( Force ){
#ifdef DEBUG
LOG("Thread B Requested Exit."); LOG("Thread B Requested Exit.");
#endif
m_bThreadBStatus = TH_ENDED; m_bThreadBStatus = TH_ENDED;
} else { } else {
#ifdef DEBUG
LOG("Thread B Wait Exit."); LOG("Thread B Wait Exit.");
#endif
}; };
while( m_bThreadBStatus != TH_EXIT ) SLEEP(DEFAULT_THREAD_SLEEP_TIME); while( m_bThreadBStatus != TH_EXIT ) SLEEP(DEFAULT_THREAD_SLEEP_TIME);
#if defined( __linux__ ) || defined(WIN_PTHREAD) #if defined( __linux__ ) || defined(WIN_PTHREAD)
@ -143,7 +161,9 @@ void basicDualThread::waitThreadBEnd( bool Force ){
WaitForSingleObject(m_hThreadBHandle, 2000); WaitForSingleObject(m_hThreadBHandle, 2000);
CloseHandle(m_hThreadBHandle); CloseHandle(m_hThreadBHandle);
#endif #endif
#ifdef DEBUG
LOG("Thread B Ended."); LOG("Thread B Ended.");
#endif
}; };
#undef LOG #undef LOG

28
lib/components/base/basicDualThread.h

@ -56,33 +56,9 @@ inline basicDualThread::basicDualThread(){
// Destructor implementation // Destructor implementation
inline basicDualThread::~basicDualThread(){ 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__ #endif // __BASICTHREAD_H_INCL__

2
lib/components/base/basicFunctionality.cpp

@ -336,7 +336,9 @@ long long getMilliseconds( void ){
tTZ.tz_dsttime = 0; tTZ.tz_dsttime = 0;
if( gettimeofday( &tData, &tTZ ) == -1 ){ if( gettimeofday( &tData, &tTZ ) == -1 ){
tMilliseconds = (long long) 0; tMilliseconds = (long long) 0;
#ifdef DEBUG
URGENT_LOG( "EbioMat'!"); URGENT_LOG( "EbioMat'!");
#endif
} else { } else {
tMilliseconds = (long long) tData.tv_sec; tMilliseconds = (long long) tData.tv_sec;
tMilliseconds = ( tMilliseconds * 1000 ); tMilliseconds = ( tMilliseconds * 1000 );

2
lib/components/base/basicFunctionality.h

@ -48,7 +48,7 @@ CSTR strReplace( CSTR orig, CSTR rep, CSTR with );
unsigned __int64 getSHTimeValue( void ); unsigned __int64 getSHTimeValue( void );
#endif #endif
CSTR getSHDTimeStamp(void);
CSTR getSHDTimeStamp(void);
#ifdef __linux__ #ifdef __linux__
inline PF_TIMESTAMP * getPFTS( PF_TIMESTAMP * ptr = NULL ){ inline PF_TIMESTAMP * getPFTS( PF_TIMESTAMP * ptr = NULL ){

19
lib/components/base/basicThread.cpp

@ -6,25 +6,6 @@
#define SLOG( X ) mThis->m_pLog->Log( "BasicThreadS", mThis, X ) #define SLOG( X ) mThis->m_pLog->Log( "BasicThreadS", mThis, X )
#define SLOG_ERROR( X ) mThis->m_pLog->Log( "BasicThreadS", mThis, _LOG_ERROR, 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 ){ bool basicThread::init( void ){
if (m_bThreadStatus == TH_PRE_INIT) { if (m_bThreadStatus == TH_PRE_INIT) {
m_bThreadStatus = TH_ARMED; m_bThreadStatus = TH_ARMED;

25
lib/components/base/basicThread.h

@ -74,22 +74,15 @@ class basicThread {
// TODO: Uncomment the assignment operator when you need it. // TODO: Uncomment the assignment operator when you need it.
//basicThread& operator=(const basicThread& src); //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__ #endif // __BASICTHREAD_H_INCL__

4
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(){ MySQL_Connector::MySQL_Connector( CSTR DBName, CSTR DBHost, CSTR DBUser, CSTR DBPassword, uint16_t Port ):m_mAccessMutex(){
m_pLog = basicLogCollection::getInstance(); m_pLog = basicLogCollection::getInstance();
m_pDBLink = mysql_init(NULL); 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 ); m_pDBHost = (CSTR) malloc( strlen( ( const char * ) DBHost ) + 1 );
strcpy( m_pDBHost, DBHost ); strcpy( m_pDBHost, DBHost );
m_pDBUser = (CSTR) malloc( strlen( ( const char * ) DBUser ) + 1 ); 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 ){ if( mysql_select_db( m_pDBLink, m_pDBName ) == 0 ){
m_bIsConnected = true; m_bIsConnected = true;
#ifdef DEBUG #ifdef DEBUG
char temp[256];
char temp[256];
sprintf( temp, "Connected to %s@%s:%d", m_pDBName, m_pDBHost, m_nPort ); sprintf( temp, "Connected to %s@%s:%d", m_pDBName, m_pDBHost, m_nPort );
LOG( temp ); LOG( temp );
#endif #endif

4
lib/data/net/netClientHandler.cpp

@ -14,7 +14,7 @@
networkClientHandler::networkClientHandler( int SocketFD, basicEngine *ptr ): basicEventHandler(){ networkClientHandler::networkClientHandler( int SocketFD, basicEngine *ptr ): basicEventHandler(){
m_pEngine = ptr; m_pEngine = ptr;
m_pLog = basicLogCollection::getInstance(); m_pLog = basicLogCollection::getInstance();
m_pPort = new serverPort( SocketFD );
m_pPort = NULL;//new serverPort( SocketFD );
#ifdef DEBUG #ifdef DEBUG
if( m_pPort ) { if( m_pPort ) {
LOG("Client Port Created OK!"); LOG("Client Port Created OK!");
@ -27,6 +27,7 @@ networkClientHandler::~networkClientHandler(){
LOG("Destructor Start"); LOG("Destructor Start");
# endif # endif
m_pEngine = NULL; m_pEngine = NULL;
/*
if( m_pPort != NULL ){ if( m_pPort != NULL ){
# ifdef DEBUG # ifdef DEBUG
LOG("Destruct Server Port"); LOG("Destruct Server Port");
@ -36,6 +37,7 @@ networkClientHandler::~networkClientHandler(){
LOG("Destruct Server Port Done"); LOG("Destruct Server Port Done");
# endif # endif
}; };
*/
# ifdef DEBUG # ifdef DEBUG
LOG("Destructor Finished"); LOG("Destructor Finished");
# endif # endif

20
lib/data/net/serverPort.cpp

@ -17,8 +17,6 @@ serverPort::serverPort( SOCKET AcceptedSocket ):transportSocket(){
serverPort::~serverPort(){ serverPort::~serverPort(){
//m_bThreadBStatus = TH_ENDED;
//m_bThreadAStatus = TH_ENDED;
}; };
int serverPort::sendBlock(unsigned char *Data, int DataSize){ int serverPort::sendBlock(unsigned char *Data, int DataSize){
@ -41,7 +39,7 @@ int serverPort::sendBlock(unsigned char *Data, int DataSize){
close( m_nSocketFD ); close( m_nSocketFD );
m_nSocketFD = -1; m_nSocketFD = -1;
m_bConnected = false; m_bConnected = false;
setConnectionStatus( CS_DISCONNECTED );
//setConnectionStatus( CS_DISCONNECTED );
return -1; return -1;
}; };
if( RetVal < 0 ) RetVal = 0; if( RetVal < 0 ) RetVal = 0;
@ -52,7 +50,7 @@ int serverPort::sendBlock(unsigned char *Data, int DataSize){
} else { } else {
LOG_ERROR("Not Connected!"); LOG_ERROR("Not Connected!");
m_bConnected = false; m_bConnected = false;
setConnectionStatus( CS_DISCONNECTED );
//setConnectionStatus( CS_DISCONNECTED );
return -1; return -1;
}; };
#else #else
@ -67,7 +65,7 @@ int serverPort::sendBlock(unsigned char *Data, int DataSize){
closesocket(m_nSocketFD); closesocket(m_nSocketFD);
WSACleanup(); WSACleanup();
m_bConnected = false; m_bConnected = false;
setConnectionStatus( CS_DISCONNECTED );
//setConnectionStatus( CS_DISCONNECTED );
return -1; return -1;
}; };
#ifdef DUBUG_COMMUNICATION #ifdef DUBUG_COMMUNICATION
@ -79,11 +77,11 @@ int serverPort::sendBlock(unsigned char *Data, int DataSize){
WSACleanup(); WSACleanup();
m_bConnected = false; m_bConnected = false;
m_nSocketFD = INVALID_SOCKET; m_nSocketFD = INVALID_SOCKET;
setConnectionStatus( CS_DISCONNECTED );
//setConnectionStatus( CS_DISCONNECTED );
}; };
} else { } else {
m_bConnected = false; m_bConnected = false;
setConnectionStatus( CS_DISCONNECTED );
//setConnectionStatus( CS_DISCONNECTED );
return -1; return -1;
}; };
#endif #endif
@ -96,7 +94,7 @@ int serverPort::recptBlock(unsigned char *Buffer, int *BufferLength){
LOG_ERROR("Not Connected!"); LOG_ERROR("Not Connected!");
m_bInitComplete = false; m_bInitComplete = false;
m_bConnected = false; m_bConnected = false;
setConnectionStatus( CS_DISCONNECTED );
//setConnectionStatus( CS_DISCONNECTED );
return -1; // Exit after unsuccess reconnect return -1; // Exit after unsuccess reconnect
} }
@ -116,7 +114,7 @@ int serverPort::recptBlock(unsigned char *Buffer, int *BufferLength){
*BufferLength = 0; *BufferLength = 0;
m_bConnected = false; m_bConnected = false;
m_nSocketFD = -1; m_nSocketFD = -1;
setConnectionStatus( CS_DISCONNECTED );
//setConnectionStatus( CS_DISCONNECTED );
return -1; return -1;
}; };
}; };
@ -131,7 +129,7 @@ int serverPort::recptBlock(unsigned char *Buffer, int *BufferLength){
LOG_ERROR("Not Connected!"); LOG_ERROR("Not Connected!");
*BufferLength = 0; *BufferLength = 0;
m_bConnected = false; m_bConnected = false;
setConnectionStatus( CS_DISCONNECTED );
//setConnectionStatus( CS_DISCONNECTED );
return -1; return -1;
}; };
#else #else
@ -160,7 +158,7 @@ int serverPort::recptBlock(unsigned char *Buffer, int *BufferLength){
LOG_ERROR("Not Connected!"); LOG_ERROR("Not Connected!");
*BufferLength = 0; *BufferLength = 0;
m_bConnected = false; m_bConnected = false;
setConnectionStatus( CS_DISCONNECTED );
//setConnectionStatus( CS_DISCONNECTED );
return -1; return -1;
}; };
#endif #endif

39
lib/data/protocol/protocol.cpp

@ -9,7 +9,12 @@
protocolParser::protocolParser() : m_mBufferProtectorMutex(){ protocolParser::protocolParser() : m_mBufferProtectorMutex(){
m_pLog = basicLogCollection::getInstance(); m_pLog = basicLogCollection::getInstance();
m_eConnectionStatus = CS_UNKNOWN; m_eConnectionStatus = CS_UNKNOWN;
m_oDataTransport = NULL;
m_pParserBuffer = (U8*) malloc(PROTOCOL_PARSER_BUFFER_SIZE); 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_nParserDataCount = 0;
m_bStatus = 0; m_bStatus = 0;
m_pCustomHandler = NULL; m_pCustomHandler = NULL;
@ -25,6 +30,7 @@ protocolParser::~protocolParser(){
LOG("Destructor Begin"); LOG("Destructor Begin");
# endif # endif
m_mBufferProtectorMutex.unlock(); m_mBufferProtectorMutex.unlock();
/*
#ifdef PROTOCOL_PARSER_IN_THREAD #ifdef PROTOCOL_PARSER_IN_THREAD
if (m_bParserThreadStatus > TH_ARMED ) { if (m_bParserThreadStatus > TH_ARMED ) {
waitParserThreadEnd( true ); waitParserThreadEnd( true );
@ -33,6 +39,7 @@ protocolParser::~protocolParser(){
waitParserThreadEnd(true); waitParserThreadEnd(true);
}; };
#endif #endif
*/
if( m_pParserBuffer != NULL ) { if( m_pParserBuffer != NULL ) {
free( m_pParserBuffer ); free( m_pParserBuffer );
}; };
@ -72,8 +79,10 @@ bool protocolParser::create(void){
}; };
void protocolParser::setConnectionStatus( CONNECTION_STATUS cStatus ){ void protocolParser::setConnectionStatus( CONNECTION_STATUS cStatus ){
#ifdef DEBUG
if (cStatus == CS_CONNECTED)LOG("Connection Status Changed - Connected!"); if (cStatus == CS_CONNECTED)LOG("Connection Status Changed - Connected!");
if (cStatus == CS_DISCONNECTED)LOG("Connection Status Changed - Disconnected!"); if (cStatus == CS_DISCONNECTED)LOG("Connection Status Changed - Disconnected!");
#endif
m_eConnectionStatus = cStatus; 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 protocolParser::parse( U8 *Buffer, size_t BufferSize ){
bool rv = false; bool rv = false;
if( m_pParserBuffer != NULL ) { 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(); m_mBufferProtectorMutex.lock();
if( ( m_nParserDataCount + BufferSize ) < PROTOCOL_PARSER_BUFFER_SIZE ) { if( ( m_nParserDataCount + BufferSize ) < PROTOCOL_PARSER_BUFFER_SIZE ) {
memcpy( m_pParserBuffer+m_nParserDataCount, Buffer, BufferSize ); memcpy( m_pParserBuffer+m_nParserDataCount, Buffer, BufferSize );
m_nParserDataCount+=BufferSize; m_nParserDataCount+=BufferSize;
rv = m_bBufferAltered = true; rv = m_bBufferAltered = true;
#ifndef PROTOCOL_PARSER_IN_THREAD #ifndef PROTOCOL_PARSER_IN_THREAD
m_mBufferProtectorMutex.lock();
while ( m_nParserDataCount > 0 ){ while ( m_nParserDataCount > 0 ){
int RetVal; int RetVal;
#ifdef DUBUG_COMMUNICATION
#ifdef DUBUG_COMMUNICATION
LOG("Check Pack"); LOG("Check Pack");
#endif
#endif
RetVal = packetChecker(m_pParserBuffer, m_nParserDataCount); RetVal = packetChecker(m_pParserBuffer, m_nParserDataCount);
#ifdef DUBUG_COMMUNICATION
#ifdef DUBUG_COMMUNICATION
LOG("Check Pack Done"); LOG("Check Pack Done");
#endif
#endif
if (RetVal < 0) { if (RetVal < 0) {
// Note: RetVal is NEGATIVE!!?? // Note: RetVal is NEGATIVE!!??
m_nParserDataCount += RetVal; m_nParserDataCount += RetVal;
memcpy(m_pParserBuffer, m_pParserBuffer - RetVal, m_nParserDataCount); memcpy(m_pParserBuffer, m_pParserBuffer - RetVal, m_nParserDataCount);
} else if (RetVal == 0) { } else if (RetVal == 0) {
protocolPackage* tVal = NULL; protocolPackage* tVal = NULL;
tVal = packetExtractor(m_pParserBuffer, m_nParserDataCount);
tVal = packetExtractor( m_pParserBuffer, m_nParserDataCount );
if (tVal != NULL) { if (tVal != NULL) {
#ifdef DUBUG_COMMUNICATION
#ifdef DUBUG_COMMUNICATION
LOG("Package Handling"); LOG("Package Handling");
char tBuf[256]; char tBuf[256];
sprintf(tBuf, "Pack Size: %d from %d bytes", tVal->m_nSize, m_nParserDataCount); sprintf(tBuf, "Pack Size: %d from %d bytes", tVal->m_nSize, m_nParserDataCount);
LOG(tBuf); LOG(tBuf);
#endif
#endif
//Move unused data toward buffer's begin to parse at next parse attempt //Move unused data toward buffer's begin to parse at next parse attempt
m_nParserDataCount -= tVal->m_nSize; 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! // In Case implementation of packetHandler - handler must return !true!
if (!packetHandler(tVal)) { if (!packetHandler(tVal)) {
m_vPackagePool.push_back(tVal); m_vPackagePool.push_back(tVal);
@ -150,7 +169,7 @@ bool protocolParser::parse( U8 *Buffer, size_t BufferSize ){
}; };
}; };
m_bBufferAltered = false; m_bBufferAltered = false;
m_mBufferProtectorMutex.unlock();
//m_mBufferProtectorMutex.unlock();
#endif #endif
}; };
m_mBufferProtectorMutex.unlock(); m_mBufferProtectorMutex.unlock();

3
lib/data/protocol/protocolDefender.cpp

@ -625,7 +625,7 @@ bool protocolDefender::packetHandler( protocolPackage *Package ){
Json::Reader reader; Json::Reader reader;
if( !reader.parse( (char *)Package->m_pData, root ) ){ if( !reader.parse( (char *)Package->m_pData, root ) ){
LOG_ERROR( "Error parsing the string" ); LOG_ERROR( "Error parsing the string" );
return false;
return true;
}; };
if (root.size()) { if (root.size()) {
Json::Value tVal; Json::Value tVal;
@ -649,7 +649,6 @@ bool protocolDefender::packetHandler( protocolPackage *Package ){
}; };
}; };
}catch( exception e ){ }catch( exception e ){
return false;
}; };
return true; return true;
}; };

1
lib/data/protocol/protocolSafeShore.cpp

@ -493,7 +493,6 @@ bool protocolSafeShore::packetHandler( protocolPackage *Package ){
}; };
}; };
}catch( exception e ){ }catch( exception e ){
return false;
}; };
return true; return true;
}; };

74
lib/data/transport/transportSocket.cpp

@ -18,6 +18,7 @@ transportSocket::transportSocket() : basicTransport(), basicDualThread(){
#ifdef DEBUG #ifdef DEBUG
LOG("Init IO Threads Done"); LOG("Init IO Threads Done");
#endif #endif
setConnectionStatus( CS_CONNECTED );
} else { } else {
LOG_ERROR("Init IO Threads ERROR!"); LOG_ERROR("Init IO Threads ERROR!");
}; };
@ -29,20 +30,7 @@ transportSocket::~transportSocket(){
LOG("Destruct: START"); LOG("Destruct: START");
# endif # endif
m_mBufferProtectorMutex.unlock(); 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"); LOG("Destruct: DONE");
# endif # endif
}; };
@ -51,7 +39,9 @@ void transportSocket::m_fThreadAProc(void){
int index; int index;
int RetVal; int RetVal;
m_bThreadAStatus = TH_WORKING; m_bThreadAStatus = TH_WORKING;
#ifdef DEBUG
LOG("Sender Thread Started!"); LOG("Sender Thread Started!");
#endif
while (m_bThreadAStatus < TH_ENDED) { while (m_bThreadAStatus < TH_ENDED) {
m_mBufferProtectorMutex.lock(); m_mBufferProtectorMutex.lock();
if( m_nOutputBufferSize > 0 ){ if( m_nOutputBufferSize > 0 ){
@ -60,11 +50,11 @@ void transportSocket::m_fThreadAProc(void){
RetVal = sendBlock(m_pOutputBuffer + index, m_nOutputBufferSize - index); RetVal = sendBlock(m_pOutputBuffer + index, m_nOutputBufferSize - index);
if( RetVal > 0 ) index += RetVal; if( RetVal > 0 ) index += RetVal;
if( RetVal == -1 ){ if( RetVal == -1 ){
setConnectionStatus( CS_DISCONNECTED );
m_nOutputBufferSize = 0;
m_bThreadBStatus = TH_ENDED; m_bThreadBStatus = TH_ENDED;
m_bThreadAStatus = TH_ENDED; m_bThreadAStatus = TH_ENDED;
LOG_ERROR("Connection Error[send]"); LOG_ERROR("Connection Error[send]");
setConnectionStatus( CS_DISCONNECTED );
m_nOutputBufferSize = 0;
}; };
}; };
m_nOutputBufferSize = 0; m_nOutputBufferSize = 0;
@ -79,42 +69,36 @@ void transportSocket::m_fThreadAProc(void){
void transportSocket::m_fThreadBProc(void){ void transportSocket::m_fThreadBProc(void){
m_bThreadBStatus = TH_WORKING; m_bThreadBStatus = TH_WORKING;
int RetVal; int RetVal;
#ifdef DEBUG
LOG("Recipient Thread Started!"); LOG("Recipient Thread Started!");
#endif
while( m_bThreadBStatus < TH_ENDED ){ while( m_bThreadBStatus < TH_ENDED ){
RetVal = recptBlock( m_pInputBuffer, &m_nInputBufferSize); RetVal = recptBlock( m_pInputBuffer, &m_nInputBufferSize);
if( RetVal == -1 ){ if( RetVal == -1 ){
LOG_ERROR("Connection Error[rcpt]");
setConnectionStatus(CS_DISCONNECTED);
m_nInputBufferSize = 0; 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 ){ } 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 { } else {
SLEEP(5);
SLEEP(2);
}; };
}; };
}; };

Loading…
Cancel
Save