PhoenixSocket  4.0.1
Library which integrates socket unix use in Phoenix
Loading...
Searching...
No Matches
PMockSocketFile Class Reference

Example of a mock socket with vector of messages. More...

#include <PMockBackendFile.h>

+ Collaboration diagram for PMockSocketFile:

Public Types

typedef DataStreamMsg Message
 Define the type of message used by the PAbstractSocketManager.
 
typedef PMockParamFile Param
 Define the type of extra parameters which can be used to create a Socket used by the PAbstractSocketManager.
 

Public Member Functions

void close ()
 Close the PMockSocketFile.
 
bool createClientSocket (const PSocketParam &socketParam, const Param &extraParam)
 Initialise a client socket.
 
bool createServerSocket (const PSocketParam &socketParam, const Param &extraParam)
 Initialise a server socket.
 
bool isConnected () const
 Say if the PMockSocketFile is connected.
 
 PMockSocketFile ()
 Default constructor of hte PMockSocketFile.
 
template<typename T>
PRecvStatus::PRecvStatus recvData (T &data, PRecvFlag::PRecvFlag flag)
 Recieved data with the socket.
 
PRecvStatus::PRecvStatus recvMsg (Message &msg, PRecvFlag::PRecvFlag flag)
 Recieved data with the socket.
 
template<typename T>
PSendStatus::PSendStatus sendData (const T &data, PSendFlag::PSendFlag flag)
 Send data with the socket.
 
PSendStatus::PSendStatus sendMsg (const Message &msg, PSendFlag::PSendFlag flag)
 Specialisation to send a Message with the socket.
 
void setIsMockRecord (bool isMockRecord)
 Set the mock prefix (where to find/save it)
 
void setMockPrefix (const std::string &mockPrefix)
 Set the mock prefix (where to find/save it)
 
virtual ~PMockSocketFile ()
 Default destructor of hte PMockSocketFile.
 

Private Attributes

Param p_extraParam
 Extra parameters of the socket.
 
PGenericFileMock< DataStreamMsg > p_mock
 Mock handler.
 
PSocketParam p_socketParam
 Parameters of the socket.
 

Detailed Description

Example of a mock socket with vector of messages.

Definition at line 17 of file PMockBackendFile.h.

Member Typedef Documentation

◆ Message

typedef DataStreamMsg PMockSocketFile::Message

Define the type of message used by the PAbstractSocketManager.

Definition at line 20 of file PMockBackendFile.h.

◆ Param

Define the type of extra parameters which can be used to create a Socket used by the PAbstractSocketManager.

Definition at line 22 of file PMockBackendFile.h.

Constructor & Destructor Documentation

◆ PMockSocketFile()

PMockSocketFile::PMockSocketFile ( )

Default constructor of hte PMockSocketFile.

Definition at line 27 of file PMockBackendFile.cpp.

27 {
28
29}

◆ ~PMockSocketFile()

PMockSocketFile::~PMockSocketFile ( )
virtual

Default destructor of hte PMockSocketFile.

Definition at line 32 of file PMockBackendFile.cpp.

32 {
33
34}

Member Function Documentation

◆ close()

void PMockSocketFile::close ( )

Close the PMockSocketFile.

Definition at line 111 of file PMockBackendFile.cpp.

111 {
112 p_mock.close();
113}
PGenericFileMock< DataStreamMsg > p_mock
Mock handler.

References p_mock.

◆ createClientSocket()

bool PMockSocketFile::createClientSocket ( const PSocketParam & socketParam,
const Param & extraParam )

Initialise a client socket.

Parameters
socketParam: parameters to be use to initialise the socket (hostname, port, etc)
extraParam: extra customisable parameters for the creation of the socket (depends on the backend)

Definition at line 40 of file PMockBackendFile.cpp.

40 {
41 p_socketParam = socketParam;
42 p_extraParam = extraParam;
43 return true;
44}
Param p_extraParam
Extra parameters of the socket.
PSocketParam p_socketParam
Parameters of the socket.

References p_extraParam, and p_socketParam.

Referenced by PMockBackendFile::createClientSocket(), createServerSocket(), and phoenix_createMockBackend().

+ Here is the caller graph for this function:

◆ createServerSocket()

bool PMockSocketFile::createServerSocket ( const PSocketParam & socketParam,
const Param & extraParam )

Initialise a server socket.

Parameters
socketParam: parameters to be use to initialise the socket (hostname, port, etc)
extraParam: extra customisable parameters for the creation of the socket (depends on the backend)

Definition at line 50 of file PMockBackendFile.cpp.

50 {
51 return createClientSocket(socketParam, extraParam);
52}
bool createClientSocket(const PSocketParam &socketParam, const Param &extraParam)
Initialise a client socket.

References createClientSocket().

+ Here is the call graph for this function:

◆ isConnected()

bool PMockSocketFile::isConnected ( ) const

Say if the PMockSocketFile is connected.

Returns
true if the PMockSocketFile is connected, false otherwise

Definition at line 106 of file PMockBackendFile.cpp.

106 {
107 return true;
108}

◆ recvData()

template<typename T>
PRecvStatus::PRecvStatus PMockSocketFile::recvData ( T & data,
PRecvFlag::PRecvFlag flag )

Recieved data with the socket.

Parameters
[out]data: data to be recieved with the socket
flag: recieving flag (BLOCK, NON_BLOCK)
Returns
status of the recv

Definition at line 52 of file PMockBackendFile_impl.h.

52 {
55 recvStatus = recvMsg(msg, flag);
56 //If the message is empty we cannot initialise the given data, so, this is an error
57 if(msg.size() != 0lu){
58 DataStreamIter iter = (DataStreamIter)msg.data();
59 if(!data_message_load<T>(iter, data)){
61 }
62 }else{
64 }
65 return recvStatus;
66}
PRecvStatus::PRecvStatus recvMsg(Message &msg, PRecvFlag::PRecvFlag flag)
Recieved data with the socket.
DataStreamMsg Message
Define the type of message used by the PAbstractSocketManager.
PRecvStatus
describe the result of the recv
Definition PSocketFlag.h:52
@ CANNOT_DESERIALIZE_DATA
Definition PSocketFlag.h:60
@ NO_MESSAGE_RECEIVED
Definition PSocketFlag.h:54

References PRecvStatus::CANNOT_DESERIALIZE_DATA, PRecvStatus::NO_MESSAGE_RECEIVED, PRecvStatus::OK, and recvMsg().

+ Here is the call graph for this function:

◆ recvMsg()

PRecvStatus::PRecvStatus PMockSocketFile::recvMsg ( PMockSocketFile::Message & msg,
PRecvFlag::PRecvFlag flag )

Recieved data with the socket.

Parameters
[out]msg: Message to be recieved with the socket
flag: recieving flag (BLOCK, NON_BLOCK)
Returns
status of the recv

Definition at line 89 of file PMockBackendFile.cpp.

89 {
90 if(p_mock.getIsRecord()){
91 p_mock.append(msg);
92 return PRecvStatus::OK;
93 }else{
94 p_mock.getCurrentValue(msg);
95 if(msg.size() == 0lu){ //If the message is empty, it is not received
97 }else{
98 return PRecvStatus::OK;
99 }
100 }
101}

References PRecvStatus::NO_MESSAGE_RECEIVED, PRecvStatus::OK, and p_mock.

Referenced by recvData().

+ Here is the caller graph for this function:

◆ sendData()

template<typename T>
PSendStatus::PSendStatus PMockSocketFile::sendData ( const T & data,
PSendFlag::PSendFlag flag )

Send data with the socket.

Parameters
data: data to be sent with the socket
flag: sending flag (BLOCK, NON_BLOCK)
Returns
status of the send

Definition at line 18 of file PMockBackendFile_impl.h.

18 {
19 if(p_mock.getIsRecord()){
20 size_t dataSize(data_size<T>(data));
23 msg.resize(dataSize);
24 DataStreamIter iter = (DataStreamIter)msg.data();
25 if(data_message_save<T>(iter, data)){ //Save the message
26 sendStatus = sendMsg(msg, flag);
27 }else{
29 }
30 return sendStatus;
31 }else{
32 T referenceData;
33 PMockSocketFile::Message referenceMsg;
34 p_mock.getCurrentValue(referenceMsg); //Let's get the reference message
35 if(referenceMsg.size() != 0lu){
36 DataStreamIter iter = (DataStreamIter)referenceMsg.data();
37 check_stream_assert(data_message_load<T>(iter, referenceData));
38 std::stringstream index;
39 index << p_mock.getCurrentIndex();
40 check_stream_assert(phoenix_check_stream("mock '"+p_mock.getFileName()+"', [mock index = "+index.str()+"]", data, referenceData));
41 }
42 return PSendStatus::OK;
43 }
44}
PSendStatus::PSendStatus sendMsg(const Message &msg, PSendFlag::PSendFlag flag)
Specialisation to send a Message with the socket.
PSendStatus
describe the result of the send
Definition PSocketFlag.h:25
@ CANNOT_SERIALIZE_DATA
Definition PSocketFlag.h:32

References PSendStatus::CANNOT_SERIALIZE_DATA, PSendStatus::OK, p_mock, and sendMsg().

+ Here is the call graph for this function:

◆ sendMsg()

PSendStatus::PSendStatus PMockSocketFile::sendMsg ( const Message & msg,
PSendFlag::PSendFlag flag )

Specialisation to send a Message with the socket.

Parameters
msg: Message to be sent
flag: sending flag (BLOCK, NON_BLOCK)
Returns
status of the send

Definition at line 75 of file PMockBackendFile.cpp.

75 {
76 if(p_mock.getIsRecord()){
77 p_mock.append(msg);
78 }else{
79 check_stream_assert(p_mock.checkCurrentValue("PMockSocketFile::sendMsg", msg));
80 }
81 return PSendStatus::OK;
82}

References PSendStatus::OK, and p_mock.

Referenced by sendData().

+ Here is the caller graph for this function:

◆ setIsMockRecord()

void PMockSocketFile::setIsMockRecord ( bool isMockRecord)

Set the mock prefix (where to find/save it)

Parameters
isMockRecord: true if the mock has to be recorded

Definition at line 66 of file PMockBackendFile.cpp.

66 {
67 p_mock.setIsRecord(isMockRecord);
68}

References p_mock.

Referenced by phoenix_createMockBackend().

+ Here is the caller graph for this function:

◆ setMockPrefix()

void PMockSocketFile::setMockPrefix ( const std::string & mockPrefix)

Set the mock prefix (where to find/save it)

Parameters
mockPrefix: prefix of the mock to find or write it

Definition at line 57 of file PMockBackendFile.cpp.

57 {
58 std::stringstream socketFileName;
59 socketFileName << mockPrefix << p_socketParam.hostname << "_" << p_socketParam.port << ".pmockbackend";
60 p_mock.setFileName(socketFileName.str());
61}

References p_mock, and p_socketParam.

Referenced by phoenix_createMockBackend().

+ Here is the caller graph for this function:

Member Data Documentation

◆ p_extraParam

Param PMockSocketFile::p_extraParam
private

Extra parameters of the socket.

Definition at line 49 of file PMockBackendFile.h.

Referenced by createClientSocket().

◆ p_mock

PGenericFileMock<DataStreamMsg> PMockSocketFile::p_mock
private

Mock handler.

Definition at line 45 of file PMockBackendFile.h.

Referenced by close(), recvMsg(), sendData(), sendMsg(), setIsMockRecord(), and setMockPrefix().

◆ p_socketParam

PSocketParam PMockSocketFile::p_socketParam
private

Parameters of the socket.

Definition at line 47 of file PMockBackendFile.h.

Referenced by createClientSocket(), and setMockPrefix().


The documentation for this class was generated from the following files: