Changeset 288 in pacpusframework for trunk/src/DBITEPlayerLib


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/src/DBITEPlayerLib
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • 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
Note: See TracChangeset for help on using the changeset viewer.