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


Ignore:
Timestamp:
Mar 26, 2014, 9:27:30 PM (11 years ago)
Author:
Marek Kurdej
Message:

Using boost::shared_ptr for storing components.

File:
1 edited

Legend:

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

    r277 r288  
    125125}
    126126
    127 bool ComponentManager::registerComponentFactory(ComponentFactoryBase* addr, const QString& type)
     127bool ComponentManager::registerComponentFactory(ComponentFactoryBase* addr, QString const& type)
    128128{
    129129    LOG_TRACE("registerComponentFactory(type="<< type << ")");
     
    141141}
    142142
    143 bool ComponentManager::unregisterComponentFactory(const QString& type)
     143bool ComponentManager::unregisterComponentFactory(QString const& type)
    144144{
    145145    LOG_TRACE("unregisterComponentFactory(type="<< type << ")");
     
    156156}
    157157
    158 bool ComponentManager::registerComponent(ComponentBase* addr, const QString& name)
     158bool ComponentManager::registerComponent(boost::shared_ptr<ComponentBase> addr, QString const& name)
    159159{
    160160    LOG_TRACE("registerComponent(name="<< name << ")");
     
    171171}
    172172
    173 bool ComponentManager::unregisterComponent(const QString& name)
     173bool ComponentManager::unregisterComponent(QString const& name)
    174174{
    175175    LOG_TRACE("unregisterComponent(name="<< name << ")");
     
    180180    }
    181181
    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   
    186184    // FIXME: remove from map (causes segfault in QMap::qMapLessThanKey on Windows)
    187185    //componentMap_.remove(name);
    188186    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
     190bool ComponentManager::createComponent(QString const& type, QString const& name)
    194191{
    195192    LOG_TRACE("createComponent(type=" << type << ", " << "name="<< name << ")");
     
    198195        ComponentFactoryBase* factory = factoryMap_.value(type);
    199196        assert(factory);
    200         factory->addComponent(name);
     197        factory->createComponent(name);
    201198        return true;
    202199    }
     
    209206}
    210207
    211 bool ComponentManager::loadPlugin(const QString& filename)
     208bool ComponentManager::loadPlugin(QString const& filename)
    212209{
    213210    LOG_TRACE("loadPlugin(filename=" << filename << ")");
     
    236233}
    237234
    238 bool ComponentManager::checkComponent(const QString & componentName)
     235bool ComponentManager::checkComponent(QString const& componentName)
    239236{
    240237    if (NULL == getComponent(componentName)) {
     
    245242}
    246243
    247 bool ComponentManager::checkComponentInput(const QString & componentName, const QString & inputName)
     244bool ComponentManager::checkComponentInput(QString const& componentName, QString const& inputName)
    248245{
    249246    if (!checkComponent(componentName)) {
     
    257254}
    258255
    259 bool ComponentManager::checkComponentOutput(const QString & componentName, const QString & outputName)
     256bool ComponentManager::checkComponentOutput(QString const& componentName, QString const& outputName)
    260257{
    261258    if (!checkComponent(componentName)) {
     
    269266}
    270267
    271 bool ComponentManager::createConnection(const QString & outputSignature, const QString & inputSignature, const QString & type, int priority = 0)
     268bool ComponentManager::createConnection(QString const& outputSignature, QString const& inputSignature, QString const& type, int priority = 0)
    272269{
    273270    // FIXME: use 2 signatures (output component + output connection) instead of 1 separated by a (".") dot
     
    289286}
    290287
    291 std::size_t ComponentManager::loadComponents(const QString& configFilename)
     288std::size_t ComponentManager::loadComponents(QString const& configFilename)
    292289{
    293290    LOG_TRACE("loadComponents(filename=" << configFilename << ")");
     
    334331
    335332        // copy locally the config parameters of the component
    336         ComponentBase * component = getComponent(componentName);
     333        ComponentSharedPointer component = getComponent(componentName);
    337334        if (NULL == component) {
    338335            LOG_WARN("component '" << componentName << "' does not exist");
     
    356353        QString componentName = cfg.getComponentName();
    357354
    358         ComponentBase * component = getComponent(componentName);
    359         if (NULL == component) {
     355        ComponentSharedPointer component = getComponent(componentName);
     356        if (!component) {
    360357            LOG_WARN("component '" << componentName << "' does not exist");
    361358            continue;
     
    430427}
    431428
    432 bool ComponentManager::start(const QString & componentName)
     429bool ComponentManager::start(QString const& componentName)
    433430{
    434431    LOG_TRACE("start(component=" << componentName << ")");
    435432
    436     ComponentBase* component = getComponent(componentName);
     433    ComponentSharedPointer component = getComponent(componentName);
    437434    if (!component) {
    438435        LOG_WARN("cannot start component '" << componentName << "'.  It does not exist!");
     
    465462}
    466463
    467 bool ComponentManager::stop(ComponentBase * component) const
     464bool ComponentManager::stop(ComponentSharedPointer component) const
    468465{
    469466    if (!component) {
     
    477474}
    478475
    479 bool ComponentManager::stop(const QString & componentName)
     476bool ComponentManager::stop(QString const& componentName)
    480477{
    481478    LOG_TRACE("stop(component=" << componentName << ")");
    482479
    483     ComponentBase* component = getComponent(componentName);
     480    ComponentSharedPointer component = getComponent(componentName);
    484481    if (!component) {
    485482        LOG_WARN("cannot stop component '" << componentName << "'" << ". It does not exist");
     
    495492}
    496493
    497 ComponentBase * ComponentManager::getComponent(const QString & name)
     494ComponentSharedPointer ComponentManager::getComponent(QString const& name)
    498495{
    499496    LOG_TRACE("getComponent(name=" << name << ")");
Note: See TracChangeset for help on using the changeset viewer.