Nymph  v1.5.2
Flow-Based Data Processing Framework
KTProcessor.cc
Go to the documentation of this file.
1 /*
2  * KTProcessor.cc
3  *
4  * Created on: Jan 5, 2012
5  * Author: nsoblath
6  */
7 
8 #include "KTProcessor.hh"
9 
10 //#include "KTLogger.hh"
11 
12 #include <boost/foreach.hpp>
13 
14 #include <string>
15 
16 using std::string;
17 
18 namespace Nymph
19 {
20  //KTLOGGER(proclog, "KTProcessor");
21 
22  ProcessorException::ProcessorException (std::string const& why)
23  : std::logic_error(why)
24  {}
25 
26 
27  KTProcessor::KTProcessor(const string& name) :
28  KTConfigurable(name),
29  fSignalMap(),
30  fSlotMap()
31  {
32  }
33 
35  {
36  for (SlotMapIt iter = fSlotMap.begin(); iter != fSlotMap.end(); iter++)
37  {
38  iter->second->Disconnect();
39  delete iter->second;
40  }
41  for (SigMapIt iter = fSignalMap.begin(); iter != fSignalMap.end(); iter++)
42  {
43  delete iter->second;
44  }
45  }
46 
47  void KTProcessor::ConnectASlot(const std::string& signalName, KTProcessor* processor, const std::string& slotName, int groupNum)
48  {
49  KTSignalWrapper* signal = GetSignal(signalName);
50  KTSlotWrapper* slot = processor->GetSlot(slotName);
51 
52  try
53  {
54  ConnectSignalToSlot(signal, slot, groupNum);
55  }
56  catch (std::exception& e)
57  {
58  string errorMsg = string("Exception caught in KTProcessor::ConnectASignal; signal: ") +
59  signalName + string(", slot: ") + slotName + string("\n") + e.what() + string("\n") +
60  string("\tIf the signal wrapper cannot be cast correctly, check that the signatures of the signal and slot match exactly.\n") +
61  string("\tIf the signal pointer is NULL, you may have the signal name wrong.\n") +
62  string("\tIf the slot pointer is NULL, you may have the slot name wrong.");
63  throw std::logic_error(errorMsg);
64  }
65  KTDEBUG(processorlog, "Connected signal <" << signalName << "> to slot <" << slotName << ">");
66 
67  return;
68  }
69 
70  void KTProcessor::ConnectASignal(KTProcessor* processor, const std::string& signalName, const std::string& slotName, int groupNum)
71  {
72  KTSignalWrapper* signal = processor->GetSignal(signalName);
73  KTSlotWrapper* slot = GetSlot(slotName);
74 
75  try
76  {
77  ConnectSignalToSlot(signal, slot, groupNum);
78  }
79  catch (std::exception& e)
80  {
81  string errorMsg = string("Exception caught in KTProcessor::ConnectASignal; signal: ") +
82  signalName + string(", slot: ") + slotName + string("\n") + e.what() + string("\n") +
83  string("Check that the signatures of the signal and slot match exactly.");
84  throw std::logic_error(errorMsg);
85  }
86  KTDEBUG(processorlog, "Connected slot <" << signalName << "> to signal <" << slotName << ">");
87 
88  return;
89  }
90 
92  {
93  if (signal == NULL)
94  {
95  throw ProcessorException("Signal pointer was NULL");
96  }
97  if (slot == NULL)
98  {
99  throw ProcessorException("Slot pointer was NULL");
100  }
101 
102  slot->SetConnection(signal, groupNum);
103 
104  return;
105  }
106 
107  KTSignalWrapper* KTProcessor::GetSignal(const std::string& name)
108  {
109  SigMapIt iter = fSignalMap.find(name);
110  if (iter == fSignalMap.end())
111  {
112  return NULL;
113  }
114  return iter->second;
115  }
116 
117  KTSlotWrapper* KTProcessor::GetSlot(const std::string& name)
118  {
119  SlotMapIt iter = fSlotMap.find(name);
120  if (iter == fSlotMap.end())
121  {
122  return NULL;
123  }
124  return iter->second;
125  }
126 
127 
128 
129 } /* namespace Nymph */
KTSignalWrapper * GetSignal(const std::string &name)
Definition: KTProcessor.cc:107
SignalMap fSignalMap
Definition: KTProcessor.hh:79
STL namespace.
void ConnectASignal(KTProcessor *processor, const std::string &signalName, const std::string &slotName, int groupNum=-1)
Definition: KTProcessor.cc:70
Contains KTProcessor.
void SetConnection(KTConnection conn)
SignalMap::iterator SigMapIt
Definition: KTProcessor.hh:44
#define KTDEBUG(...)
Definition: KTLogger.hh:343
void ConnectASlot(const std::string &signalName, KTProcessor *processor, const std::string &slotName, int groupNum=-1)
Definition: KTProcessor.cc:47
ProcessorException(std::string const &why)
Definition: KTProcessor.cc:22
void ConnectSignalToSlot(KTSignalWrapper *signal, KTSlotWrapper *slot, int groupNum=-1)
Definition: KTProcessor.cc:91
KTSlotWrapper * GetSlot(const std::string &name)
Definition: KTProcessor.cc:117
SlotMap::iterator SlotMapIt
Definition: KTProcessor.hh:48
virtual ~KTProcessor()
Definition: KTProcessor.cc:34
KTProcessor(const std::string &name="default-proc-name")
Definition: KTProcessor.cc:27