* The declaration of this class can be found in the SRTMinorServoTestingSocket.h header file.
* Instructions on how to use this for testing purposes can be found there as well.
*/
classSRTMinorServoTestingSocket;
classSRTMinorServoSocket:publicIRA::CSocket
{
/**
* This class implements a singleton socket. The singleton pattern was necessary to provide each servo system component communication capabilities with the Leonardo system.
* As long as all the said components run on the same container this will only be instanced once.
*/
/**
* Declare the testing classes as friend classes in order for them to have access to destroyInstance for testing purposes
*/
friendclass::SRTMinorServoSocketTest;
friendclass::SRPProgramTrackTest;
friendclass::DerotatorProgramTrackTest;
friendclass::CombinedProgramTrackTest;
friendclass::ReadStatusOnlyTest;
public:
/**
* Calls the constructor and returns the singleton socket instance
* @param ip_address the IP address to which the socket will connect
* @param port the port to which the socket will connect
* @param timeout the timeout, in seconds, for the communication to be considered failed
* @throw MinorServoErrors::CommunicationErrorExImpl when the user calls this method a second time with different IP address and port arguments
* @throw MinorServoErrors::MinorServoErrorsEx when the user calls this method a second time with different IP address and port arguments (non testing mode)
* This class is a friend class of SRTMinorServoSocket. It can be used for testing purposes without altering the behavior of the original class.
* Instructions on how to use this class inside tests:
* 1) Declare the test class with a forward declaration
* 2) Define the FRIEND_CLASS_DECLARATION macro
* 3) Include this header file
* 4) Finally implement the test class
* Example:
*
* ...
* class TestClass;
* #define FRIEND_CLASS_DECLARATION friend class ::TestClass;
* #include "SRTMinorServoTestingSocket.h"
*
* class TestClass : public ::testing::Test
* {
* ...
*/
/**
* This is a macro that each test file will have to define prior to including this header file.
* It can be a single or multiple lines each one containing a friend class declaration.
*/
FRIEND_CLASS_DECLARATION;
public:
/**
* Ovverride of the original SRTMinorServoSocket getInstance methods. Before doing anything, they set the c_testing variable of the original class to true.
* This changes how the exceptions are thrown.
* In non testing purposes, exceptions are thrown as MinorServoErrorsEx
* In testing purposes, exceptions are thrown as they are (ExImpl)
* This change in behavior allow for better testing and debugging purposes, while still allowing the socket to throw the base MinorServoErrorsEx when not used in testing purposes.
* This allow us to avoid catching exceptions in the component, since MinorServoErrorsEx are already captured by CORBA
* This method explicitly destroys the singleton socket instance.
* Each test in the same test file is executed under the same process, therefore a singleton instance that does not get destroyed will still exist in the next executed tests.
* We want to test a new instance of the socket every time, therefore the existence of this method is critical.
impl.setReason(("Socket already open on '"+m_instance->m_ip_address+":"+std::to_string(m_instance->m_port)+"' . Use getInstance() (no arguments) to retrieve the object.").c_str());