Nymph  v1.5.2
Flow-Based Data Processing Framework
KTProcessorToolbox.hh
Go to the documentation of this file.
1 
9 #ifndef KTPROCESSORTOOLBOX_HH_
10 #define KTPROCESSORTOOLBOX_HH_
11 
12 #include "KTConfigurable.hh"
13 
14 #include <deque>
15 #include <initializer_list>
16 #include <limits>
17 #include <set>
18 
19 namespace Nymph
20 {
21  class KTPrimaryProcessor;
22  class KTProcessor;
23 
72  {
73  public:
74  KTProcessorToolbox(const std::string& name = "processor-toolbox");
75  virtual ~KTProcessorToolbox();
76 
77  public:
79  bool Configure(const scarab::param_node& node);
80 
82  bool ConfigureProcessors(const scarab::param_node& node);
84  bool ConfigureProcessors(const std::string& config);
85 
86 
87  public:
90  bool Run();
91 
92 
93  private:
95  {
97  };
98  typedef std::map< std::string, ProcessorInfo > ProcessorMap;
99  typedef ProcessorMap::iterator ProcMapIt;
100  typedef ProcessorMap::const_iterator ProcMapCIt;
101  typedef ProcessorMap::value_type ProcMapValue;
102 
103  public:
105  KTProcessor* GetProcessor(const std::string& procName);
107  const KTProcessor* GetProcessor(const std::string& procName) const;
108 
111  bool AddProcessor(const std::string& procName, KTProcessor* proc);
112  bool AddProcessor(const std::string& procType, const std::string& procName);
113 
115  bool RemoveProcessor(const std::string& procName);
116 
119  KTProcessor* ReleaseProcessor(const std::string& procName);
120 
123  void ClearProcessors();
124 
125  private:
126  ProcessorMap fProcMap;
127 
128 
129  public:
133  bool MakeConnection(const std::string& signal, const std::string& slot, int order = std::numeric_limits< int >::min());
134 
137  bool MakeConnection(const std::string& signalProcName, const std::string& signalName, const std::string& slotProcName, const std::string& slotName, int order = std::numeric_limits< int >::min());
138 
139  private:
140  bool ParseSignalSlotName(const std::string& toParse, std::string& nameOfProc, std::string& nameOfSigSlot) const;
141  static const char fSigSlotNameSep = ':';
142 
143 
144  public:
146  bool PushBackToRunQueue(const std::string& name);
147 
149  bool PushBackToRunQueue(std::initializer_list< std::string > names);
151  bool PushBackToRunQueue(std::vector< std::string > names);
152 
154  void PopBackOfRunQueue();
155 
157  void ClearRunQueue();
158 
159  private:
160  struct Thread
161  {
163  std::string fName;
164  Thread(KTPrimaryProcessor* proc, const std::string& name) : fProc(proc), fName(name)
165  {}
166  };
167  //typedef std::set< KTPrimaryProcessor* > ThreadGroup;
169  {
170  bool operator() (const Thread& lhs, const Thread& rhs) const
171  {
172  return lhs.fName < rhs.fName;
173  }
174  };
175  typedef std::set< Thread, CompareThread > ThreadGroup;
176  typedef std::deque< ThreadGroup > RunQueue;
177  bool AddProcessorToThreadGroup(const std::string& name, ThreadGroup& group);
178 
179  RunQueue fRunQueue;
180 
181  };
182 
184  {
185  fRunQueue.pop_back();
186  return;
187  }
188 
190  {
191  fRunQueue.clear();
192  return;
193  }
194 
195 } /* namespace Nymph */
196 #endif /* KTPROCESSORTOOLBOX_HH_ */
KTProcessor * ReleaseProcessor(const std::string &procName)
void ClearRunQueue()
Clear the run queue.
ProcessorMap::iterator ProcMapIt
Manages processors requested by the user at run time.
std::deque< ThreadGroup > RunQueue
KTProcessor * GetProcessor(const std::string &procName)
Get a pointer to a processor in the toolbox.
ProcessorMap::value_type ProcMapValue
bool AddProcessorToThreadGroup(const std::string &name, ThreadGroup &group)
bool AddProcessor(const std::string &procName, KTProcessor *proc)
ProcessorMap::const_iterator ProcMapCIt
bool ParseSignalSlotName(const std::string &toParse, std::string &nameOfProc, std::string &nameOfSigSlot) const
bool PushBackToRunQueue(const std::string &name)
Push a single processor to the back of the run queue.
Thread(KTPrimaryProcessor *proc, const std::string &name)
std::map< std::string, ProcessorInfo > ProcessorMap
bool ConfigureProcessors(const scarab::param_node &node)
Configure processors (only those specified in the toolbox)
void PopBackOfRunQueue()
Remove the last item in the run queue, whether it&#39;s a single processor or a group of processors...
bool Configure(const scarab::param_node &node)
Configure the toolbox: create the processors; connnect signals and slots; and setup the run queue...
bool MakeConnection(const std::string &signal, const std::string &slot, int order=std::numeric_limits< int >::min())
KTProcessorToolbox(const std::string &name="processor-toolbox")
bool RemoveProcessor(const std::string &procName)
Remove a processor from the toolbox.
std::set< Thread, CompareThread > ThreadGroup
static const char fSigSlotNameSep