Control2Data.cxx

Go to the documentation of this file.
00001 /*
00002  * Copyright (c) 2001-2004 MUSIC TECHNOLOGY GROUP (MTG)
00003  *                         UNIVERSITAT POMPEU FABRA
00004  *
00005  *
00006  * This program is free software; you can redistribute it and/or modify
00007  * it under the terms of the GNU General Public License as published by
00008  * the Free Software Foundation; either version 2 of the License, or
00009  * (at your option) any later version.
00010  *
00011  * This program is distributed in the hope that it will be useful,
00012  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00013  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00014  * GNU General Public License for more details.
00015  *
00016  * You should have received a copy of the GNU General Public License
00017  * along with this program; if not, write to the Free Software
00018  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
00019  *
00020  */
00021 
00022 #include "Control2Data.hxx"
00023 
00024 namespace CLAM {
00025 
00026 void Control2DataConfig::DefaultInit(void)
00027 {
00028         AddNumControls();
00029         UpdateData();
00030         SetNumControls(0);
00031 }
00032 
00033 Control2Data::Control2Data(const Config& c)
00034         : mStop("stop",this)
00035 {
00036         Configure(c);
00037 }
00038 
00039 bool Control2Data::ConcreteConfigure(const ProcessingConfig& c)
00040 {
00041         CopyAsConcreteConfig(mConfig, c);
00042         int nControls=mConfig.GetNumControls();
00043         
00044         // Initializing InControlArray
00045         mInArray.Resize(nControls, "array_control", this, &Control2Data::EnqueueControl);
00046 
00047         // Buffer Queues initialization
00048         BufferQueueInit( nControls );
00049         //Initialize mStop to false
00050         mStop.DoControl(0);
00051 
00052         return true;
00053 
00054 }
00055 
00056 bool Control2Data::Do()
00057 {                       
00058         IdxList::iterator ListIt;                               
00059         Mutex::ScopedLock lock( mControl2DataDoMutex );
00060                 
00061         IdxList qs = GetQueues();
00062         if (!qs.empty())  
00063         { 
00064                 for (ListIt=qs.begin();ListIt!=qs.end() ;ListIt++ )
00065                 {                                       
00066                         TControlData val = PopControl( (*ListIt) );
00067                         GenerateOutputData((*ListIt),val); 
00068                 }       
00069         }
00070         return !mStop.GetLastValue();
00071 }
00072 
00073 void Control2Data::BufferQueueInit( int ncontrols )
00074 {
00075         Mutex::ScopedLock lock( mDataMutex );
00076 
00077         mDataQueues.resize(0);
00078         mDataQueues.reserve(ncontrols);
00079         for (int j = 0; j < ncontrols  ;j ++ )
00080         {
00081                 mDataQueues.push_back( TQueue() );
00082         }
00083 
00084 }
00085 
00086 const ProcessingConfig&  Control2Data::GetConfig() const 
00087 { 
00088         return mConfig; 
00089 }
00090 
00091 
00092 void Control2Data::EnqueueControl(unsigned id, TControlData data)
00093 {
00094         Mutex::ScopedLock lock( mDataMutex );
00095         
00096 #ifdef HAVE_STANDARD_VECTOR_AT
00097         mDataQueues.at(id).push(data);
00098 #else
00099         mDataQueues[id].push(data);
00100 #endif
00101 
00102 }
00103 
00104 Control2Data::IdxList Control2Data::GetQueues()
00105 {
00106         IdxList modifiedQs;
00107         std::vector<TQueue>::iterator it;
00108 
00109         int k = 0;
00110         for (it=mDataQueues.begin(); it != mDataQueues.end() ; it++ )
00111         {
00112                 if (!(*it).empty())
00113                 {
00114                         modifiedQs.push_back(k);
00115                 }
00116                 k++;
00117         }
00118         return modifiedQs;
00119 }
00120 
00121 bool Control2Data::Empty(unsigned id)
00122 {
00123         Mutex::ScopedLock lock( mDataMutex );
00124         
00125 #ifdef HAVE_STANDARD_VECTOR_AT
00126         return mDataQueues.at(id).empty();
00127 #else
00128         return mDataQueues[id].empty();
00129 #endif
00130 
00131 }
00132 
00133 TControlData Control2Data::PopControl(unsigned id)
00134 {
00135         Mutex::ScopedLock lock( mDataMutex );
00136 #ifdef HAVE_STANDARD_VECTOR_AT
00137         TControlData ret=mDataQueues.at(id).front();
00138 #else
00139         TControlData ret=mDataQueues[id].front();
00140 #endif
00141         mDataQueues[id].pop();
00142         return ret;
00143 }
00144 
00145 void Control2Data::ControlCallbackId(int id, TControlData val)
00146 {
00147         EnqueueControl(id,val);
00148 }
00149 
00150 }; //namespace CLAM
00151 
Generated by  doxygen 1.6.3