Controller.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 "Controller.hxx"
00023 #include "ProcessingFactory.hxx"
00024 
00025 
00026 namespace CLAM 
00027 {
00028 
00029 namespace Hidden
00030 {
00031         static const char * metadata[] = {
00032                 "key", "Controller",
00033                 "category", "Controls",
00034                 "description", "Controller",
00035                 0
00036         };
00037         static FactoryRegistrator<ProcessingFactory, Controller> reg = metadata;
00038 }
00039         
00040 Controller::Controller()
00041 {
00042 
00043 }
00044 
00045 
00046 bool Controller::ConcreteConfigure(const ProcessingConfig& c)
00047 {
00048         CopyAsConcreteConfig(mConfig, c);
00049         int n = mConfig.GetNumControls();
00050 
00051         CLAM_ASSERT( !OutControls.Size() ||
00052                                  n == OutControls.Size(),
00053                                  "Controller::ConcreteConfigure(): Size can not change.");
00054 
00055         if (!OutControls.Size())
00056                 OutControls.Resize(n,"Output",this);
00057 
00058         OutValues.resize(n);
00059 
00060         for (int k = 0; k < n ; k++ )
00061         {
00062                 OutValues[k]=0.0;
00063         }
00064 
00065         // Buffer Queues initialization
00066 
00067         BufferQueueInit( n );
00068 
00069         return true;
00070 
00071 }
00072 
00073 void Controller::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&  Controller::GetConfig() const 
00087 { 
00088         return mConfig; 
00089 }
00090 
00091 
00092 void Controller::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 TControlData Controller::LastDequeuedValue(unsigned id)
00105 {
00106         TControlData val;
00107 
00108         Mutex::ScopedLock lock( mDataMutex );
00109 
00110 #ifdef HAVE_STANDARD_VECTOR_AT
00111         val = OutValues.at(id);
00112 #else
00113         val = OutValues[id];
00114 #endif
00115 
00116         return val;
00117 }
00118 
00119 bool Controller::Empty(unsigned id)
00120 {
00121         Mutex::ScopedLock lock( mDataMutex );
00122         
00123 #ifdef HAVE_STANDARD_VECTOR_AT
00124         return mDataQueues.at(id).empty();
00125 #else
00126         return mDataQueues[id].empty();
00127 #endif
00128 
00129 }
00130 
00131 TControlData Controller::PopControl(unsigned id)
00132 {
00133         Mutex::ScopedLock lock( mDataMutex );
00134 #ifdef HAVE_STANDARD_VECTOR_AT
00135         TControlData ret=mDataQueues.at(id).front();
00136 #else
00137         TControlData ret=mDataQueues[id].front();
00138 #endif
00139         mDataQueues[id].pop();
00140         return ret;
00141 }
00142 
00143 
00144 
00145 }; //namespace CLAM
00146 
Generated by  doxygen 1.6.3