PhoenixSwarm  6.1.0
Persistent processing programs exchanging data over sockets
Loading...
Searching...
No Matches
main.cpp
Go to the documentation of this file.
1/***************************************
2 Auteur : Pierre Aubert
3 Mail : pierre.aubert@lapp.in2p3.fr
4 Licence : LGPL-3.0-only
5****************************************/
6
7#include <iostream>
8#include <functional>
9#include "phoenix_assert.h"
10#include "phoenix_check.h"
11
12#include "Shadok.h"
13#include "ProcessClass.h"
14#include "Daemon.h"
15#include "DaemonSlot.h"
16
17#include "DaemonEmptyBackend.h"
18
20
22
25PUncastableBool testShadokProcessing(const Shadok & shadok){
26 //Let's do something
27 std::cout << "testShadokProcessing : we are processing a Shadok" << std::endl;
28 //I do not know what it was, but is was OK
29 return UNCASTABLE_TRUE;
30}
31
33
36PUncastableBool testIntProcessing(const int & value){
37 //Let's do something
38 std::cout << "testIntProcessing : we are processing an int" << std::endl;
39 //I do not know what it was, but is was OK
40 return UNCASTABLE_TRUE;
41}
42
44
46void testBaseDaemonLoadConfig(const PPath & fileName){
47 TestDaemon daemon;
48 daemon.setSocketMode(PSocketMode::MOCK);
49 daemon.setClockMode(PClockMode::MOCK);
50 daemon.getLog().setLogLevel(PLog::DEBUG);
51 daemon.getLog().setFileName(PPath("Daemon.log"));
52 phoenix_assert(daemon.getLog().open());
53 phoenix_assert(daemon.addDataCallableMethod(testShadokProcessing, 0, 0.f, 0.f));
54 phoenix_assert(daemon.addDataCallableMethod(testIntProcessing, 0, 0.f, 0.f));
55 //Add a non static method
56 ProcessClass processClass;
57 phoenix_assert(daemon.addDataCallableMethod(ProcessClass::SWARM_SLOT(fillLong), processClass, 10lu, 0.0, 1e6));
58 phoenix_assert(daemon.addDataCallableMethod(ProcessClass::SWARM_SLOT(fillShort), processClass, 0, 0.f, 0.f));
59 //The function is added already
60// phoenix_assert(!daemon.addCallableMethod(testCallFunction, "testCallFunction"));
61
62 int value(42);
63 Data dataInt(phoenix_createData(value));
64 phoenix_assert(daemon.processData(dataInt));
65
66 Shadok shadok;
67 shadok.setAge(42);
68 shadok.setName("Shadoko");
69 Data data(phoenix_createData(shadok));
70 phoenix_assert(daemon.processData(data));
71
72 long longValue(42);
73 Data dataLong(phoenix_createData(longValue));
74 phoenix_assert(daemon.processData(dataLong));
75
76 short shortValue(42);
77 Data dataShort(phoenix_createData(shortValue));
78 phoenix_assert(daemon.processData(dataShort));
79}
80
83 DaemonSlot daemon;
84 daemon.setSocketMode(PSocketMode::MOCK);
85 daemon.setClockMode(PClockMode::MOCK);
86 daemon.getLog().setLogLevel(PLog::DEBUG);
87 daemon.getLog().setFileName(PPath("DaemonSlot.log"));
88 phoenix_assert(daemon.getLog().open());
89 daemon.addCallMethod();
90 int value(42);
91 Data dataInt(phoenix_createData(value));
92 phoenix_assert(daemon.processData(dataInt));
93}
94
95int main(int argc, char** argv){
96 testBaseDaemonLoadConfig(PPath(DAEMON_CONFIG_OK));
98 return 0;
99}
100
101
int main(int argc, char **argv)
Definition main.cpp:21
void testBaseDaemonLoadConfig(const PPath &fileName)
Test the load configuration of a Daemon.
Definition main.cpp:46
void testDaemonSlot()
Test the DaemonSlot.
Definition main.cpp:82
PUncastableBool testIntProcessing(const int &value)
Process a Shadok.
Definition main.cpp:36
Daemon< DaemonEmptyBackend > TestDaemon
Definition main.cpp:19
PUncastableBool testShadokProcessing(const Shadok &shadok)
Process a Shadok.
Definition main.cpp:25
class test to use a Daemon
Definition DaemonSlot.h:16
virtual void addCallMethod()
Add all call Daemon.
Test ProcessClass.
Test Shadok.
Definition Shadok.h:15
void setAge(int age)
Sets the age of the Shadok.
Definition Shadok.cpp:47
void setName(const std::string &name)
Sets the name of the Shadok.
Definition Shadok.cpp:54
bool addDataCallableMethod(PUncastableBool(&function)(const _Data &), size_t nbBin, float histLowerBound, float histUpperBound)
Add a callable method of the Daemon.
Definition BaseDaemon.h:105
PLog & getLog()
Get the log of the current BaseDaemon.
bool processData(const Swarm::Data &data)
Process given data with the proper method.
Class which describes a Daemon with connections to other daemons.
Definition Daemon.h:17
void setClockMode(PClockMode::PClockMode mode)
Set the mode of the clock.
Definition Daemon_impl.h:55
void setSocketMode(PSocketMode::PSocketMode mode)
Set the mode of the sockets of the SocketManager.
Definition Daemon_impl.h:33
Basic Data exchanged in the swarm.
Swarm::Data phoenix_createData(const T &value)
Create a Data from a value.