4S Device Communication Module Collection  Version 0.6-SNAPSHOT
Full documentation of the modules in the 4SDC collection (aimed at 4SDC module developers)
msgaddrgenerator.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 
33 #ifndef MSGADDRGENERATOR_H
34 #define MSGADDRGENERATOR_H
35 
36 #include "handle.h"
37 #include "msgaddr.h"
38 #include "msgqueue.h"
39 
40 namespace FSYS
41 {
50 template<class T> class MsgAddrGenerator : private virtual Handle
51 {
52 private:
57 
63  inline void *generateMagicKey( void )
64  {
65  //return static_cast<T*>(this);
66  return this;
67  }
68 
72  inline void ensureInit( void )
73  {
74  msgAddr.magicKey = generateMagicKey();
75  }
76 
77  inline MsgAddr &GetAddr( void )
78  {
79  ensureInit();
80  return msgAddr;
81  }
82 
83 public:
88  : msgAddr(*this, MsgQueue::getHandle(), nullptr)
89  {
90 
91  }
92 
99 // inline operator MsgAddr()
100 // {
101 // return GetAddr();
102 // }
103 
110  inline operator MsgAddr&()
111  {
112  return GetAddr();
113  }
114 
115 };
116 
117 }
118 
119 #endif // MSGADDRGENERATOR_H
void ensureInit(void)
Function ensuring that the address is generated.
Definition: msgaddrgenerator.h:72
Contains interface for a message address.
This is a wrapper class for the class that does all the hard work.
Definition: msgqueue.h:69
Contains interface declaration for the FSYS::Handle class.
MsgAddr msgAddr
The address stored in this handle.
Definition: msgaddrgenerator.h:56
Definition: basemsg.h:38
void * magicKey
The magic key of objecjt this is the address of.
Definition: msgaddr.h:73
Contains interface declaration for the FSYS::MsgQueue class.
MsgAddrGenerator(void)
Constructor that creates an address.
Definition: msgaddrgenerator.h:87
void * generateMagicKey(void)
Generates the magic key for T.
Definition: msgaddrgenerator.h:63
The MsgAddr class contains a unique address in the message system.
Definition: msgaddr.h:52