| 1 |
|
|---|
| 2 |
|
|---|
| 3 |
|
|---|
| 4 |
|
|---|
| 5 |
|
|---|
| 6 |
|
|---|
| 7 |
|
|---|
| 8 |
|
|---|
| 9 |
|
|---|
| 10 |
|
|---|
| 11 |
|
|---|
| 12 |
|
|---|
| 13 |
|
|---|
| 14 |
|
|---|
| 15 |
|
|---|
| 16 |
|
|---|
| 17 |
|
|---|
| 18 |
|
|---|
| 19 |
|
|---|
| 20 |
|
|---|
| 21 |
|
|---|
| 22 |
|
|---|
| 23 |
|
|---|
| 24 |
|
|---|
| 25 |
|
|---|
| 26 |
|
|---|
| 27 |
|
|---|
| 28 |
|
|---|
| 29 |
|
|---|
| 30 |
|
|---|
| 31 |
|
|---|
| 32 |
|
|---|
| 33 |
#include <vjConfig.h> |
|---|
| 34 |
#include <Kernel/vjConfigChunkHandler.h> |
|---|
| 35 |
#include <Kernel/vjConfigManager.h> |
|---|
| 36 |
#include <Config/vjConfigChunk.h> |
|---|
| 37 |
#include <Kernel/vjDependencyManager.h> |
|---|
| 38 |
#include <Kernel/vjDebug.h> |
|---|
| 39 |
#include <typeinfo> |
|---|
| 40 |
|
|---|
| 41 |
namespace { |
|---|
| 42 |
enum PendItemResult |
|---|
| 43 |
{ SUCCESS, FAILED, NEED_DEPS }; |
|---|
| 44 |
|
|---|
| 45 |
void outputPendingItemState(int debugLevel, std::string chunkName, std::string chunkType, PendItemResult result); |
|---|
| 46 |
|
|---|
| 47 |
} |
|---|
| 48 |
|
|---|
| 49 |
|
|---|
| 50 |
|
|---|
| 51 |
int vjConfigChunkHandler::configProcessPending(bool lockIt) |
|---|
| 52 |
{ |
|---|
| 53 |
vjConfigManager* cfg_mgr = vjConfigManager::instance(); |
|---|
| 54 |
vjDependencyManager* dep_mgr = vjDependencyManager::instance(); |
|---|
| 55 |
|
|---|
| 56 |
bool scan_for_lost_dependants(false); |
|---|
| 57 |
|
|---|
| 58 |
|
|---|
| 59 |
int num_pending_before = cfg_mgr->getNumPending(); |
|---|
| 60 |
int num_pending_after(0); |
|---|
| 61 |
|
|---|
| 62 |
vjDEBUG_BEGIN(vjDBG_ALL,vjDBG_STATE_LVL) << typeid(*this).name() << "::configProcessPending: Entering: " |
|---|
| 63 |
<< num_pending_before << " items pending.\n" << vjDEBUG_FLUSH; |
|---|
| 64 |
|
|---|
| 65 |
if(lockIt) |
|---|
| 66 |
cfg_mgr->lockPending(); |
|---|
| 67 |
{ |
|---|
| 68 |
std::list<vjConfigManager::vjPendingChunk>::iterator current, end, remove_me; |
|---|
| 69 |
current = cfg_mgr->getPendingBegin(); |
|---|
| 70 |
end = cfg_mgr->getPendingEnd(); |
|---|
| 71 |
|
|---|
| 72 |
|
|---|
| 73 |
while(current != end) |
|---|
| 74 |
{ |
|---|
| 75 |
|
|---|
| 76 |
vjConfigChunk* cur_chunk = (*current).mChunk; |
|---|
| 77 |
vjASSERT(cur_chunk != NULL && "Trying to use an invalid chunk"); |
|---|
| 78 |
std::string chunk_name = cur_chunk->getProperty("name"); |
|---|
| 79 |
std::string chunk_type = cur_chunk->getType(); |
|---|
| 80 |
|
|---|
| 81 |
vjDEBUG_BEGIN(vjDBG_ALL,vjDBG_VERB_LVL) << "Item: name:" << chunk_name << " type:" << chunk_type << std::endl << vjDEBUG_FLUSH; |
|---|
| 82 |
|
|---|
| 83 |
|
|---|
| 84 |
if(this->configCanHandle(cur_chunk)) |
|---|
| 85 |
{ |
|---|
| 86 |
|
|---|
| 87 |
switch ((*current).mType) |
|---|
| 88 |
{ |
|---|
| 89 |
case vjConfigManager::vjPendingChunk::ADD: |
|---|
| 90 |
if(dep_mgr->depSatisfied(cur_chunk)) |
|---|
| 91 |
{ |
|---|
| 92 |
bool added = this->configAdd(cur_chunk); |
|---|
| 93 |
if(added) |
|---|
| 94 |
{ |
|---|
| 95 |
remove_me = current; |
|---|
| 96 |
current++; |
|---|
| 97 |
cfg_mgr->removePending(remove_me); |
|---|
| 98 |
cfg_mgr->addActive(cur_chunk); |
|---|
| 99 |
|
|---|
| 100 |
outputPendingItemState(vjDBG_CONFIG_LVL, |
|---|
| 101 |
cur_chunk->getProperty("name"), |
|---|
| 102 |
((std::string)cur_chunk->getType()).c_str(), |
|---|
| 103 |
SUCCESS); |
|---|
| 104 |
} |
|---|
| 105 |
else |
|---|
| 106 |
{ |
|---|
| 107 |
outputPendingItemState(vjDBG_CRITICAL_LVL, |
|---|
| 108 |
cur_chunk->getProperty("name"), |
|---|
| 109 |
((std::string)cur_chunk->getType()).c_str(), |
|---|
| 110 |
FAILED); |
|---|
| 111 |
current++; |
|---|
| 112 |
} |
|---|
| 113 |
} |
|---|
| 114 |
else |
|---|
| 115 |
{ |
|---|
| 116 |
|
|---|
| 117 |
outputPendingItemState(vjDBG_WARNING_LVL, |
|---|
| 118 |
cur_chunk->getProperty("name"), |
|---|
| 119 |
((std::string)cur_chunk->getType()).c_str(), |
|---|
| 120 |
NEED_DEPS); |
|---|
| 121 |
vjDEBUG_CONT(vjDBG_ALL,vjDBG_WARNING_LVL) << std::endl << vjDEBUG_FLUSH; |
|---|
| 122 |
dep_mgr->debugOutDependencies(cur_chunk,vjDBG_WARNING_LVL); |
|---|
| 123 |
current++; |
|---|
| 124 |
} |
|---|
| 125 |
break; |
|---|
| 126 |
|
|---|
| 127 |
case vjConfigManager::vjPendingChunk::REMOVE: |
|---|
| 128 |
{ |
|---|
| 129 |
bool removed = this->configRemove(cur_chunk); |
|---|
| 130 |
if(removed) |
|---|
| 131 |
{ |
|---|
| 132 |
remove_me = current; |
|---|
| 133 |
current++; |
|---|
| 134 |
cfg_mgr->removePending(remove_me); |
|---|
| 135 |
cfg_mgr->removeActive(cur_chunk->getProperty("name")); |
|---|
| 136 |
scan_for_lost_dependants = true; |
|---|
| 137 |
} |
|---|
| 138 |
else |
|---|
| 139 |
{ |
|---|
| 140 |
current++; |
|---|
| 141 |
} |
|---|
| 142 |
} |
|---|
| 143 |
break; |
|---|
| 144 |
|
|---|
| 145 |
default: |
|---|
| 146 |
current++; |
|---|
| 147 |
break; |
|---|
| 148 |
} |
|---|
| 149 |
} |
|---|
| 150 |
|
|---|
| 151 |
else |
|---|
| 152 |
{ |
|---|
| 153 |
vjDEBUG_NEXT(vjDBG_ALL,vjDBG_STATE_LVL) << "Pending item: " << cur_chunk->getProperty("name") |
|---|
| 154 |
<< " type: " << ((std::string)cur_chunk->getType()).c_str() |
|---|
| 155 |
<< " --> Not handled by this handler.\n" << vjDEBUG_FLUSH; |
|---|
| 156 |
current++; |
|---|
| 157 |
} |
|---|
| 158 |
vjDEBUG_END(vjDBG_ALL,vjDBG_VERB_LVL) << "==== End item =====\n" << vjDEBUG_FLUSH; |
|---|
| 159 |
|
|---|
| 160 |
} |
|---|
| 161 |
|
|---|
| 162 |
} |
|---|
| 163 |
if(lockIt) |
|---|
| 164 |
cfg_mgr->unlockPending(); |
|---|
| 165 |
|
|---|
| 166 |
num_pending_after = cfg_mgr->getNumPending(); |
|---|
| 167 |
|
|---|
| 168 |
vjDEBUG_END(vjDBG_ALL,vjDBG_STATE_LVL) |
|---|
| 169 |
<< " Exiting: " |
|---|
| 170 |
<< num_pending_after << " items now pending ==> We processed " |
|---|
| 171 |
<< (num_pending_before-num_pending_after) << " items.\n" << vjDEBUG_FLUSH; |
|---|
| 172 |
|
|---|
| 173 |
|
|---|
| 174 |
if(scan_for_lost_dependants) |
|---|
| 175 |
{ |
|---|
| 176 |
cfg_mgr->scanForLostDependencies(); |
|---|
| 177 |
} |
|---|
| 178 |
|
|---|
| 179 |
return (num_pending_before-num_pending_after); |
|---|
| 180 |
} |
|---|
| 181 |
|
|---|
| 182 |
namespace { |
|---|
| 183 |
|
|---|
| 184 |
void outputPendingItemState(int debugLevel, std::string chunkName, std::string chunkType, PendItemResult result) |
|---|
| 185 |
{ |
|---|
| 186 |
const int item_width(25); |
|---|
| 187 |
const int type_width(20); |
|---|
| 188 |
|
|---|
| 189 |
const std::string name_prefix("Pending item: "); |
|---|
| 190 |
const std::string type_prefix(" type: "); |
|---|
| 191 |
vjDEBUG(vjDBG_ALL,debugLevel) << "Pending item: " << std::setiosflags(std::ios::right) << std::setfill(' ') << std::setw(item_width) << chunkName |
|---|
| 192 |
<< " type: " << std::setiosflags(std::ios::right) << std::setfill(' ') << std::setw(type_width) << chunkType |
|---|
| 193 |
<< std::resetiosflags(std::ios::right) << " "; |
|---|
| 194 |
|
|---|
| 195 |
|
|---|
| 196 |
|
|---|
| 197 |
|
|---|
| 198 |
|
|---|
| 199 |
|
|---|
| 200 |
|
|---|
| 201 |
|
|---|
| 202 |
|
|---|
| 203 |
|
|---|
| 204 |
|
|---|
| 205 |
|
|---|
| 206 |
switch(result) |
|---|
| 207 |
{ |
|---|
| 208 |
case SUCCESS: |
|---|
| 209 |
vjDEBUG_CONTnl(vjDBG_ALL,debugLevel) << "[ " << clrSetNORM(clrGREEN) << "OK" << clrRESET << " ]"; |
|---|
| 210 |
break; |
|---|
| 211 |
case FAILED: |
|---|
| 212 |
vjDEBUG_CONTnl(vjDBG_ALL,debugLevel) << "[ " << clrSetNORM(clrRED) << "FAILED" << clrRESET << " ]"; |
|---|
| 213 |
break; |
|---|
| 214 |
case NEED_DEPS: |
|---|
| 215 |
vjDEBUG_CONTnl(vjDBG_ALL,debugLevel) << "[ " << clrSetNORM(clrYELLOW) << "NEED DEPS" << clrRESET << " ]"; |
|---|
| 216 |
break; |
|---|
| 217 |
} |
|---|
| 218 |
|
|---|
| 219 |
vjDEBUG_CONTnl(vjDBG_ALL,debugLevel) << std::endl << vjDEBUG_FLUSH; |
|---|
| 220 |
} |
|---|
| 221 |
|
|---|
| 222 |
} |
|---|
| 223 |
|
|---|
| 224 |
|
|---|
| 225 |
|
|---|