Changeset 288 in pacpusframework for trunk/src/PacpusLib
- Timestamp:
- Mar 26, 2014, 9:27:30 PM (11 years ago)
- Location:
- trunk/src/PacpusLib
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/PacpusLib/ComponentBase.cpp
r286 r288 17 17 #include <boost/program_options/parsers.hpp> 18 18 #include <boost/program_options/variables_map.hpp> 19 #include <boost/thread/thread.hpp>19 //#include <boost/thread/thread.hpp> 20 20 #include <ostream> 21 21 #include <string> … … 77 77 DECLARE_STATIC_LOGGER("pacpus.core.ComponentBase"); 78 78 79 ComponentBase::ComponentBase( const QString& componentName)79 ComponentBase::ComponentBase(QString const& componentName) 80 80 : m_componentName(componentName) 81 81 , m_isActive(false) … … 131 131 } 132 132 133 void ComponentBase::startComponentWithException(boost::exception_ptr& error)134 {135 try {136 startActivity();137 error = boost::exception_ptr();138 } catch (...) {139 error = boost::current_exception();140 }141 }142 143 void ComponentBase::startComponentInThread()144 {145 boost::exception_ptr error;146 boost::thread t(147 boost::bind(148 &ComponentBase::startComponentWithException,149 this,150 boost::ref(error)151 )152 );153 t.join();154 if (error) {155 try {156 boost::rethrow_exception(error);157 } catch (boost::exception& e) {158 LOG_FATAL("[" << getName() << "]" << "\tboost::exception thrown: " << boost::diagnostic_information(e));159 //throw;160 }161 }162 }133 //void ComponentBase::startComponentWithException(boost::exception_ptr& error) 134 //{ 135 // try { 136 // startActivity(); 137 // error = boost::exception_ptr(); 138 // } catch (...) { 139 // error = boost::current_exception(); 140 // } 141 //} 142 // 143 //void ComponentBase::startComponentInThread() 144 //{ 145 // boost::exception_ptr error; 146 // boost::thread t( 147 // boost::bind( 148 // &ComponentBase::startComponentWithException, 149 // this, 150 // boost::ref(error) 151 // ) 152 // ); 153 // t.join(); 154 // if (error) { 155 // try { 156 // boost::rethrow_exception(error); 157 // } catch (boost::exception& e) { 158 // LOG_FATAL("[" << getName() << "]" << "\tboost::exception thrown: " << boost::diagnostic_information(e)); 159 // //throw; 160 // } 161 // } 162 //} 163 163 164 164 int ComponentBase::startComponent() … … 170 170 171 171 setActive(true); 172 boost::thread worker(&ComponentBase::startComponentInThread, this); 173 //boost::thread worker(&ComponentBase::startActivity, this); 174 //startActivity(); 172 //boost::thread worker(&ComponentBase::startComponentInThread, this); 173 startActivity(); 174 //moveToThread(&mThread); 175 //mThread.start(); 175 176 return true; 176 177 } … … 185 186 setActive(false); 186 187 stopActivity(); 187 188 //QMetaObject::invokeMethod(&mThread, "quit"); 188 189 return true; 189 190 } -
trunk/src/PacpusLib/ComponentFactoryBase.cpp
r89 r288 10 10 #include <Pacpus/kernel/Log.h> 11 11 12 #include < cassert>12 #include <boost/assert.hpp> 13 13 #include <QString> 14 14 … … 23 23 // get the adress of the ComponentManager instance 24 24 mgr_ = ComponentManager::getInstance(); 25 BOOST_ASSERT(mgr_); 25 26 } 26 27 … … 30 31 } 31 32 32 void ComponentFactoryBase::addFactory(ComponentFactoryBase* addr, const QString& type)33 void ComponentFactoryBase::addFactory(ComponentFactoryBase* addr, QString const& type) 33 34 { 34 35 LOG_DEBUG("addFactory(type="<< type << ")"); 35 36 36 assert(mgr_);37 37 if (!mgr_->registerComponentFactory(addr, type)) { 38 38 /* … … 44 44 } 45 45 46 void ComponentFactoryBase:: addComponent(const QString& name)46 void ComponentFactoryBase::createComponent(QString const& name) 47 47 { 48 48 LOG_DEBUG("addComponent(" << name << ")"); 49 49 50 // FIXME: instantiated component is never deleted! 51 // who should do it? ComponentManager? 52 ComponentBase * addr = instantiateComponent(name); 53 assert(mgr_); 54 if (!mgr_->registerComponent(addr, name)) { 55 delete addr; 56 addr = NULL; 57 } 50 ComponentSharedPointer component = instantiateComponent(name); 51 mgr_->registerComponent(component, name); 58 52 } -
trunk/src/PacpusLib/ComponentManager.cpp
r277 r288 125 125 } 126 126 127 bool ComponentManager::registerComponentFactory(ComponentFactoryBase* addr, const QString& type)127 bool ComponentManager::registerComponentFactory(ComponentFactoryBase* addr, QString const& type) 128 128 { 129 129 LOG_TRACE("registerComponentFactory(type="<< type << ")"); … … 141 141 } 142 142 143 bool ComponentManager::unregisterComponentFactory( const QString& type)143 bool ComponentManager::unregisterComponentFactory(QString const& type) 144 144 { 145 145 LOG_TRACE("unregisterComponentFactory(type="<< type << ")"); … … 156 156 } 157 157 158 bool ComponentManager::registerComponent( ComponentBase* addr, const QString& name)158 bool ComponentManager::registerComponent(boost::shared_ptr<ComponentBase> addr, QString const& name) 159 159 { 160 160 LOG_TRACE("registerComponent(name="<< name << ")"); … … 171 171 } 172 172 173 bool ComponentManager::unregisterComponent( const QString& name)173 bool ComponentManager::unregisterComponent(QString const& name) 174 174 { 175 175 LOG_TRACE("unregisterComponent(name="<< name << ")"); … … 180 180 } 181 181 182 // FIXME: delete component 183 ComponentBase* component = componentMap_.value(name, NULL); 184 //delete component; 185 182 boost::shared_ptr<ComponentBase> component = componentMap_.value(name, NULL); 183 186 184 // FIXME: remove from map (causes segfault in QMap::qMapLessThanKey on Windows) 187 185 //componentMap_.remove(name); 188 186 LOG_INFO("unregistered component '" << name << "'"); 189 190 return true; 191 } 192 193 bool ComponentManager::createComponent(const QString& type, const QString& name) 187 return true; 188 } 189 190 bool ComponentManager::createComponent(QString const& type, QString const& name) 194 191 { 195 192 LOG_TRACE("createComponent(type=" << type << ", " << "name="<< name << ")"); … … 198 195 ComponentFactoryBase* factory = factoryMap_.value(type); 199 196 assert(factory); 200 factory-> addComponent(name);197 factory->createComponent(name); 201 198 return true; 202 199 } … … 209 206 } 210 207 211 bool ComponentManager::loadPlugin( const QString& filename)208 bool ComponentManager::loadPlugin(QString const& filename) 212 209 { 213 210 LOG_TRACE("loadPlugin(filename=" << filename << ")"); … … 236 233 } 237 234 238 bool ComponentManager::checkComponent( const QString& componentName)235 bool ComponentManager::checkComponent(QString const& componentName) 239 236 { 240 237 if (NULL == getComponent(componentName)) { … … 245 242 } 246 243 247 bool ComponentManager::checkComponentInput( const QString & componentName, const QString& inputName)244 bool ComponentManager::checkComponentInput(QString const& componentName, QString const& inputName) 248 245 { 249 246 if (!checkComponent(componentName)) { … … 257 254 } 258 255 259 bool ComponentManager::checkComponentOutput( const QString & componentName, const QString& outputName)256 bool ComponentManager::checkComponentOutput(QString const& componentName, QString const& outputName) 260 257 { 261 258 if (!checkComponent(componentName)) { … … 269 266 } 270 267 271 bool ComponentManager::createConnection( const QString & outputSignature, const QString & inputSignature, const QString& type, int priority = 0)268 bool ComponentManager::createConnection(QString const& outputSignature, QString const& inputSignature, QString const& type, int priority = 0) 272 269 { 273 270 // FIXME: use 2 signatures (output component + output connection) instead of 1 separated by a (".") dot … … 289 286 } 290 287 291 std::size_t ComponentManager::loadComponents( const QString& configFilename)288 std::size_t ComponentManager::loadComponents(QString const& configFilename) 292 289 { 293 290 LOG_TRACE("loadComponents(filename=" << configFilename << ")"); … … 334 331 335 332 // copy locally the config parameters of the component 336 Component Base *component = getComponent(componentName);333 ComponentSharedPointer component = getComponent(componentName); 337 334 if (NULL == component) { 338 335 LOG_WARN("component '" << componentName << "' does not exist"); … … 356 353 QString componentName = cfg.getComponentName(); 357 354 358 Component Base *component = getComponent(componentName);359 if ( NULL ==component) {355 ComponentSharedPointer component = getComponent(componentName); 356 if (!component) { 360 357 LOG_WARN("component '" << componentName << "' does not exist"); 361 358 continue; … … 430 427 } 431 428 432 bool ComponentManager::start( const QString& componentName)429 bool ComponentManager::start(QString const& componentName) 433 430 { 434 431 LOG_TRACE("start(component=" << componentName << ")"); 435 432 436 Component Base*component = getComponent(componentName);433 ComponentSharedPointer component = getComponent(componentName); 437 434 if (!component) { 438 435 LOG_WARN("cannot start component '" << componentName << "'. It does not exist!"); … … 465 462 } 466 463 467 bool ComponentManager::stop(Component Base *component) const464 bool ComponentManager::stop(ComponentSharedPointer component) const 468 465 { 469 466 if (!component) { … … 477 474 } 478 475 479 bool ComponentManager::stop( const QString& componentName)476 bool ComponentManager::stop(QString const& componentName) 480 477 { 481 478 LOG_TRACE("stop(component=" << componentName << ")"); 482 479 483 Component Base*component = getComponent(componentName);480 ComponentSharedPointer component = getComponent(componentName); 484 481 if (!component) { 485 482 LOG_WARN("cannot stop component '" << componentName << "'" << ". It does not exist"); … … 495 492 } 496 493 497 Component Base * ComponentManager::getComponent(const QString& name)494 ComponentSharedPointer ComponentManager::getComponent(QString const& name) 498 495 { 499 496 LOG_TRACE("getComponent(name=" << name << ")"); -
trunk/src/PacpusLib/XmlComponentConfig.cpp
r270 r288 22 22 static const char* kPropertyConnectionPriority = "priority"; 23 23 24 XmlComponentConfig::XmlComponentConfig( const QString& name)24 XmlComponentConfig::XmlComponentConfig(QString const& name) 25 25 { 26 26 LOG_TRACE("XmlComponentConfig(QString)"); … … 43 43 } 44 44 45 void XmlComponentConfig::addProperty( const QString& name)45 void XmlComponentConfig::addProperty(QString const& name) 46 46 { 47 47 if (hasProperty(name)) { … … 62 62 } 63 63 64 int XmlComponentConfig::delProperty( const QString& name)64 int XmlComponentConfig::delProperty(QString const& name) 65 65 { 66 66 if (!hasProperty(name)) { … … 82 82 } 83 83 84 QString XmlComponentConfig::getProperty( const QString& name, const QString& defaultValue) const84 QString XmlComponentConfig::getProperty(QString const& name, QString const& defaultValue) const 85 85 { 86 86 if (!hasProperty(name)) … … 97 97 } 98 98 99 bool XmlComponentConfig::getBoolProperty( const QString& name, bool defaultValue) const99 bool XmlComponentConfig::getBoolProperty(QString const& name, bool defaultValue) const 100 100 { 101 101 return hasProperty(name) ? getProperty(name) == "true" : defaultValue; 102 102 } 103 103 104 int XmlComponentConfig::getIntProperty( const QString& name, int defaultValue) const104 int XmlComponentConfig::getIntProperty(QString const& name, int defaultValue) const 105 105 { 106 106 return hasProperty(name) ? getProperty(name).toInt() : defaultValue; 107 107 } 108 108 109 double XmlComponentConfig::getDoubleProperty( const QString& name, double defaultValue) const109 double XmlComponentConfig::getDoubleProperty(QString const& name, double defaultValue) const 110 110 { 111 111 return hasProperty(name) ? getProperty(name).toDouble() : defaultValue; 112 112 } 113 113 114 void XmlComponentConfig::setProperty( const QString& name, const QString& value)114 void XmlComponentConfig::setProperty(QString const& name, QString const& value) 115 115 { 116 116 component_.setAttribute(name, value); … … 121 121 } 122 122 123 bool XmlComponentConfig::hasProperty( const QString& name) const123 bool XmlComponentConfig::hasProperty(QString const& name) const 124 124 { 125 125 return component_.hasAttribute(name);
Note:
See TracChangeset
for help on using the changeset viewer.