Main Page | Modules | Class Hierarchy | Alphabetical List | Class List | File List | Class Members | File Members | Related Pages

CC_ManoeuvreManager.cpp

00001 // 00002 // Copyright 2004 P&P Software GmbH - All Rights Reserved 00003 // 00004 // CC_ManoeuvreManager.cpp 00005 // 00006 // Version 1.1 00007 // Date 09.05.03 00008 // Author A. Pasetti (P&P Software), R. Totaro 00009 00010 #include "../GeneralInclude/CompilerSwitches.h" 00011 #include "../GeneralInclude/DebugSupport.h" 00012 #include "../GeneralInclude/Constants.h" 00013 #include "../GeneralInclude/ClassId.h" 00014 #include "../Base/CC_RootObject.h" 00015 #include "CC_ManoeuvreManager.h" 00016 00017 CC_ManoeuvreManager::CC_ManoeuvreManager(void) { 00018 pManList = pNULL; 00019 manListSize = 0; 00020 manCounter = 0; 00021 setClassId(ID_MANOEUVREMANAGER); 00022 } 00023 00024 void CC_ManoeuvreManager::reset(void) { 00025 assert( pManList != pNULL ); 00026 for (unsigned int i=0; i<manListSize; i++) 00027 if (pManList[i] != pNULL) 00028 abort(pManList[i]); 00029 assert( manCounter == 0); 00030 } 00031 00032 void CC_ManoeuvreManager::setPendingManoeuvreListSize(const unsigned int listSize) { 00033 assert( manListSize == 0); // should not be called more than once 00034 assert( listSize > 0 ); 00035 manListSize = listSize; 00036 pManList = new Manoeuvre*[manListSize]; 00037 00038 for (unsigned int i=0; i<manListSize; i++) 00039 pManList[i] = pNULL; 00040 } 00041 00042 unsigned int CC_ManoeuvreManager::getPendingManoeuvreListSize(void) { 00043 assert( manListSize > 0 ); 00044 return manListSize; 00045 } 00046 00047 void CC_ManoeuvreManager::load(Manoeuvre* pManoeuvre) { 00048 assert ( isObjectConfigured() ); 00049 00050 // Check whether list of pending manoeuvres is full 00051 if ( manCounter == manListSize ) { 00052 CC_RootObject::getEventRepository()->create(pManoeuvre,EVT_MAN_LIST_FULL); 00053 return; 00054 } 00055 00056 // Insert manoeuvre in the list of pending manoeuvres 00057 for (unsigned int i=0; i<manListSize; i++) { 00058 if (pManList[i] == pNULL) { 00059 pManList[i] = pManoeuvre; 00060 manCounter++; 00061 CC_RootObject::getEventRepository()->create(pManoeuvre,EVT_MAN_LOADED); 00062 return; 00063 } 00064 } 00065 00066 // This point shall never be reached 00067 assert(false); 00068 } 00069 00070 void CC_ManoeuvreManager::unload(Manoeuvre* pManoeuvre) { 00071 assert ( isObjectConfigured() ); 00072 assert ( pManoeuvre != pNULL ); 00073 assert ( manCounter > 0 ); 00074 assert ( pManoeuvre->isInUse() ); 00075 assert ( !pManoeuvre->isExecuting() ); 00076 00077 // Remove manoeuvre from the list of pending telecommands 00078 for (unsigned int i=0; i<manListSize; i++) { 00079 if (pManList[i] == pManoeuvre) { 00080 pManoeuvre->setInUse(MAN_NOT_IN_USE); 00081 pManList[i] = pNULL; 00082 manCounter--; 00083 CC_RootObject::getEventRepository()->create(pManoeuvre,EVT_MAN_UNLOADED); 00084 return; 00085 } 00086 } 00087 00088 // This point shall never be reached 00089 assert(false); 00090 } 00091 00092 unsigned int CC_ManoeuvreManager::getPendingManoeuvres(void) { 00093 assert(isObjectConfigured()); 00094 return manCounter; 00095 } 00096 00097 void CC_ManoeuvreManager::abort(Manoeuvre* pManoeuvre) { 00098 assert(isObjectConfigured() && pManoeuvre!=pNULL); 00099 00100 for (unsigned int i=0; i<manListSize; i++) { 00101 if (pManList[i] == pManoeuvre) { 00102 pManoeuvre->abort(); 00103 pManoeuvre->setInUse(MAN_NOT_IN_USE); 00104 pManList[i] = pNULL; 00105 manCounter--; 00106 CC_RootObject::getEventRepository()->create(pManoeuvre,EVT_MAN_UNLOADED); 00107 return; 00108 } 00109 } 00110 00111 // This point shall never be reached 00112 assert(false); 00113 } 00114 00115 void CC_ManoeuvreManager::activate(void) { 00116 assert(isObjectConfigured()); 00117 00118 for (unsigned int i=0;i<manListSize;i++) { 00119 Manoeuvre *pM=pManList[i]; 00120 00121 if (pM!=pNULL) { 00122 if (!pM->isExecuting()) { 00123 if (pM->canStart()) { 00124 pM->initialize(); 00125 pM->doContinue(); 00126 } 00127 } 00128 else if (pM->isFinished()) { 00129 pM->terminate(); 00130 unload(pM); 00131 } 00132 else if (pM->canContinue()) { 00133 pM->doContinue(); 00134 } 00135 else { 00136 pM->abort(); 00137 unload(pM); 00138 } 00139 } 00140 } 00141 } 00142 00143 bool CC_ManoeuvreManager::isObjectConfigured(void) { 00144 return (CC_RootObject::isObjectConfigured() && manListSize>0); 00145 }
Copyright 2003 P&P Software GmbH - All Rights Reserved