ActiveObjectManagerAce.cpp

Go to the documentation of this file.
00001 /*
00002 Copyright 2007, 2008, 2009, 2010, 2011 Instituto de Sistemas e Robotica, Instituto Superior Tecnico
00003 
00004 This file is part of MeRMaID.
00005 
00006 MeRMaID is free software: you can redistribute it and/or modify
00007 it under the terms of the GNU Lesser General Public License as published by
00008 the Free Software Foundation, either version 3 of the License, or
00009 (at your option) any later version.
00010 
00011 MeRMaID 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 Lesser General Public License for more details.
00015 
00016 You should have received a copy of the GNU Lesser General Public License
00017 along with MeRMaID.  If not, see <http://www.gnu.org/licenses/>.
00018 */
00019 
00020 
00021 
00022 /**
00023  * @Filename ActiveObjectManagerAce.cpp
00024  * @Description ActiveObjectManagerAce implementation
00025  * @Status Work in Progress
00026  * @Version $Id: ActiveObjectManagerAce.cpp 1 2011-03-04 18:13:18Z jreis $
00027  * @Maintainer
00028  */
00029 
00030 #include "config.h"
00031 
00032 #include <ActiveObjectManagerAce.hpp>
00033 #include <ActiveObjectAce.hpp>
00034 
00035 #include <iostream>
00036 
00037 
00038 
00039 using namespace mermaid::support::activeobject;
00040 
00041 
00042 
00043 shared_ptr<ActiveObjectManagerAce>
00044 ActiveObjectManagerAce::
00045 instance_ = shared_ptr<ActiveObjectManagerAce> ();
00046 
00047 
00048 
00049 ActiveObjectManagerAce::
00050 ActiveObjectManagerAce() :
00051     ActiveObjectManager()
00052 {
00053   waitForTerminateSemaphore_ =
00054     shared_ptr<ACE_Semaphore> (new ACE_Semaphore (0));
00055 }
00056 
00057 
00058 
00059 ActiveObjectManagerAce::
00060 ~ActiveObjectManagerAce()
00061 {
00062 
00063 }
00064 
00065 
00066 
00067 void
00068 ActiveObjectManagerAce::
00069 notifyActiveObjectStateChange (ActiveObject * ao,
00070                                ActiveObjectState previousState)
00071 {
00072   internalDataMutex_.acquire();
00073   
00074   ActiveObjectManager::notifyActiveObjectStateChange (ao, previousState);
00075   
00076   int numAO =
00077     ActiveObjectManager::getActiveObjectVector().size();
00078   // int numUnknown = ActiveObjectManager::getActiveObjectStateSet(UNKNOWN).size();
00079   // int numInitializing = ActiveObjectManager::getActiveObjectStateSet(INITIALIZING).size();
00080   // int numInitialized = ActiveObjectManager::getActiveObjectStateSet(INITIALIZED).size();
00081   // int numStopping = ActiveObjectManager::getActiveObjectStateSet(STOPPING).size();
00082   int numStopped =
00083     ActiveObjectManager::getActiveObjectStateSet (STOPPED).size();
00084   // int numPausing = ActiveObjectManager::getActiveObjectStateSet(PAUSING).size();
00085   // int numPaused = ActiveObjectManager::getActiveObjectStateSet(PAUSED).size();
00086   // int numRunning = ActiveObjectManager::getActiveObjectStateSet(RUNNING).size();
00087   
00088   // std::cerr << "numAO...........= " << numAO << std::endl;
00089   // std::cerr << "numUnknown......= " << numUnknown << std::endl;
00090   // std::cerr << "numInitializing.= " << numInitializing << std::endl;
00091   // std::cerr << "numInitialized..= " << numInitialized << std::endl;
00092   // std::cerr << "numStopping.....= " << numStopping << std::endl;
00093   // std::cerr << "numStopped......= " << numStopped << std::endl;
00094   // std::cerr << "numPausing......= " << numPausing << std::endl;
00095   // std::cerr << "numPaused.......= " << numPaused << std::endl;
00096   // std::cerr << "numRunning......= " << numRunning << std::endl;
00097   
00098   if (numAO == numStopped) {
00099     waitForTerminateSemaphore_->release();
00100   }
00101   
00102   internalDataMutex_.release();
00103   
00104 }
00105 
00106 
00107 
00108 shared_ptr<ActiveObject> ActiveObjectManagerAce::createActiveObject()
00109 {
00110   shared_ptr<ActiveObject> ao = shared_ptr<ActiveObject> (new ActiveObjectAce (this));
00111   addActiveObject (ao);
00112   return ao;
00113   
00114 }
00115 
00116 
00117 
00118 shared_ptr<ActiveObjectManagerAce> ActiveObjectManagerAce::getInstance()
00119 {
00120   if (! instance_)
00121     instance_ = shared_ptr<ActiveObjectManagerAce> (new ActiveObjectManagerAce());
00122   return instance_;
00123 }
00124 
00125 
00126 
00127 void ActiveObjectManagerAce::waitForActiveObjectsToStop()
00128 {
00129   waitForTerminateSemaphore_->acquire();
00130 }
00131 
00132 
00133 
00134 vector<shared_ptr<ActiveObject> > ActiveObjectManagerAce::getActiveObjectVector()
00135 {
00136   internalDataMutex_.acquire();
00137   vector<shared_ptr<ActiveObject> > ret = ActiveObjectManager::getActiveObjectVector();
00138   internalDataMutex_.release();
00139   return ret;
00140 }
00141 
00142 
00143 
00144 set<shared_ptr<ActiveObject> > ActiveObjectManagerAce::getActiveObjectStateSet (ActiveObjectState s)
00145 {
00146   internalDataMutex_.acquire();
00147   set<shared_ptr<ActiveObject> > ret = ActiveObjectManager::getActiveObjectStateSet (s);
00148   internalDataMutex_.release();
00149   return ret;
00150 }
00151 
00152 
00153 
00154 void ActiveObjectManagerAce::addActiveObject (shared_ptr<ActiveObject> ao)
00155 {
00156   internalDataMutex_.acquire();
00157   ActiveObjectManager::addActiveObject (ao);
00158   internalDataMutex_.release();
00159 }
00160 
00161 
00162 
00163 void ActiveObjectManagerAce::stopAllActiveObjects()
00164 {
00165   vector<shared_ptr<ActiveObject> > aov = getActiveObjectVector();
00166   
00167   vector<shared_ptr<ActiveObject> >::iterator it;
00168   
00169   for (it = aov.begin(); it != aov.end(); it++) {
00170     shared_ptr<ActiveObject> ao = *it;
00171     ao->stop();
00172   }
00173 }
Generated on Fri Mar 4 22:14:58 2011 for MeRMaID::support by  doxygen 1.6.3