Changeset 47 in pacpusframework


Ignore:
Timestamp:
01/09/13 00:24:45 (11 years ago)
Author:
sgosseli
Message:

Minor: cleanup, coding style, remove useless search in a map.

File:
1 edited

Legend:

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

    r31 r47  
    2828    LOG_TRACE("getInstance()");
    2929    LOG_TRACE("before:  mInstance = " << mInstance);
    30     if (NULL == mInstance) {
     30
     31    if (!mInstance)
     32    {
    3133        LOG_INFO("creating new instance...");
    3234        mInstance = new ComponentManager();
    3335        LOG_DEBUG("mInstance = " << mInstance);
    3436    }
     37
    3538    LOG_TRACE("after:   mInstance = " << mInstance);
    3639    return mInstance;
     
    5861
    5962    QMutableMapIterator<ComponentMap::key_type, ComponentMap::mapped_type> it(componentMap_);
    60     while (it.hasNext()) {
     63    while (it.hasNext())
    6164        unRegisterComponent(it.next().key());
    62     }
     65
    6366    LOG_DEBUG("component manager was deleted");
    6467}
     
    6871    LOG_TRACE("registerComponentFactory(type="<< type << ")");
    6972
    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");
    7476        return false;
    7577    }
    7678
    7779    factoryMap_[type] = addr;
    78     LOG_INFO("registered component factory '" << type << "'"
    79              );
     80    LOG_INFO("registered component factory '" << type << "'");
     81
    8082    return true;
    8183}
     
    8587    LOG_TRACE("unRegisterComponentFactory(type="<< type << ")");
    8688
    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
    9395    factoryMap_.remove(type);
    94     LOG_INFO("unregistered component factory '" << type << "'"
    95              );
     96    LOG_INFO("unregistered component factory '" << type << "'");
     97
    9698    return true;
    9799}
     
    101103    LOG_TRACE("registerComponent(name="<< name << ")");
    102104
    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
    109111    componentMap_[name] = addr;
    110     LOG_INFO("registered component " << name
    111              );
     112    LOG_INFO("registered component " << name);
     113
    112114    return true;
    113115}
     
    117119    LOG_TRACE("unRegisterComponent(name="<< name << ")");
    118120
    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
    125127    // FIXME: delete component
    126128    //delete componentMap_[name];
    127129    componentMap_.remove(name);
    128     LOG_INFO("unregistered component '" << name << "'"
    129              );
     130    LOG_INFO("unregistered component '" << name << "'");
     131
    130132    return true;
    131133}
     
    135137    LOG_TRACE("createComponent(type=" << type << ", " << "name="<< name << ")");
    136138
    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
    141146    LOG_WARN("cannot create component '" << name << "'"
    142147             << ". Component factory for type '" << type << "'"
     
    178183
    179184    // load the components tree in memory
    180     /*int loadedComponentsCount = */xmlTree_->loadFile(configFilename);
     185    xmlTree_->loadFile(configFilename);
    181186
    182187    {
     
    264269}
    265270
    266 int ComponentManager::start()
     271bool ComponentManager::start()
    267272{
    268273    LOG_TRACE("start()");
    269274
    270275    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
    274279    return result;
    275280}
    276281
    277 int ComponentManager::start(const QString& componentName)
     282bool ComponentManager::start(const QString& componentName)
    278283{
    279284    LOG_TRACE("start(component=" << componentName << ")");
    280285
    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!");
    286290        return false;
    287291    }
    288292
    289293    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
     300bool ComponentManager::stop()
    299301{
    300302    LOG_TRACE("stop()");
    301303
    302304    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
    306308    return result;
    307309}
    308310
    309 int ComponentManager::stop(const QString& componentName)
     311bool ComponentManager::stop(const QString& componentName)
    310312{
    311313    LOG_TRACE("stop(component=" << componentName << ")");
    312314
    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");
    318319        return false;
    319320    }
    320321
    321322    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
    327326    return true;
    328327}
     
    332331    LOG_TRACE("getComponent(name=" << name << ")");
    333332
    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
     341QStringList ComponentManager::getAllComponentsName() const
    344342{
    345343    LOG_TRACE("getAllComponentsName()");
    346 
    347344    return xmlTree_->getAllComponents();
    348345}
Note: See TracChangeset for help on using the changeset viewer.