PhoenixSwarm  5.1.1
Library to ease communication between daemons
Loading...
Searching...
No Matches
main.cpp File Reference
#include <iostream>
#include "swarm_mock_daemon.h"
+ Include dependency graph for main.cpp:

Go to the source code of this file.

Functions

void createDaemon (const PPath &fileName, const PString &daemonName)
 Create a simple Daemon stat manager.
 
void createMockFileMainRecv (const PString &hostName, size_t port, const PString &prefix)
 Simulate data to send.
 
void createMockFileMainSend (const PString &hostName, size_t port, const PString &prefix)
 Simulate data to send.
 
int main (int argc, char **argv)
 
void testMonitoring (const PPath &fileName)
 Test a simple Daemon stat manager.
 

Function Documentation

◆ createDaemon()

void createDaemon ( const PPath & fileName,
const PString & daemonName )

Create a simple Daemon stat manager.

Parameters
fileName: Daemon configuration
daemonName: name of the current Daemon

Definition at line 109 of file main.cpp.

109 {
110 RecvDataDaemon daemon;
111 daemon.setSocketMode(PSocketMode::MOCK);
112 daemon.setClockMode(PClockMode::MOCK);
113 phoenix_assert(daemon.load(fileName, daemonName));
114 phoenix_assert(daemon.run());
115}

Referenced by testBaseDaemonLoadConfig(), and testMonitoring().

+ Here is the caller graph for this function:

◆ createMockFileMainRecv()

void createMockFileMainRecv ( const PString & hostName,
size_t port,
const PString & prefix )

Simulate data to send.

Parameters
mockName: name of the associated mock

Definition at line 70 of file main.cpp.

70 {
71 PMockSocketGenerator::Socket mock;
72 phoenix_assert(phoenix_initializeMockSocket(mock, PSocketParam{hostName, port}, prefix));
73
74 //We receive a Shadok message
75 Message shadokMsg;
76 shadokMsg.setId(1lu);
77 shadokMsg.setSendTime(0lu);
78 shadokMsg.setIsConfirmationNeeded(true);
79 shadokMsg.setType(MessageType::RESULT_DATA);
80 shadokMsg.setSender("test");
81 Shadok shadok("Bob", 42);
82 shadokMsg.setData(phoenix_createData(shadok));
83 shadokMsg.getVecRecver().push_back("main");
84 mock.sendData(shadokMsg);
85
86 //We receive a Gibis message
87 Message gibisMsg;
88 gibisMsg.setId(2lu);
89 gibisMsg.setSendTime(1lu);
90 gibisMsg.setIsConfirmationNeeded(true);
91 gibisMsg.setType(MessageType::RESULT_DATA);
92 gibisMsg.setSender("test");
93 Gibis gibis("Red", 100);
94 gibisMsg.setData(phoenix_createData(gibis));
95 gibisMsg.getVecRecver().push_back("main");
96 mock.sendData(gibisMsg);
97
98 //Finally we stop the Daemon
99 Message messageStop;
100 messageStop.setId(3lu);
101 messageStop.setType(MessageType::STOP);
102 mock.sendData(messageStop);
103}
Swarm::Data phoenix_createData(const T &value)
Create a Data from a value.

References phoenix_createData(), MessageType::RESULT_DATA, and MessageType::STOP.

Referenced by testBaseDaemonLoadConfig(), and testMonitoring().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ createMockFileMainSend()

void createMockFileMainSend ( const PString & hostName,
size_t port,
const PString & prefix )

Simulate data to send.

Parameters
hostName: name of the host
port: port to be used
prefix: prefix of the mock file of the current test

Definition at line 44 of file main.cpp.

44 {
45 PMockSocketGenerator::Socket mock;
46 phoenix_assert(phoenix_initializeMockSocket(mock, PSocketParam{hostName, port}, prefix));
47 PVecMockMessage vecOutput;
48 //At time 0, whe receive a confiramtion for the Shadok message sent
49 Message confirmationShadok;
50 confirmationShadok.setSendTime(0lu);
51 confirmationShadok.setId(1lu);
52 confirmationShadok.setSender("main");
53 confirmationShadok.setType(MessageType::MESSAGE_CONFIRMATION);
54 confirmationShadok.getVecRecver().push_back("test");
55 mock.sendData(confirmationShadok);
56
57 //At time 1, we receive a confirmation for the Gibis message sent
58 Message confirmationGibis;
59 confirmationGibis.setSendTime(1lu);
60 confirmationGibis.setId(2lu);
61 confirmationGibis.setSender("main");
62 confirmationGibis.setType(MessageType::MESSAGE_CONFIRMATION);
63 confirmationGibis.getVecRecver().push_back("test");
64 mock.sendData(confirmationGibis);
65}
@ MESSAGE_CONFIRMATION
Definition MessageType.h:20

References MessageType::MESSAGE_CONFIRMATION.

Referenced by testBaseDaemonLoadConfig(), and testMonitoring().

+ Here is the caller graph for this function:

◆ main()

int main ( int argc,
char ** argv )

Definition at line 127 of file main.cpp.

127 {
128 testMonitoring(PPath(DAEMON_CONFIG_OK));
129 return 0;
130}
void testMonitoring(const PPath &fileName)
Test a simple Daemon stat manager.
Definition main.cpp:120

References testMonitoring().

+ Here is the call graph for this function:

◆ testMonitoring()

void testMonitoring ( const PPath & fileName)

Test a simple Daemon stat manager.

Parameters
fileName: Daemon configuration

Definition at line 120 of file main.cpp.

120 {
121 phoenix_createClockMock("main_", 4lu);
122 createMockFileMainSend("localhost", 3391lu, "main_");
123 createMockFileMainRecv("localhost", 3390, "main_");
124 createDaemon(fileName, "main");
125}
void createDaemon(const PPath &fileName, const PString &daemonName)
Create a simple Daemon stat manager.
Definition main.cpp:109
void createMockFileMainRecv(const PString &hostName, size_t port, const PString &prefix)
Simulate data to send.
Definition main.cpp:70
void createMockFileMainSend(const PString &hostName, size_t port, const PString &prefix)
Simulate data to send.
Definition main.cpp:44

References createDaemon(), createMockFileMainRecv(), and createMockFileMainSend().

Referenced by main().

+ Here is the call graph for this function:
+ Here is the caller graph for this function: