7#ifndef __BASE_DAEMON_H__
8#define __BASE_DAEMON_H__
12#include "OptionParser.h"
13#include "parser_toml.h"
14#include "PSocketFlag.h"
15#include "PUncastableBool.h"
29#define SWARM_MAKE_SLOT(C,X,D) static PUncastableBool slot_##X(C & self, const D & _data){\
30 return self.X(_data);\
36#define SWARM_SLOT(X) slot_##X
48 PRecvFlag::PRecvFlag
recvFlag{PRecvFlag::NON_BLOCK};
50 PSendFlag::PSendFlag
sendFlag{PSendFlag::NON_BLOCK};
62 bool load(
const PPath & fileName,
const PString & daemonName);
64 virtual bool extraLoad(
const ConfigNode * config);
72 template<
typename _Callable>
76 getLog().getLogError() <<
"BaseDaemon::addCallableMethod : function '"<<name<<
"' already added" << std::endl;
104 template<
typename _Data>
105 bool addDataCallableMethod(PUncastableBool(&function)(
const _Data &),
size_t nbBin,
float histLowerBound,
float histUpperBound){
106 PString prototype(phoenix_getTypeToStr<_Data>());
107 std::cout <<
"BaseDaemon::addDataCallableMethod : prototype = " << prototype << std::endl;
108 std::map<PString, AbstractDataFunction*>::iterator it(
p_mapDataFunction.find(prototype));
110 getLog().getLogError() <<
"BaseDaemon::addDataCallableMethod : function to process data '"<<prototype<<
"' already added" << std::endl;
113 getLog().getLogDebug() <<
"BaseDaemon::addDataCallableMethod : add method to process data '"<<prototype<<
"'" << std::endl;
115 p_config.getDaemonStatAccumulator().getMapStatComputing()[prototype] =
createNewStat(nbBin, histLowerBound, histUpperBound);
127 template<
typename _Class,
typename _Data>
128 bool addDataCallableMethod(PUncastableBool(&function)(_Class &,
const _Data &), _Class & persistentData,
size_t nbBin,
float histLowerBound,
float histUpperBound){
129 PString prototype(phoenix_getTypeToStr<_Data>());
130 std::cout <<
"BaseDaemon::addDataCallableMethod : prototype = " << prototype << std::endl;
131 std::map<PString, AbstractDataFunction*>::iterator it(
p_mapDataFunction.find(prototype));
133 getLog().getLogError() <<
"BaseDaemon::addDataCallableMethod : function to process data '"<<prototype<<
"' already added" << std::endl;
136 getLog().getLogDebug() <<
"BaseDaemon::addDataCallableMethod : add method to process data '"<<prototype<<
"'" << std::endl;
138 p_config.getDaemonStatAccumulator().getMapStatComputing()[prototype] =
createNewStat(nbBin, histLowerBound, histUpperBound);
176 std::map<PString, StatAccumulator>
createNewCommunicationStatMap(
const PString & dataType,
size_t nbBin,
float histLowerBound,
float histUpperBound);
177 void getCommunicationStat(
const PString & destName,
const PString & dataType,
float latency,
size_t nbBin,
float histLowerBound,
float histUpperBound);
std::map< PString, std::map< PString, StatAccumulator > > MapDaemonStatAccumulator
std::map< PString, StatAccumulator > MapStatAccumulator
Abstract function definition which will be callable in Daemon.
PLog p_log
Logger of the current Daemon.
void clearCallableMethod()
Clear the map of callable methods.
bool p_isRun
True if the current BaseDaemon is running.
void loadConfigFromNode(const ConfigNode &dico, const PString &daemonName)
Load configuration form a node of ConfigNode.
bool isDaemonExist(const PString &name) const
Say if a neighbour Daemon does exist.
OptionParser p_optionParser
Option parser of the Daemon.
void updateStatAccumulator(StatAccumulator &stat, float value)
Update a computing statistic with a new value.
size_t p_messageId
Id counter of the message of the current Daemon.
OptionParser & getOptionParser()
Return the OptionParser of the current BaseDaemon.
std::map< PString, StatAccumulator > createNewCommunicationStatMap(const PString &dataType, size_t nbBin, float histLowerBound, float histUpperBound)
Create a new map of communication statistic.
bool p_isFullMockRecord
True if the daemon has to be executed in mock record mode for socket and clock.
bool getMessageToConfirm(Message &message, size_t id) const
Get a message to confirm by id if it exists.
VecStat fillVecStat(const StatAccumulator &accumulator, time_t startTimestamp, time_t endTimestamp)
Fill a VecStat from a StatAccumulator to send to the DamonStat.
bool processData(const Data &data)
Process given data with the proper method.
PLog & getLogger()
Get the logger of the current BaseDaemon.
bool load(const PString &configFileContent, const PString &daemonName, ConfigFormat::ConfigFormat format)
Load the Json configuration which define all BaseDaemons of the Swarm.
DaemonMainConfig p_mainConfig
Main configuration of the Daemon.
bool p_isFullMock
True if the daemon has to be executed in mock mode for socket and clock.
void initialisationBaseDaemon()
Initialisation function of the class BaseDaemon.
bool addCallableMethod(_Callable &&function, const PString &name)
Add a callable method of the Daemon.
MapDaemonConfig & getMapDaemonConfig()
Get the map of all Daemon configurations.
DaemonConfig & getConfig()
Get the configuration of the current BaseDaemon.
bool callMethod(Data &result, const PString &name, const Data ¶meter)
Call an added callable method by name.
std::map< PString, AbstractFunction * > p_mapCallableMethod
Map of callable method of the Daemon.
DaemonMainConfig & getMainConfig()
Get the main configuration of the swarm.
void addMessageToConfirm(const Message &message)
Add a message to confirm.
virtual void addCallMethod()
Do the addCallableMethod here.
virtual bool extraLoad(const ConfigNode *config)
Extra call on load for the current Daemon.
AbstractDataFunction * getDataFunction(const Data &data)
Get the data function associated with the given data.
bool addDataCallableMethod(PUncastableBool(&function)(_Class &, const _Data &), _Class &persistentData, size_t nbBin, float histLowerBound, float histUpperBound)
Add a callable method of the Daemon.
void fillDaemonStat(DaemonStat &stat, time_t startTimestamp, time_t endTimestamp)
Fill the DaemonStat with the current statistics of the daemon.
PLog & getLog()
Get the log of the current BaseDaemon.
void clearStat()
Clear all the statistics of the daemon.
void stop()
Stops the BaseDaemon.
std::map< PString, AbstractDataFunction * > p_mapDataFunction
Map of methods which have to be called when receiving data.
void checkMessageTimeout(time_t currentTime)
Check if a message has reached the timeout.
DaemonConfig p_config
Configuration of the curent Daemon.
MapDaemonConfig p_mapDaemon
Map of the other Daemon of the Swarm.
size_t getMessageId()
Get current message id.
void getCommunicationStat(const PString &destName, const PString &dataType, float latency, size_t nbBin, float histLowerBound, float histUpperBound)
Add a communication statistic.
bool addDataCallableMethod(PUncastableBool(&function)(const _Data &), size_t nbBin, float histLowerBound, float histUpperBound)
Add a callable method of the Daemon.
BaseDaemon()
Default constructor of BaseDaemon.
StatAccumulator createNewStat(size_t nbBin, float histLowerBound, float histUpperBound)
Create a new clear computing statistic.
std::map< size_t, Message > p_mapMessageToBeConfirmed
Map of messages which have to be confirmed by destination Daemon.
const std::map< size_t, Message > & getMapMessageToBeConfirmed() const
Get the map of message to be confirmed.
void processConfirmedMessage(size_t id, time_t currentTime)
Process confirmed message.
virtual ~BaseDaemon()
Destructor of BaseDaemon.
bool parseArgument(int argc, char **argv)
Parse arguments given to the BaseDaemon with command line.
Describe a Daemon of the Swarm.
Function which can be called in a Daemon.
Function which can be called in a Daemon.
Basic Data exchanged in the swarm.
Function which can be called in a Daemon.
Message exchanged by Daemons.
Accumulator of event occurence to build swarm statistics over a time period.
General statistics in the swarm.
std::map< PString, DaemonConfig > MapDaemonConfig
Main Daemon configuration which drives timeouts and flags of send and recv calls.
PSendFlag::PSendFlag sendFlag
Send flag to be used for every send of the Daemon.
int sendTimeoutMs
Send time out in miliseconds.
int recvTimeoutMs
Recv time out in miliseconds.
PRecvFlag::PRecvFlag recvFlag
Recv flag to be used for every recv of the Daemon.