ActiveObjectManagerAce.cpp
Go to the documentation of this file.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
00026
00027
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
00079
00080
00081
00082 int numStopped =
00083 ActiveObjectManager::getActiveObjectStateSet (STOPPED).size();
00084
00085
00086
00087
00088
00089
00090
00091
00092
00093
00094
00095
00096
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 }