diff --git a/Linux_Workspace.vpw b/Linux_Workspace.vpw
index 78842a0d..0f2fa7c0 100644
--- a/Linux_Workspace.vpw
+++ b/Linux_Workspace.vpw
@@ -20,5 +20,6 @@
+
diff --git a/Projects/la_mojo/la_mojo.vpj b/Projects/la_mojo/la_mojo.vpj
index 909d172f..fcfc4e8b 100644
--- a/Projects/la_mojo/la_mojo.vpj
+++ b/Projects/la_mojo/la_mojo.vpj
@@ -526,6 +526,7 @@
+
diff --git a/Projects/la_mojo/makefile b/Projects/la_mojo/makefile
index e0fa8136..ff7e349b 100644
--- a/Projects/la_mojo/makefile
+++ b/Projects/la_mojo/makefile
@@ -38,9 +38,10 @@ COMMON_OBJ=$(OUTDIR)/base64.o $(OUTDIR)/basicCameraInfo.o \
$(OUTDIR)/basicRing.o $(OUTDIR)/basicSettings.o \
$(OUTDIR)/basicSettingsProvider.o $(OUTDIR)/basicThread.o \
$(OUTDIR)/basicTransport.o $(OUTDIR)/clientPort.o \
- $(OUTDIR)/curlRequest.o $(OUTDIR)/curlRequestsManager.o \
- $(OUTDIR)/dataBinder.o $(OUTDIR)/dataBinder_ReportAux.o \
- $(OUTDIR)/detector.o $(OUTDIR)/deviceNode.o $(OUTDIR)/deviceNode2D.o \
+ $(OUTDIR)/cmdNodeConveyor.o $(OUTDIR)/curlRequest.o \
+ $(OUTDIR)/curlRequestsManager.o $(OUTDIR)/dataBinder.o \
+ $(OUTDIR)/dataBinder_ReportAux.o $(OUTDIR)/detector.o \
+ $(OUTDIR)/deviceNode.o $(OUTDIR)/deviceNode2D.o \
$(OUTDIR)/deviceNode3D.o $(OUTDIR)/deviceNodeCamera.o \
$(OUTDIR)/deviceNodeEthernet2Serial.o $(OUTDIR)/deviceNodeFactory.o \
$(OUTDIR)/deviceNodePTZCamControl.o $(OUTDIR)/deviceNodeSensor.o \
@@ -87,9 +88,10 @@ ALL_OBJ=$(OUTDIR)/base64.o $(OUTDIR)/basicCameraInfo.o \
$(OUTDIR)/basicRing.o $(OUTDIR)/basicSettings.o \
$(OUTDIR)/basicSettingsProvider.o $(OUTDIR)/basicThread.o \
$(OUTDIR)/basicTransport.o $(OUTDIR)/clientPort.o \
- $(OUTDIR)/curlRequest.o $(OUTDIR)/curlRequestsManager.o \
- $(OUTDIR)/dataBinder.o $(OUTDIR)/dataBinder_ReportAux.o \
- $(OUTDIR)/detector.o $(OUTDIR)/deviceNode.o $(OUTDIR)/deviceNode2D.o \
+ $(OUTDIR)/cmdNodeConveyor.o $(OUTDIR)/curlRequest.o \
+ $(OUTDIR)/curlRequestsManager.o $(OUTDIR)/dataBinder.o \
+ $(OUTDIR)/dataBinder_ReportAux.o $(OUTDIR)/detector.o \
+ $(OUTDIR)/deviceNode.o $(OUTDIR)/deviceNode2D.o \
$(OUTDIR)/deviceNode3D.o $(OUTDIR)/deviceNodeCamera.o \
$(OUTDIR)/deviceNodeEthernet2Serial.o $(OUTDIR)/deviceNodeFactory.o \
$(OUTDIR)/deviceNodePTZCamControl.o $(OUTDIR)/deviceNodeSensor.o \
@@ -227,9 +229,10 @@ COMMON_OBJ=$(OUTDIR)/base64.o $(OUTDIR)/basicCameraInfo.o \
$(OUTDIR)/basicRing.o $(OUTDIR)/basicSettings.o \
$(OUTDIR)/basicSettingsProvider.o $(OUTDIR)/basicThread.o \
$(OUTDIR)/basicTransport.o $(OUTDIR)/clientPort.o \
- $(OUTDIR)/curlRequest.o $(OUTDIR)/curlRequestsManager.o \
- $(OUTDIR)/dataBinder.o $(OUTDIR)/dataBinder_ReportAux.o \
- $(OUTDIR)/detector.o $(OUTDIR)/deviceNode.o $(OUTDIR)/deviceNode2D.o \
+ $(OUTDIR)/cmdNodeConveyor.o $(OUTDIR)/curlRequest.o \
+ $(OUTDIR)/curlRequestsManager.o $(OUTDIR)/dataBinder.o \
+ $(OUTDIR)/dataBinder_ReportAux.o $(OUTDIR)/detector.o \
+ $(OUTDIR)/deviceNode.o $(OUTDIR)/deviceNode2D.o \
$(OUTDIR)/deviceNode3D.o $(OUTDIR)/deviceNodeCamera.o \
$(OUTDIR)/deviceNodeEthernet2Serial.o $(OUTDIR)/deviceNodeFactory.o \
$(OUTDIR)/deviceNodePTZCamControl.o $(OUTDIR)/deviceNodeSensor.o \
@@ -276,9 +279,10 @@ ALL_OBJ=$(OUTDIR)/base64.o $(OUTDIR)/basicCameraInfo.o \
$(OUTDIR)/basicRing.o $(OUTDIR)/basicSettings.o \
$(OUTDIR)/basicSettingsProvider.o $(OUTDIR)/basicThread.o \
$(OUTDIR)/basicTransport.o $(OUTDIR)/clientPort.o \
- $(OUTDIR)/curlRequest.o $(OUTDIR)/curlRequestsManager.o \
- $(OUTDIR)/dataBinder.o $(OUTDIR)/dataBinder_ReportAux.o \
- $(OUTDIR)/detector.o $(OUTDIR)/deviceNode.o $(OUTDIR)/deviceNode2D.o \
+ $(OUTDIR)/cmdNodeConveyor.o $(OUTDIR)/curlRequest.o \
+ $(OUTDIR)/curlRequestsManager.o $(OUTDIR)/dataBinder.o \
+ $(OUTDIR)/dataBinder_ReportAux.o $(OUTDIR)/detector.o \
+ $(OUTDIR)/deviceNode.o $(OUTDIR)/deviceNode2D.o \
$(OUTDIR)/deviceNode3D.o $(OUTDIR)/deviceNodeCamera.o \
$(OUTDIR)/deviceNodeEthernet2Serial.o $(OUTDIR)/deviceNodeFactory.o \
$(OUTDIR)/deviceNodePTZCamControl.o $(OUTDIR)/deviceNodeSensor.o \
@@ -416,9 +420,10 @@ COMMON_OBJ=$(OUTDIR)/base64.o $(OUTDIR)/basicCameraInfo.o \
$(OUTDIR)/basicRing.o $(OUTDIR)/basicSettings.o \
$(OUTDIR)/basicSettingsProvider.o $(OUTDIR)/basicThread.o \
$(OUTDIR)/basicTransport.o $(OUTDIR)/clientPort.o \
- $(OUTDIR)/curlRequest.o $(OUTDIR)/curlRequestsManager.o \
- $(OUTDIR)/dataBinder.o $(OUTDIR)/dataBinder_ReportAux.o \
- $(OUTDIR)/detector.o $(OUTDIR)/deviceNode.o $(OUTDIR)/deviceNode2D.o \
+ $(OUTDIR)/cmdNodeConveyor.o $(OUTDIR)/curlRequest.o \
+ $(OUTDIR)/curlRequestsManager.o $(OUTDIR)/dataBinder.o \
+ $(OUTDIR)/dataBinder_ReportAux.o $(OUTDIR)/detector.o \
+ $(OUTDIR)/deviceNode.o $(OUTDIR)/deviceNode2D.o \
$(OUTDIR)/deviceNode3D.o $(OUTDIR)/deviceNodeCamera.o \
$(OUTDIR)/deviceNodeEthernet2Serial.o $(OUTDIR)/deviceNodeFactory.o \
$(OUTDIR)/deviceNodePTZCamControl.o $(OUTDIR)/deviceNodeSensor.o \
@@ -465,9 +470,10 @@ ALL_OBJ=$(OUTDIR)/base64.o $(OUTDIR)/basicCameraInfo.o \
$(OUTDIR)/basicRing.o $(OUTDIR)/basicSettings.o \
$(OUTDIR)/basicSettingsProvider.o $(OUTDIR)/basicThread.o \
$(OUTDIR)/basicTransport.o $(OUTDIR)/clientPort.o \
- $(OUTDIR)/curlRequest.o $(OUTDIR)/curlRequestsManager.o \
- $(OUTDIR)/dataBinder.o $(OUTDIR)/dataBinder_ReportAux.o \
- $(OUTDIR)/detector.o $(OUTDIR)/deviceNode.o $(OUTDIR)/deviceNode2D.o \
+ $(OUTDIR)/cmdNodeConveyor.o $(OUTDIR)/curlRequest.o \
+ $(OUTDIR)/curlRequestsManager.o $(OUTDIR)/dataBinder.o \
+ $(OUTDIR)/dataBinder_ReportAux.o $(OUTDIR)/detector.o \
+ $(OUTDIR)/deviceNode.o $(OUTDIR)/deviceNode2D.o \
$(OUTDIR)/deviceNode3D.o $(OUTDIR)/deviceNodeCamera.o \
$(OUTDIR)/deviceNodeEthernet2Serial.o $(OUTDIR)/deviceNodeFactory.o \
$(OUTDIR)/deviceNodePTZCamControl.o $(OUTDIR)/deviceNodeSensor.o \
@@ -610,9 +616,10 @@ COMMON_OBJ=$(OUTDIR)/base64.o $(OUTDIR)/basicCameraInfo.o \
$(OUTDIR)/basicRing.o $(OUTDIR)/basicSettings.o \
$(OUTDIR)/basicSettingsProvider.o $(OUTDIR)/basicThread.o \
$(OUTDIR)/basicTransport.o $(OUTDIR)/clientPort.o \
- $(OUTDIR)/curlRequest.o $(OUTDIR)/curlRequestsManager.o \
- $(OUTDIR)/dataBinder.o $(OUTDIR)/dataBinder_ReportAux.o \
- $(OUTDIR)/detector.o $(OUTDIR)/deviceNode.o $(OUTDIR)/deviceNode2D.o \
+ $(OUTDIR)/cmdNodeConveyor.o $(OUTDIR)/curlRequest.o \
+ $(OUTDIR)/curlRequestsManager.o $(OUTDIR)/dataBinder.o \
+ $(OUTDIR)/dataBinder_ReportAux.o $(OUTDIR)/detector.o \
+ $(OUTDIR)/deviceNode.o $(OUTDIR)/deviceNode2D.o \
$(OUTDIR)/deviceNode3D.o $(OUTDIR)/deviceNodeCamera.o \
$(OUTDIR)/deviceNodeEthernet2Serial.o $(OUTDIR)/deviceNodeFactory.o \
$(OUTDIR)/deviceNodePTZCamControl.o $(OUTDIR)/deviceNodeSensor.o \
@@ -659,9 +666,10 @@ ALL_OBJ=$(OUTDIR)/base64.o $(OUTDIR)/basicCameraInfo.o \
$(OUTDIR)/basicRing.o $(OUTDIR)/basicSettings.o \
$(OUTDIR)/basicSettingsProvider.o $(OUTDIR)/basicThread.o \
$(OUTDIR)/basicTransport.o $(OUTDIR)/clientPort.o \
- $(OUTDIR)/curlRequest.o $(OUTDIR)/curlRequestsManager.o \
- $(OUTDIR)/dataBinder.o $(OUTDIR)/dataBinder_ReportAux.o \
- $(OUTDIR)/detector.o $(OUTDIR)/deviceNode.o $(OUTDIR)/deviceNode2D.o \
+ $(OUTDIR)/cmdNodeConveyor.o $(OUTDIR)/curlRequest.o \
+ $(OUTDIR)/curlRequestsManager.o $(OUTDIR)/dataBinder.o \
+ $(OUTDIR)/dataBinder_ReportAux.o $(OUTDIR)/detector.o \
+ $(OUTDIR)/deviceNode.o $(OUTDIR)/deviceNode2D.o \
$(OUTDIR)/deviceNode3D.o $(OUTDIR)/deviceNodeCamera.o \
$(OUTDIR)/deviceNodeEthernet2Serial.o $(OUTDIR)/deviceNodeFactory.o \
$(OUTDIR)/deviceNodePTZCamControl.o $(OUTDIR)/deviceNodeSensor.o \
@@ -803,6 +811,7 @@ $(OUTDIR)/basicSettingsProvider.o: ../../lib/components/base/basicSettingsProvid
$(OUTDIR)/basicThread.o: ../../lib/components/base/basicThread.cpp ../../lib/components/base/basicThread.h ../../lib/components/base/basicLogCollection.h ../../lib/components/base/basicLoggingService.h ../../lib/components/base/basicRing.h ../../lib/components/base/basicMutex.h
$(OUTDIR)/basicTransport.o: ../../lib/components/base/basicTransport.cpp ../../lib/components/base/basicTransport.h ../../lib/data/protocol/protocol.h
$(OUTDIR)/clientPort.o: ../../lib/data/net/clientPort.cpp ../../lib/data/net/clientPort.h ../../lib/data/transport/transportSocket.h ../../lib/components/base/basicDualThread.h ../../lib/components/base/basicThread.h ../../lib/components/base/basicLogCollection.h ../../lib/components/base/basicLoggingService.h ../../lib/components/base/basicRing.h ../../lib/components/base/basicMutex.h ../../lib/components/base/basicTransport.h
+$(OUTDIR)/cmdNodeConveyor.o: ../../lib/App/common/cmdNodeConveyor.cpp ../../lib/App/common/cmdNodeConveyor.h
$(OUTDIR)/curlRequest.o: ../../lib/data/curl/curlRequest.cpp ../../lib/data/curl/curlRequest.h
$(OUTDIR)/curlRequestsManager.o: ../../lib/data/curl/curlRequestsManager.cpp ../../lib/data/curl/curlRequestsManager.h
$(OUTDIR)/dataBinder.o: ../../lib/App/common/dataBinder.cpp ../../lib/App/common/dataBinder.h ../../lib/App/common/dataBinder_structures.h ../../lib/App/common/dataBinder_ReportAux.h
diff --git a/Projects/watchDogDaemon/Debug/default.conf b/Projects/watchDogDaemon/Debug/default.conf
new file mode 100644
index 00000000..32e1d724
--- /dev/null
+++ b/Projects/watchDogDaemon/Debug/default.conf
@@ -0,0 +1,4 @@
+KERNEL :
+{
+ SOCKET_PATH = "/srv/etc/watchdog";
+};
diff --git a/Projects/watchDogDaemon/Debug/watchdogDaemon b/Projects/watchDogDaemon/Debug/watchdogDaemon
new file mode 100755
index 00000000..be65e933
Binary files /dev/null and b/Projects/watchDogDaemon/Debug/watchdogDaemon differ
diff --git a/Projects/watchDogDaemon/Release/watchdogDaemon b/Projects/watchDogDaemon/Release/watchdogDaemon
new file mode 100755
index 00000000..61cd95df
Binary files /dev/null and b/Projects/watchDogDaemon/Release/watchdogDaemon differ
diff --git a/Projects/watchDogDaemon/build b/Projects/watchDogDaemon/build
new file mode 100755
index 00000000..a01bb9e3
--- /dev/null
+++ b/Projects/watchDogDaemon/build
@@ -0,0 +1,9 @@
+#! /bin/sh
+
+
+make clean -e "CFG=Debug"
+make -j4 -e "CFG=Debug"
+
+
+make clean -e "CFG=Release"
+make -j4 -e "CFG=Release"
diff --git a/Projects/watchDogDaemon/kernel.cpp b/Projects/watchDogDaemon/kernel.cpp
new file mode 100644
index 00000000..51b584de
--- /dev/null
+++ b/Projects/watchDogDaemon/kernel.cpp
@@ -0,0 +1,359 @@
+#include "kernel.h"
+
+#define LOG( X ) m_pLog->Log( "KERNEL", this, X )
+#define LOG_ERROR( X ) m_pLog->Log( "KERNEL", this, _LOG_ERROR, X )
+
+SP_KERNEL *SP_KERNEL::_instance = NULL;
+
+SP_KERNEL *SP_KERNEL::getInstance( bool ColdStart ){
+ if( _instance == NULL ) {
+ _instance = new SP_KERNEL();
+ };
+ return _instance;
+};
+
+SP_KERNEL::SP_KERNEL(): basicThread(){
+ m_pLog = basicLogCollection::getInstance();
+ m_pSettings = basicSettingsProvider::getInstance()->getSubNode( NULL, (CSTR)"KERNEL" );
+ m_iServerSocket = INVALID_SOCKET;
+ m_iExitCause = 0;
+};
+
+SP_KERNEL::~SP_KERNEL(){
+ if( m_iServerSocket != INVALID_SOCKET ) {
+ shutdown( m_iServerSocket, 2 );
+ close( m_iServerSocket );
+ if( fileExist ( m_pUnixSocketName ) ) unlink( m_pUnixSocketName );
+ };
+};
+
+void SP_KERNEL::wd_shutdown( void ){
+ m_bThreadStatus = TH_ENDED;
+ m_iExitCause = 33;
+};
+//Use Killall prior to kill all instances of mojo
+
+// https://stackoverflow.com/questions/8166415/how-to-get-the-pid-of-a-process-in-linux-in-c
+
+#include
+#include
+//#include
+#include
+#include
+#include
+#include
+
+
+
+//https://www.educative.io/answers/unix-socket-programming-in-c
+
+
+/************************************************************************
+ *
+ * Returns the pid of the process name which is given as the function
+ * argument.
+ * In case no process found with the given name -1 will be returned.
+ *
+ ************************************************************************* /
+pid_t getProcessId(const char * csProcessName){
+ struct kinfo_proc * sProcesses = NULL;
+ struct kinfo_proc * sNewProcesses = NULL;
+ pid_t iCurrentPid;
+ int aiNames[4];
+ size_t iNamesLength;
+ int i, iRetCode, iNumProcs;
+ size_t iSize = 0;
+
+ aiNames[0] = CTL_KERN;
+ aiNames[1] = KERN_PROC;
+ aiNames[2] = KERN_PROC_ALL;
+ aiNames[3] = 0;
+
+ iNamesLength = 3;
+ iRetCode = sysctl( aiNames, iNamesLength, NULL, &iSize, NULL, 0 );
+
+ /*
+ * Allocate memory and populate info in the processes structure
+ * /
+
+ do {
+ iSize += iSize / 10;
+ sNewProcesses = (struct kinfo_proc *) realloc( sProcesses, iSize );
+ if( sNewProcesses == 0 ){
+ if( sProcesses ) free(sProcesses);
+ errx(1, "could not reallocate memory");
+ };
+ sProcesses = sNewProcesses;
+ iRetCode = sysctl(aiNames, iNamesLength, sProcesses, &iSize, NULL, 0);
+ } while ( iRetCode == -1 && errno == ENOMEM );
+
+ iNumProcs = iSize / sizeof(struct kinfo_proc);
+ /*
+ * Search for the given process name and return its pid.
+ * /
+
+ for (i = 0; i < iNumProcs; i++) {
+ iCurrentPid = sProcesses[i].kp_proc.p_pid;
+ if( strncmp(csProcessName, sProcesses[i].kp_proc.p_comm, MAXCOMLEN) == 0 ) {
+ free(sProcesses);
+ return iCurrentPid;
+ }
+ }
+
+ /*
+ * Clean up and return -1 because the given proc name was not found
+ * /
+
+ free(sProcesses);
+ return (-1);
+} /* end of getProcessId() * /
+
+
+int main(int argc, char **argv)
+
+{
+ int pid = 0;
+ pid = getProcessId( argv[1] );
+ if( pid < 0 ){
+ printf("process [%s] not found in the system\n", argv[1]);
+ } else {
+ printf("pid of [%s] is %d\n", argv[1], pid);
+ }
+}
+*/
+
+
+bool SP_KERNEL::create(void){
+ char tBuffer[PATH_MAX];
+ if( m_pSettings != NULL ) {
+ config_setting_t * pSetting;
+ int tVal;
+ const char * tBuf;
+ LOG("Getting Settings ...");
+ if( !config_setting_lookup_string( m_pSettings, "SOCKET_PATH", &tBuf ) ){
+ LOG("Socket Path not defined - generating dummy!");
+ sprintf( m_pUnixSocketName, "/srv/etc/watchdog" );
+ pSetting = config_setting_add( m_pSettings, "SOCKET_PATH", CONFIG_TYPE_STRING );
+ config_setting_set_string( pSetting, m_pUnixSocketName );
+ basicSettingsProvider::getInstance()->compromise();
+ } else {
+ sprintf( m_pUnixSocketName, tBuf );
+ sprintf( tBuffer, "Socket Path From Settings: %s", tBuf );
+ LOG( tBuffer );
+ };
+ /*
+ if( !config_setting_lookup_string( m_pSettings, "TARGET_APP_FILE", &tBuf ) ){
+ LOG("Target Application not defined - generating dummy!");
+ sprintf( m_pTargetAppFile, "TARGET_APP_NAME" );
+ pSetting = config_setting_add( m_pSettings, "TARGET_APP_FILE", CONFIG_TYPE_STRING );
+ config_setting_set_string( pSetting, m_pTargetAppFile );
+ basicSettingsProvider::getInstance()->compromise();
+ basicSettingsProvider::getInstance()->validate();
+ LOG_ERROR("Exiting!");
+ return false;
+ } else {
+ sprintf( m_pTargetAppFile, "%s/%s", m_pTargetEnvPath, tBuf );
+ sprintf( tBuffer, "Target Application Read From Settings: %s", tBuf );
+ LOG( tBuffer );
+ if( !fileExist ( m_pTargetAppFile ) ) {
+ LOG_ERROR("Target Application File Not Exists!");
+ LOG_ERROR("Exiting!");
+ return false;
+ };
+ };
+ if( !config_setting_lookup_string( m_pSettings, "TARGET_PID_FILE", &tBuf ) ){
+ LOG("Target PID File not defined - generating dummy!");
+ sprintf( m_pTargetPIDFile, "TARGET_FILE_PATH" );
+ pSetting = config_setting_add( m_pSettings, "TARGET_PID_FILE", CONFIG_TYPE_STRING );
+ config_setting_set_string( pSetting, m_pTargetPIDFile );
+ basicSettingsProvider::getInstance()->compromise();
+ basicSettingsProvider::getInstance()->validate();
+ LOG_ERROR("Exiting!");
+ return false;
+ } else {
+ sprintf( m_pTargetPIDFile, tBuf );
+ sprintf( tBuffer, "Target PID File Read From Settings: %s", tBuf );
+ LOG( tBuffer );
+ if( !fileExist ( m_pTargetPIDFile ) ) {
+ LOG_ERROR("Target PID File Not Exists!");
+ LOG_ERROR("Starting Target Application!");
+ if( !startTargetApplication() ){
+ LOG_ERROR("Can not start application!");
+ return false;
+ };
+ };
+ };
+ */
+ basicSettingsProvider::getInstance()->validate();
+ } else {
+ LOG_ERROR("Failed Read Config Settings!");
+ return false;
+ };
+
+ m_iServerSocket = socket( AF_UNIX, SOCK_STREAM, 0 );
+ struct sockaddr_un server_addr;
+
+ server_addr.sun_family = AF_UNIX;
+ strcpy( server_addr.sun_path, m_pUnixSocketName );
+ int slen = sizeof( server_addr );
+
+ int x = fcntl( m_iServerSocket ,F_GETFL, 0);
+ fcntl( m_iServerSocket, F_SETFL, x | O_NONBLOCK);
+
+ bind( m_iServerSocket, (struct sockaddr *) &server_addr, slen );
+ if ( m_iServerSocket == INVALID_SOCKET ){
+ LOG_ERROR("Could not bind to the UX socket!");
+ return false;
+ };
+ listen( m_iServerSocket, 5 );
+ return init();
+ };
+
+void SP_KERNEL::WaitFinish( bool force ){
+ waitThreadEnd( force );
+};
+
+void *SP_KERNEL::sw_proc( void *ptr ){
+ char tB[64];
+ uint64_t cMS;
+ uint64_t tMS;
+ WATCHDOG_PROC_REC * mR = (WATCHDOG_PROC_REC *) ptr;
+ pid_t CPID = 0;
+ if ( mR ) {
+ cMS = getMilliseconds();
+ tMS = cMS + SW_DEFAULT_TIMEOUT;
+ while( 1 ){
+ cMS = getMilliseconds();
+ int retVal = readLine( mR->client_socket, tB, 64 );
+ if ( retVal < 0 ) {
+ if( errno!=EAGAIN && errno!=EINTR ) {
+ mR->master->m_pLog->Log( "K_T", mR->master, "Peer Closes Connection!");
+ shutdown( mR->client_socket, 2 );
+ close( mR->client_socket );
+ mR->client_socket = -1;
+ break; //-----> exit thread
+ };
+ } else {
+ if ( retVal ) {
+ //char jB[128];
+ //sprintf( jB, "Server: I recieved [%d] %s from client!", retVal, tB );
+ //mR->master->m_pLog->Log( "K_T", mR->master, jB );
+ if( CPID ){
+ uint64_t nMS = atoll(tB);
+ //sprintf( jB, "Will Wait next [%d] milliseconds", nMS );
+ //mR->master->m_pLog->Log( "K_T", mR->master, jB );
+ tMS = cMS + nMS;
+ } else {
+ CPID = ( pid_t ) atoll(tB);
+ };
+ };
+ };
+ if ( cMS > tMS ) {
+ // WD TO EXIT!
+ mR->master->m_pLog->Log( "K_T", mR->master, "WD update STALLED!" );
+ if ( CPID ) {
+ // Try Kill Client Process;
+ char jB[128];
+ sprintf( jB, "Try Killing Process[%lld] By Signal 9!", CPID );
+ mR->master->m_pLog->Log( "K_T", mR->master, jB );
+ kill( CPID, 9 );
+ } else {
+ mR->master->wd_shutdown();
+ };
+ break; //-----> exit thread
+ };
+ SLEEP( SW_TIMEOUT_PERCISION );
+ };
+ };
+ mR->finished = true;
+ pthread_exit( NULL );
+ return NULL;
+ /*
+ read(client_socket, &ch, 1);
+ printf("\nServer: I recieved %c from client!\n", ch);
+ ch++;
+ write(client_socket, &ch, 1);
+ close(client_socket);
+ */
+};
+
+void SP_KERNEL::m_fThreadProc( void ){
+ struct sockaddr_un client_addr;
+ unsigned int clen = sizeof( client_addr );
+ int ClientSocket;
+ m_bThreadStatus = TH_WORKING;
+ while( m_bThreadStatus < TH_ENDED ) {
+
+ ClientSocket = accept( m_iServerSocket, (struct sockaddr *) &client_addr, &clen );
+
+ if ( ClientSocket < 0 ) {
+ switch( errno ){
+ case EAGAIN:{
+ // Checkup client disconnection
+ if( m_vWPV.size()) {
+ for( WATCHDOG_PROCS_VECTOR::iterator index = m_vWPV.begin(); index < m_vWPV.end(); index++ ) {
+ if( (*index)->finished ){
+ LOG("Detach WD Procedure");
+ pthread_join((*index)->handler, NULL);
+ LOG("WD Procedure Detached");
+ // Remove Client Handler
+ LOG("Remove WD Procedure");
+ m_vWPV.erase( index );
+ };
+ };
+ };
+ SLEEP(10);
+ continue;
+ };
+ //case EWOULDBLOCK: me->Log(" The socket is marked non-blocking and no connections are present to be accepted."); break;
+ case EBADF: LOG_ERROR( "The descriptor is invalid." ); break;
+ case ECONNABORTED: LOG_ERROR( "A connection has been aborted."); break;
+ case EINTR: LOG_ERROR( "The system call was interrupted by a signal that was caught before a valid connection arrived."); break;
+ case EINVAL: LOG_ERROR( "Socket is not listening for connections, or addrlen is invalid (e.g., is negative)."); break;
+ case EMFILE: LOG_ERROR( "The per-process limit of open file descriptors has been reached."); break;
+ case ENFILE: LOG_ERROR( "The system limit on the total number of open files has been reached."); break;
+ case ENOTSOCK: LOG_ERROR( "The descriptor references a file, not a socket."); break;
+ case EOPNOTSUPP: LOG_ERROR( "The referenced socket is not of type SOCK_STREAM."); break;
+ case EFAULT: LOG_ERROR( "The addr argument is not in a writable part of the user address space."); break;
+ case ENOBUFS:
+ case ENOMEM: LOG_ERROR( "Not enough free memory. This often means that the memory allocation is limited by the socket buffer limits, not by the system memory."); break;
+ case EPROTO: LOG_ERROR( "Protocol error."); break;
+ case EPERM: LOG_ERROR( "Firewall rules forbid connection."); break;
+ case ENOSR:
+#ifdef __linux__
+ case ESOCKTNOSUPPORT:
+#endif
+ case EPROTONOSUPPORT:
+ case ETIMEDOUT: LOG_ERROR( " Unusual error in Kernel (Timeout, No Socket Support in Kernel, Unsupported Protocol)"); break;
+ //case ERESTARTSYS: me->Log(" Unusual error by Kernel"); break;
+ default: LOG_ERROR( " Unhandled error in Kernel"); break;
+ };
+ m_bThreadStatus = TH_ENDED;
+ } else {
+ WATCHDOG_PROC_REC *tPRC = (WATCHDOG_PROC_REC *) malloc(sizeof(WATCHDOG_PROC_REC));
+ if ( tPRC ) {
+
+ int x = fcntl( ClientSocket, F_GETFL, 0 );
+ fcntl( ClientSocket, F_SETFL, x | O_NONBLOCK );
+
+ tPRC->client_socket = ClientSocket;
+ tPRC->master = this;
+ int RetVal = pthread_create( &tPRC->handler, NULL, sw_proc, ( void * ) tPRC );
+ if( RetVal == -1 ) {
+ LOG_ERROR("No Client Thread Created!");
+ shutdown( ClientSocket, 2 );
+ close( ClientSocket );
+ } else {
+ m_vWPV.push_back( tPRC );
+ };
+ } else {
+ LOG_ERROR("No Client Handler Created!");
+ shutdown( ClientSocket, 2 );
+ close( ClientSocket );
+ };
+ };
+ };
+};
+
+#undef LOG_ERROR
+#undef LOG
diff --git a/Projects/watchDogDaemon/kernel.h b/Projects/watchDogDaemon/kernel.h
new file mode 100644
index 00000000..0f22a4d3
--- /dev/null
+++ b/Projects/watchDogDaemon/kernel.h
@@ -0,0 +1,49 @@
+#ifndef __START_PROC_KERNEL_HEADER__
+#define __START_PROC_KERNEL_HEADER__
+
+#include "../../lib/components/base/basicThread.h"
+#include "../../lib/components/base/basicSettingsProvider.h"
+
+
+class SP_KERNEL;
+
+#define SW_DEFAULT_TIMEOUT 60000 // 60 seconds
+
+#define SW_TIMEOUT_PERCISION 100 // 0.1 second
+#define INVALID_SOCKET -1
+
+typedef struct S_WATCHDOG_PROC_REC{
+ SP_KERNEL * master;
+ int client_socket;
+ uint64_t timeout;
+ bool finished;
+ pthread_t handler;
+}WATCHDOG_PROC_REC;
+
+
+typedef std::vector WATCHDOG_PROCS_VECTOR;
+
+class SP_KERNEL: public basicThread {
+ protected:
+ virtual void m_fThreadProc( void );
+ public:
+ static SP_KERNEL * getInstance( bool ColdStart = true );
+ bool create(void);
+ int getExitCause(){ return m_iExitCause; };
+ void WaitFinish( bool force );
+ ~SP_KERNEL();
+ private:
+ int m_iServerSocket;
+ int m_iExitCause;
+ WATCHDOG_PROCS_VECTOR m_vWPV;
+
+ static SP_KERNEL * _instance;
+ static void * sw_proc( void * );
+ void wd_shutdown( void );
+ SP_KERNEL();
+ basicLogCollection * m_pLog;
+ config_setting_t * m_pSettings;
+ char m_pUnixSocketName[PATH_MAX];
+};
+
+#endif
diff --git a/Projects/watchDogDaemon/makefile b/Projects/watchDogDaemon/makefile
new file mode 100644
index 00000000..4fc61d36
--- /dev/null
+++ b/Projects/watchDogDaemon/makefile
@@ -0,0 +1,160 @@
+# SlickEdit generated file. Do not edit this file except in designated areas.
+
+# Make command to use for dependencies
+MAKE=make
+RM=rm
+MKDIR=mkdir
+
+# -----Begin user-editable area-----
+
+# -----End user-editable area-----
+
+# If no configuration is specified, "Debug" will be used
+ifndef CFG
+CFG=Debug
+endif
+
+#
+# Configuration: Debug
+#
+ifeq "$(CFG)" "Debug"
+OUTDIR=Debug
+OUTFILE=$(OUTDIR)/watchdogDaemon
+CFG_INC=
+CFG_LIB=-lpthread -lm -lconfig
+CFG_OBJ=
+COMMON_OBJ=$(OUTDIR)/basicFunctionality.o \
+ $(OUTDIR)/basicLogCollection.o $(OUTDIR)/basicLoggingService.o \
+ $(OUTDIR)/basicMemoryOperation.o $(OUTDIR)/basicRing.o \
+ $(OUTDIR)/basicSettings.o $(OUTDIR)/basicSettingsProvider.o \
+ $(OUTDIR)/basicThread.o $(OUTDIR)/kernel.o $(OUTDIR)/md5.o \
+ $(OUTDIR)/objectConsoleLoggingService.o \
+ $(OUTDIR)/objectFileLoggingService.o $(OUTDIR)/watchDogDaemon.o
+OBJ=$(COMMON_OBJ) $(CFG_OBJ)
+ALL_OBJ=$(OUTDIR)/basicFunctionality.o $(OUTDIR)/basicLogCollection.o \
+ $(OUTDIR)/basicLoggingService.o $(OUTDIR)/basicMemoryOperation.o \
+ $(OUTDIR)/basicRing.o $(OUTDIR)/basicSettings.o \
+ $(OUTDIR)/basicSettingsProvider.o $(OUTDIR)/basicThread.o \
+ $(OUTDIR)/kernel.o $(OUTDIR)/md5.o \
+ $(OUTDIR)/objectConsoleLoggingService.o \
+ $(OUTDIR)/objectFileLoggingService.o $(OUTDIR)/watchDogDaemon.o \
+ -lpthread -lm -lconfig
+
+COMPILE=g++ -c -O0 -g3 -ggdb -o "$(OUTDIR)/$(*F).o" $(CFG_INC) $<
+LINK=g++ -O0 -g3 -ggdb -o "$(OUTFILE)" $(ALL_OBJ)
+
+# Pattern rules
+$(OUTDIR)/%.o : ../../lib/components/object/%.cpp
+ $(COMPILE)
+
+$(OUTDIR)/%.o : ../../lib/components/base/%.cpp
+ $(COMPILE)
+
+$(OUTDIR)/%.o : ../../lib/alg/generic/%.cpp
+ $(COMPILE)
+
+$(OUTDIR)/%.o : %.cpp
+ $(COMPILE)
+
+# Build rules
+all: $(OUTFILE)
+
+$(OUTFILE): $(OUTDIR) $(OBJ)
+ $(LINK)
+
+$(OUTDIR):
+ $(MKDIR) -p "$(OUTDIR)"
+
+# Rebuild this project
+rebuild: cleanall
+ @$(MAKE) -f "$(strip $(MAKEFILE_LIST))" $(MAKEFLAGS) all
+
+# Clean this project
+clean:
+ $(RM) -f $(OUTFILE)
+ $(RM) -f $(OBJ)
+
+# Clean this project and all dependencies
+cleanall: clean
+endif
+
+#
+# Configuration: Release
+#
+ifeq "$(CFG)" "Release"
+OUTDIR=Release
+OUTFILE=$(OUTDIR)/watchdogDaemon
+CFG_INC=
+CFG_LIB=-lpthread -lm -lconfig
+CFG_OBJ=
+COMMON_OBJ=$(OUTDIR)/basicFunctionality.o \
+ $(OUTDIR)/basicLogCollection.o $(OUTDIR)/basicLoggingService.o \
+ $(OUTDIR)/basicMemoryOperation.o $(OUTDIR)/basicRing.o \
+ $(OUTDIR)/basicSettings.o $(OUTDIR)/basicSettingsProvider.o \
+ $(OUTDIR)/basicThread.o $(OUTDIR)/kernel.o $(OUTDIR)/md5.o \
+ $(OUTDIR)/objectConsoleLoggingService.o \
+ $(OUTDIR)/objectFileLoggingService.o $(OUTDIR)/watchDogDaemon.o
+OBJ=$(COMMON_OBJ) $(CFG_OBJ)
+ALL_OBJ=$(OUTDIR)/basicFunctionality.o $(OUTDIR)/basicLogCollection.o \
+ $(OUTDIR)/basicLoggingService.o $(OUTDIR)/basicMemoryOperation.o \
+ $(OUTDIR)/basicRing.o $(OUTDIR)/basicSettings.o \
+ $(OUTDIR)/basicSettingsProvider.o $(OUTDIR)/basicThread.o \
+ $(OUTDIR)/kernel.o $(OUTDIR)/md5.o \
+ $(OUTDIR)/objectConsoleLoggingService.o \
+ $(OUTDIR)/objectFileLoggingService.o $(OUTDIR)/watchDogDaemon.o \
+ -lpthread -lm -lconfig
+
+COMPILE=g++ -c -O3 -o "$(OUTDIR)/$(*F).o" $(CFG_INC) $<
+LINK=g++ -O3 -o "$(OUTFILE)" $(ALL_OBJ)
+
+# Pattern rules
+$(OUTDIR)/%.o : ../../lib/components/object/%.cpp
+ $(COMPILE)
+
+$(OUTDIR)/%.o : ../../lib/components/base/%.cpp
+ $(COMPILE)
+
+$(OUTDIR)/%.o : ../../lib/alg/generic/%.cpp
+ $(COMPILE)
+
+$(OUTDIR)/%.o : %.cpp
+ $(COMPILE)
+
+# Build rules
+all: $(OUTFILE)
+
+$(OUTFILE): $(OUTDIR) $(OBJ)
+ $(LINK)
+
+$(OUTDIR):
+ $(MKDIR) -p "$(OUTDIR)"
+
+# Rebuild this project
+rebuild: cleanall
+ @$(MAKE) -f "$(strip $(MAKEFILE_LIST))" $(MAKEFLAGS) all
+
+# Clean this project
+clean:
+ $(RM) -f $(OUTFILE)
+ $(RM) -f $(OBJ)
+
+# Clean this project and all dependencies
+cleanall: clean
+endif
+
+#
+# include dependencies:
+#
+$(OUTDIR)/basicFunctionality.o: ../../lib/components/base/basicFunctionality.cpp ../../lib/components/base/basicFunctionality.h ../../lib/alg/generic/md5.h ../../lib/components/base/basicLogCollection.h
+$(OUTDIR)/basicLogCollection.o: ../../lib/components/base/basicLogCollection.cpp ../../lib/components/base/basicLogCollection.h ../../lib/alg/generic/heapDebug.h
+$(OUTDIR)/basicLoggingService.o: ../../lib/components/base/basicLoggingService.cpp ../../lib/components/base/basicLoggingService.h
+$(OUTDIR)/basicMemoryOperation.o: ../../lib/components/base/basicMemoryOperation.cpp ../../lib/components/base/basicMemoryOperation.h
+$(OUTDIR)/basicRing.o: ../../lib/components/base/basicRing.cpp ../../lib/components/base/basicRing.h
+$(OUTDIR)/basicSettings.o: ../../lib/components/base/basicSettings.cpp ../../lib/components/base/basicSettings.h
+$(OUTDIR)/basicSettingsProvider.o: ../../lib/components/base/basicSettingsProvider.cpp ../../lib/components/base/basicSettingsProvider.h
+$(OUTDIR)/basicThread.o: ../../lib/components/base/basicThread.cpp ../../lib/components/base/basicThread.h
+$(OUTDIR)/kernel.o: kernel.cpp kernel.h ../../lib/components/base/basicThread.h ../../lib/components/base/basicSettingsProvider.h
+$(OUTDIR)/md5.o: ../../lib/alg/generic/md5.cpp ../../lib/alg/generic/md5.h
+$(OUTDIR)/objectConsoleLoggingService.o: ../../lib/components/object/objectConsoleLoggingService.cpp ../../lib/components/object/objectConsoleLoggingService.h
+$(OUTDIR)/objectFileLoggingService.o: ../../lib/components/object/objectFileLoggingService.cpp ../../lib/components/object/objectFileLoggingService.h
+$(OUTDIR)/watchDogDaemon.o: watchDogDaemon.cpp watchDogDaemon.h ../../lib/components/base/basicSettings.h ../../lib/components/base/basicLogCollection.h ../../lib/components/base/basicSettingsProvider.h ../../lib/components/base/basicMemoryOperation.h ../../lib/components/object/objectFileLoggingService.h ../../lib/components/object/objectConsoleLoggingService.h kernel.h ../../lib/components/base/basicThread.h ../../lib/components/base/basicSettingsProvider.h
diff --git a/Projects/watchDogDaemon/watchDogDaemon.cpp b/Projects/watchDogDaemon/watchDogDaemon.cpp
new file mode 100644
index 00000000..e2cd9bb0
--- /dev/null
+++ b/Projects/watchDogDaemon/watchDogDaemon.cpp
@@ -0,0 +1,327 @@
+#include "watchDogDaemon.h"
+
+// Global Variables
+
+CSTR gsCFG_ADDRESS;
+uint16_t guCFG_PORT = DEFAULT_SERVER_PORT;
+CSTR gsCFG_LICENSE;
+CSTR gsCFG_DB_SERVER;
+CSTR gsCFG_DB_NAME;
+CSTR gsCFG_DB_USER;
+CSTR gsCFG_DB_PASSWORD;
+char gsCFG_PID_FILE[PATH_MAX]; //= (CSTR) DEFAULT_SERVER_PID_FILE;
+SOFTWARE_INFO gsSOFT_INFO;
+bool gbCFG_MASTER_ROLE = true;
+
+bool gModule_GeoFence_Enabled = true;
+bool gModule_SMS_Enabled = false;
+bool gModule_Email_Enabled = false;
+bool gSignal_Handler_Enabled = true;
+
+#define LOG( X ) m_pLog->Log( "main", 0, X )
+#define LOG_ERROR( X ) m_pLog->Log( "main", 0, _LOG_ERROR, X )
+
+SP_KERNEL * Kernel = NULL;
+basicLogCollection * m_pLog = NULL;
+
+void (*old_update_handler_2)(int); //SIGINT
+void (*old_kill_handler_3)(int); //SIGQUIT
+void (*old_kill_handler_9)(int); //SIGKILL
+void (*old_alarm_handler_14)(int); //SIGALRM
+void (*old_kill_handler_15)(int); //SIGTERM
+
+
+/*
+
+FILE *f;
+pid_t pid_child;
+char proc_path[256];
+
+f = fopen("/tmp/mydaemon.pid", "r");
+fscanf(f, "%d", &pid_child);
+fclose(f);
+sprintf(proc_path, "/proc/%d/exe", pid_child);
+
+while(1) {
+ if (access(proc_path, F_OK) == 0) {
+ printf("Program alive !\n");
+ sleep(1);
+ } else {
+ printf("Program dead!\n");
+ break;
+ }
+}
+
+
+*/
+
+void signal_SIGKILL_handler( int SIG ){
+ if( Kernel!= NULL ){
+ if( gSignal_Handler_Enabled ){
+ m_pLog->Log("SIG", 0, _LOG_DEBUG, "Shutdown Service by Signal" );
+ Kernel->setStatus( TH_ENDED ); // Closing all Connections;
+ } else {
+ m_pLog->Log("SIG", 0, _LOG_DEBUG, "Shutdown Signal Handler Disabled" );
+ };
+ };
+};
+
+//#include
+
+int main (int argc, char *argv[]){
+ /*
+ const rlim_t kStackSize = 16 * 1024 * 1024; // min stack size = 16 MB
+ struct rlimit rl;
+ int result;
+
+ result = getrlimit(RLIMIT_STACK, &rl);
+ if (result == 0){
+ printf( "Stack Size: %d\n", rl.rlim_cur );
+ if ( rl.rlim_cur < kStackSize ){
+ printf( "Resize Stack to: %d\n", kStackSize );
+ rl.rlim_cur = kStackSize;
+ result = setrlimit(RLIMIT_STACK, &rl);
+ if (result != 0){
+ fprintf(stderr, "setrlimit returned result = %d\n", result);
+ return -1;
+ };
+ };
+ };
+ */
+
+ //MySQL_Connector * DBC = NULL;
+ basicSettingsProvider * SETTINGS = NULL;
+ bool WBG = true; // Working Background
+ bool SSE = true; // Server Statistics Engine
+ bool NDC = true; // No Default Configuration
+ bool COLD_START = true;
+ char FLE_NAME[PATH_MAX] = {0};
+ char DVD_NAME[PATH_MAX] = {0};
+ CSTR DCF_NAME;
+ CSTR SSP_NAME;
+ objectFileLoggingService * FLE = NULL;
+ objectConsoleLoggingService * CLE = NULL;
+ // default init
+ DCF_NAME = (CSTR) DEFAULT_SERVER_CONFIG_PATH;
+ SSP_NAME = (CSTR) DEFAULT_SERVER_SOCKET_PATH;
+
+ CSTR tB = get_current_dir_name();
+ if( tB ) {
+ sprintf( DVD_NAME , "%s", tB );
+ free( tB );
+ } else {
+ printf( "Can Not Get CWD!\n");
+ };
+ sprintf( gsCFG_PID_FILE, "%s/%s", DVD_NAME, DEFAULT_SERVER_PID_FILE );
+ sprintf( FLE_NAME , "%s/%s", DVD_NAME, DEFAULT_SERVER_LOG_FILE );
+ gsSOFT_INFO.SW_BUILD_DATE = UNIX_TIMESTAMP;
+ gsSOFT_INFO.DATA_VALID = false;
+ m_pLog = basicLogCollection::getInstance( _LOG_LVL_TIME_PTR );
+ gsSOFT_INFO.SW_MODE_FLAGS = 0
+#ifdef SKIP_TARGET_LOG
+ | SW_INFO_NO_TARGET_LOG
+#endif
+#ifdef HIBERNATE_ENABLE
+ | SW_INFO_HIBERNATE_ENA
+#endif
+#ifdef TGD
+ | SW_INFO_TGD_MOTORS
+ #ifdef TGD_VERSION_2
+ | SW_INFO_TGD_VER_2
+ #endif
+#endif
+#ifdef ENCODER_8192
+ | SW_INFO_EU_PROJECT
+#endif
+#ifdef NO_BLACK_TARGETS
+ | SW_INFO_NO_BLACK_TARGETS
+#endif
+#ifndef NO_MOTORS
+ | SW_INFO_MOTOR_CTRL_ENA
+#endif
+#ifdef THREADED_FLIP
+ | SW_INFO_THREAD_FLIP
+#endif
+#ifndef PRU_SLAVE
+ | SW_INFO_FLAG_MASTER
+#endif
+#ifdef DEBUG
+ | SW_INFO_DEBUG_MODE
+#endif
+ ;
+ if( !isProcessUniq( argv[0] ) ){
+ printf( "The Process [%s] Already is Runing\n", argv[0] );
+ return 33;
+ };
+ // Reading Config
+ if( argc > 1 ){
+ for( int i = 1; i < argc; i++ ){
+ switch( argv[i][0] ){
+ case '-':
+ case '\\':
+ case '/':{
+ switch( argv[i][1] ){
+ case 'h': case 'H': case 'v': case 'V': case '?':{
+ printf( "Dr Frucht Systems R-Goose Server\n");
+ printf( "Software version <%s>\n", VERSION_NUMBER );
+ printf( " -h -H This Message\n" );
+ printf( " -i -I Interactive Mode\n" );
+ return 0;
+ break;
+ };
+ case 'i': case 'I':{
+ WBG = false;
+ CLE = new objectConsoleLoggingService();
+ if( CLE != NULL ) {
+ m_pLog->addHandler( CLE );
+ };
+ break;
+ };
+ case 'c': case 'C':{
+ DCF_NAME = (CSTR) malloc( MAX_PATH_LEN );
+ if( DCF_NAME != NULL ) {
+ sprintf( DCF_NAME, "%s", argv[i+1] );
+ } else {
+ printf("ERROR!\n\n");
+ return -1;
+ };
+ break;
+ };
+ };
+ break;
+ };
+ };
+ };
+ };
+ FLE = new objectFileLoggingService( FLE_NAME );
+ if( FLE != NULL ) {
+ m_pLog->addHandler( FLE );
+ };
+ LOG("Starting Log Engne!");
+ if ( fileExist( DCF_NAME ) ){
+ SETTINGS = basicSettingsProvider::getInstance(DCF_NAME);
+ } else {
+ SETTINGS = basicSettingsProvider::getInstance();
+ };
+ if ( fileExist( gsCFG_PID_FILE ) ){
+ COLD_START = false;
+ //check if process already running
+ FILE *tFD = fopen( gsCFG_PID_FILE, "r" );
+ if( tFD ) {
+ pid_t pid;
+ char tBuff[256];
+ //fscanf( tFD, "%d\n", pid );
+ fread( tBuff, 1, 255, tFD );
+ pid = atoi( tBuff );
+ printf("Old Process PID: %d\n", pid );
+ if( kill( pid, 0 )==0 ){
+ printf("Process Already Running --> exiting!\n");
+ delete( FLE );
+ fclose( tFD );
+ exit(12);
+ } else {
+ printf("No Running Process --> Hot Restart Detected!\n");
+ };
+ fclose( tFD );
+ };
+ };
+ // Demonizing or not
+ if( WBG ){
+ printf( "Dr Frucht Systems Software Watchdog Daemon ver. %s\n", VERSION_NUMBER );
+ printf( "Configuration Applied:\n");
+ printf( " Service Established %s at %d\n", gsCFG_ADDRESS, guCFG_PORT );
+ printf( " PID File: %s\n", gsCFG_PID_FILE );
+ printf( " Log File: %s\n", FLE_NAME );
+ printf( " License: %s\n", gsCFG_LICENSE );
+ printf( " Database Server: %s Database: %s\n", gsCFG_DB_SERVER, gsCFG_DB_NAME );
+ if( NDC ){
+ printf( " No configuration file (%s) supplied.\n", DCF_NAME);
+ } else {
+ printf( " Configuration read from: %s\n", DCF_NAME );
+ };
+
+ //Demonizing
+ pid_t pid, sid;
+ sync();
+ close( STDIN_FILENO );
+ close( STDOUT_FILENO );
+ close( STDERR_FILENO );
+
+ pid = fork();
+ if( pid < 0 ){
+ return pid;
+ };
+ if( pid > 0 ){
+ return 0;
+ };
+ //umask(0);
+ sid = setsid();
+ if (sid < 0) {
+ return sid;
+ };
+
+ pid = fork();
+ if( pid < 0 ){
+ return pid;
+ };
+ if( pid > 0 ){
+ FILE *pPIDF = fopen( gsCFG_PID_FILE, "w+" );
+ if( pPIDF ){
+ fprintf( pPIDF, "%d\n", pid );
+ fclose( pPIDF );
+ }
+ return 0;
+ };
+ };
+
+ uint8_t m_bKernelExitCode = 0;
+
+ do{
+ Kernel = SP_KERNEL::getInstance( COLD_START );
+ if( Kernel == NULL ) {
+ // Aborting Work
+ LOG_ERROR( "++++ Kernel failed to born ++++" );
+ unlink( gsCFG_PID_FILE );
+ LOG( "PID File Deleted" );
+ delete( m_pLog );
+ return -1;
+ };
+ //Loop till some Restart action
+ if( Kernel != NULL ){
+ LOG( "++++ Server Started ++++" );
+ if ( Kernel->create() == false ){
+ LOG_ERROR("Kernel create failure!");
+ } else {
+ //Install Signal Listeners
+ old_kill_handler_15 = signal( 15, signal_SIGKILL_handler );
+ old_kill_handler_9 = signal( 9, signal_SIGKILL_handler );
+ // Waiting for Worker to Shut Down
+ Kernel->WaitFinish( false );
+ m_bKernelExitCode = Kernel->getExitCause();
+ signal( 9, old_kill_handler_9 );
+ signal( 15, old_kill_handler_15 );
+ };
+ delete( Kernel );
+ LOG( "++++ Server Ended ++++" );
+ if ( m_bKernelExitCode == 33 ) {
+ m_bKernelExitCode = 0;
+ LOG( "Reboot The System by WD!" );
+ if( FLE!= NULL ) delete( FLE );
+ FLE = NULL;
+ if( CLE!= NULL ) delete( CLE );
+ CLE = NULL;
+ if( m_pLog ) delete( m_pLog );
+ m_pLog = NULL;
+ system("/sbin/reboot");
+ };
+ };
+ } while( m_bKernelExitCode > 0 );
+ unlink( gsCFG_PID_FILE );
+ if( m_pLog ) LOG( "PID File Deleted" );
+ if( FLE!= NULL ) delete( FLE );
+ if( CLE!= NULL ) delete( CLE );
+ if( m_pLog ) delete( m_pLog );
+ return(0);
+}
+
+
diff --git a/Projects/watchDogDaemon/watchDogDaemon.h b/Projects/watchDogDaemon/watchDogDaemon.h
new file mode 100644
index 00000000..7f5c85d1
--- /dev/null
+++ b/Projects/watchDogDaemon/watchDogDaemon.h
@@ -0,0 +1,31 @@
+
+/*******************************************************************
+*
+* DESCRIPTION: starProcDaemon project main header file
+*
+* AUTHOR: Gagua
+*
+* HISTORY:
+*
+* DATE:2/13/2022
+*
+*******************************************************************/
+#ifndef __START_PROC_MAIN_HEADER__
+#define __START_PROC_MAIN_HEADER__
+
+/** include files **/
+
+#include
+#include
+#include
+
+#include "../../lib/components/base/basicSettings.h"
+#include "../../lib/components/base/basicLogCollection.h"
+#include "../../lib/components/base/basicSettingsProvider.h"
+#include "../../lib/components/base/basicMemoryOperation.h"
+#include "../../lib/components/object/objectFileLoggingService.h"
+#include "../../lib/components/object/objectConsoleLoggingService.h"
+#include "kernel.h"
+
+
+#endif
diff --git a/Projects/watchDogDaemon/watchDogDaemon.vpj b/Projects/watchDogDaemon/watchDogDaemon.vpj
new file mode 100644
index 00000000..3edae74d
--- /dev/null
+++ b/Projects/watchDogDaemon/watchDogDaemon.vpj
@@ -0,0 +1,254 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/lib/App/common/cmdNodeConveyor.cpp b/lib/App/common/cmdNodeConveyor.cpp
new file mode 100644
index 00000000..20ff64bb
--- /dev/null
+++ b/lib/App/common/cmdNodeConveyor.cpp
@@ -0,0 +1,41 @@
+#include "cmdNodeConveyor.h"
+
+cmdNodeConveyor::cmdNodeConveyor(){
+ m_pCurrentCMD = NULL;
+ m_mCommandProtector.unlock();
+};
+
+cmdNodeConveyor::~cmdNodeConveyor(){
+ m_mCommandProtector.lock();
+ if( m_qCommands.size() ) {
+ NI_COMMAND *tVal = NULL;
+ while( tVal = m_qCommands.front() ){
+ m_qCommands.pop();
+ if( tVal->parameter ) {
+ free( tVal->parameter );
+ };
+ free( tVal );
+ };
+ };
+ m_mCommandProtector.unlock();
+};
+
+
+NI_COMMAND *cmdNodeConveyor::fetchCommand(){
+ NI_COMMAND *RetVal = NULL;
+ m_mCommandProtector.lock();
+ if( m_qCommands.size() ) {
+ RetVal = m_qCommands.front();
+ m_qCommands.pop();
+ };
+ m_mCommandProtector.unlock();
+ return RetVal;
+};
+
+void cmdNodeConveyor::enqueueCommand( NI_COMMAND *ptr ){
+ if( ptr ) {
+ m_mCommandProtector.lock();
+ m_qCommands.push( ptr );
+ m_mCommandProtector.unlock();
+ };
+};
diff --git a/lib/App/common/cmdNodeConveyor.h b/lib/App/common/cmdNodeConveyor.h
new file mode 100644
index 00000000..d6a0ffe5
--- /dev/null
+++ b/lib/App/common/cmdNodeConveyor.h
@@ -0,0 +1,42 @@
+#ifndef __CMD_NODE_CONVEYOUR_HEADER__
+#define __CMD_NODE_CONVEYOUR_HEADER__
+
+#include "dataBinder.h"
+#include
+#include
+#include