4S Device Communication Module Collection  Version 0.6-SNAPSHOT
Full documentation of the modules in the 4SDC collection (aimed at 4SDC module developers)
msgreceiver.h
Go to the documentation of this file.
1 /*
2  * Copyright 2014-2015 The 4S Foundation (www.4s-online.dk)
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
31 #ifndef MSGRECEIVER_H
32 #define MSGRECEIVER_H
33 
34 #include "msgaddrgenerator.h"
35 #include "msgcallback.h"
36 #include "msgqueue.h"
37 
38 namespace FSYS
39 {
78  template<class TReceiverClass, class TMsg> class MsgReceiver : private MsgCallBackT<TMsg>,
79  public virtual MsgAddrGenerator<TReceiverClass>
80  {
81  public:
88  MsgReceiver( void )
89  {
90  // Register this object on the listener queue of this thread
91  MsgAddr destination = *this;
92  MsgQueue::addListenerToQueue(destination,
93  typeid(TMsg),
94  this);
95  }
96 
104  {
105  // Remove this object for the listener queue
107  }
108 
109  private:
118  TReceiverClass* parentClassPointer()
119  {
120  return static_cast<TReceiverClass*>(this);
121  }
122 
131  void callBack(TMsg &msg)
132  {
133  parentClassPointer()->receive(msg);
134  }
135  };
136 }
137 
138 #endif // MSGRECEIVER_H
Constructor to MsgAddrGenerator object.
Definition: msgaddr.h:43
Template class allowing other classes to receive messages.
Definition: msgreceiver.h:78
MsgReceiver(void)
Constructor for MsgReceiver class.
Definition: msgreceiver.h:88
static void removeListenerFromQueue(MsgCallBack *msgCallBack)
Function that unregisters a listener from the message queue.
Definition: msgqueue.cpp:44
Definition: basemsg.h:38
Contains interface declaration for the FSYS::MsgCallBack class.
~MsgReceiver()
Destructor for MsgReceiver class.
Definition: msgreceiver.h:103
TReceiverClass * parentClassPointer()
Function to generate a pointer to the parent class.
Definition: msgreceiver.h:118
static void addListenerToQueue(MsgAddr &receiverAddr, const std::type_info &typeOfMsg, MsgCallBack *msgCallBack)
Function that registers a listener to the message queue.
Definition: msgqueue.cpp:35
Contains interface declaration for the FSYS::MsgQueue class.
void callBack(TMsg &msg)
Function that does the actually call into the listening class.
Definition: msgreceiver.h:131
Contains interface for a message address generator class.
Template class that inherits from MsgCallBack.
Definition: msgcallback.h:79
The MsgAddr class contains a unique address in the message system.
Definition: msgaddr.h:52