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
00031
00032
00033 #include <jccl/jcclConfig.h>
00034 #include <iomanip>
00035 #include <typeinfo>
00036 #include <string>
00037 #include <jccl/RTRC/ConfigManager.h>
00038 #include <jccl/Config/ConfigElement.h>
00039 #include <jccl/RTRC/DependencyManager.h>
00040 #include <jccl/Util/Debug.h>
00041 #include <jccl/RTRC/ConfigElementHandler.h>
00042
00043 namespace jccl
00044 {
00045
00046 enum PendItemResult
00047 { SUCCESS, FAILED, NEED_DEPS };
00048
00049
00050 static void outputPendingItemState(int debugLevel,
00051 const std::string& elementName,
00052 const std::string& elementType,
00053 PendItemResult result);
00054
00055
00056 int ConfigElementHandler::configProcessPending()
00057 {
00058 ConfigManager* cfg_mgr = ConfigManager::instance();
00059 DependencyManager* dep_mgr = DependencyManager::instance();
00060
00061 bool scan_for_lost_dependants(false);
00062
00063
00064 std::list<ConfigManager::PendingElement>::size_type num_pending_before =
00065 cfg_mgr->getNumPending();
00066 std::list<ConfigManager::PendingElement>::size_type num_pending_after(0);
00067
00068 vprDEBUG_BEGIN(vprDBG_ALL,vprDBG_STATE_LVL)
00069 << typeid(*this).name() << "::configProcessPending: Entering: "
00070 << num_pending_before << " items pending.\n" << vprDEBUG_FLUSH;
00071
00072
00073 {
00074 std::list<ConfigManager::PendingElement>::iterator current, end, remove_me;
00075 current = cfg_mgr->getPendingBegin();
00076 end = cfg_mgr->getPendingEnd();
00077
00078
00079 while(current != end)
00080 {
00081
00082 ConfigElementPtr cur_element = (*current).mElement;
00083 vprASSERT(cur_element.get() != NULL && "Trying to use an invalid element");
00084 std::string element_name = cur_element->getName();
00085 std::string element_type = cur_element->getID();
00086
00087 vprDEBUG_BEGIN(vprDBG_ALL,vprDBG_VERB_LVL)
00088 << "Item: name:" << element_name << " type:" << element_type
00089 << std::endl << vprDEBUG_FLUSH;
00090
00091
00092 if(this->configCanHandle(cur_element))
00093 {
00094
00095 switch ((*current).mType)
00096 {
00097 case ConfigManager::PendingElement::ADD:
00098 if(dep_mgr->isSatisfied(cur_element))
00099 {
00100 bool added = this->configAdd(cur_element);
00101 if(added)
00102 {
00103 remove_me = current;
00104 current++;
00105 cfg_mgr->removePending(remove_me);
00106 cfg_mgr->addActive(cur_element);
00107
00108 outputPendingItemState(vprDBG_CONFIG_STATUS_LVL,
00109 element_name, element_type,
00110 SUCCESS);
00111 }
00112 else
00113 {
00114 outputPendingItemState(vprDBG_CRITICAL_LVL, element_name,
00115 element_type, FAILED);
00116 current++;
00117 }
00118 }
00119 else
00120 {
00121 outputPendingItemState(vprDBG_CONFIG_LVL, element_name,
00122 element_type, NEED_DEPS);
00123 vprDEBUG_CONT(vprDBG_ALL,vprDBG_CONFIG_LVL)
00124 << std::endl << vprDEBUG_FLUSH;
00125 dep_mgr->debugOutDependencies(cur_element,vprDBG_CONFIG_LVL);
00126 current++;
00127 }
00128 break;
00129
00130 case ConfigManager::PendingElement::REMOVE:
00131 {
00132 bool removed = this->configRemove(cur_element);
00133 if(removed)
00134 {
00135 remove_me = current;
00136 current++;
00137 cfg_mgr->removePending(remove_me);
00138 cfg_mgr->removeActive(cur_element->getName());
00139 scan_for_lost_dependants = true;
00140 }
00141 else
00142 {
00143 current++;
00144 }
00145 }
00146 break;
00147
00148 default:
00149 current++;
00150 break;
00151 }
00152 }
00153
00154 else
00155 {
00156 vprDEBUG_NEXT(vprDBG_ALL,vprDBG_STATE_LVL)
00157 << "Pending item: " << cur_element->getName()
00158 << " type: " << cur_element->getID()
00159 << " --> Not handled by this handler.\n" << vprDEBUG_FLUSH;
00160 current++;
00161 }
00162
00163 vprDEBUG_END(vprDBG_ALL,vprDBG_VERB_LVL) << "==== End item =====\n"
00164 << vprDEBUG_FLUSH;
00165 }
00166 }
00167
00168 num_pending_after = cfg_mgr->getNumPending();
00169
00170 vprDEBUG_END(vprDBG_ALL,vprDBG_STATE_LVL)
00171 << " Exiting: "
00172 << num_pending_after << " items now pending ==> We processed "
00173 << (num_pending_before-num_pending_after) << " items.\n"
00174 << vprDEBUG_FLUSH;
00175
00176
00177 if(scan_for_lost_dependants)
00178 {
00179 cfg_mgr->scanForLostDependencies();
00180 }
00181
00182 return (num_pending_before-num_pending_after);
00183 }
00184
00185 void outputPendingItemState(int debugLevel, const std::string& elementName,
00186 const std::string& elementType,
00187 PendItemResult result)
00188 {
00189 const int item_width(39);
00190 const int type_width(20);
00191
00192 vprDEBUG(vprDBG_ALL,debugLevel)
00193 << "Type: " << std::setiosflags(std::ios::right)
00194 << std::setfill(' ') << std::setw(type_width) << elementType
00195 << std::setiosflags(std::ios::right)
00196 << std::setfill(' ') << std::setw(item_width) << elementName
00197 << std::resetiosflags(std::ios::right) << " ";
00198
00199
00200
00201
00202
00203
00204
00205
00206
00207
00208
00209
00210 switch(result)
00211 {
00212 case SUCCESS:
00213 vprDEBUG_CONTnl(vprDBG_ALL,debugLevel) << "[ " << clrSetNORM(clrGREEN) << "OK" << clrRESET << " ]";
00214 break;
00215 case FAILED:
00216 vprDEBUG_CONTnl(vprDBG_ALL,debugLevel) << "[ " << clrSetNORM(clrRED) << "FAILED" << clrRESET << " ]";
00217 break;
00218 case NEED_DEPS:
00219 vprDEBUG_CONTnl(vprDBG_ALL,debugLevel) << "[ " << clrSetNORM(clrYELLOW) << "NEED DEPS" << clrRESET << " ]";
00220 break;
00221 }
00222
00223 vprDEBUG_CONTnl(vprDBG_ALL,debugLevel) << std::endl << vprDEBUG_FLUSH;
00224 }
00225
00226 }