PeerReader         PeerOS - Message handler
Print

PeerReader is also known as the 'handler' of the message. This should be the class to take action upon the message you are publishing.

Example Class

If you want to handle existing messages in a new way, you'll extend the PeerReader class. For instance, here is a class which handles messages of the CM_Camera type.

class CMRead_Camera :
    public ImaginaryOgre3DCameraClass,
    public PeerReader<CM_Camera>
  {
  public:
    virtual ~CMRead_Camera() { }
    virtual void process(CM_Camera *_msg)
    {
        std::cout << "Camera message at ("
                << _msg->getPos(0) << ", " 
                << _msg->getPos(1) << ", " 
                << _msg->getPos(2) << ") successfully processed!\n";
    }
  };

 

Example Implementation

 

CMRead_Camera_Logging camloggger;
  CM_Camera	msg;		// The conversation
  keyb.Subscribe(cam, msg);	// Now observes sub for 'msg' conversation topics

 

Handling Multiple Messages

This is as easy as adding another PeerReader and another process() function:

class CMRead_Camera :
    public ImaginaryOgre3DCameraClass,
    public PeerReader<CM_Camera>,
    '''public PeerReader<CM_SomeOtherClass>'''
  {
  public:
    virtual ~CMRead_Camera() { }
    virtual void process(CM_Camera *_msg)
    {
        std::cout << "Camera message at ("
                << _msg->getPos(0) << ", " 
                << _msg->getPos(1) << ", " 
                << _msg->getPos(2) << ") successfully processed!\n";
    }
    virtual void process('''CM_SomeOtherClass''' *_msg)
    {
        _msg->someFancyCall();
        _msg->someFancyCall2( m_somePrivateVariableOfMine );
    }
  };

 


Contributors to this page: jacmoe133512 points  .
Page last modified on Sunday 03 of January, 2010 00:41:52 UTC by jacmoe133512 points .


The content on this page is licensed under the terms of the Creative Commons Attribution-ShareAlike License.
As an exception, any source code contributed within the content is released into the Public Domain.