~nrtb-core/nrtb/alpha

« back to all changes in this revision

Viewing changes to cpp/common/ipc_channel/ipc_channel.h

  • Committer: Rick Stovall
  • Date: 2013-11-16 21:09:50 UTC
  • mfrom: (15.1.16 ricks-sprint-003)
  • Revision ID: rick_stovall_fpstovall-20131116210950-riiyz7lv1njccv96
Merging sprint-003. some refactoring, a couple bug fixes, and the interthread communications modules.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/***********************************************
 
2
 This file is part of the NRTB project (https://*launchpad.net/nrtb).
 
3
 
 
4
 NRTB is free software: you can redistribute it and/or modify
 
5
 it under the terms of the GNU General Public License as published by
 
6
 the Free Software Foundation, either version 3 of the License, or
 
7
 (at your option) any later version.
 
8
 
 
9
 NRTB is distributed in the hope that it will be useful,
 
10
 but WITHOUT ANY WARRANTY; without even the implied warranty of
 
11
 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
12
 GNU General Public License for more details.
 
13
 
 
14
 You should have received a copy of the GNU General Public License
 
15
 along with NRTB.  If not, see <http://www.gnu.org/licenses/>.
 
16
 
 
17
 **********************************************/
 
18
 
 
19
#ifndef ipc_channel_header
 
20
#define ipc_channel_header
 
21
 
 
22
#include <common.h>
 
23
#include <linear_queue.h>
 
24
#include <memory>
 
25
#include <singleton.h>
 
26
 
 
27
 
 
28
namespace nrtb
 
29
{
 
30
  
 
31
class abs_ipc_record;
 
32
 
 
33
typedef std::unique_ptr<abs_ipc_record> ipc_record_p;
 
34
 
 
35
typedef linear_queue<ipc_record_p> ipc_queue;
 
36
 
 
37
/** abs_ipc_record is the base for all ipc messages.
 
38
 * This abstract includes a return_address (the
 
39
 * ipc_queue the a return should be put to). but 
 
40
 * no other payload. It'll need to be overriden to 
 
41
 * provide whatever payload a given channel may 
 
42
 * need.
 
43
 */
 
44
class abs_ipc_record
 
45
{
 
46
public:
 
47
  ipc_queue & return_to;
 
48
  abs_ipc_record(ipc_queue & q);
 
49
};
 
50
 
 
51
/** ipc_channel_manager provides a place to stash ipc_queues
 
52
 * so that their scope is not tied to the lifetime of any
 
53
 * particular thread.  Ideally, this should be used as s 
 
54
 * singleton class.
 
55
 */
 
56
class ipc_channel_manager
 
57
{
 
58
public:
 
59
  typedef std::map<std::string,ipc_queue> channel_List;
 
60
  typedef channel_List::iterator iterator;
 
61
  
 
62
  ipc_queue & get(std::string name);
 
63
  iterator begin();
 
64
  iterator end();
 
65
  
 
66
private:
 
67
  channel_List channels;
 
68
};
 
69
 
 
70
/// And here is the singleton class to make ipc channels safe.
 
71
typedef singleton<ipc_channel_manager> global_ipc_channel_manager;
 
72
 
 
73
} // namepace nrtb
 
74
 
 
75
#endif // ipc_channel_header