push all
This commit is contained in:
parent
6eca831c80
commit
c2c4296a20
|
@ -0,0 +1,107 @@
|
||||||
|
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
|
||||||
|
<?fileVersion 4.0.0?>
|
||||||
|
|
||||||
|
<cproject storage_type_id="org.eclipse.cdt.core.XmlProjectDescriptionStorage">
|
||||||
|
<storageModule moduleId="org.eclipse.cdt.core.settings">
|
||||||
|
<cconfiguration id="cdt.managedbuild.toolchain.gnu.base.1489137557">
|
||||||
|
<storageModule buildSystemId="org.eclipse.cdt.managedbuilder.core.configurationDataProvider" id="cdt.managedbuild.toolchain.gnu.base.1489137557" moduleId="org.eclipse.cdt.core.settings" name="Default">
|
||||||
|
<externalSettings/>
|
||||||
|
<extensions>
|
||||||
|
<extension id="org.eclipse.cdt.core.ELF" point="org.eclipse.cdt.core.BinaryParser"/>
|
||||||
|
<extension id="org.eclipse.cdt.core.GmakeErrorParser" point="org.eclipse.cdt.core.ErrorParser"/>
|
||||||
|
<extension id="org.eclipse.cdt.core.CWDLocator" point="org.eclipse.cdt.core.ErrorParser"/>
|
||||||
|
<extension id="org.eclipse.cdt.core.GCCErrorParser" point="org.eclipse.cdt.core.ErrorParser"/>
|
||||||
|
<extension id="org.eclipse.cdt.core.GASErrorParser" point="org.eclipse.cdt.core.ErrorParser"/>
|
||||||
|
<extension id="org.eclipse.cdt.core.GLDErrorParser" point="org.eclipse.cdt.core.ErrorParser"/>
|
||||||
|
</extensions>
|
||||||
|
</storageModule>
|
||||||
|
<storageModule moduleId="cdtBuildSystem" version="4.0.0">
|
||||||
|
<configuration artifactName="git" buildProperties="" description="" id="cdt.managedbuild.toolchain.gnu.base.1489137557" name="Default" parent="org.eclipse.cdt.build.core.emptycfg">
|
||||||
|
<folderInfo id="cdt.managedbuild.toolchain.gnu.base.1489137557.45876174" name="/" resourcePath="">
|
||||||
|
<toolChain id="cdt.managedbuild.toolchain.gnu.base.1604623789" name="cdt.managedbuild.toolchain.gnu.base" superClass="cdt.managedbuild.toolchain.gnu.base">
|
||||||
|
<targetPlatform archList="all" binaryParser="org.eclipse.cdt.core.ELF" id="cdt.managedbuild.target.gnu.platform.base.1489688336" name="Debug Platform" osList="linux,hpux,aix,qnx" superClass="cdt.managedbuild.target.gnu.platform.base"/>
|
||||||
|
<builder id="cdt.managedbuild.target.gnu.builder.base.1594561920" keepEnvironmentInBuildfile="false" managedBuildOn="false" name="Gnu Make Builder" superClass="cdt.managedbuild.target.gnu.builder.base"/>
|
||||||
|
<tool id="cdt.managedbuild.tool.gnu.archiver.base.1326612781" name="GCC Archiver" superClass="cdt.managedbuild.tool.gnu.archiver.base"/>
|
||||||
|
<tool id="cdt.managedbuild.tool.gnu.cpp.compiler.base.637187500" name="GCC C++ Compiler" superClass="cdt.managedbuild.tool.gnu.cpp.compiler.base">
|
||||||
|
<inputType id="cdt.managedbuild.tool.gnu.cpp.compiler.input.1015923900" superClass="cdt.managedbuild.tool.gnu.cpp.compiler.input"/>
|
||||||
|
</tool>
|
||||||
|
<tool id="cdt.managedbuild.tool.gnu.c.compiler.base.1814883119" name="GCC C Compiler" superClass="cdt.managedbuild.tool.gnu.c.compiler.base">
|
||||||
|
<inputType id="cdt.managedbuild.tool.gnu.c.compiler.input.1118638960" superClass="cdt.managedbuild.tool.gnu.c.compiler.input"/>
|
||||||
|
</tool>
|
||||||
|
<tool id="cdt.managedbuild.tool.gnu.c.linker.base.1481582528" name="GCC C Linker" superClass="cdt.managedbuild.tool.gnu.c.linker.base"/>
|
||||||
|
<tool id="cdt.managedbuild.tool.gnu.cpp.linker.base.1048700328" name="GCC C++ Linker" superClass="cdt.managedbuild.tool.gnu.cpp.linker.base">
|
||||||
|
<inputType id="cdt.managedbuild.tool.gnu.cpp.linker.input.1629920531" superClass="cdt.managedbuild.tool.gnu.cpp.linker.input">
|
||||||
|
<additionalInput kind="additionalinputdependency" paths="$(USER_OBJS)"/>
|
||||||
|
<additionalInput kind="additionalinput" paths="$(LIBS)"/>
|
||||||
|
</inputType>
|
||||||
|
</tool>
|
||||||
|
<tool id="cdt.managedbuild.tool.gnu.assembler.base.264833315" name="GCC Assembler" superClass="cdt.managedbuild.tool.gnu.assembler.base">
|
||||||
|
<inputType id="cdt.managedbuild.tool.gnu.assembler.input.853558430" superClass="cdt.managedbuild.tool.gnu.assembler.input"/>
|
||||||
|
</tool>
|
||||||
|
</toolChain>
|
||||||
|
</folderInfo>
|
||||||
|
</configuration>
|
||||||
|
</storageModule>
|
||||||
|
<storageModule moduleId="org.eclipse.cdt.core.externalSettings"/>
|
||||||
|
</cconfiguration>
|
||||||
|
</storageModule>
|
||||||
|
<storageModule moduleId="cdtBuildSystem" version="4.0.0">
|
||||||
|
<project id="git.null.364140434" name="git"/>
|
||||||
|
</storageModule>
|
||||||
|
<storageModule moduleId="scannerConfiguration">
|
||||||
|
<autodiscovery enabled="true" problemReportingEnabled="true" selectedProfileId=""/>
|
||||||
|
</storageModule>
|
||||||
|
<storageModule moduleId="org.eclipse.cdt.core.LanguageSettingsProviders"/>
|
||||||
|
<storageModule moduleId="refreshScope"/>
|
||||||
|
<storageModule moduleId="org.eclipse.cdt.make.core.buildtargets">
|
||||||
|
<buildTargets>
|
||||||
|
<target name="cliever" path="AusRegCliever" targetID="org.eclipse.cdt.build.MakeTargetBuilder">
|
||||||
|
<buildCommand>make</buildCommand>
|
||||||
|
<buildTarget>cliever</buildTarget>
|
||||||
|
<stopOnError>true</stopOnError>
|
||||||
|
<useDefaultCommand>true</useDefaultCommand>
|
||||||
|
<runAllBuilders>true</runAllBuilders>
|
||||||
|
</target>
|
||||||
|
<target name="clean" path="AusRegCliever" targetID="org.eclipse.cdt.build.MakeTargetBuilder">
|
||||||
|
<buildCommand>make</buildCommand>
|
||||||
|
<buildArguments/>
|
||||||
|
<buildTarget>clean</buildTarget>
|
||||||
|
<stopOnError>true</stopOnError>
|
||||||
|
<useDefaultCommand>true</useDefaultCommand>
|
||||||
|
<runAllBuilders>true</runAllBuilders>
|
||||||
|
</target>
|
||||||
|
<target name="distclean" path="AusRegCliever" targetID="org.eclipse.cdt.build.MakeTargetBuilder">
|
||||||
|
<buildCommand>make</buildCommand>
|
||||||
|
<buildArguments/>
|
||||||
|
<buildTarget>distclean</buildTarget>
|
||||||
|
<stopOnError>true</stopOnError>
|
||||||
|
<useDefaultCommand>true</useDefaultCommand>
|
||||||
|
<runAllBuilders>true</runAllBuilders>
|
||||||
|
</target>
|
||||||
|
<target name="AusRegEPPTK.so" path="AusRegEPPTK" targetID="org.eclipse.cdt.build.MakeTargetBuilder">
|
||||||
|
<buildCommand>make</buildCommand>
|
||||||
|
<buildArguments/>
|
||||||
|
<buildTarget>all</buildTarget>
|
||||||
|
<stopOnError>true</stopOnError>
|
||||||
|
<useDefaultCommand>true</useDefaultCommand>
|
||||||
|
<runAllBuilders>true</runAllBuilders>
|
||||||
|
</target>
|
||||||
|
<target name="tests" path="AusRegEPPTK" targetID="org.eclipse.cdt.build.MakeTargetBuilder">
|
||||||
|
<buildCommand>make</buildCommand>
|
||||||
|
<buildArguments/>
|
||||||
|
<buildTarget>tests</buildTarget>
|
||||||
|
<stopOnError>true</stopOnError>
|
||||||
|
<useDefaultCommand>true</useDefaultCommand>
|
||||||
|
<runAllBuilders>true</runAllBuilders>
|
||||||
|
</target>
|
||||||
|
<target name="clean" path="AusRegEPPTK" targetID="org.eclipse.cdt.build.MakeTargetBuilder">
|
||||||
|
<buildCommand>make</buildCommand>
|
||||||
|
<buildArguments/>
|
||||||
|
<buildTarget>clean</buildTarget>
|
||||||
|
<stopOnError>true</stopOnError>
|
||||||
|
<useDefaultCommand>true</useDefaultCommand>
|
||||||
|
<runAllBuilders>true</runAllBuilders>
|
||||||
|
</target>
|
||||||
|
</buildTargets>
|
||||||
|
</storageModule>
|
||||||
|
</cproject>
|
|
@ -0,0 +1,27 @@
|
||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<projectDescription>
|
||||||
|
<name>git</name>
|
||||||
|
<comment></comment>
|
||||||
|
<projects>
|
||||||
|
</projects>
|
||||||
|
<buildSpec>
|
||||||
|
<buildCommand>
|
||||||
|
<name>org.eclipse.cdt.managedbuilder.core.genmakebuilder</name>
|
||||||
|
<triggers>clean,full,incremental,</triggers>
|
||||||
|
<arguments>
|
||||||
|
</arguments>
|
||||||
|
</buildCommand>
|
||||||
|
<buildCommand>
|
||||||
|
<name>org.eclipse.cdt.managedbuilder.core.ScannerConfigBuilder</name>
|
||||||
|
<triggers>full,incremental,</triggers>
|
||||||
|
<arguments>
|
||||||
|
</arguments>
|
||||||
|
</buildCommand>
|
||||||
|
</buildSpec>
|
||||||
|
<natures>
|
||||||
|
<nature>org.eclipse.cdt.core.cnature</nature>
|
||||||
|
<nature>org.eclipse.cdt.core.ccnature</nature>
|
||||||
|
<nature>org.eclipse.cdt.managedbuilder.core.managedBuildNature</nature>
|
||||||
|
<nature>org.eclipse.cdt.managedbuilder.core.ScannerConfigNature</nature>
|
||||||
|
</natures>
|
||||||
|
</projectDescription>
|
|
@ -0,0 +1,11 @@
|
||||||
|
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
|
||||||
|
<project>
|
||||||
|
<configuration id="cdt.managedbuild.toolchain.gnu.base.1489137557" name="Default">
|
||||||
|
<extension point="org.eclipse.cdt.core.LanguageSettingsProvider">
|
||||||
|
<provider copy-of="extension" id="org.eclipse.cdt.ui.UserLanguageSettingsProvider"/>
|
||||||
|
<provider class="org.eclipse.cdt.managedbuilder.language.settings.providers.GCCBuildCommandParser" id="org.eclipse.cdt.managedbuilder.core.GCCBuildCommandParser" keep-relative-paths="false" name="CDT GCC Build Output Parser" parameter="(gcc)|([gc]\+\+)|(clang)" prefer-non-shared="true"/>
|
||||||
|
<provider-reference id="org.eclipse.cdt.managedbuilder.core.GCCBuiltinSpecsDetector" ref="shared-provider"/>
|
||||||
|
<provider-reference id="org.eclipse.cdt.managedbuilder.core.MBSLanguageSettingsProvider" ref="shared-provider"/>
|
||||||
|
</extension>
|
||||||
|
</configuration>
|
||||||
|
</project>
|
|
@ -0,0 +1,81 @@
|
||||||
|
LOCATION=authoring
|
||||||
|
#
|
||||||
|
# LOCATION just reflects accidents of different host
|
||||||
|
# setups, it could be made consistent acroos different
|
||||||
|
# dev envs if any.
|
||||||
|
#
|
||||||
|
#
|
||||||
|
# Boost, the AusReg client toolkit and the latter's dependencies
|
||||||
|
# are initially all that's required.
|
||||||
|
#
|
||||||
|
CC=g++
|
||||||
|
Cc=gcc
|
||||||
|
|
||||||
|
|
||||||
|
#ifeq ($(LOCATION),authoring)
|
||||||
|
BOSTLIB=-L/usr/local/lib/boost
|
||||||
|
BOSINCL=-L/usr/local/include/boost
|
||||||
|
#endif
|
||||||
|
|
||||||
|
SLIBS= -L/usr/local/lib $(BOSTLIB) $(LOG4LIB) -l boost_system -l boost_thread
|
||||||
|
|
||||||
|
ARTKFLAGS=-shared -fPIC -Wl,-soname,libAusRegEPPTK.so
|
||||||
|
|
||||||
|
ifeq ($(LOCATION),authoring)
|
||||||
|
SINCL= -I src/include -I /usr/local/include/log4cpp $(BOSINCL)
|
||||||
|
CFLAGS= -DCURRENT_DEBUG=1000
|
||||||
|
CINCL= -I src/include -I /usr/local/include/log4cpp
|
||||||
|
endif
|
||||||
|
|
||||||
|
CLIBS= -L$(USRLIB)
|
||||||
|
|
||||||
|
|
||||||
|
CLFLAGS= -Wall -Wundef -Wpointer-arith -Wshadow \
|
||||||
|
-Wcast-align -Winline -Wmissing-declarations -Wredundant-decls \
|
||||||
|
-Wmissing-prototypes -Wnested-externs \
|
||||||
|
-Wstrict-prototypes -Waggregate-return -Wno-implicit
|
||||||
|
|
||||||
|
# --- targets
|
||||||
|
# Because of the dependency on introspection of the
|
||||||
|
# current XMLRPC API, all doesn't include md_client.
|
||||||
|
#
|
||||||
|
# If MD is running do make cleanclient;make client;make all
|
||||||
|
# to do an actual complete rebuild of the entire unix system.
|
||||||
|
#
|
||||||
|
|
||||||
|
ifeq ($(LOCATION),authoring)
|
||||||
|
all: cliever
|
||||||
|
endif
|
||||||
|
|
||||||
|
cliever: build/drde-cliever
|
||||||
|
|
||||||
|
.c.o:
|
||||||
|
$(Cc) -c $(CLFLAGS) -o $<
|
||||||
|
|
||||||
|
build/cliever.o: server/cliever.cpp include/*.h
|
||||||
|
$(CC) $(CFLAGS) server/cliever.cpp -c -o build/cliever.o $(SINCL)
|
||||||
|
|
||||||
|
bin/drde-cliever: build/drde-cliever.o build/clieverLogger.o
|
||||||
|
$(CC) $(CFLAGS) -o bin/md $(SINCL) $(LIBS) build/drde-cliever.o build/clieverLogger.o $(SLIBS)
|
||||||
|
|
||||||
|
doxygen/index.html: etc/doxygen.config
|
||||||
|
doxygen etc/doxygen.config
|
||||||
|
|
||||||
|
# --- rebuild on copy to a new host
|
||||||
|
distclean:
|
||||||
|
clrbak
|
||||||
|
rm -rf build
|
||||||
|
rm -rf doxygen
|
||||||
|
mkdir doxygen
|
||||||
|
mkdir build
|
||||||
|
touch etc/doxygen.config
|
||||||
|
|
||||||
|
clean:
|
||||||
|
clrbak
|
||||||
|
find ./build -name "*.o" -print | perl -ne "print;chop;unlink"
|
||||||
|
find ./build -name "*.rpo" -print | perl -ne "print;chop;unlink"
|
||||||
|
rm build/drde-cliever
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
File diff suppressed because it is too large
Load Diff
|
@ -0,0 +1,51 @@
|
||||||
|
#include <cassert>
|
||||||
|
#include <cstdarg>
|
||||||
|
#include <cstdlib>
|
||||||
|
#include <iostream>
|
||||||
|
#include <boost/thread.hpp>
|
||||||
|
#include <boost/date_time/posix_time/posix_time.hpp>
|
||||||
|
#include <boost/statechart/event.hpp>
|
||||||
|
#include <boost/statechart/state_machine.hpp>
|
||||||
|
#include <boost/statechart/simple_state.hpp>
|
||||||
|
#include <boost/statechart/transition.hpp>
|
||||||
|
#include <boost/bind.hpp>
|
||||||
|
#include <boost/asio.hpp>
|
||||||
|
#include <boost/shared_ptr.hpp>
|
||||||
|
#include <Category.hh>
|
||||||
|
#include <FileAppender.hh>
|
||||||
|
#include <PatternLayout.hh>
|
||||||
|
#include <map>
|
||||||
|
#include <utility>
|
||||||
|
#include <map>
|
||||||
|
#include <string>
|
||||||
|
#include <queue>
|
||||||
|
|
||||||
|
namespace fsm = boost::statechart;
|
||||||
|
|
||||||
|
#include "mdcommon.h"
|
||||||
|
#include "mdevents.h"
|
||||||
|
#include "mdLogger.h"
|
||||||
|
|
||||||
|
#define MD_HAUSHALT 1200000 // milliseconds between attention routine
|
||||||
|
#define MD_LOCK_FILE "cliever-md.lock"
|
||||||
|
|
||||||
|
#include "masterDaemonConfig.h"
|
||||||
|
|
||||||
|
#ifdef MD_MAIN
|
||||||
|
|
||||||
|
mdGTEEngine *engineFactory;
|
||||||
|
mdLogger *theseLogs;
|
||||||
|
masterDaemonConfig *thisConfig;
|
||||||
|
|
||||||
|
extern void runMasterDaemon();
|
||||||
|
extern void runClientServiceLayer();
|
||||||
|
|
||||||
|
#else
|
||||||
|
|
||||||
|
extern mdGTEEngine *engineFactory;
|
||||||
|
extern mdLogger *theseLogs;
|
||||||
|
extern masterDaemonConfig *thisConfig;
|
||||||
|
|
||||||
|
#endif
|
||||||
|
|
||||||
|
|
|
@ -0,0 +1,47 @@
|
||||||
|
#ifndef MD_CONFIG
|
||||||
|
#define MD_CONFIG
|
||||||
|
|
||||||
|
typedef struct MDCLIENT {
|
||||||
|
md_device devType;
|
||||||
|
int mdStdDevIdx;
|
||||||
|
} mdLiveClient;
|
||||||
|
|
||||||
|
|
||||||
|
typedef std::map<int,mdLiveClient*> ClientsByHandle;
|
||||||
|
typedef std::map<int,mdDataClient*> DataClientsByHandle;
|
||||||
|
typedef std::map<int,mdInstrument*> InstrumentsByHandle;
|
||||||
|
|
||||||
|
class masterDaemonConfig {
|
||||||
|
|
||||||
|
friend class mdState;
|
||||||
|
|
||||||
|
public:
|
||||||
|
|
||||||
|
bool daemonized;
|
||||||
|
bool halt;
|
||||||
|
bool shuttingDown;
|
||||||
|
bool shutdown;
|
||||||
|
const char *configPath,**err,*logPath,
|
||||||
|
*xmlrpcLogpath;
|
||||||
|
mdClientServer *cliever[MAX_CLIEVER];
|
||||||
|
mdMachine *machine[MAX_CLIEVER];
|
||||||
|
|
||||||
|
ClientsByHandle allClients;
|
||||||
|
DataClientsByHandle clients;
|
||||||
|
|
||||||
|
date epoch(MD_EPOCH);
|
||||||
|
int debugThreshold,nClients,nClievers,
|
||||||
|
servicePort,thisMachineContext,
|
||||||
|
clientPort;
|
||||||
|
pid_t daemonProcess, shellProcess;
|
||||||
|
std::string cfg_path,log_path;
|
||||||
|
std::string clievers[MAX_CLIEVER];
|
||||||
|
|
||||||
|
masterDaemonConfig();
|
||||||
|
|
||||||
|
int loadMachineConfiguration(int machineClass);
|
||||||
|
|
||||||
|
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif
|
|
@ -0,0 +1,30 @@
|
||||||
|
#ifndef MD_LOGGER
|
||||||
|
#define MD_LOGGER
|
||||||
|
|
||||||
|
#include "log4cpp/Category.hh"
|
||||||
|
#include "log4cpp/Appender.hh"
|
||||||
|
#include "log4cpp/FileAppender.hh"
|
||||||
|
#include "log4cpp/Layout.hh"
|
||||||
|
#include "log4cpp/BasicLayout.hh"
|
||||||
|
#include "log4cpp/Priority.hh"
|
||||||
|
|
||||||
|
using namespace log4cpp;
|
||||||
|
|
||||||
|
class mdLogger {
|
||||||
|
public:
|
||||||
|
char *logPath;
|
||||||
|
|
||||||
|
mdLogger() {};
|
||||||
|
|
||||||
|
void init();
|
||||||
|
void logN(int n, const char *format, ...);
|
||||||
|
// log iff m positive and >= config.debugThreshold,
|
||||||
|
// set in powers of 10
|
||||||
|
void logNdebug(int m, int n, const char *format, ...);
|
||||||
|
void logNdev(int n, const char *format, ...);
|
||||||
|
|
||||||
|
~mdLogger(){};
|
||||||
|
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif
|
|
@ -0,0 +1,525 @@
|
||||||
|
/**
|
||||||
|
* \mainpage AusReg Cliever
|
||||||
|
*
|
||||||
|
* <br><hr>
|
||||||
|
*
|
||||||
|
* \par About
|
||||||
|
* \par
|
||||||
|
* <a href="http://dnseppus.meansofproduction.biz/doc/ausregcliever">The Generics Document</a>
|
||||||
|
*
|
||||||
|
* \htmlonly
|
||||||
|
* \endhtmlonly
|
||||||
|
*
|
||||||
|
* <br><hr>
|
||||||
|
*
|
||||||
|
* \par AusReg Cliever requirements
|
||||||
|
*
|
||||||
|
* The AusReg Cliever was originally developed on Debian Wheezy 64 but
|
||||||
|
* should compile on any Unix where all of the requirements are present. The master
|
||||||
|
* daemon programs was developed for a cluster but in this design that's cut back to
|
||||||
|
* a stub.
|
||||||
|
*
|
||||||
|
*
|
||||||
|
* <br><hr>
|
||||||
|
*
|
||||||
|
* \par Access AusReg Cliever source code
|
||||||
|
*
|
||||||
|
*
|
||||||
|
* See 'DEVOPS" at the delivert/support site
|
||||||
|
*
|
||||||
|
*
|
||||||
|
*
|
||||||
|
* <br><hr>
|
||||||
|
*
|
||||||
|
* \par Top Level External Dependencies... and version currently used
|
||||||
|
* <br>
|
||||||
|
* \b boost: 1.49 <br>
|
||||||
|
* \b log4cpp: 1.0 <br>
|
||||||
|
* \b sigc++: 2.0 <br>
|
||||||
|
* \b AusRegTk: 1.3.2 <br>
|
||||||
|
* <br>
|
||||||
|
* See the Tk for it's dependencies, besides that and above everything should be in the git tree.
|
||||||
|
*
|
||||||
|
* <br><hr>
|
||||||
|
*
|
||||||
|
* mdcommon.h - Core Daemon Level definitions.
|
||||||
|
*
|
||||||
|
* \par Authors Support Site
|
||||||
|
*
|
||||||
|
* \htmlonly <a href=http://dnseppus.meansofproduction.biz/doc/drkoeln.de>Delivery/Suppor site</a> \endhtmlonly
|
||||||
|
*
|
||||||
|
* \par License
|
||||||
|
* juan@acm.org for Secura
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef MD_COMMON
|
||||||
|
#define MD_COMMON
|
||||||
|
|
||||||
|
#include<boost/asio/datagram_socket_service.hpp>
|
||||||
|
|
||||||
|
using namespace std;
|
||||||
|
using boost::asio::ip::udp;
|
||||||
|
|
||||||
|
#define MAX_CLIENTS 1000
|
||||||
|
#define MAX_CLIEVER 1
|
||||||
|
#define MAX_CLIENTS 200
|
||||||
|
#define MAX_SERVERS 3 // Per Cliever cluster.
|
||||||
|
#define MAX_DEBUG 1000 // Set the config parm higher than this to inhibit logNdebug(m...) where m < this
|
||||||
|
#define MAX_DEVICE (((MAX_CLIEVER + 1) * MAX_INSTRUMENTS) + MAX_DATACLIENTS)
|
||||||
|
|
||||||
|
#define MD_EPOCH date()
|
||||||
|
#define MD_HEARTBEAT 1 // Network peer heartbeat in seconds.
|
||||||
|
#define MD_MAX_DATAGRAM (32*1024) // half of the IPV4 max
|
||||||
|
#define AUSREGCLIEVER_APP "Generic"
|
||||||
|
#define MD_COMPONENT "Master Daemon" // Cliever Component
|
||||||
|
#define MD_NAME DACLIPS_APP " " MD_COMPONENT
|
||||||
|
#define MD_VERSION " 1.0 " // Version
|
||||||
|
#define MD_REFRESH 10 // default milliseconds between telemetry frame updates
|
||||||
|
#define MD_TYPE "AUSREGCLIEVER" // i.e. what a MACHINE is, Change per your Cliever derivation
|
||||||
|
#define NORMAL_DEBUG 10
|
||||||
|
#ifndef CURRENT_DEBUG
|
||||||
|
#define CURRENT_DEBUG NORMAL_DEBUG
|
||||||
|
#endif
|
||||||
|
#define NOT_OK -1
|
||||||
|
#define OK 0
|
||||||
|
#define RUNNING_DIR "/tmp"
|
||||||
|
|
||||||
|
#define theMachine thisConfig->machine[thisConfig->thisMachineContext]
|
||||||
|
|
||||||
|
enum md_mand {
|
||||||
|
MD_NAM, // Not a Mand.
|
||||||
|
MD_USER_MAND, // User defined mand type
|
||||||
|
MD_EPP,
|
||||||
|
MD_RULE_ACTION,
|
||||||
|
MD_CLIEVER_CMD, // From CD command loop or other UI
|
||||||
|
MD_CLIENT_CMD, // From APIG
|
||||||
|
MD_NMANDS
|
||||||
|
};
|
||||||
|
|
||||||
|
enum mdErrorCode { // In auc-md/kb index to masterDaemonConfig.err
|
||||||
|
MDERR_OK,
|
||||||
|
MDERR_MISSING,
|
||||||
|
MDERR_EXISTS,
|
||||||
|
MDERR_CONFLICT,
|
||||||
|
MDERR_NOTREADY,
|
||||||
|
MDERR_SYNTAX,
|
||||||
|
N_MDSTDERR
|
||||||
|
};
|
||||||
|
|
||||||
|
enum md_dispatch_category {
|
||||||
|
MD_NEWBORN = 0, // inbound this isn't dispatched
|
||||||
|
CD_FRAME,
|
||||||
|
MD_FRAME,
|
||||||
|
DV_MDQUERY,
|
||||||
|
MD_SHUTDOWN
|
||||||
|
};
|
||||||
|
|
||||||
|
enum md_device {
|
||||||
|
MDDEV_MD = 0,
|
||||||
|
MDDEV_CD,
|
||||||
|
MACHINE,
|
||||||
|
MDDEV_DATACLIENT,
|
||||||
|
N_MDDEV_TYPES
|
||||||
|
};
|
||||||
|
|
||||||
|
enum md_units {
|
||||||
|
MD_UNITS_UNDEFINED = 0,
|
||||||
|
N_MD_UNITS
|
||||||
|
};
|
||||||
|
|
||||||
|
enum mdDGtype {
|
||||||
|
MDDG_HEARTBEAT = 0,
|
||||||
|
MDDG_DEVICEHB,
|
||||||
|
MDDG_NEWBORN,
|
||||||
|
MDDG_MDQUERY,
|
||||||
|
MDDG_MDDATA,
|
||||||
|
MDDG_MDMAND,
|
||||||
|
N_MDDG_TYPES
|
||||||
|
};
|
||||||
|
|
||||||
|
typedef
|
||||||
|
struct MD_DG_TYPE {
|
||||||
|
unsigned inBandOnly : 1;
|
||||||
|
unsigned requiresAck : 1;
|
||||||
|
unsigned isAckNak : 1;
|
||||||
|
unsigned value : 1; // i.e. boolean for ack/nak etc. where true = ack.
|
||||||
|
unsigned reserved : 4;
|
||||||
|
unsigned clieverGroup : 8; // masterDaemonConfig.thisMachineContext
|
||||||
|
unsigned reserved2 : 16;
|
||||||
|
}
|
||||||
|
mdDGflags;
|
||||||
|
|
||||||
|
typedef
|
||||||
|
struct MD_DG_HEADER {
|
||||||
|
mdDGtype msgType;
|
||||||
|
mdDGflags dgType;
|
||||||
|
mdDGtype dgSubType;
|
||||||
|
int msgSN; // Ordinal in a dialog
|
||||||
|
md_device clientType;
|
||||||
|
int sourceHandle;
|
||||||
|
int sinkHandle;
|
||||||
|
int handle; // for example if query about a device other than source or sink.
|
||||||
|
mdErrorCode ec;
|
||||||
|
int payloadSize;
|
||||||
|
int primeOffset; // for example to the name associated with the data
|
||||||
|
}
|
||||||
|
mdDGHeader;
|
||||||
|
|
||||||
|
typedef
|
||||||
|
struct MD_DATAGRAM {
|
||||||
|
mdDGHeader hdr;
|
||||||
|
char payLoad[MD_MAX_DATAGRAM - (sizeof(mdDGHeader))];
|
||||||
|
}
|
||||||
|
mdDatagram;
|
||||||
|
|
||||||
|
typedef
|
||||||
|
struct MD_REPLY {
|
||||||
|
mdDGHeader hdr;
|
||||||
|
char payLoad[512 - sizeof(mdDGHeader)];
|
||||||
|
}
|
||||||
|
mdDGReply;
|
||||||
|
|
||||||
|
class mdReply {
|
||||||
|
public:
|
||||||
|
|
||||||
|
mdDGReply dg;
|
||||||
|
|
||||||
|
mdReply() {memset((void *)&dg,0,sizeof(mdDGReply));
|
||||||
|
dg.hdr.dgType.isAckNak = true;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
#if (defined(MD_MAIN) )
|
||||||
|
const char *clientTypes[N_MDDEV_TYPES ] = { "Master Daemon", "Cliever", "MD Client" };
|
||||||
|
#else
|
||||||
|
extern const char *clientTypes[N_MDDEV_TYPES];
|
||||||
|
#endif
|
||||||
|
|
||||||
|
/* \brief mdProcess
|
||||||
|
* Abstract base class of various subprocesses
|
||||||
|
*
|
||||||
|
* AC is (potentially) a distributed system with various subprocesses
|
||||||
|
* spanning the central server, the 'Cliever' middleware component and clients.
|
||||||
|
* Root class for these.
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
|
||||||
|
class mdWQitem {
|
||||||
|
public:
|
||||||
|
md_dispatch_category kind;
|
||||||
|
const void *what;
|
||||||
|
int user; // User defined
|
||||||
|
mdWQitem (const void *work,md_dispatch_category priority,int x)
|
||||||
|
: what(work), kind(priority), user(x) {}
|
||||||
|
|
||||||
|
bool operator< (const mdWQitem & right) const {
|
||||||
|
return kind < right.kind;
|
||||||
|
}
|
||||||
|
|
||||||
|
};
|
||||||
|
|
||||||
|
typedef std::priority_queue < mdWQitem* > MDWQ;
|
||||||
|
|
||||||
|
class mdProcess {
|
||||||
|
public: MDWQ q;
|
||||||
|
mdProcess() {}
|
||||||
|
~mdProcess() {}
|
||||||
|
|
||||||
|
void queue(mdWQitem *w) {q.push(w);}
|
||||||
|
virtual void dispatch(mdWQitem *w)=0;
|
||||||
|
virtual void run() = 0;
|
||||||
|
|
||||||
|
};
|
||||||
|
#define MD_DEFAULT_DEVICE_PROTOCOL 0
|
||||||
|
#define MD_DEFAULT_RULE 0
|
||||||
|
|
||||||
|
typedef
|
||||||
|
struct {
|
||||||
|
unsigned open:1;
|
||||||
|
unsigned looped:1; // back channel established from passive connection.
|
||||||
|
unsigned reserved:30;
|
||||||
|
} mdCnctBool;
|
||||||
|
|
||||||
|
typedef
|
||||||
|
struct MD_CONTROL_BLOCK
|
||||||
|
{int handle; // debug mark
|
||||||
|
mdCnctBool connection;
|
||||||
|
boost::asio::ip::udp::endpoint ep;
|
||||||
|
boost::asio::ip::udp::resolver::iterator it;
|
||||||
|
boost::asio::ip::udp::socket *udp;
|
||||||
|
MD_CONTROL_BLOCK() {
|
||||||
|
handle = 0;
|
||||||
|
memset((void *)&connection,0,sizeof(connection));
|
||||||
|
udp = NULL;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
mdCB;
|
||||||
|
|
||||||
|
typedef std::map<int,mdCB*> mdStdDevicePODMap; // MD Standard Device Map -
|
||||||
|
/*
|
||||||
|
*\brief stdDev: collection with MD at: 0, CD in: 1 - MAX_CLIEVER,
|
||||||
|
* MACHINEs in: MAX_CLIEVER+1 - MAX_CLIEVER*2,
|
||||||
|
* Servers in: (MAX_CLIEVER*2)+1 - (((MAX_CLIEVER*2)+1)+(MAX_CLIEVER*MAX_INSTRUMENTS)),
|
||||||
|
* Clients in: (MAX_CLIEVER*MAX_INSTRUMENTS)+1 - MAX_CLIENT
|
||||||
|
* localhost at: MAX_CLIENT+1
|
||||||
|
*
|
||||||
|
* The mdStdDevIdx of a device is its index above.
|
||||||
|
* Within intervals clients are assigned compactly in the same order as thier handles are created and assigned.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#if (defined(MD_MAIN) || defined(CD_MAIN) || defined(DV_DLL_MAIN))
|
||||||
|
mdStdDevicePODMap cb;
|
||||||
|
int myStdDevIdx=MAX_CLIENTS+1; // global default to localhost
|
||||||
|
#else
|
||||||
|
extern mdStdDevicePODMap cb;
|
||||||
|
extern int myStdDevIdx;
|
||||||
|
#endif
|
||||||
|
|
||||||
|
class mdDGChannel
|
||||||
|
{public:
|
||||||
|
|
||||||
|
boost::asio::io_service& io_service_;
|
||||||
|
boost::asio::ip::udp::endpoint p_endpoint_;
|
||||||
|
boost::asio::ip::udp::endpoint a_endpoint_;
|
||||||
|
boost::asio::ip::udp::endpoint *ep_;
|
||||||
|
boost::asio::ip::udp::resolver *r;
|
||||||
|
boost::asio::ip::udp::resolver::query *q;
|
||||||
|
boost::asio::ip::udp::socket passive_;
|
||||||
|
boost::asio::ip::udp::socket *active_;
|
||||||
|
boost::asio::ip::udp::socket *s_;
|
||||||
|
|
||||||
|
char ack_[sizeof(mdDGReply)];
|
||||||
|
char data_[MD_MAX_DATAGRAM];
|
||||||
|
|
||||||
|
int mdStdDevIdx;
|
||||||
|
|
||||||
|
mdDatagram *inProcess;
|
||||||
|
mdReply *reply;
|
||||||
|
|
||||||
|
short port;
|
||||||
|
|
||||||
|
mdDGChannel(boost::asio::io_service& io_service,
|
||||||
|
short inport, int stdDevIdx=myStdDevIdx)
|
||||||
|
: io_service_(io_service), mdStdDevIdx(stdDevIdx),
|
||||||
|
passive_(io_service, udp::endpoint(udp::v4(), inport))
|
||||||
|
{
|
||||||
|
inProcess = (mdDatagram *)data_;
|
||||||
|
ep_ = &p_endpoint_;
|
||||||
|
port = inport;
|
||||||
|
reply = (mdReply *)ack_;
|
||||||
|
q = NULL;
|
||||||
|
r = NULL;
|
||||||
|
s_ = &passive_;
|
||||||
|
|
||||||
|
passive_.async_receive_from(
|
||||||
|
boost::asio::buffer(data_, MD_MAX_DATAGRAM), p_endpoint_,
|
||||||
|
boost::bind(&mdDGChannel::handle_receive_from, this,
|
||||||
|
boost::asio::placeholders::error,
|
||||||
|
boost::asio::placeholders::bytes_transferred));
|
||||||
|
}
|
||||||
|
|
||||||
|
void async_send(mdDatagram &dg) {
|
||||||
|
|
||||||
|
size_t dgSize = sizeof(mdDGHeader) + dg.hdr.payloadSize;
|
||||||
|
|
||||||
|
*inProcess = dg;
|
||||||
|
//std::memcpy(this->data_,(char *)&dg,dgSize);
|
||||||
|
|
||||||
|
active_->async_send_to(
|
||||||
|
boost::asio::buffer(data_, dgSize), *ep_,
|
||||||
|
boost::bind(&mdDGChannel::handle_send_to, this,
|
||||||
|
boost::asio::placeholders::error,
|
||||||
|
boost::asio::placeholders::bytes_transferred));
|
||||||
|
}
|
||||||
|
|
||||||
|
bool connect_to (std::string &host, std::string &port, int stdDevIdx=-1) {
|
||||||
|
|
||||||
|
bool value = false;
|
||||||
|
int rport = atoi(port.c_str());
|
||||||
|
boost::system::error_code ec;
|
||||||
|
boost::asio::ip::udp::endpoint remote ( boost::asio::ip::address::from_string(host.c_str()), rport);
|
||||||
|
|
||||||
|
stdDevIdx = (stdDevIdx == -1) ? mdStdDevIdx : stdDevIdx;
|
||||||
|
map<int,mdCB *>::iterator iter = cb.find(stdDevIdx);
|
||||||
|
if( iter == cb.end() ) cb[stdDevIdx] = new mdCB();
|
||||||
|
|
||||||
|
try {
|
||||||
|
if (!r) r = new udp::resolver(io_service_);
|
||||||
|
if ( q) delete q;
|
||||||
|
q = new udp::resolver::query(udp::v4(), host.c_str(), port.c_str());
|
||||||
|
cb[stdDevIdx]->it = r->resolve(*q);
|
||||||
|
if (!cb[mdStdDevIdx]->udp)
|
||||||
|
cb[mdStdDevIdx]->udp = new udp::socket(io_service_, udp::endpoint(udp::v4(), 0));
|
||||||
|
active_ = cb[mdStdDevIdx]->udp;
|
||||||
|
if (active_->is_open())
|
||||||
|
active_->connect(remote,ec);
|
||||||
|
|
||||||
|
if (!ec) value = true;
|
||||||
|
|
||||||
|
}
|
||||||
|
catch(...) {}
|
||||||
|
|
||||||
|
return (cb[stdDevIdx]->connection.open=value);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
bool connect_to (boost::asio::ip::udp::endpoint &ep,boost::system::error_code &ec,int &step,int stdDevIdx=-1)
|
||||||
|
{
|
||||||
|
|
||||||
|
bool value = false;
|
||||||
|
|
||||||
|
stdDevIdx = stdDevIdx == -1 ? mdStdDevIdx : stdDevIdx;
|
||||||
|
map<int,mdCB *>::iterator iter = cb.find(stdDevIdx);
|
||||||
|
if( iter == cb.end() ) cb[stdDevIdx] = new mdCB();
|
||||||
|
|
||||||
|
try { if (cb[stdDevIdx]->udp) {if (cb[stdDevIdx]->udp->is_open())
|
||||||
|
cb[stdDevIdx]->udp->close();
|
||||||
|
delete cb[stdDevIdx]->udp;}
|
||||||
|
|
||||||
|
cb[stdDevIdx]->ep = ep;
|
||||||
|
active_ = cb[stdDevIdx]->udp = new boost::asio::ip::udp::socket( io_service_ , udp::endpoint(udp::v4(), 0) );
|
||||||
|
ec.clear();
|
||||||
|
active_->connect( cb[stdDevIdx]->ep, ec );
|
||||||
|
if (active_->is_open()) { value = true; cb[stdDevIdx]->connection.open=1; }
|
||||||
|
else {
|
||||||
|
step++;
|
||||||
|
active_->open( udp::v4(), ec );
|
||||||
|
if (active_->is_open()) {value = true; cb[stdDevIdx]->connection.open=1; }
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
catch(boost::system::system_error &be) {boost::system::system_error warning = be;}
|
||||||
|
catch(...) {}
|
||||||
|
|
||||||
|
return (value);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
void handle_receive_from(const boost::system::error_code& error, size_t bytes_recvd);
|
||||||
|
|
||||||
|
void handle_send_to(const boost::system::error_code& asioEC, size_t sentByes)
|
||||||
|
{
|
||||||
|
size_t dgSize = inProcess->hdr.dgType.requiresAck
|
||||||
|
? sizeof(mdReply) : sizeof(mdDatagram);
|
||||||
|
|
||||||
|
// std::string debugMsg = asioEC.message();
|
||||||
|
|
||||||
|
if (inProcess->hdr.dgType.requiresAck)
|
||||||
|
active_->async_receive_from(
|
||||||
|
boost::asio::buffer(ack_, dgSize), *ep_,
|
||||||
|
boost::bind(&mdDGChannel::handle_receive_from, this,
|
||||||
|
boost::asio::placeholders::error,
|
||||||
|
boost::asio::placeholders::bytes_transferred));
|
||||||
|
else
|
||||||
|
active_->async_receive_from(
|
||||||
|
boost::asio::buffer(data_, dgSize), *ep_,
|
||||||
|
boost::bind(&mdDGChannel::handle_receive_from, this,
|
||||||
|
boost::asio::placeholders::error,
|
||||||
|
boost::asio::placeholders::bytes_transferred));
|
||||||
|
}
|
||||||
|
|
||||||
|
bool send(mdDatagram &dg) {
|
||||||
|
|
||||||
|
size_t dgSize = sizeof(mdDGHeader) + dg.hdr.payloadSize;
|
||||||
|
|
||||||
|
return (dgSize ==
|
||||||
|
active_->send(boost::asio::buffer((void *)&dg, dgSize)));
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
bool send_to(mdDatagram &dg, int mdStdDevIdx) {
|
||||||
|
|
||||||
|
size_t dgSize = sizeof(mdDGHeader) + dg.hdr.payloadSize;
|
||||||
|
|
||||||
|
return (dgSize ==
|
||||||
|
active_->send_to(boost::asio::buffer((void *)&dg, dgSize), *cb[mdStdDevIdx]->it));
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
size_t send(mdReply &dg, boost::system::error_code &ec) {
|
||||||
|
|
||||||
|
size_t dgSize = sizeof(mdDGReply);
|
||||||
|
boost::asio::socket_base::message_flags flags=0;
|
||||||
|
|
||||||
|
return (active_->send(boost::asio::buffer((void *)&dg, dgSize), flags, ec));
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
size_t send_back(mdReply &dg, boost::system::error_code &ec, int &step) {
|
||||||
|
|
||||||
|
size_t dgSize = sizeof(mdDGReply);
|
||||||
|
boost::asio::socket_base::message_flags flags=0;
|
||||||
|
step = 1;
|
||||||
|
|
||||||
|
a_endpoint_ = passive_.remote_endpoint(ec);
|
||||||
|
|
||||||
|
if (ec) return 0;
|
||||||
|
|
||||||
|
return (passive_.send_to(boost::asio::buffer((void *)&dg, dgSize), a_endpoint_, flags, ec));
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
bool send_to(mdReply &dg,int mdStdDevIdx) {
|
||||||
|
|
||||||
|
size_t dgSize = sizeof(mdDGReply);
|
||||||
|
|
||||||
|
return (dgSize ==
|
||||||
|
active_->send_to(boost::asio::buffer((void *)&dg, dgSize), *cb[mdStdDevIdx]->it));
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
typedef std::map<int,std::string> mdErrMsgMap;
|
||||||
|
|
||||||
|
class mdError {
|
||||||
|
|
||||||
|
int instance;
|
||||||
|
mdErrMsgMap text;
|
||||||
|
|
||||||
|
public:
|
||||||
|
mdError() { text[0] = std::string("OK");
|
||||||
|
instance = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
~mdError() {}
|
||||||
|
|
||||||
|
// The below populate the additional messages;
|
||||||
|
// Instances below 1000 are reserved for system errors, negative
|
||||||
|
// integers not used.
|
||||||
|
// Users derive from this class and implement additionalUsrMsgs.
|
||||||
|
|
||||||
|
void additionalUserMsg(int instCode,const char *msgText)
|
||||||
|
{if (instCode >= 1000) text[instCode] = std::string(msgText);}
|
||||||
|
void additionalSystemMsg(int instCode,const char *msgText)
|
||||||
|
{if (instCode < 1000 && instCode >0) text[instCode] = std::string(msgText);}
|
||||||
|
|
||||||
|
int get() {return instance;}
|
||||||
|
void get(mdError **parentPtr)
|
||||||
|
{*parentPtr = this;}
|
||||||
|
void set(int i) {instance = i;}
|
||||||
|
|
||||||
|
const char *what(char *buffer=NULL) {
|
||||||
|
if (text.find(get()) == text.end()) {
|
||||||
|
{if (!buffer) return NULL;
|
||||||
|
sprintf(buffer,"Unknown error code: %d",get());
|
||||||
|
return buffer;
|
||||||
|
}
|
||||||
|
return text[get()].c_str();
|
||||||
|
}
|
||||||
|
return "unknown";
|
||||||
|
}
|
||||||
|
|
||||||
|
};
|
||||||
|
|
||||||
|
class mdDG {
|
||||||
|
public:
|
||||||
|
mdDatagram dg;
|
||||||
|
|
||||||
|
mdDG() {memset(&dg,0,sizeof(mdDatagram));}
|
||||||
|
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif
|
|
@ -0,0 +1,199 @@
|
||||||
|
#define MD_MAIN
|
||||||
|
#include "cliever-md.h"
|
||||||
|
|
||||||
|
#include <stdio.h>
|
||||||
|
#include <fcntl.h>
|
||||||
|
#include <signal.h>
|
||||||
|
#include <unistd.h>
|
||||||
|
|
||||||
|
using namespace std;
|
||||||
|
|
||||||
|
bool mdHasEPPTk;
|
||||||
|
|
||||||
|
const char *mdOrAC; // Process capability based on boolean above
|
||||||
|
|
||||||
|
void setSignals();
|
||||||
|
void signal_handler(int);
|
||||||
|
void usage();
|
||||||
|
void md() {
|
||||||
|
|
||||||
|
bool daemonized=false;
|
||||||
|
int i,lfp,rc; // log file pointer
|
||||||
|
char str[32];
|
||||||
|
|
||||||
|
if (thisConfig->daemonized) {
|
||||||
|
|
||||||
|
rc = fork();
|
||||||
|
if (rc < 0) {
|
||||||
|
puts("Can't initialize process!");
|
||||||
|
exit(1);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (getpid() == thisConfig->shellProcess)
|
||||||
|
exit(0);
|
||||||
|
|
||||||
|
setsid(); /* obtain a new process group */
|
||||||
|
for (i=getdtablesize();i>=0;--i) close(i); /* close all descriptors */
|
||||||
|
i=open("/dev/null",O_RDWR); dup(i); dup(i); /* handle standard I/O */
|
||||||
|
umask(027); /* set newly created file permissions */
|
||||||
|
chdir(RUNNING_DIR); /* change running directory */
|
||||||
|
lfp=open(MD_LOCK_FILE,O_RDWR|O_CREAT,0640); /* make sure were The MD */
|
||||||
|
|
||||||
|
if (lfp<0) {printf("Can't open lockfile(%d)! Ctl-C me."); exit(1);}
|
||||||
|
|
||||||
|
if ((rc=lockf(lfp,F_TLOCK,0))<0)
|
||||||
|
{printf("Can't lock lockfile (%d)! Ctl-C me.",rc); exit(0);}
|
||||||
|
|
||||||
|
thisConfig->daemonProcess = getpid();
|
||||||
|
|
||||||
|
sprintf(str,"%d\n",getpid());
|
||||||
|
write(lfp,str,strlen(str)); /* record pid to lockfile */
|
||||||
|
daemonized = true;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
setSignals();
|
||||||
|
|
||||||
|
try {
|
||||||
|
|
||||||
|
theseLogs = new mdLogger();
|
||||||
|
theseLogs->init();
|
||||||
|
|
||||||
|
theseLogs->logN(1,MD_NAME " " MD_VERSION " compiled on " __DATE__ " @ " __TIME__ "(%d)",thisConfig->daemonProcess);
|
||||||
|
if (daemonized) theseLogs->logN(1,"(detached from %d)",thisConfig->shellProcess);
|
||||||
|
|
||||||
|
if (mdHasEPPTk) {
|
||||||
|
theseLogs->logN(0,"AusReg Cliever <- MasterDaemon.");
|
||||||
|
}
|
||||||
|
|
||||||
|
boost::thread foreground(runMasterDaemon);
|
||||||
|
boost::thread background(runClientLayer);
|
||||||
|
|
||||||
|
if (!foreground.joinable()) {
|
||||||
|
theseLogs->logN(0,"Fatal Error: couldn't start master daemon!");
|
||||||
|
exit(1);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (background.joinable()) {
|
||||||
|
theseLogs->logN(2,"%s %d","Accepting API Requests on Port",thisConfig->clientPort);
|
||||||
|
myAusRegProcess.run();
|
||||||
|
background.join(); // normally unreachable
|
||||||
|
} else
|
||||||
|
theseLogs->logN(0,"Fatal Error: couldn't start client service layer!");
|
||||||
|
}
|
||||||
|
//catch (XmlRpcFault::XmlRpcFault& e)
|
||||||
|
//{
|
||||||
|
// theseLogs->logN(1,"xmlrpc_c fault: %s",e.getFaultString().c_str());
|
||||||
|
// exit(1);
|
||||||
|
//}
|
||||||
|
catch (std::exception& e)
|
||||||
|
{
|
||||||
|
theseLogs->logN(1,"Exception: %s",e.what());
|
||||||
|
exit(1);
|
||||||
|
}
|
||||||
|
catch (...) {
|
||||||
|
theseLogs->logN(1,"General Fault!");
|
||||||
|
exit(1);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
int
|
||||||
|
main(int const argc,
|
||||||
|
const char ** const argv) {
|
||||||
|
|
||||||
|
char msg[512];
|
||||||
|
const char *banner = MD_NAME " " MD_VERSION " compiled on " __DATE__ " @ " __TIME__ "(%d)\n";
|
||||||
|
int mthParm, rc = 0;
|
||||||
|
|
||||||
|
thisConfig = new masterDaemonConfig();
|
||||||
|
thisConfig->shellProcess = getpid();
|
||||||
|
|
||||||
|
mdOrKb = (strcspn(argv[0],"./") == strlen(argv[0])) ? argv[0] : strrchr(argv[0],'/') + 1;
|
||||||
|
mdHasKb = strstr(argv[0],"clips") ? true : false;
|
||||||
|
|
||||||
|
if (argc < 3 || argc > 6) usage();
|
||||||
|
|
||||||
|
thisConfig->servicePort = atoi(argv[1]);
|
||||||
|
thisConfig->clientPort = atoi(argv[2]);
|
||||||
|
|
||||||
|
if (thisConfig->clientPort < 1000 || thisConfig->clientPort > 65535)
|
||||||
|
{
|
||||||
|
std::cerr << "The <client-udp-port> value is invalid.\n";
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (thisConfig->servicePort < 1000 || thisConfig->servicePort > 65535)
|
||||||
|
{
|
||||||
|
std::cerr << "The <service-socket-port> value is invalid.\n";
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (thisConfig->servicePort == thisConfig->clientPort)
|
||||||
|
{
|
||||||
|
std::cerr << "The <service-socket-port> and <client-udp-port> cannot be the same.\n";
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
for (mthParm=3;mthParm < argc;mthParm++) {
|
||||||
|
if (*argv[mthParm] == '!') {
|
||||||
|
thisConfig->daemonized = false;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
if (!strncmp(argv[mthParm],"logs=",4)) {
|
||||||
|
thisConfig->log_path = std::string(argv[mthParm]+4);
|
||||||
|
thisConfig->logPath = thisConfig->log_path.c_str();
|
||||||
|
}
|
||||||
|
else
|
||||||
|
if (!strncmp(argv[mthParm],"cfg=",3)) {
|
||||||
|
thisConfig->cfg_path = std::string(argv[mthParm]+3);
|
||||||
|
thisConfig->configPath = thisConfig->cfg_path.c_str();
|
||||||
|
}
|
||||||
|
else usage();
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!thisConfig->daemonized) printf(banner,thisConfig->shellProcess);
|
||||||
|
md();
|
||||||
|
while(!thisConfig->halt) sleep(5);
|
||||||
|
|
||||||
|
}
|
||||||
|
void setSignals() {
|
||||||
|
|
||||||
|
signal(SIGCHLD,SIG_IGN); /* ignore child */
|
||||||
|
signal(SIGTSTP,SIG_IGN); /* ignore tty signals */
|
||||||
|
signal(SIGTTOU,SIG_IGN); // both input
|
||||||
|
signal(SIGTTIN,SIG_IGN); // and output
|
||||||
|
signal(SIGSEGV,signal_handler);
|
||||||
|
signal(SIGUSR1,signal_handler); // commander log messages
|
||||||
|
signal(SIGUSR2,signal_handler); // reserved
|
||||||
|
signal(SIGHUP,signal_handler); /* catch hangup signal */
|
||||||
|
signal(SIGTERM,signal_handler); /* catch kill signal */
|
||||||
|
|
||||||
|
}
|
||||||
|
void signal_handler(int sig)
|
||||||
|
{
|
||||||
|
switch(sig) {
|
||||||
|
case SIGSEGV:
|
||||||
|
theseLogs->logN(0,"SEGV ABEND.");
|
||||||
|
exit(NOT_OK);
|
||||||
|
break;
|
||||||
|
case SIGUSR1:
|
||||||
|
break;
|
||||||
|
case SIGUSR2:
|
||||||
|
break;
|
||||||
|
case SIGHUP:
|
||||||
|
theseLogs->logN(0,"hangup signal caught, currently md ignores this.");
|
||||||
|
break;
|
||||||
|
case SIGTERM:
|
||||||
|
theseLogs->logN(0,"terminate signal caught, auc-md will shutdown.");
|
||||||
|
exit(0);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
void usage() {
|
||||||
|
|
||||||
|
std::cerr << "Usage: " << mdOrAC << " <client-udp-port> <service-socket-port> [cfg=<path>] [log=<path>] [!] \n\n"
|
||||||
|
" where \n\nconfig directory defaults to the current directory \n"
|
||||||
|
"log directory to /tmp \nand ! to not daemonize (for diagnostic purposes)\n\n";
|
||||||
|
exit(1);
|
||||||
|
|
||||||
|
}
|
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in New Issue