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 Control2DataConfig& c):mStop("stop",this)
00034 {
00035         Configure(c);
00036 }
00037 
00038 Control2Data::Control2Data():mStop("stop",this)
00039 {
00040         Configure(Control2DataConfig());
00041 }
00042 
00043 bool Control2Data::ConcreteConfigure(const ProcessingConfig& c)
00044 {
00045         CopyAsConcreteConfig(mConfig, c);
00046         int nControls=mConfig.GetNumControls();
00047         
00048         // Initializing InControlArray
00049         mpInArray=new InControlTmplArray<Control2Data>(nControls, "array_control", this,&Control2Data::ControlCallbackId);
00050           
00051         // Buffer Queues initialization
00052         BufferQueueInit( nControls );
00053         //Initialize mStop to false
00054         mStop.DoControl(0);
00055 
00056         return true;
00057 
00058 }
00059 
00060 bool Control2Data::Do()
00061 {                       
00062         IdxList::iterator ListIt;                               
00063         Mutex::ScopedLock lock( mControl2DataDoMutex );
00064                 
00065         IdxList qs = GetQueues();
00066         if (!qs.empty())  
00067         { 
00068                 for (ListIt=qs.begin();ListIt!=qs.end() ;ListIt++ )
00069                 {                                       
00070                         TControlData val = PopControl( (*ListIt) );
00071                         GenerateOutputData((*ListIt),val); 
00072                 }       
00073         }
00074         return !mStop.GetLastValue();
00075 }
00076 
00077 void Control2Data::BufferQueueInit( int ncontrols )
00078 {
00079         Mutex::ScopedLock lock( mDataMutex );
00080 
00081         mDataQueues.resize(0);
00082         mDataQueues.reserve(ncontrols);
00083         for (int j = 0; j < ncontrols  ;j ++ )
00084         {
00085                 mDataQueues.push_back( TQueue() );
00086         }
00087 
00088 }
00089 
00090 const ProcessingConfig&  Control2Data::GetConfig() const 
00091 { 
00092         return mConfig; 
00093 }
00094 
00095 
00096 void Control2Data::EnqueueControl(unsigned id, TControlData data)
00097 {
00098         Mutex::ScopedLock lock( mDataMutex );
00099         
00100 #ifdef HAVE_STANDARD_VECTOR_AT
00101         mDataQueues.at(id).push(data);
00102 #else
00103         mDataQueues[id].push(data);
00104 #endif
00105 
00106 }
00107 
00108 Control2Data::IdxList Control2Data::GetQueues()
00109 {
00110         IdxList modifiedQs;
00111         std::vector<TQueue>::iterator it;
00112 
00113         int k = 0;
00114         for (it=mDataQueues.begin(); it != mDataQueues.end() ; it++ )
00115         {
00116                 if (!(*it).empty())
00117                 {
00118                         modifiedQs.push_back(k);
00119                 }
00120                 k++;
00121         }
00122         return modifiedQs;
00123 }
00124 
00125 bool Control2Data::Empty(unsigned id)
00126 {
00127         Mutex::ScopedLock lock( mDataMutex );
00128         
00129 #ifdef HAVE_STANDARD_VECTOR_AT
00130         return mDataQueues.at(id).empty();
00131 #else
00132         return mDataQueues[id].empty();
00133 #endif
00134 
00135 }
00136 
00137 TControlData Control2Data::PopControl(unsigned id)
00138 {
00139         Mutex::ScopedLock lock( mDataMutex );
00140 #ifdef HAVE_STANDARD_VECTOR_AT
00141         TControlData ret=mDataQueues.at(id).front();
00142 #else
00143         TControlData ret=mDataQueues[id].front();
00144 #endif
00145         mDataQueues[id].pop();
00146         return ret;
00147 }
00148 
00149 int Control2Data::ControlCallbackId(int id, TControlData val)
00150 {
00151         EnqueueControl(id,val);
00152         return 0;
00153 }
00154 
00155 }; //namespace CLAM
00156 

Generated on Tue Aug 12 22:33:42 2008 for CLAM by  doxygen 1.5.5