Skip to content
Snippets Groups Projects
phoenix_mock_socket.cpp 2.03 KiB
Newer Older
Pierre Aubert's avatar
Pierre Aubert committed
/***************************************
	Auteur : Pierre Aubert
	Mail : pierre.aubert@lapp.in2p3.fr
	Licence : CeCILL-C
****************************************/

#include <sstream>
#include "phoenix_mock_socket.h"

///Create a mock socket
/**	@param[out] vecInput : vector of input message to be read
 * 	@param[out] inputFileName : name of the input message file to be loaded
 * 	@param[out] outputFileName : name of the output message file to be written
 * 	@param address : host address
 * 	@param port : port to be used
 * 	@return true on success, false otherwise
*/
bool phoenix_createMockSocket(PVecMockMessage & vecInput, std::string & inputFileName, std::string & outputFileName, const std::string & address, size_t port){
	std::stringstream strFileName;
	strFileName << address << "_" << port << "_";
	std::string baseFileName(strFileName.str());
// 	inputFileName = baseFileName + "_recv.pmocksocket";
// 	outputFileName = baseFileName + "_send.pmocksocket";
	
	inputFileName = baseFileName + ".pmocksocket";
	outputFileName = baseFileName + ".pmocksocket";
	
	data_load(inputFileName, vecInput);
	return true;
}

///Read a mock socket
/**	@param[out] vecInput : vector of input message to be read
 * 	@param address : host address
 * 	@param port : port to be used
 * 	@return true on success, false otherwise
*/
bool phoenix_readMockSocket(PVecMockMessage & vecInput, const std::string & address, size_t port){
	std::stringstream strFileName;
	strFileName << address << "_" << port << "_";
	std::string baseFileName(strFileName.str());
	
	std::string inputFileName = baseFileName + ".pmocksocket";
	
	return data_load(inputFileName, vecInput);
}

Pierre Aubert's avatar
Pierre Aubert committed
///Close a mock socket
/**	@param vecOutput : vector of output messages to be saved
 * 	@param outputFileName : name of the output message file to be written
 * 	@return true on success, false otherwise
*/
bool phoenix_closeMockSocket(const PVecMockMessage & vecOutput, const std::string & outputFileName){
	if(vecOutput.size() != 0lu){
		return data_save(outputFileName, vecOutput);
	}else{
		return true;
	}
}