00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025 #ifndef _Controller_
00026 #define _Controller_
00027
00028 #include "OutControl.hxx"
00029 #include "OutControlArray.hxx"
00030 #include "Processing.hxx"
00031 #include "ProcessingData.hxx"
00032
00033 #include <typeinfo>
00034 #include <string>
00035 #include <vector>
00036 #include <queue>
00037
00038 #include "Mutex.hxx"
00039
00040 namespace CLAM {
00041
00043
00048 class ControllerConfig : public ProcessingConfig
00049 {
00050 public:
00051 DYNAMIC_TYPE_USING_INTERFACE (ControllerConfig, 3, ProcessingConfig);
00052 DYN_ATTRIBUTE (0, public, unsigned, NumControls);
00053 DYN_CONTAINER_ATTRIBUTE (1, public, std::vector<TControlData>, MinValues, foo);
00054 DYN_CONTAINER_ATTRIBUTE (2, public, std::vector<TControlData>, MaxValues, foo);
00055 protected:
00059 void DefaultInit(void)
00060 {
00061 AddAll();
00062 UpdateData();
00063 SetNumControls(0);
00064 }
00065 };
00067
00077 class Controller : public Processing
00078 {
00079 public:
00080 Controller ();
00081 Controller(const ControllerConfig& c)
00082 {
00083 Configure(c);
00084 }
00085
00086 const char *GetClassName() const {return "Controller";}
00087
00088 bool Do()
00089 {
00090 IdxList::iterator ListIt;
00091
00092 Mutex::ScopedLock lock( mControllerDoMutex );
00093
00094 IdxList qs = getQueues();
00095
00096 if (!qs.empty())
00097 {
00098 for (ListIt=qs.begin();ListIt!=qs.end() ;ListIt++ )
00099 {
00100 TControlData val = PopControl( (*ListIt) );
00101 OutControls[(*ListIt)].SendControl(val);
00102 OutValues[(*ListIt)] = val;
00103 }
00104 }
00105
00106
00107 return true;
00108 }
00109
00110 const ProcessingConfig& GetConfig() const;
00111 virtual bool ConcreteConfigure(const ProcessingConfig&);
00112
00113
00114
00116 void EnqueueControl(unsigned id, TControlData data);
00117 TControlData LastDequeuedValue(unsigned id);
00118
00119 OutControlArray OutControls;
00120 std::vector<TControlData> OutValues;
00121 private:
00122 ControllerConfig mConfig;
00123
00124 TControlData PopControl(unsigned id);
00125 bool Empty(unsigned id);
00126
00127 typedef std::queue<TControlData> TQueue;
00128 typedef std::list<int> IdxList;
00129
00130 std::vector<TQueue> mDataQueues;
00131
00132 void BufferQueueInit( int ncontrols );
00133
00134 IdxList getQueues()
00135 {
00136 IdxList modifiedQs;
00137 std::vector<TQueue>::iterator it;
00138
00139 int k = 0;
00140 for (it=mDataQueues.begin(); it != mDataQueues.end() ; it++ )
00141 {
00142 if (!(*it).empty())
00143 {
00144 modifiedQs.push_back(k);
00145 }
00146 k++;
00147 }
00148
00149 return modifiedQs;
00150 }
00151 Mutex mDataMutex;
00152 Mutex mControllerDoMutex;
00153 };
00155 };
00156
00157 #endif // _Controller_
00158