blackboard.h
1 /***************************************************************************
2  blackboard.h - description
3  -------------------
4  begin : Mon Jan 24 2007
5  copyright : (C) 2000-2015 by Thies Jochimsen
6  email : thies@jochimsen.de
7  ***************************************************************************/
8 
9 /***************************************************************************
10  * *
11  * This program is free software; you can redistribute it and/or modify *
12  * it under the terms of the GNU General Public License as published by *
13  * the Free Software Foundation; either version 2 of the License, or *
14  * (at your option) any later version. *
15  * *
16  ***************************************************************************/
17 
18 #ifndef RECOBLACKBOARD_H
19 #define RECOBLACKBOARD_H
20 
21 #include <odinreco/odinreco.h>
22 #include <odinreco/data.h>
23 #include <odinreco/step.h>
24 
36 
37  public:
38 
43 
44  ~RecoBlackBoard();
45 
49  void announce(const STD_string& label) {ann[label]++;}
50 
54  void post(const STD_string& label, const RecoData& data);
55 
59  bool announced(const STD_string& label) const {return ann.find(label)!=ann.end();}
60 
66  bool inquire(const STD_string& label, RecoData& data, bool blocking=false);
67 
68 
69  private:
70 
71  bool get_data(const STD_string& label, RecoData& data);
72 
73  // The data on the blackboard
74  typedef STD_map<RecoCoord, RecoData> CoordDataMap;
75  typedef STD_map<STD_string,CoordDataMap> LabelDataMap;
76  LabelDataMap posted;
77 
78  // The events to signal the availability of new data
79  typedef STD_map<RecoCoord, Event*> CoordEventMap;
80  typedef STD_map<STD_string,CoordEventMap> LabelEventMap;
81  LabelEventMap eventmap;
82 
83  Mutex mutex; // Mutex for both maps
84 
85  STD_map<STD_string,UInt> ann;
86 
87 };
88 
89 
93 
95 
96 class RecoPost : public RecoStep {
97 
98  // implementing virtual functions of RecoStep
99  STD_string label() const {return "post";}
100  STD_string description() const {return "Post data on blackboard";}
101  bool process(RecoData& rd, RecoController& controller);
102  RecoCoord input_coord() const {return RecoCoord::any();}
103  void modify_coord(RecoCoord& coord) const {}
104  bool query(RecoQueryContext& context);
105  RecoStep* allocate() const {return new RecoPost;}
106  void init();
107 
108  LDRstring postlabel;
109 
110 };
111 
112 
113 
114 #endif
115 
Definition: tjthread.h:46
static RecoCoord any()
Definition: index.h:219
post: Post data on blackboard
Definition: blackboard.h:95
bool inquire(const STD_string &label, RecoData &data, bool blocking=false)
void post(const STD_string &label, const RecoData &data)
void announce(const STD_string &label)
Definition: blackboard.h:49
bool announced(const STD_string &label) const
Definition: blackboard.h:59