35 changed files with 1781 additions and 432 deletions
-
1Linux_Workspace.vpw
-
1Projects/la_mojo/la_mojo.vpj
-
57Projects/la_mojo/makefile
-
4Projects/watchDogDaemon/Debug/default.conf
-
BINProjects/watchDogDaemon/Debug/watchdogDaemon
-
BINProjects/watchDogDaemon/Release/watchdogDaemon
-
9Projects/watchDogDaemon/build
-
359Projects/watchDogDaemon/kernel.cpp
-
49Projects/watchDogDaemon/kernel.h
-
160Projects/watchDogDaemon/makefile
-
327Projects/watchDogDaemon/watchDogDaemon.cpp
-
31Projects/watchDogDaemon/watchDogDaemon.h
-
254Projects/watchDogDaemon/watchDogDaemon.vpj
-
41lib/App/common/cmdNodeConveyor.cpp
-
42lib/App/common/cmdNodeConveyor.h
-
15lib/App/common/dataBinder_structures.h
-
38lib/App/common/deviceNode.cpp
-
23lib/App/common/deviceNode.h
-
2lib/App/common/deviceNodeFactory.cpp
-
26lib/App/common/hardwareManager.cpp
-
3lib/App/common/hardwareManager.h
-
2lib/App/common/hardwareResourceNetworkProvider.h
-
8lib/App/common/kernelEventFilterTrain.cpp
-
2lib/App/common/kernelModule.cpp
-
2lib/App/common/kernelModule.h
-
502lib/App/common/kernelModuleModemManager.cpp
-
51lib/App/common/kernelModuleModemManager.h
-
46lib/App/common/kernelPrototype.cpp
-
10lib/App/common/kernelPrototype.h
-
8lib/App/mojo/mojoBackend.cpp
-
36lib/App/mojo/mojoKernel.cpp
-
61lib/components/base/basicFunctionality.cpp
-
3lib/components/base/basicFunctionality.h
-
33lib/components/base/basicThread.cpp
-
7lib/components/base/basicThread.h
@ -0,0 +1,4 @@ |
|||
KERNEL : |
|||
{ |
|||
SOCKET_PATH = "/srv/etc/watchdog"; |
|||
}; |
|||
Binary file not shown.
Binary file not shown.
@ -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" |
|||
@ -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 <sys/param.h>
|
|||
#include <sys/user.h>
|
|||
//#include <sys/sysctl.h>
|
|||
#include <sys/socket.h>
|
|||
#include <sys/un.h>
|
|||
#include <stdio.h>
|
|||
#include <stdlib.h>
|
|||
|
|||
|
|||
|
|||
//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
|
|||
@ -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_PROC_REC *> 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 |
|||
@ -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 |
|||
@ -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 <sys/resource.h>
|
|||
|
|||
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); |
|||
} |
|||
|
|||
|
|||
@ -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 <stdlib.h> |
|||
#include <stdio.h> |
|||
#include <signal.h> |
|||
|
|||
#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 |
|||
@ -0,0 +1,254 @@ |
|||
<!DOCTYPE Project SYSTEM "http://www.slickedit.com/dtd/vse/10.0/vpj.dtd"> |
|||
<Project |
|||
Version="10.0" |
|||
VendorName="SlickEdit" |
|||
TemplateName="GNU C/C++" |
|||
WorkingDir="." |
|||
BuildSystem="automakefile" |
|||
BuildMakeFile="makefile"> |
|||
<Config |
|||
Name="Debug" |
|||
Type="gnuc" |
|||
DebugCallbackName="gdb" |
|||
Version="1" |
|||
OutputFile="%bdwatchdogDaemon" |
|||
CompilerConfigName="Latest Version" |
|||
Defines=""> |
|||
<Menu> |
|||
<Target |
|||
Name="Compile" |
|||
MenuCaption="&Compile" |
|||
Dialog="_gnuc_options_form Compile" |
|||
CaptureOutputWith="ProcessBuffer" |
|||
Deletable="0" |
|||
OutputExts="*.o" |
|||
SaveOption="SaveCurrent" |
|||
RunFromDir="%rw"> |
|||
<Exec CmdLine='g++ -c %xup %defd -O0 -g3 -ggdb -o "%bd%n%oe" %i %f'/> |
|||
</Target> |
|||
<Target |
|||
Name="Link" |
|||
MenuCaption="&Link" |
|||
ShowOnMenu="Never" |
|||
Dialog="_gnuc_options_form Link" |
|||
CaptureOutputWith="ProcessBuffer" |
|||
Deletable="0" |
|||
SaveOption="SaveCurrent" |
|||
RunFromDir="%rw"> |
|||
<Exec CmdLine='g++ %xup -O0 -g3 -ggdb -o "%o" %objs'/> |
|||
</Target> |
|||
<Target |
|||
Name="Build" |
|||
MenuCaption="&Build" |
|||
CaptureOutputWith="ProcessBuffer" |
|||
Deletable="0" |
|||
SaveOption="SaveWorkspaceFiles" |
|||
RunFromDir="%rw"> |
|||
<Exec CmdLine='make -f "makefile" CFG=%b'/> |
|||
</Target> |
|||
<Target |
|||
Name="Rebuild" |
|||
MenuCaption="&Rebuild" |
|||
CaptureOutputWith="ProcessBuffer" |
|||
Deletable="0" |
|||
SaveOption="SaveWorkspaceFiles" |
|||
RunFromDir="%rw"> |
|||
<Exec CmdLine='make -f "makefile" rebuild CFG=%b'/> |
|||
</Target> |
|||
<Target |
|||
Name="Debug" |
|||
MenuCaption="&Debug" |
|||
Dialog="_gnuc_options_form Run/Debug" |
|||
BuildFirst="1" |
|||
CaptureOutputWith="ProcessBuffer" |
|||
Deletable="0" |
|||
SaveOption="SaveNone" |
|||
RunFromDir="%rw"> |
|||
<Exec CmdLine='vsdebugio -prog "%o"'/> |
|||
</Target> |
|||
<Target |
|||
Name="Execute" |
|||
MenuCaption="E&xecute" |
|||
Dialog="_gnuc_options_form Run/Debug" |
|||
BuildFirst="1" |
|||
CaptureOutputWith="ProcessBuffer" |
|||
Deletable="0" |
|||
SaveOption="SaveWorkspaceFiles" |
|||
RunFromDir="%rw"> |
|||
<Exec CmdLine='"%o"'/> |
|||
</Target> |
|||
<Target |
|||
Name="dash" |
|||
MenuCaption="-" |
|||
Deletable="0"> |
|||
<Exec/> |
|||
</Target> |
|||
<Target |
|||
Name="GNU C Options" |
|||
MenuCaption="GNU C &Options..." |
|||
ShowOnMenu="HideIfNoCmdLine" |
|||
Deletable="0" |
|||
SaveOption="SaveNone"> |
|||
<Exec |
|||
CmdLine="gnucoptions" |
|||
Type="Slick-C"/> |
|||
</Target> |
|||
</Menu> |
|||
<List Name="GNUC Options"> |
|||
<Item |
|||
Name="LinkerOutputType" |
|||
Value="Executable"/> |
|||
</List> |
|||
<Includes/> |
|||
<Libs PreObjects="0"> |
|||
<Lib File="-lpthread"/> |
|||
<Lib File="-lm"/> |
|||
<Lib File="-lconfig"/> |
|||
</Libs> |
|||
</Config> |
|||
<Config |
|||
Name="Release" |
|||
Type="gnuc" |
|||
DebugCallbackName="gdb" |
|||
Version="1" |
|||
OutputFile="%bdwatchdogDaemon" |
|||
CompilerConfigName="Latest Version" |
|||
Defines=""> |
|||
<Menu> |
|||
<Target |
|||
Name="Compile" |
|||
MenuCaption="&Compile" |
|||
Dialog="_gnuc_options_form Compile" |
|||
CaptureOutputWith="ProcessBuffer" |
|||
Deletable="0" |
|||
OutputExts="*.o" |
|||
SaveOption="SaveCurrent" |
|||
RunFromDir="%rw"> |
|||
<Exec CmdLine='g++ -c %xup %defd -O3 -o "%bd%n%oe" %i %f'/> |
|||
</Target> |
|||
<Target |
|||
Name="Link" |
|||
MenuCaption="&Link" |
|||
ShowOnMenu="Never" |
|||
Dialog="_gnuc_options_form Link" |
|||
CaptureOutputWith="ProcessBuffer" |
|||
Deletable="0" |
|||
SaveOption="SaveCurrent" |
|||
RunFromDir="%rw"> |
|||
<Exec CmdLine='g++ %xup -O3 -o "%o" %objs'/> |
|||
</Target> |
|||
<Target |
|||
Name="Build" |
|||
MenuCaption="&Build" |
|||
CaptureOutputWith="ProcessBuffer" |
|||
Deletable="0" |
|||
SaveOption="SaveWorkspaceFiles" |
|||
RunFromDir="%rw"> |
|||
<Exec CmdLine='make -f "makefile" CFG=%b'/> |
|||
</Target> |
|||
<Target |
|||
Name="Rebuild" |
|||
MenuCaption="&Rebuild" |
|||
CaptureOutputWith="ProcessBuffer" |
|||
Deletable="0" |
|||
SaveOption="SaveWorkspaceFiles" |
|||
RunFromDir="%rw"> |
|||
<Exec CmdLine='make -f "makefile" rebuild CFG=%b'/> |
|||
</Target> |
|||
<Target |
|||
Name="Debug" |
|||
MenuCaption="&Debug" |
|||
Dialog="_gnuc_options_form Run/Debug" |
|||
BuildFirst="1" |
|||
CaptureOutputWith="ProcessBuffer" |
|||
Deletable="0" |
|||
SaveOption="SaveNone" |
|||
RunFromDir="%rw"> |
|||
<Exec CmdLine='vsdebugio -prog "%o"'/> |
|||
</Target> |
|||
<Target |
|||
Name="Execute" |
|||
MenuCaption="E&xecute" |
|||
Dialog="_gnuc_options_form Run/Debug" |
|||
BuildFirst="1" |
|||
CaptureOutputWith="ProcessBuffer" |
|||
Deletable="0" |
|||
SaveOption="SaveWorkspaceFiles" |
|||
RunFromDir="%rw"> |
|||
<Exec CmdLine='"%o"'/> |
|||
</Target> |
|||
<Target |
|||
Name="dash" |
|||
MenuCaption="-" |
|||
Deletable="0"> |
|||
<Exec/> |
|||
</Target> |
|||
<Target |
|||
Name="GNU C Options" |
|||
MenuCaption="GNU C &Options..." |
|||
ShowOnMenu="HideIfNoCmdLine" |
|||
Deletable="0" |
|||
SaveOption="SaveNone"> |
|||
<Exec |
|||
CmdLine="gnucoptions" |
|||
Type="Slick-C"/> |
|||
</Target> |
|||
</Menu> |
|||
<List Name="GNUC Options"> |
|||
<Item |
|||
Name="LinkerOutputType" |
|||
Value="Executable"/> |
|||
</List> |
|||
<Includes/> |
|||
<Libs PreObjects="0"> |
|||
<Lib File="-lpthread"/> |
|||
<Lib File="-lm"/> |
|||
<Lib File="-lconfig"/> |
|||
</Libs> |
|||
</Config> |
|||
<Files> |
|||
<Folder |
|||
Name="Source Files" |
|||
Filters="*.c;*.C;*.cc;*.cpp;*.cp;*.cxx;*.c++;*.prg;*.pas;*.dpr;*.asm;*.s;*.bas;*.java;*.cs;*.sc;*.e;*.cob;*.html;*.rc;*.tcl;*.py;*.pl;*.d" |
|||
GUID="{AB1D1AAF-5346-4C5D-A822-A09005FF1FDB}"> |
|||
<F N="../../lib/components/base/basicFunctionality.cpp"/> |
|||
<F N="../../lib/components/base/basicLogCollection.cpp"/> |
|||
<F N="../../lib/components/base/basicLoggingService.cpp"/> |
|||
<F N="../../lib/components/base/basicMemoryOperation.cpp"/> |
|||
<F N="../../lib/components/base/basicRing.cpp"/> |
|||
<F N="../../lib/components/base/basicSettings.cpp"/> |
|||
<F N="../../lib/components/base/basicSettingsProvider.cpp"/> |
|||
<F N="../../lib/components/base/basicThread.cpp"/> |
|||
<F N="kernel.cpp"/> |
|||
<F N="../../lib/alg/generic/md5.cpp"/> |
|||
<F N="../../lib/components/object/objectConsoleLoggingService.cpp"/> |
|||
<F N="../../lib/components/object/objectFileLoggingService.cpp"/> |
|||
<F N="watchDogDaemon.cpp"/> |
|||
</Folder> |
|||
<Folder |
|||
Name="Header Files" |
|||
Filters="*.h;*.H;*.hh;*.hpp;*.hxx;*.inc;*.sh;*.cpy;*.if" |
|||
GUID="{5B58AB4B-6CE2-4BED-9064-3BE3352BE41B}"> |
|||
<F N="kernel.h"/> |
|||
<F N="watchDogDaemon.h"/> |
|||
</Folder> |
|||
<Folder |
|||
Name="Resource Files" |
|||
Filters="*.ico;*.cur;*.dlg" |
|||
GUID="{4F2C4DE1-AF37-4CD8-9D86-7ED5339BB24A}"/> |
|||
<Folder |
|||
Name="Bitmaps" |
|||
Filters="*.bmp" |
|||
GUID="{BA95632D-28AC-4E2F-85BA-9525941729BB}"/> |
|||
<Folder |
|||
Name="Other Files" |
|||
Filters="" |
|||
GUID="{18FB0B77-BFBE-49D7-83ED-CA528836B30D}"> |
|||
<F |
|||
N="makefile" |
|||
Type="Makefile"/> |
|||
</Folder> |
|||
</Files> |
|||
<List Name="RTE"> |
|||
</List> |
|||
</Project> |
|||
@ -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(); |
|||
}; |
|||
}; |
|||
@ -0,0 +1,42 @@ |
|||
#ifndef __CMD_NODE_CONVEYOUR_HEADER__ |
|||
#define __CMD_NODE_CONVEYOUR_HEADER__ |
|||
|
|||
#include "dataBinder.h" |
|||
#include <queue> |
|||
#include <vector> |
|||
#include <map> |
|||
|
|||
typedef struct S_NI_COMMAND{ |
|||
uint8_t cmd; |
|||
uint32_t db_cmd; |
|||
void * parameter; |
|||
}NI_COMMAND; |
|||
|
|||
typedef std::queue<NI_COMMAND *> queueNI_COMMANDS; |
|||
|
|||
typedef enum E_NI_COMMAND_STATUSES{ |
|||
NI_CMD_NEW = 0, |
|||
NI_CMD_STARTED = 1, |
|||
NI_CMD_FINISHED = 100, |
|||
NI_CMD_FAILED = 128 |
|||
}NI_COMMAND_STATUSES; |
|||
|
|||
class cmdNodeConveyor{ |
|||
private: |
|||
queueNI_COMMANDS m_qCommands; |
|||
basicMutex m_mCommandProtector; |
|||
NI_COMMAND * m_pCurrentCMD; |
|||
basicMutex m_mCurrentCMDProtector; |
|||
protected: |
|||
NI_COMMAND * fetchCommand(); |
|||
public: |
|||
cmdNodeConveyor(); |
|||
~cmdNodeConveyor(); |
|||
void enqueueCommand( NI_COMMAND *ptr ); |
|||
virtual bool updateCommandStatus( NI_COMMAND_STATUSES stt ){ return true; }; |
|||
virtual bool updateCommandAccomplishment( uint8_t perc ){ return true; }; |
|||
}; |
|||
|
|||
|
|||
|
|||
#endif |
|||
Write
Preview
Loading…
Cancel
Save
Reference in new issue