m2etis  0.4
MessageBuffer.h
Go to the documentation of this file.
1 /*
2  Copyright (2016) Michael Baer, Daniel Bonrath, All rights reserved.
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 
22 #ifndef __M2ETIS_PUBSUB_MESSAGEBUFFER_H__
23 #define __M2ETIS_PUBSUB_MESSAGEBUFFER_H__
24 
25 #include <map>
26 
28 
29 namespace m2etis {
30 namespace pubsub {
31 
32  class MessageBuffer {
33  public:
34  MessageBuffer() : buffer_(), counter(0) {
35  }
36 
37  uint64_t insert(const boost::function<void(void)> & func) {
38  buffer_.insert(std::make_pair(counter, func));
39  return counter++;
40  }
41 
42  void deliver(uint64_t id, msgProcess proc) {
43  assert(buffer_.find(id) != buffer_.end());
44  boost::function<void(void)> p = buffer_[id];
46  buffer_.erase(id);
47  assert(buffer_.find(id) == buffer_.end());
48  }
50  p();
51  }
52  }
53 
54  private:
55  std::map<uint64_t, boost::function<void(void)>> buffer_;
56  uint64_t counter;
57  };
58 
59 } /* namespace pubsub */
60 } /* namespace m2etis */
61 
62 #endif /* __M2ETIS_PUBSUB_MESSAGEBUFFER_H__ */
63 
void deliver(uint64_t id, msgProcess proc)
Definition: MessageBuffer.h:42
uint64_t insert(const boost::function< void(void)> &func)
Definition: MessageBuffer.h:37