Changeset 47 in pacpusframework for trunk/src/PacpusLib/ComponentManager.cpp
- Timestamp:
- Jan 9, 2013, 12:24:45 AM (12 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/PacpusLib/ComponentManager.cpp
r31 r47 28 28 LOG_TRACE("getInstance()"); 29 29 LOG_TRACE("before: mInstance = " << mInstance); 30 if (NULL == mInstance) { 30 31 if (!mInstance) 32 { 31 33 LOG_INFO("creating new instance..."); 32 34 mInstance = new ComponentManager(); 33 35 LOG_DEBUG("mInstance = " << mInstance); 34 36 } 37 35 38 LOG_TRACE("after: mInstance = " << mInstance); 36 39 return mInstance; … … 58 61 59 62 QMutableMapIterator<ComponentMap::key_type, ComponentMap::mapped_type> it(componentMap_); 60 while (it.hasNext()) {63 while (it.hasNext()) 61 64 unRegisterComponent(it.next().key()); 62 } 65 63 66 LOG_DEBUG("component manager was deleted"); 64 67 } … … 68 71 LOG_TRACE("registerComponentFactory(type="<< type << ")"); 69 72 70 if (factoryMap_.contains(type)) { 71 LOG_WARN("cannot register a component factory of type '" << type << "'" 72 << ". It already belongs to the manager" 73 ); 73 if (factoryMap_.contains(type)) 74 { 75 LOG_WARN("cannot register a component factory of type '" << type << "'. It already belongs to the manager"); 74 76 return false; 75 77 } 76 78 77 79 factoryMap_[type] = addr; 78 LOG_INFO("registered component factory '" << type << "'" 79 ); 80 LOG_INFO("registered component factory '" << type << "'"); 81 80 82 return true; 81 83 } … … 85 87 LOG_TRACE("unRegisterComponentFactory(type="<< type << ")"); 86 88 87 if (!factoryMap_.contains(type)) {88 LOG_WARN("cannot unregister component factory '" << type << "'"89 << ". It was not registered"90 );91 return false;92 } 89 if (!factoryMap_.contains(type)) 90 { 91 LOG_WARN("cannot unregister component factory '" << type << "'. It was not registered"); 92 return false; 93 } 94 93 95 factoryMap_.remove(type); 94 LOG_INFO("unregistered component factory '" << type << "'" 95 ); 96 LOG_INFO("unregistered component factory '" << type << "'"); 97 96 98 return true; 97 99 } … … 101 103 LOG_TRACE("registerComponent(name="<< name << ")"); 102 104 103 if (componentMap_.contains(name)) {104 LOG_WARN("cannot register component '" << name << "'"105 << ". A component with the same name exists already"106 );107 return false;108 } 105 if (componentMap_.contains(name)) 106 { 107 LOG_WARN("cannot register component '" << name << "'. A component with the same name exists already"); 108 return false; 109 } 110 109 111 componentMap_[name] = addr; 110 LOG_INFO("registered component " << name 111 ); 112 LOG_INFO("registered component " << name); 113 112 114 return true; 113 115 } … … 117 119 LOG_TRACE("unRegisterComponent(name="<< name << ")"); 118 120 119 if (!componentMap_.contains(name)) {120 LOG_WARN("cannot unregister component '" << name << "'"121 << ". It was not registered"122 );123 return false;124 } 121 if (!componentMap_.contains(name)) 122 { 123 LOG_WARN("cannot unregister component '" << name << "'. It was not registered"); 124 return false; 125 } 126 125 127 // FIXME: delete component 126 128 //delete componentMap_[name]; 127 129 componentMap_.remove(name); 128 LOG_INFO("unregistered component '" << name << "'" 129 ); 130 LOG_INFO("unregistered component '" << name << "'"); 131 130 132 return true; 131 133 } … … 135 137 LOG_TRACE("createComponent(type=" << type << ", " << "name="<< name << ")"); 136 138 137 if (factoryMap_.contains(type)) { 138 factoryMap_[type]->addComponent(name); 139 return true; 140 } 139 FactoryMap::iterator it = factoryMap_.find(type); 140 if (it != factoryMap_.end()) 141 { 142 (*it)->addComponent(name); 143 return true; 144 } 145 141 146 LOG_WARN("cannot create component '" << name << "'" 142 147 << ". Component factory for type '" << type << "'" … … 178 183 179 184 // load the components tree in memory 180 /*int loadedComponentsCount = */xmlTree_->loadFile(configFilename);185 xmlTree_->loadFile(configFilename); 181 186 182 187 { … … 264 269 } 265 270 266 intComponentManager::start()271 bool ComponentManager::start() 267 272 { 268 273 LOG_TRACE("start()"); 269 274 270 275 bool result = true; 271 for (ComponentMap::iterator it = componentMap_.begin(), itend = componentMap_.end(); it != itend; ++it ) {272 result &= (0 < start(it.key()));273 } 276 for (ComponentMap::iterator it = componentMap_.begin(), itend = componentMap_.end(); it != itend; ++it ) 277 result &= start(it.key()); 278 274 279 return result; 275 280 } 276 281 277 intComponentManager::start(const QString& componentName)282 bool ComponentManager::start(const QString& componentName) 278 283 { 279 284 LOG_TRACE("start(component=" << componentName << ")"); 280 285 281 ComponentBase * component = getComponent(componentName); 282 if (NULL == component) { 283 LOG_WARN("cannot start component '" << componentName << "'" 284 << ". It does not exist!" 285 ); 286 ComponentBase* component = getComponent(componentName); 287 if (!component) 288 { 289 LOG_WARN("cannot start component '" << componentName << "'. It does not exist!"); 286 290 return false; 287 291 } 288 292 289 293 LOG_INFO("starting component '" << componentName << "'..."); 290 if (!component->startComponent()) { 291 LOG_WARN("cannot start component '" << componentName << "'" 292 ". It can already be started" 293 ); 294 } 295 return true; 296 } 297 298 int ComponentManager::stop() 294 if (!component->startComponent()) 295 LOG_WARN("cannot start component '" << componentName << "'. It can already be started"); 296 297 return true; 298 } 299 300 bool ComponentManager::stop() 299 301 { 300 302 LOG_TRACE("stop()"); 301 303 302 304 bool result = true; 303 for (ComponentMap::iterator it = componentMap_.begin(); it != componentMap_.end(); ++it) {304 result &= (0 < stop(it.key()));305 } 305 for (ComponentMap::iterator it = componentMap_.begin(); it != componentMap_.end(); ++it) 306 result &= stop(it.key()); 307 306 308 return result; 307 309 } 308 310 309 intComponentManager::stop(const QString& componentName)311 bool ComponentManager::stop(const QString& componentName) 310 312 { 311 313 LOG_TRACE("stop(component=" << componentName << ")"); 312 314 313 ComponentBase * component = getComponent(componentName); 314 if (NULL == component) { 315 LOG_WARN("cannot stop component '" << componentName << "'" 316 << ". It does not exist" 317 ); 315 ComponentBase* component = getComponent(componentName); 316 if (!component) 317 { 318 LOG_WARN("cannot stop component '" << componentName << "'" << ". It does not exist"); 318 319 return false; 319 320 } 320 321 321 322 LOG_INFO("stopping component '" << componentName << "'..."); 322 if (!component->stopComponent()) { 323 LOG_WARN("cannot stop component '" << componentName << "'" 324 << ". It can be already stopped" 325 ); 326 } 323 if (!component->stopComponent()) 324 LOG_WARN("cannot stop component '" << componentName << "'" << ". It can be already stopped"); 325 327 326 return true; 328 327 } … … 332 331 LOG_TRACE("getComponent(name=" << name << ")"); 333 332 334 if (!componentMap_.contains(name)) { 335 LOG_WARN("cannot retrieve component '" << name << "'" 336 << ". It does not exist" 337 ); 338 return NULL; 339 } 340 return componentMap_[name]; 341 } 342 343 QStringList ComponentManager::getAllComponentsName() 333 ComponentMap::iterator it = componentMap_.find(name); 334 if (it != componentMap_.end()) 335 return *it; 336 337 LOG_WARN("cannot retrieve component '" << name << "'" << ". It does not exist"); 338 return NULL; 339 } 340 341 QStringList ComponentManager::getAllComponentsName() const 344 342 { 345 343 LOG_TRACE("getAllComponentsName()"); 346 347 344 return xmlTree_->getAllComponents(); 348 345 }
Note:
See TracChangeset
for help on using the changeset viewer.