Changeset 201 in pacpusframework for trunk/src/PacpusLib/ComponentManager.cpp


Ignore:
Timestamp:
10/28/13 15:24:14 (11 years ago)
Author:
Marek Kurdej
Message:

Major: rethrow PacpusException on parameter parsing, set configurationState to ComponentBase::CONFIGURED_FAILED.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/PacpusLib/ComponentManager.cpp

    r199 r201  
    1313#include <Pacpus/kernel/InputOutputBase.h>
    1414#include <Pacpus/kernel/Log.h>
     15#include <Pacpus/kernel/PacpusException.h>
    1516
    1617#include <QDomNodeList>
     
    290291        if (NULL == component) {
    291292            LOG_WARN("component '" << componentName << "' does not exist");
    292         } else {
    293             component->param.localCopy(cfg.qDomElement());
     293            continue;
     294        }
     295
     296        component->param.localCopy(cfg.qDomElement());
     297        try {
    294298            component->parseParameters(cfg);
    295299            component->setConfigurationState(component->configureComponent(cfg));
     300        } catch (PacpusException & e) {
     301            LOG_ERROR("component '" << componentName << "' has thrown an exception");
     302            LOG_ERROR(e.what());
     303            component->setConfigurationState(ComponentBase::CONFIGURED_FAILED);
    296304        }
    297305    } // for
    298306
    299307    // Third, if some components requested a delayed configuration, retry
    300     for (int i = 0; i < componentsNodeList.size(); ++i) {
     308    for (int i = 0, iend = componentsNodeList.size(); i < iend; ++i) {
    301309        cfg.localCopy(componentsNodeList.item(i).toElement());
    302310        QString componentName = cfg.getComponentName();
     
    305313        if (NULL == component) {
    306314            LOG_WARN("component '" << componentName << "' does not exist");
     315            continue;
     316        }
     317         
     318        // Pacpus 2.0 : add inputs and outputs
     319        component->addInputs();
     320        component->addOutputs();
     321
     322        if (ComponentBase::CONFIGURATION_DELAYED == component->configurationState()) {
     323            LOG_DEBUG("try to configure component '" << componentName << "'");
     324
     325            // copy locally the config parameters of the component
     326            component->param.localCopy(cfg.qDomElement());
     327            component->setConfigurationState(component->configureComponent(cfg));
     328        }
     329
     330        if (ComponentBase::CONFIGURED_OK == component->configurationState()) {
     331            --componentsToConfigureCount;
    307332        } else {
    308            // Pacpus 2.0 : add inputs and outputs
    309             component->addInputs();
    310             component->addOutputs();
    311 
    312             if (ComponentBase::CONFIGURATION_DELAYED == component->configurationState()) {
    313                 LOG_DEBUG("try to configure component '" << componentName << "'");
    314 
    315                 // copy locally the config parameters of the component
    316                 component->param.localCopy(cfg.qDomElement());
    317                 component->setConfigurationState(component->configureComponent(cfg));
    318             }
    319 
    320             if (ComponentBase::CONFIGURED_OK == component->configurationState()) {
    321                 --componentsToConfigureCount;
    322             } else {
    323                 LOG_ERROR("cannot configure component '" << componentName << "'"
    324                           << ". Dependencies with other components are too complex"
    325                           << ". It was not configured, please review your configuration and/or your component"
    326                           );
    327                 component->setConfigurationState(ComponentBase::CONFIGURED_FAILED);
    328             }
     333            LOG_ERROR("cannot configure component '" << componentName << "'"
     334                        << ". Dependencies with other components are too complex"
     335                        << ". It was not configured, please review your configuration and/or your component"
     336                        );
     337            component->setConfigurationState(ComponentBase::CONFIGURED_FAILED);
    329338        }
    330339    } // for
     
    338347    QDomNodeList connectionsNodeList = xmlTree_->getAllConnections();
    339348
    340     for (int i = 0; i < connectionsNodeList.size(); ++i) {
     349    for (int i = 0, iend = connectionsNodeList.size(); i < iend; ++i) {
    341350        cfg.localCopy(connectionsNodeList.item(i).toElement());
    342351        QString connectionInput = cfg.getConnectionInput();
     
    372381}
    373382
    374 bool ComponentManager::start(const QString& componentName)
     383bool ComponentManager::start(const QString & componentName)
    375384{
    376385    LOG_TRACE("start(component=" << componentName << ")");
     
    382391    }
    383392
     393    if (ComponentBase::CONFIGURED_OK != component->configurationState()) {
     394        LOG_WARN("cannot start component '" << componentName << "'.  It has not been configured properly!");
     395        return false;
     396    }
     397
    384398    LOG_INFO("starting component '" << componentName << "'...");
    385399    if (!component->startComponent()) {
     
    402416}
    403417
    404 bool ComponentManager::stop(ComponentBase* component) const
     418bool ComponentManager::stop(ComponentBase * component) const
    405419{
    406420    if (!component) {
     
    414428}
    415429
    416 bool ComponentManager::stop(const QString& componentName)
     430bool ComponentManager::stop(const QString & componentName)
    417431{
    418432    LOG_TRACE("stop(component=" << componentName << ")");
     
    432446}
    433447
    434 ComponentBase* ComponentManager::getComponent(const QString& name)
     448ComponentBase * ComponentManager::getComponent(const QString & name)
    435449{
    436450    LOG_TRACE("getComponent(name=" << name << ")");
Note: See TracChangeset for help on using the changeset viewer.