Changeset 288 in pacpusframework for trunk


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

Using boost::shared_ptr for storing components.

Location:
trunk
Files:
21 edited

Legend:

Unmodified
Added
Removed
  • trunk/examples/ProducerConsumerExample/ConsumerExample.cpp

    r272 r288  
    1010DECLARE_STATIC_LOGGER("pacpus.cityvip.test.ConsumerExample");
    1111
    12 /// Construct the factory
    13 static ComponentFactory<ConsumerExample> sFactory("ConsumerExample");
     12PACPUS_REGISTER_COMPONENT(ConsumerExample);
    1413
    1514ConsumerExample::ConsumerExample(QString name)
  • trunk/examples/ProducerConsumerExample/ConsumerExample.h

    r176 r288  
    1010#include <string>
    1111
    12 namespace pacpus {
     12namespace pacpus
     13{
    1314
    1415class PRODUCERCONSUMEREXAMPLE_API ConsumerExample
    15         : public QObject
    16         , public ComponentBase
     16    : public QObject
     17    , public ComponentBase
    1718{
    1819    Q_OBJECT
  • trunk/examples/ProducerConsumerExample/ProducerExample.cpp

    r202 r288  
    1212DECLARE_STATIC_LOGGER("pacpus.cityvip.test.ProducerExample");
    1313
    14 /// Construct the factory
    15 static ComponentFactory<ProducerExample> sFactory("ProducerExample");
     14PACPUS_REGISTER_COMPONENT(ProducerExample);
    1615
    1716static const char * outputFileName = "producer.txt";
  • trunk/include/Pacpus/DbitePlayer/DbtPlyFileManager.h

    r181 r288  
    9797
    9898    /// a pointer on the player engine
    99     DbtPlyEngine * mEngine;
     99    boost::shared_ptr<DbtPlyEngine> mEngine;
    100100
    101101    QStringList getDbiteFilenameList() const;
  • trunk/include/Pacpus/DbitePlayer/DbtPlyTrigger.h

    r152 r288  
    6464
    6565private:
    66     DbtPlyEngine * mEngine;
     66    boost::shared_ptr<DbtPlyEngine> mEngine;
    6767};
    6868
  • trunk/include/Pacpus/DbitePlayer/DbtPlyUserInterface.h

    r152 r288  
    9999   
    100100private:
    101     DbtPlyEngine * mEngine;
     101    boost::shared_ptr<DbtPlyEngine> mEngine;
    102102
    103103    QWidget * wTel_ ;
  • trunk/include/Pacpus/kernel/ComponentBase.h

    r286 r288  
    2323#define DEF_PACPUS_COMPONENTBASE_H
    2424
    25 #include <Pacpus/kernel/ComponentManager.h>
     25//#include <Pacpus/kernel/ComponentManager.h>
    2626#include <Pacpus/kernel/InputOutputBase.h>
    2727// InputOutputInterface.h must be included, otherwise we could not use addInput, addOutput template methods
     
    3333#include <boost/program_options/options_description.hpp>
    3434#include <boost/program_options/value_semantic.hpp>
     35#include <QMap>
    3536#include <QString>
    36 #include <QMap>
    3737#include <string>
    3838
     
    5252namespace pacpus
    5353{
     54
     55class ComponentBase;
    5456
    5557class ComponentManager;
     
    9193    /// Ctor of ComponentBase.
    9294    /// @param name Name of your component.
    93     ComponentBase(const QString & name);
     95    ComponentBase(QString const& name);
    9496
    9597    /// Dtor of ComponentBase.
     
    195197    std::string mName;
    196198    std::string mTypeName;
    197    
     199    //QThread mThread;
     200
    198201    /// Whether to display or not the graphical interface (GUI)
    199202    bool hasGui() const;
  • trunk/include/Pacpus/kernel/ComponentFactory.h

    r89 r288  
    1616#define DEF_PACPUS_COMPONENTFACTORY_H
    1717
    18 #include <cassert>
    19 
    20 //#include <boost/static_assert.hpp>
    21 //#include <boost/type_traits/is_base_of.hpp>
     18#include <boost/assert.hpp>
     19#include <boost/static_assert.hpp>
     20#include <boost/type_traits/is_base_of.hpp>
    2221
    2322#include <Pacpus/kernel/ComponentFactoryBase.h>
     
    3736  static pacpus::ComponentFactory<className> sFactory(factoryName)
    3837
    39 namespace pacpus {
     38#define PACPUS_REGISTER_COMPONENT(Class) \
     39    static pacpus::ComponentFactory<Class> sFactory(#Class)
     40
     41namespace pacpus
     42{
    4043
    4144/// Use it to interface your components with the application.
     
    4750    : public ComponentFactoryBase
    4851{
    49     //static_assert(,"T must inherit from ComponentBase")
    50     //  BOOST_STATIC_ASSERT_MSG((boost::is_base_of<ComponentBase, T>::value), "T must inherit from ComponentBase");
     52    BOOST_STATIC_ASSERT_MSG((boost::is_base_of<ComponentBase, T>::value), "component T must inherit from ComponentBase");
     53
    5154public:
    5255    /** Ctor of ComponentFactory, initialize the factory of the components of type @em T.
    5356     * @param type Name of the type of the components.
    5457     */
    55     ComponentFactory(const QString& type);
     58    ComponentFactory(QString const& type);
    5659   
    5760    /** Dtor of ComponentFactory. */
     
    6164     * @return Name of the type of the components.
    6265     */
    63     const QString& getType() const;
     66    QString const& getType() const;
    6467
    6568protected:
    66     virtual ComponentBase* instantiateComponent(const QString& name);
    67  
     69    virtual ComponentSharedPointer instantiateComponent(QString const& name);
     70
    6871private:
    6972    QString mType;
     
    7174
    7275template <typename T>
    73 ComponentFactory<T>::ComponentFactory(const QString& type)
    74   : mType(type)
     76ComponentFactory<T>::ComponentFactory(QString const& type)
     77    : mType(type)
    7578{
    76     assert(!type.isEmpty());
     79    BOOST_ASSERT(!type.isEmpty());
    7780    addFactory(this, mType);
    7881}
     
    8487
    8588template <typename T>
    86 const QString& ComponentFactory<T>::getType() const
     89QString const& ComponentFactory<T>::getType() const
    8790{
    8891    return mType;
     
    9093
    9194template<typename T>
    92 ComponentBase* ComponentFactory<T>::instantiateComponent(const QString& name)
     95ComponentSharedPointer ComponentFactory<T>::instantiateComponent(QString const& name)
    9396{
    94     return new T(name);
     97    return ComponentSharedPointer(new T(name));
    9598}
    9699
    97 } // pacpus
     100} // namespace pacpus
    98101
    99102#endif // DEF_PACPUS_DBITEEXCEPTION_H
  • trunk/include/Pacpus/kernel/ComponentFactoryBase.h

    r196 r288  
    1818#include <Pacpus/kernel/PacpusLibConfig.h>
    1919
     20#include <boost/shared_ptr.hpp>
     21//#include <boost/weak_ptr.hpp>
     22
    2023class QString;
    2124
    22 namespace pacpus {
     25namespace pacpus
     26{
     27
     28class ComponentBase;
     29
     30typedef boost::shared_ptr<ComponentBase> ComponentSharedPointer;
     31//typedef boost::weak_ptr<ComponentBase> ComponentWeakPointer;
    2332
    2433class ComponentManager;
    25 class ComponentBase;
    2634
    2735/** ComponentFactoryBase
     
    3139{
    3240    friend class ComponentManager;
     41
    3342public:
    3443    /** Ctor of ComponentFactoryBase. */
     
    4251     * @return Pointer on the newly created component, you become the owner of its lifetime.
    4352     */
    44     virtual ComponentBase * instantiateComponent(const QString& name) = 0;
     53    virtual ComponentSharedPointer instantiateComponent(QString const& name) = 0;
    4554   
    4655    /** Register a new factory.
     
    4857     * @param type Name of the type created by the factory.
    4958     */
    50     void addFactory(ComponentFactoryBase* addr, const QString& type);
     59    void addFactory(ComponentFactoryBase* addr, QString const& type);
    5160   
    5261    /** Add a new component.
    5362     * @param name Name of the new component.
    5463     */
    55     void addComponent(const QString& name);
     64    void createComponent(QString const& name);
    5665
    5766private:
  • trunk/include/Pacpus/kernel/ComponentManager.h

    r207 r288  
    2828#include <QPluginLoader>
    2929
    30 namespace pacpus {
     30namespace pacpus
     31{
    3132
    3233class ComponentBase;
    3334
    3435/// @todo Documentation
    35 typedef QMap<QString, ComponentBase *> ComponentMap;
     36typedef QMap<QString, ComponentSharedPointer> ComponentMap;
    3637/// @todo Documentation
    37 typedef QMap<QString, ComponentFactoryBase *> FactoryMap;
     38typedef QMap<QString, ComponentFactoryBase* > FactoryMap;
    3839
    3940/// Singleton recording the components and managing them.
     
    5960    struct destroyer {
    6061        /// Invokes ComponentManager::destroy() method if @b mgr pointer is not null.
    61         void operator()(ComponentManager * mgr) const
     62        void operator()(ComponentManager* mgr) const
    6263        {
    6364            if (!mgr) {
     
    7273     * @return Number of components loaded by the manager.
    7374     */
    74     std::size_t loadComponents(const QString& file);
     75    std::size_t loadComponents(QString const& file);
    7576
    7677    /** Start all the components
     
    8384     * @return True if the component exists and has been started, otherwise false.
    8485     */
    85     bool start(const QString & component);
     86    bool start(QString const& component);
    8687
    8788    /** Stop all the components
     
    9495     * @return True if the component has been stopped, otherwise false.
    9596     */
    96     bool stop(const QString& component);
     97    bool stop(QString const& component);
    9798
    9899    /** Get a pointer to the component referred by @em name.
     
    100101     * @return Pointer to the component if it exists, otherwise @em NULL.
    101102     */
    102     ComponentBase* getComponent(const QString& name);
     103    ComponentSharedPointer getComponent(QString const& name);
    103104
    104105    /** Get the list of all the names of the component known by the manager.
     
    111112     * @return True if the plugin has been loaded, otherwise false.
    112113     */
    113     bool loadPlugin(const QString& filename);
     114    bool loadPlugin(QString const& filename);
    114115
    115116private:
    116     bool stop(ComponentBase* component) const;
     117    bool stop(ComponentSharedPointer component) const;
    117118
    118119    /// Create a new component of type 'type' and with the name 'name'
    119     bool createComponent(const QString& type, const QString& name);
     120    bool createComponent(QString const& type, QString const& name);
    120121
    121     bool checkComponent(const QString & componentName);
    122     bool checkComponentInput(const QString & componentName, const QString & inputName);
    123     bool checkComponentOutput(const QString & componentName, const QString & outputName);
     122    bool checkComponent(QString const& componentName);
     123    bool checkComponentInput(QString const& componentName, QString const& inputName);
     124    bool checkComponentOutput(QString const& componentName, QString const& outputName);
    124125
    125     bool createConnection(const QString& type, const QString& name, const QString& , int );
     126    bool createConnection(QString const& type, QString const& name, QString const& , int );
    126127
    127     bool registerComponent(ComponentBase* addr, const QString& name);
    128     bool registerComponentFactory(ComponentFactoryBase* addr, const QString& type);
     128    bool registerComponent(ComponentSharedPointer addr, QString const& name);
     129    bool registerComponentFactory(ComponentFactoryBase* addr, QString const& type);
    129130
    130     bool unregisterComponent(const QString& name);
    131     bool unregisterComponentFactory(const QString& type);
     131    bool unregisterComponent(QString const& name);
     132    bool unregisterComponentFactory(QString const& type);
    132133
    133134    // Allow 2 functions to access to private members of ComponentManager
    134     friend void ComponentFactoryBase::addFactory(ComponentFactoryBase* addr, const QString & type);
    135     friend void ComponentFactoryBase::addComponent(const QString & name);
     135    friend void ComponentFactoryBase::addFactory(ComponentFactoryBase* addr, QString const& type);
     136    friend void ComponentFactoryBase::createComponent(QString const& name);
    136137
    137138    /// private constructor accessible only via static create() function
  • trunk/include/Pacpus/kernel/XmlComponentConfig.h

    r270 r288  
    3535     * @param name Name of the ComponentFactory, by convention equal to class name.
    3636     */
    37     explicit XmlComponentConfig(const QString& name = QString::null);
     37    explicit XmlComponentConfig(QString const& name = QString::null);
    3838
    3939    /** Dtor of XmlComponentConfig. */
     
    4545     * @param name Name of the property.
    4646     */
    47     void addProperty(const QString& name);
     47    void addProperty(QString const& name);
    4848
    4949    /** Delete a property from the XML.
    5050     * @return False if the property does not exist, false otherwise.
    5151     */
    52     int delProperty(const QString& name);
     52    int delProperty(QString const& name);
    5353
    5454    /** Get the value of a property.
     
    5757     * @return Value of the property, @em defaultValue otherwise.
    5858     */
    59     QString getProperty(const QString& name, const QString& defaultValue = QString::null) const;
     59    QString getProperty(QString const& name, QString const& defaultValue = QString::null) const;
    6060
    6161    /** Get the value of a property as a boolean.
     
    6464     * @return Value of the property, @em defaultValue otherwise.
    6565     */
    66     bool getBoolProperty(const QString& name, bool defaultValue = false) const;
     66    bool getBoolProperty(QString const& name, bool defaultValue = false) const;
    6767
    6868    /** Get the value of a property as an integer.
     
    7171     * @return Value of the property, @em defaultValue otherwise.
    7272     */
    73     int getIntProperty(const QString& name, int defaultValue = 0) const;
     73    int getIntProperty(QString const& name, int defaultValue = 0) const;
    7474
    7575    /** Get the value of a property as a double.
     
    7878     * @return Value of the property, @em defaultValue otherwise.
    7979     */
    80     double getDoubleProperty(const QString& name, double defaultValue = 0.0) const;
     80    double getDoubleProperty(QString const& name, double defaultValue = 0.0) const;
    8181
    8282    /** Set the value of a property.
     
    8484     * @param value Value to set.
    8585     */
    86     void setProperty(const QString& name, const QString& value);
     86    void setProperty(QString const& name, QString const& value);
    8787
    8888    /** Check if a property exists.
     
    9090     * @return True if the property exists, false otherwise.
    9191     */
    92     bool hasProperty(const QString& name) const;
     92    bool hasProperty(QString const& name) const;
    9393   
    9494public:
  • trunk/include/Pacpus/kernel/XmlConfigFile.h

    r197 r288  
    4141class PACPUSLIB_API XmlConfigFile
    4242{
    43     friend XmlComponentConfig::XmlComponentConfig(const QString&);
     43    friend XmlComponentConfig::XmlComponentConfig(QString const&);
    4444    friend class ComponentManager;
    4545
  • trunk/src/DBITEPlayerLib/DbtPlyEngine.cpp

    r277 r288  
    1010#include <Pacpus/kernel/Log.h>
    1111
    12 #include <cassert>
     12#include <boost/assert.hpp>
    1313#include <limits>
    1414#include <QDir>
     
    226226void DbtPlyEngine::playEvent()
    227227{
     228    using boost::dynamic_pointer_cast;
     229
    228230    LOG_DEBUG("Clicked: play");
    229231
    230232    // get user interface
    231233    ComponentManager * mgr = ComponentManager::getInstance();
    232     DbtPlyUserInterface * ui = dynamic_cast<DbtPlyUserInterface *>(mgr->getComponent("dbiteUserInterface"));
    233     assert(ui);
     234    boost::shared_ptr<DbtPlyUserInterface> ui = dynamic_pointer_cast<DbtPlyUserInterface>(mgr->getComponent("dbiteUserInterface"));
     235    BOOST_ASSERT(ui);
    234236    // get time value from slider
    235237    lastTDbt_ = ui->getTime() + tDbtMin_;
     
    268270void DbtPlyEngine::setState(DbtPlyEngineState * newState)
    269271{
    270     assert(newState);
     272    BOOST_ASSERT(newState);
    271273    LOG_DEBUG(mCurrentState->toString() << " => " << newState->toString());
    272274    mCurrentState = newState;
     
    284286        mSpeed = kMaxSpeed;
    285287    }
    286     assert(kMinSpeed <= mSpeed);
    287     assert(mSpeed <= kMaxSpeed);
     288    BOOST_ASSERT(kMinSpeed <= mSpeed);
     289    BOOST_ASSERT(mSpeed <= kMaxSpeed);
    288290    LOG_INFO("event: Speed Up, speed = " << mSpeed);
    289291    Q_EMIT displayStateSig(mCurrentState, mSpeed);
     
    296298        mSpeed = kMinSpeed;
    297299    }
    298     assert(kMinSpeed <= mSpeed);
    299     assert(mSpeed <= kMaxSpeed);
     300    BOOST_ASSERT(kMinSpeed <= mSpeed);
     301    BOOST_ASSERT(mSpeed <= kMaxSpeed);
    300302    LOG_INFO("event: Speed Up, speed = " << mSpeed);
    301303    Q_EMIT displayStateSig(mCurrentState, mSpeed);
     
    304306void DbtPlyEngine::reset()
    305307{
     308    using boost::dynamic_pointer_cast;
     309
    306310    lastTNow_ = road_time();
    307311    lastTDbt_ = tDbtMin_;
     
    311315    // get user interface
    312316    ComponentManager * mgr = ComponentManager::getInstance();
    313     DbtPlyUserInterface * ui = dynamic_cast<DbtPlyUserInterface *>(mgr->getComponent("dbiteUserInterface"));
    314     assert(ui);
     317    boost::shared_ptr<DbtPlyUserInterface> ui = dynamic_pointer_cast<DbtPlyUserInterface>(mgr->getComponent("dbiteUserInterface"));
     318    BOOST_ASSERT(ui);
    315319    // reset time value of the slider
    316320    ui->resetTime();
  • trunk/src/DBITEPlayerLib/DbtPlyFileManager.cpp

    r181 r288  
    6767ComponentBase::COMPONENT_CONFIGURATION DbtPlyFileManager::configureComponent(XmlComponentConfig config)
    6868{
     69    using boost::dynamic_pointer_cast;
     70
    6971    ComponentManager * mgr = ComponentManager::getInstance();
    70     mEngine = static_cast<DbtPlyEngine *>(mgr->getComponent("dbiteEngine"));
    71     if (NULL == mEngine ) {
     72    mEngine = dynamic_pointer_cast<DbtPlyEngine>(mgr->getComponent("dbiteEngine"));
     73    if (!mEngine) {
    7274        LOG_FATAL("cannot get a pointer of the 'dbiteEngine' component");
    7375        return CONFIGURED_FAILED;
     
    8183    // register the road_time_t type for the connection
    8284    qRegisterMetaType<road_time_t>("road_time_t");
    83     connect(mEngine, SIGNAL(play(road_time_t,road_time_t, bool)),
     85    connect(mEngine.get(), SIGNAL(play(road_time_t,road_time_t, bool)),
    8486            this, SLOT(playData(road_time_t,road_time_t, bool)),
    8587            Qt::DirectConnection);
    8688    connect(this, SIGNAL(tMinMaxIs(road_time_t,road_time_t )),
    87             mEngine, SLOT(tMinMax(road_time_t, road_time_t)));
    88     connect(mEngine, SIGNAL(stopfile()),
     89            mEngine.get(), SLOT(tMinMax(road_time_t, road_time_t)));
     90    connect(mEngine.get(), SIGNAL(stopfile()),
    8991            this, SLOT (beginfile()));
    9092
  • trunk/src/DBITEPlayerLib/DbtPlyTrigger.cpp

    r152 r288  
    3939ComponentBase::COMPONENT_CONFIGURATION DbtPlyTrigger::configureComponent(XmlComponentConfig /*config*/)
    4040{
     41    using boost::dynamic_pointer_cast;
     42
    4143    ComponentManager * mgr = ComponentManager::getInstance();
    4244    // we get a pointer to the engine component
    43     mEngine = dynamic_cast<DbtPlyEngine *>(mgr->getComponent("dbiteEngine"));
    44     if (NULL == mEngine) {
     45    mEngine = dynamic_pointer_cast<DbtPlyEngine>(mgr->getComponent("dbiteEngine"));
     46    if (!mEngine) {
    4547        LOG_FATAL("cannot get a pointer of the 'dbiteEngine' component");
    4648        return CONFIGURED_FAILED;
    4749    }
    4850    connect(this, SIGNAL(triggerSig()),
    49             mEngine,SLOT(engReceiver()),
     51            mEngine.get(), SLOT(engReceiver()),
    5052            Qt::DirectConnection);
    5153
  • trunk/src/DBITEPlayerLib/DbtPlyUserInterface.cpp

    r152 r288  
    6161ComponentBase::COMPONENT_CONFIGURATION DbtPlyUserInterface::configureComponent(XmlComponentConfig /*config*/)
    6262{
     63    using boost::dynamic_pointer_cast;
     64
    6365    ComponentManager * mgr = ComponentManager::getInstance();
    64     mEngine = dynamic_cast<DbtPlyEngine *>(mgr->getComponent("dbiteEngine"));
    65     if (NULL == mEngine) {
     66    mEngine = dynamic_pointer_cast<DbtPlyEngine>(mgr->getComponent("dbiteEngine"));
     67    if (!mEngine) {
    6668        LOG_FATAL("cannot get a pointer of the 'dbiteEngine' component");
    6769        return CONFIGURED_FAILED;
     
    275277        componentTableWidget->setItem(idx, 0, new QTableWidgetItem(componentName));
    276278
    277         ComponentBase * component = mgr->getComponent(componentName);
    278         if (component) {
    279             COMPONENT_STATE state = component->getState();
    280 
    281             QString stateString;
    282             switch (state) {
    283             case STOPPED:
    284                 stateString = tr("Stopped");
    285                 break;
    286             case NOT_MONITORED:
    287                 stateString = tr("Not monitored");
    288                 break;
    289             case MONITOR_OK:
    290                 stateString = tr("Monitor OK");
    291                 break;
    292             case MONITOR_NOK:
    293                 stateString = tr("Monitor wrong");
    294                 break;
    295 
    296             default:
    297                 stateString = tr("UNKNOWN");
    298                 break;
    299             }
    300             componentTableWidget->setItem(idx, 1, new QTableWidgetItem(stateString));
    301 
    302             // TODO: ADD component type and some detailed information (e.g. parameters)
    303             //QString componentInfo = component->getDetails();
    304             //componentTableWidget->setItem(idx, 2, new QTableWidgetItem(componentInfo));
     279        ComponentSharedPointer component = mgr->getComponent(componentName);
     280        if (!component) {
     281            continue;
    305282        }
     283
     284        COMPONENT_STATE state = component->getState();
     285
     286        QString stateString;
     287        switch (state) {
     288        case STOPPED:
     289            stateString = tr("Stopped");
     290            break;
     291        case NOT_MONITORED:
     292            stateString = tr("Not monitored");
     293            break;
     294        case MONITOR_OK:
     295            stateString = tr("Monitor OK");
     296            break;
     297        case MONITOR_NOK:
     298            stateString = tr("Monitor wrong");
     299            break;
     300
     301        default:
     302            stateString = tr("UNKNOWN");
     303            break;
     304        }
     305        componentTableWidget->setItem(idx, 1, new QTableWidgetItem(stateString));
     306
     307        // TODO: ADD component type and some detailed information (e.g. parameters)
     308        //QString componentInfo = component->getDetails();
     309        //componentTableWidget->setItem(idx, 2, new QTableWidgetItem(componentInfo));
    306310    }
    307311}
     
    309313void DbtPlyUserInterface::connectButtons()
    310314{
     315    // FIXME: use Qt5 connect style
    311316    connect(playBut, SIGNAL(clicked()),
    312         mEngine, SLOT(playEvent()));
     317        mEngine.get(), SLOT(playEvent()));
    313318    connect(pauseBut, SIGNAL(clicked()),
    314         mEngine, SLOT(pauseEvent()));
     319        mEngine.get(), SLOT(pauseEvent()));
    315320    connect(stopBut, SIGNAL(clicked()),
    316         mEngine, SLOT(stopEvent()));
     321        mEngine.get(), SLOT(stopEvent()));
    317322    connect(speedUpBut, SIGNAL(clicked()),
    318         mEngine, SLOT(speedUpEvent()));
     323        mEngine.get(), SLOT(speedUpEvent()));
    319324    connect(speedDownBut, SIGNAL(clicked()),
    320         mEngine, SLOT(speedDownEvent()));
     325        mEngine.get(), SLOT(speedDownEvent()));
    321326}
    322327
    323328void DbtPlyUserInterface::connectDisplay()
    324329{
    325     connect(mEngine, SIGNAL(displayStateSig(DbtPlyEngineState *, float)),
     330    connect(mEngine.get(), SIGNAL(displayStateSig(DbtPlyEngineState *, float)),
    326331        this, SLOT(displayStateSlot(DbtPlyEngineState *, float)));
    327332
    328     connect (mEngine, SIGNAL(timeMinMax(road_time_t, road_time_t)),
     333    connect (mEngine.get(), SIGNAL(timeMinMax(road_time_t, road_time_t)),
    329334        this, SLOT(displayMinMaxTime(road_time_t , road_time_t)));
    330     connect (mEngine, SIGNAL(curReplayTime(road_time_t)),
     335    connect (mEngine.get(), SIGNAL(curReplayTime(road_time_t)),
    331336        this, SLOT(displayTime(road_time_t)));
    332337    connect (rev, SIGNAL(toggled(bool)),
    333         mEngine, SLOT(changeDirection(bool)));
     338        mEngine.get(), SLOT(changeDirection(bool)));
    334339}
    335340
     
    337342{
    338343    connect (timeSlider, SIGNAL(sliderPressed()),
    339         mEngine, SLOT(pauseEvent()));
     344        mEngine.get(), SLOT(pauseEvent()));
    340345    connect (timeSlider, SIGNAL(sliderReleased()),
    341         mEngine, SLOT(playEvent()));
     346        mEngine.get(), SLOT(playEvent()));
    342347}
    343348
  • trunk/src/PacpusLib/ComponentBase.cpp

    r286 r288  
    1717#include <boost/program_options/parsers.hpp>
    1818#include <boost/program_options/variables_map.hpp>
    19 #include <boost/thread/thread.hpp>
     19//#include <boost/thread/thread.hpp>
    2020#include <ostream>
    2121#include <string>
     
    7777DECLARE_STATIC_LOGGER("pacpus.core.ComponentBase");
    7878
    79 ComponentBase::ComponentBase(const QString & componentName)
     79ComponentBase::ComponentBase(QString const& componentName)
    8080    : m_componentName(componentName)
    8181    , m_isActive(false)
     
    131131}
    132132
    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//}
    163163
    164164int ComponentBase::startComponent()
     
    170170
    171171    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();
    175176    return true;
    176177}
     
    185186    setActive(false);
    186187    stopActivity();
    187    
     188    //QMetaObject::invokeMethod(&mThread, "quit");
    188189    return true;
    189190}
  • trunk/src/PacpusLib/ComponentFactoryBase.cpp

    r89 r288  
    1010#include <Pacpus/kernel/Log.h>
    1111
    12 #include <cassert>
     12#include <boost/assert.hpp>
    1313#include <QString>
    1414
     
    2323    // get the adress of the ComponentManager instance
    2424    mgr_ = ComponentManager::getInstance();
     25    BOOST_ASSERT(mgr_);
    2526}
    2627
     
    3031}
    3132
    32 void ComponentFactoryBase::addFactory(ComponentFactoryBase* addr, const QString& type)
     33void ComponentFactoryBase::addFactory(ComponentFactoryBase* addr, QString const& type)
    3334{
    3435    LOG_DEBUG("addFactory(type="<< type << ")");
    3536
    36     assert(mgr_);
    3737    if (!mgr_->registerComponentFactory(addr, type)) {
    3838        /*
     
    4444}
    4545
    46 void ComponentFactoryBase::addComponent(const QString& name)
     46void ComponentFactoryBase::createComponent(QString const& name)
    4747{
    4848    LOG_DEBUG("addComponent(" << name << ")");
    4949
    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);
    5852}
  • 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 << ")");
  • trunk/src/PacpusLib/XmlComponentConfig.cpp

    r270 r288  
    2222static const char* kPropertyConnectionPriority = "priority";
    2323
    24 XmlComponentConfig::XmlComponentConfig(const QString& name)
     24XmlComponentConfig::XmlComponentConfig(QString const& name)
    2525{
    2626    LOG_TRACE("XmlComponentConfig(QString)");
     
    4343}
    4444
    45 void XmlComponentConfig::addProperty(const QString& name)
     45void XmlComponentConfig::addProperty(QString const& name)
    4646{
    4747    if (hasProperty(name)) {
     
    6262}
    6363
    64 int XmlComponentConfig::delProperty(const QString& name)
     64int XmlComponentConfig::delProperty(QString const& name)
    6565{
    6666    if (!hasProperty(name)) {
     
    8282}
    8383
    84 QString XmlComponentConfig::getProperty(const QString& name, const QString& defaultValue) const
     84QString XmlComponentConfig::getProperty(QString const& name, QString const& defaultValue) const
    8585{
    8686    if (!hasProperty(name))
     
    9797}
    9898
    99 bool XmlComponentConfig::getBoolProperty(const QString& name, bool defaultValue) const
     99bool XmlComponentConfig::getBoolProperty(QString const& name, bool defaultValue) const
    100100{
    101101  return hasProperty(name) ? getProperty(name) == "true" : defaultValue;
    102102}
    103103
    104 int XmlComponentConfig::getIntProperty(const QString& name, int defaultValue) const
     104int XmlComponentConfig::getIntProperty(QString const& name, int defaultValue) const
    105105{
    106106  return hasProperty(name) ? getProperty(name).toInt() : defaultValue;
    107107}
    108108
    109 double XmlComponentConfig::getDoubleProperty(const QString& name, double defaultValue) const
     109double XmlComponentConfig::getDoubleProperty(QString const& name, double defaultValue) const
    110110{
    111111  return hasProperty(name) ? getProperty(name).toDouble() : defaultValue;
    112112}
    113113
    114 void XmlComponentConfig::setProperty(const QString& name, const QString& value)
     114void XmlComponentConfig::setProperty(QString const& name, QString const& value)
    115115{
    116116    component_.setAttribute(name, value);
     
    121121}
    122122
    123 bool XmlComponentConfig::hasProperty(const QString& name) const
     123bool XmlComponentConfig::hasProperty(QString const& name) const
    124124{
    125125    return component_.hasAttribute(name);
  • trunk/src/PacpusSensor/src/ui/pacpusmainwindow.h

    r162 r288  
    3636public:
    3737    /// @todo Documentation
    38     ComponentCheckBox(const QString & text, QWidget * parent, const char * /*name*/ = 0 )
     38    ComponentCheckBox(QString const& text, QWidget * parent, const char * /*name*/ = 0 )
    3939        : QCheckBox(text, parent)
    4040    {
Note: See TracChangeset for help on using the changeset viewer.