4S Device Communication Module Collection  Version 0.6-SNAPSHOT
Full documentation of the modules in the 4SDC collection (aimed at 4SDC module developers)
FSYS::MsgReceiver< TReceiverClass, TMsg > Class Template Reference

Template class allowing other classes to receive messages. More...

#include <msgreceiver.h>

+ Inheritance diagram for FSYS::MsgReceiver< TReceiverClass, TMsg >:
+ Collaboration diagram for FSYS::MsgReceiver< TReceiverClass, TMsg >:

Public Member Functions

 MsgReceiver (void)
 Constructor for MsgReceiver class. More...
 
 ~MsgReceiver ()
 Destructor for MsgReceiver class. More...
 
- Public Member Functions inherited from FSYS::MsgAddrGenerator< TReceiverClass >
 MsgAddrGenerator (void)
 Constructor that creates an address.
 
 operator MsgAddr & ()
 MsgAddr operator for type conversion of MsgAddrGenerator to a MsgAddr. More...
 

Private Member Functions

TReceiverClass * parentClassPointer ()
 Function to generate a pointer to the parent class. More...
 
void callBack (TMsg &msg)
 Function that does the actually call into the listening class. More...
 
- Private Member Functions inherited from FSYS::MsgCallBackT< TMsg >
void callBack (std::shared_ptr< BaseMsg > &baseMsg)
 callBack function that casts the message to the correct typedef More...
 
- Private Member Functions inherited from FSYS::MsgCallBack
 MsgCallBack (void)
 Default constructor.
 
- Private Member Functions inherited from FSYS::Handle
 Handle (void)
 Default constructor. More...
 
 Handle (Handle &ref)
 Copy constructor for handle object. More...
 
 Handle (const Handle &ref)
 Copy constructor for handle object. More...
 
Handleoperator= (Handle const &theOtherOne)
 
bool operator== (Handle const &compareTo) const
 Equality comparator. More...
 
bool operator!= (Handle const &compareTo) const
 Not equalify operator. More...
 
bool operator> (Handle const &compareTo) const
 Greater than operator ('>') More...
 
bool operator< (Handle const &compareTo) const
 Less than operator ('<') More...
 

Additional Inherited Members

- Static Private Member Functions inherited from FSYS::Handle
static HandlebroadCastHandle (void)
 Generic broadcast handle. More...
 
static Handlenull (void)
 The null handle. More...
 

Detailed Description

template<class TReceiverClass, class TMsg>
class FSYS::MsgReceiver< TReceiverClass, TMsg >

This is the class that other classes can inherit from in order to receive specific messages.

When inheriting from this class you give the parent class and the class of the message that you want to receive as template parameters.

In order to receive a message, the class must inherit from this class and implement a receive function that takes the type of message as parameter.

class MyClass : public MsgReceiver<MyClass, MyMessage>
{
public:
void receive(MyMessage &message);
}

Remember to take a copy of message if you want to use its content later, or want to respond to it.

The receive function will be called in the thread context where the object was initialised, and it is not possible to move it to another thead.

Note
The thread where the object is instantiatet must be a thread that is created in a way that is compatible with the C++11 thread system.
A class can only count on receiving a message if the class is fully constructed and registered with the queue/message system at the time where the message is sent.

It is possible to declare the receive function as virtual if that is desired.

Constructor & Destructor Documentation

template<class TReceiverClass, class TMsg>
FSYS::MsgReceiver< TReceiverClass, TMsg >::MsgReceiver ( void  )
inline

The constructor will register this class with the message system, so it is possible for it to receive messages of the specific type.

template<class TReceiverClass, class TMsg>
FSYS::MsgReceiver< TReceiverClass, TMsg >::~MsgReceiver ( )
inline

The destructor of the MsgReceiver class unregisters this class from the message system, so it won't attempt to call it again.

Member Function Documentation

template<class TReceiverClass, class TMsg>
void FSYS::MsgReceiver< TReceiverClass, TMsg >::callBack ( TMsg &  msg)
inlineprivatevirtual

This function takes the pointer to the listening class and calls the receive function on that class

Parameters
msgA reference to the message that is being received

Implements FSYS::MsgCallBackT< TMsg >.

template<class TReceiverClass, class TMsg>
TReceiverClass* FSYS::MsgReceiver< TReceiverClass, TMsg >::parentClassPointer ( )
inlineprivate

This class uses the pointer to the parent in order to call the receive function on the parent.

Returns
A pointer to the parent class

+ Here is the caller graph for this function:


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