Ignore:
Timestamp:
Jul 31, 2013, 11:20:11 AM (11 years ago)
Author:
Marek Kurdej
Message:

Update: refactoring in XmlConfigFile.
Added: attributes 'prefix', 'postfix', 'extension' in <parameters>.
Example: <parameters prefix="" postfix="_d" extension="dll">

File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/2.0-beta1/src/PacpusLib/ComponentManager.cpp

    r141 r146  
    2727{
    2828    LOG_TRACE("getInstance()");
    29     LOG_TRACE("before:  mInstance = " << mInstance);
    30 
    31     if (!mInstance)
    32     {
     29    LOG_TRACE("before: mInstance = " << mInstance);
     30
     31    if (!mInstance) {
    3332        LOG_INFO("creating new instance...");
    3433        mInstance = new ComponentManager();
     
    3635    }
    3736
    38     LOG_TRACE("after mInstance = " << mInstance);
     37    LOG_TRACE("after : mInstance = " << mInstance);
    3938    return mInstance;
    4039}
     
    4443    LOG_TRACE("destroy");
    4544
     45    LOG_TRACE("before: mInstance = " << mInstance);
    4646    delete mInstance;
    4747    mInstance = NULL;
     48    LOG_TRACE("after : mInstance = " << mInstance);
    4849}
    4950
     
    6061    LOG_TRACE("destructor");
    6162
    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    }
    6566
    6667    LOG_DEBUG("component manager was deleted");
     
    8384}
    8485
    85 bool ComponentManager::unRegisterComponentFactory(const QString& type)
    86 {
    87     LOG_TRACE("unRegisterComponentFactory(type="<< type << ")");
    88 
    89     if (!factoryMap_.contains(type))
    90     {
     86bool ComponentManager::unregisterComponentFactory(const QString& type)
     87{
     88    LOG_TRACE("unregisterComponentFactory(type="<< type << ")");
     89
     90    if (!factoryMap_.contains(type)) {
    9191        LOG_WARN("cannot unregister component factory '" << type << "'. It was not registered");
    9292        return false;
     
    115115}
    116116
    117 bool ComponentManager::unRegisterComponent(const QString& name)
    118 {
    119     LOG_TRACE("unRegisterComponent(name="<< name << ")");
    120 
    121     if (!componentMap_.contains(name))
    122     {
     117bool ComponentManager::unregisterComponent(const QString& name)
     118{
     119    LOG_TRACE("unregisterComponent(name="<< name << ")");
     120
     121    if (!componentMap_.contains(name)) {
    123122        LOG_WARN("cannot unregister component '" << name << "'. It was not registered");
    124123        return false;
     
    126125
    127126    // 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);
    130132    LOG_INFO("unregistered component '" << name << "'");
    131133
     
    137139    LOG_TRACE("createComponent(type=" << type << ", " << "name="<< name << ")");
    138140
    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);
    143145        return true;
    144146    }
     
    211213    {
    212214        // Load the plugins containing the components
    213         QStringList plugins = xmlTree_->getAllPlugins();
     215        QStringList plugins = xmlTree_->getAllPluginsNames();
    214216        Q_FOREACH (QString plugin, plugins) {
    215217            if (!loadPlugin(plugin)) {
    216218                LOG_WARN("cannot load plugin '" << plugin << "'");
     219            } else {
     220                LOG_INFO("successfully loaded plugin '" << plugin << "'");
    217221            }
    218222        }
     
    296300
    297301    for (int i = 0; i < connectionsNodeList.size(); ++i) {
    298 
    299302        cfg.localCopy(connectionsNodeList.item(i).toElement());
    300303        QString connectionInput = cfg.getConnectionInput();
     
    303306        int connectionPriority = cfg.getConnectionPriority();
    304307
    305 
    306308        //TODO set connection mode from string
    307309
     
    309311        //InputInterfaceBase::NeverSkip;
    310312        //InputInterfaceBase::TimeBounded;
    311 
    312313
    313314        if (!createConnection(connectionOutput, connectionInput, connectionType,connectionPriority)) {
     
    325326
    326327    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) {
    328329        result &= start(it.key());
     330    }
    329331
    330332    return result;
     
    355357
    356358    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    }
    359362
    360363    return result;
    361364}
    362365
     366bool 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
    363378bool ComponentManager::stop(const QString& componentName)
    364379{
     
    366381
    367382    ComponentBase* component = getComponent(componentName);
    368     if (!component)
    369     {
     383    if (!component) {
    370384        LOG_WARN("cannot stop component '" << componentName << "'" << ". It does not exist");
    371385        return false;
     
    373387
    374388    LOG_INFO("stopping component '" << componentName << "'...");
    375     if (!component->stopComponent()) {
     389    if (!stop(component)) {
    376390        LOG_WARN("cannot stop component '" << componentName << "'" << ". It can be already stopped");
    377391    }
Note: See TracChangeset for help on using the changeset viewer.