Changeset 146 in pacpusframework for branches/2.0-beta1/src/PacpusLib/ComponentManager.cpp
- Timestamp:
- Jul 31, 2013, 11:20:11 AM (11 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/2.0-beta1/src/PacpusLib/ComponentManager.cpp
r141 r146 27 27 { 28 28 LOG_TRACE("getInstance()"); 29 LOG_TRACE("before: mInstance = " << mInstance); 30 31 if (!mInstance) 32 { 29 LOG_TRACE("before: mInstance = " << mInstance); 30 31 if (!mInstance) { 33 32 LOG_INFO("creating new instance..."); 34 33 mInstance = new ComponentManager(); … … 36 35 } 37 36 38 LOG_TRACE("after :mInstance = " << mInstance);37 LOG_TRACE("after : mInstance = " << mInstance); 39 38 return mInstance; 40 39 } … … 44 43 LOG_TRACE("destroy"); 45 44 45 LOG_TRACE("before: mInstance = " << mInstance); 46 46 delete mInstance; 47 47 mInstance = NULL; 48 LOG_TRACE("after : mInstance = " << mInstance); 48 49 } 49 50 … … 60 61 LOG_TRACE("destructor"); 61 62 62 QMutableMapIterator<ComponentMap::key_type, ComponentMap::mapped_type> it(componentMap_);63 while (it.hasNext())64 unRegisterComponent(it.next().key());63 for (ComponentMap::iterator it = componentMap_.begin(), itend = componentMap_.end(); it != itend; ++it) { 64 bool unregisteredSuccessfully = unregisterComponent(it.key()); 65 } 65 66 66 67 LOG_DEBUG("component manager was deleted"); … … 83 84 } 84 85 85 bool ComponentManager::unRegisterComponentFactory(const QString& type) 86 { 87 LOG_TRACE("unRegisterComponentFactory(type="<< type << ")"); 88 89 if (!factoryMap_.contains(type)) 90 { 86 bool ComponentManager::unregisterComponentFactory(const QString& type) 87 { 88 LOG_TRACE("unregisterComponentFactory(type="<< type << ")"); 89 90 if (!factoryMap_.contains(type)) { 91 91 LOG_WARN("cannot unregister component factory '" << type << "'. It was not registered"); 92 92 return false; … … 115 115 } 116 116 117 bool ComponentManager::unRegisterComponent(const QString& name) 118 { 119 LOG_TRACE("unRegisterComponent(name="<< name << ")"); 120 121 if (!componentMap_.contains(name)) 122 { 117 bool ComponentManager::unregisterComponent(const QString& name) 118 { 119 LOG_TRACE("unregisterComponent(name="<< name << ")"); 120 121 if (!componentMap_.contains(name)) { 123 122 LOG_WARN("cannot unregister component '" << name << "'. It was not registered"); 124 123 return false; … … 126 125 127 126 // FIXME: delete component 128 //delete componentMap_[name]; 129 componentMap_.remove(name); 127 ComponentBase* component = componentMap_.value(name, NULL); 128 //delete component; 129 130 // FIXME: remove from map (causes segfault in QMap::qMapLessThanKey on Windows) 131 //componentMap_.remove(name); 130 132 LOG_INFO("unregistered component '" << name << "'"); 131 133 … … 137 139 LOG_TRACE("createComponent(type=" << type << ", " << "name="<< name << ")"); 138 140 139 FactoryMap::iterator it = factoryMap_.find(type);140 if (it != factoryMap_.end())141 {142 (*it)->addComponent(name);141 if (factoryMap_.contains(type)) { 142 ComponentFactoryBase* factory = factoryMap_.value(type); 143 assert(factory); 144 factory->addComponent(name); 143 145 return true; 144 146 } … … 211 213 { 212 214 // Load the plugins containing the components 213 QStringList plugins = xmlTree_->getAllPlugins ();215 QStringList plugins = xmlTree_->getAllPluginsNames(); 214 216 Q_FOREACH (QString plugin, plugins) { 215 217 if (!loadPlugin(plugin)) { 216 218 LOG_WARN("cannot load plugin '" << plugin << "'"); 219 } else { 220 LOG_INFO("successfully loaded plugin '" << plugin << "'"); 217 221 } 218 222 } … … 296 300 297 301 for (int i = 0; i < connectionsNodeList.size(); ++i) { 298 299 302 cfg.localCopy(connectionsNodeList.item(i).toElement()); 300 303 QString connectionInput = cfg.getConnectionInput(); … … 303 306 int connectionPriority = cfg.getConnectionPriority(); 304 307 305 306 308 //TODO set connection mode from string 307 309 … … 309 311 //InputInterfaceBase::NeverSkip; 310 312 //InputInterfaceBase::TimeBounded; 311 312 313 313 314 if (!createConnection(connectionOutput, connectionInput, connectionType,connectionPriority)) { … … 325 326 326 327 bool result = true; 327 for (ComponentMap::iterator it = componentMap_.begin(), itend = componentMap_.end(); it != itend; ++it )328 for (ComponentMap::iterator it = componentMap_.begin(), itend = componentMap_.end(); it != itend; ++it) { 328 329 result &= start(it.key()); 330 } 329 331 330 332 return result; … … 355 357 356 358 bool result = true; 357 for (ComponentMap::iterator it = componentMap_.begin(); it != componentMap_.end(); ++it) 358 result &= stop(it.key()); 359 for (ComponentMap::iterator it = componentMap_.begin(), itend = componentMap_.end(); it != itend; ++it) { 360 result &= stop(*it); 361 } 359 362 360 363 return result; 361 364 } 362 365 366 bool ComponentManager::stop(ComponentBase* component) const 367 { 368 if (!component) { 369 LOG_WARN("NULL component pointer"); 370 return false; 371 } 372 if (!component->stopComponent()) { 373 return false; 374 } 375 return true; 376 } 377 363 378 bool ComponentManager::stop(const QString& componentName) 364 379 { … … 366 381 367 382 ComponentBase* component = getComponent(componentName); 368 if (!component) 369 { 383 if (!component) { 370 384 LOG_WARN("cannot stop component '" << componentName << "'" << ". It does not exist"); 371 385 return false; … … 373 387 374 388 LOG_INFO("stopping component '" << componentName << "'..."); 375 if (! component->stopComponent()) {389 if (!stop(component)) { 376 390 LOG_WARN("cannot stop component '" << componentName << "'" << ". It can be already stopped"); 377 391 }
Note:
See TracChangeset
for help on using the changeset viewer.