PhoenixZMQ  2.0.0
Library which integrates zeromq use in Phoenix
main.cpp File Reference
#include <unistd.h>
#include <fstream>
#include <iostream>
#include <thread>
#include "data_stream_assert.h"
#include "PGenericSocketManager.h"
+ Include dependency graph for main.cpp:

Go to the source code of this file.

Typedefs

typedef SocketManager::Backend Backend
 
typedef SocketManager::Mock Mock
 
typedef PGenericSocketManager< std::string, PEmptyBackend, PMockBackendSocketManager
 

Functions

int main (int argc, char **argv)
 
void testMockSocket (PSocketMode::PSocketMode mode)
 Launch the process. More...
 
void testMockSocketMessage (PSocketMode::PSocketMode mode)
 Launch the process. More...
 
void threadRecievedData (PSocketMode::PSocketMode mode, const std::string &address, size_t nbMessage, size_t port)
 Recieved messages on socket. More...
 
void threadRecievedMessage (PSocketMode::PSocketMode mode, const std::string &address, size_t nbMessage, size_t port)
 Recieved messages on socket. More...
 
void threadSendData (PSocketMode::PSocketMode mode, size_t nbMessage, const std::string &address, size_t port)
 Send messages on socket. More...
 
void threadSendMessage (PSocketMode::PSocketMode mode, size_t nbMessage, const std::string &address, size_t port)
 Send messages on socket. More...
 

Typedef Documentation

◆ Backend

Definition at line 18 of file main.cpp.

◆ Mock

Definition at line 19 of file main.cpp.

◆ SocketManager

Definition at line 17 of file main.cpp.

Function Documentation

◆ main()

int main ( int  argc,
char **  argv 
)

Definition at line 136 of file main.cpp.

136  {
139 
142  return 0;
143 }
void testMockSocket(PSocketMode::PSocketMode mode)
Launch the process.
Definition: main.cpp:66
void testMockSocketMessage(PSocketMode::PSocketMode mode)
Launch the process.
Definition: main.cpp:129

References PSocketMode::MOCK, PSocketMode::NO_MOCK, testMockSocket(), and testMockSocketMessage().

+ Here is the call graph for this function:

◆ testMockSocket()

void testMockSocket ( PSocketMode::PSocketMode  mode)

Launch the process.

Parameters
mode: mode of the socket

Definition at line 66 of file main.cpp.

66  {
67  size_t nbMessage(10lu), port(3390lu);
68  std::string hostName("localhost");
69  threadSendData(mode, nbMessage, hostName, port);
70  threadRecievedData(mode, hostName, nbMessage, port);
71 }
void threadSendData(PSocketMode::PSocketMode mode, size_t nbMessage, const std::string &address, size_t port)
Send messages on socket.
Definition: main.cpp:28
void threadRecievedData(PSocketMode::PSocketMode mode, const std::string &address, size_t nbMessage, size_t port)
Recieved messages on socket.
Definition: main.cpp:46

References threadRecievedData(), and threadSendData().

Referenced by main().

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

◆ testMockSocketMessage()

void testMockSocketMessage ( PSocketMode::PSocketMode  mode)

Launch the process.

Parameters
mode: mode of the socket

Definition at line 129 of file main.cpp.

129  {
130  size_t nbMessage(10lu), port(3390lu);
131  std::string hostName("localhost");
132  threadSendMessage(mode, nbMessage, hostName, port);
133  threadRecievedMessage(mode, hostName, nbMessage, port);
134 }
void threadRecievedMessage(PSocketMode::PSocketMode mode, const std::string &address, size_t nbMessage, size_t port)
Recieved messages on socket.
Definition: main.cpp:103
void threadSendMessage(PSocketMode::PSocketMode mode, size_t nbMessage, const std::string &address, size_t port)
Send messages on socket.
Definition: main.cpp:80

References threadRecievedMessage(), and threadSendMessage().

Referenced by main().

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

◆ threadRecievedData()

void threadRecievedData ( PSocketMode::PSocketMode  mode,
const std::string &  address,
size_t  nbMessage,
size_t  port 
)

Recieved messages on socket.

Parameters
mode: mode of the mock to be used
address: address of the socket
nbMessage: number of message to be read
port: connection port to be used

Definition at line 46 of file main.cpp.

46  {
47  SocketManager manager(mode); //Mock mode
48  data_stream_assert(manager.addClientSocket("Bob",
49  Backend::client(address, port),
50  Mock::client(address, port, false, "./")));
51  size_t i(0lu);
52  while(i < nbMessage){
53  size_t value(0lu);
54  if(mode == PSocketMode::NO_MOCK){
55  data_stream_assert(!manager.recvData("Bob", value));
56  }else{
57  data_stream_assert(manager.recvData("Bob", value));
58  }
59  ++i;
60  }
61 }
Socket manager for PGenericSocket.
#define data_stream_assert(isOk)

References PGenericSocketManager< _TSocketKey, _TBackend, _TMockBackend >::addClientSocket(), data_stream_assert, PSocketMode::NO_MOCK, and PGenericSocketManager< _TSocketKey, _TBackend, _TMockBackend >::recvData().

Referenced by testMockSocket().

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

◆ threadRecievedMessage()

void threadRecievedMessage ( PSocketMode::PSocketMode  mode,
const std::string &  address,
size_t  nbMessage,
size_t  port 
)

Recieved messages on socket.

Parameters
mode: mode of the mock to be used
address: address of the socket
nbMessage: number of message to be read
port: connection port to be used

Definition at line 103 of file main.cpp.

103  {
104  SocketManager manager(mode); //Mock mode
105  data_stream_assert(manager.addClientSocket("Bob",
106  Backend::client(address, port),
107  Mock::client(address, port, false, "./testMessage")));
108  size_t i(0lu);
109  while(i < nbMessage){
110  Backend::Message msg;
111  if(mode == PSocketMode::NO_MOCK){
112  data_stream_assert(!manager.recvMsg("Bob", msg));
113  }else{
114  data_stream_assert(manager.recvMsg("Bob", msg));
115  data_stream_assert(Backend::msgSize(msg) == 3lu);
116 
117  DataStreamIter data = Backend::msgData(msg);
118  data_stream_assert(data[0] == (char)i + 1);
119  data_stream_assert(data[1] == (char)i + 2);
120  data_stream_assert(data[2] == (char)i + 3);
121  }
122  ++i;
123  }
124 }
DataStreamType * DataStreamIter

References PGenericSocketManager< _TSocketKey, _TBackend, _TMockBackend >::addClientSocket(), data_stream_assert, PSocketMode::NO_MOCK, and PGenericSocketManager< _TSocketKey, _TBackend, _TMockBackend >::recvMsg().

Referenced by testMockSocketMessage().

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

◆ threadSendData()

void threadSendData ( PSocketMode::PSocketMode  mode,
size_t  nbMessage,
const std::string &  address,
size_t  port 
)

Send messages on socket.

Parameters
mode: mode of the mock to be used
nbMessage: number of message to be sent
address: address of the socket
port: connection port to be used

Definition at line 28 of file main.cpp.

28  {
29  SocketManager manager(mode); //Mock mode
30  data_stream_assert(manager.addServerSocket("Alice",
31  Backend::server(address, port),
32  Mock::server(address, port, true, "./")));
33  data_stream_assert(manager.isConnected("Alice"));
34  for(size_t i(0lu); i < nbMessage; ++i){
35  data_stream_assert(manager.sendData("Alice", i));
36  std::cout << "message n°"<<i<<", Send value " << i << std::endl;
37  }
38 }

References PGenericSocketManager< _TSocketKey, _TBackend, _TMockBackend >::addServerSocket(), data_stream_assert, PGenericSocketManager< _TSocketKey, _TBackend, _TMockBackend >::isConnected(), and PGenericSocketManager< _TSocketKey, _TBackend, _TMockBackend >::sendData().

Referenced by testMockSocket().

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

◆ threadSendMessage()

void threadSendMessage ( PSocketMode::PSocketMode  mode,
size_t  nbMessage,
const std::string &  address,
size_t  port 
)

Send messages on socket.

Parameters
mode: mode of the mock to be used
nbMessage: number of message to be sent
address: address of the socket
port: connection port to be used

Definition at line 80 of file main.cpp.

80  {
81  SocketManager manager(mode); //Mock mode
82  data_stream_assert(manager.addServerSocket("Alice",
83  Backend::server(address, port),
84  Mock::server(address, port, true, "./testMessage")));
85  data_stream_assert(manager.isConnected("Alice"));
86  for(size_t i(0lu); i < nbMessage; ++i){
87  Backend::Message msg;
88  msg.push_back(i + 1);
89  msg.push_back(i + 2);
90  msg.push_back(i + 3);
91 
92  data_stream_assert(manager.sendMsg("Alice", msg));
93  std::cout << "message n°"<<i<<", Send message " << i << std::endl;
94  }
95 }

References PGenericSocketManager< _TSocketKey, _TBackend, _TMockBackend >::addServerSocket(), data_stream_assert, PGenericSocketManager< _TSocketKey, _TBackend, _TMockBackend >::isConnected(), and PGenericSocketManager< _TSocketKey, _TBackend, _TMockBackend >::sendMsg().

Referenced by testMockSocketMessage().

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