| [76] | 1 | // %pacpus:license{
|
|---|
| [73] | 2 | // This file is part of the PACPUS framework distributed under the
|
|---|
| 3 | // CECILL-C License, Version 1.0.
|
|---|
| [76] | 4 | // %pacpus:license}
|
|---|
| [91] | 5 | /// @author Gerald Dherbomez <firstname.surname@utc.fr>
|
|---|
| [73] | 6 | /// @version $Id: DbtPlyTrigger.cpp 91 2013-05-19 10:32:48Z gdherbom $
|
|---|
| 7 |
|
|---|
| 8 | #include <Pacpus/DbitePlayer/DbtPlyTrigger.h>
|
|---|
| 9 |
|
|---|
| 10 | #include <Pacpus/kernel/ComponentManager.h>
|
|---|
| 11 | #include <Pacpus/kernel/Log.h>
|
|---|
| 12 |
|
|---|
| 13 | namespace pacpus {
|
|---|
| 14 |
|
|---|
| 15 | DECLARE_STATIC_LOGGER("pacpus.core.DbtPlyTrigger");
|
|---|
| 16 |
|
|---|
| 17 | // Construction de la fabrique de composant DbtPlyTrigger
|
|---|
| 18 | //static ComponentFactory<DbtPlyTrigger> factory("DbtPlyTrigger");
|
|---|
| 19 |
|
|---|
| 20 | DbtPlyTrigger::DbtPlyTrigger(QString name)
|
|---|
| 21 | : ComponentBase(name)
|
|---|
| 22 | , mEngine(NULL)
|
|---|
| 23 | {
|
|---|
| 24 | THREAD_ALIVE = false;
|
|---|
| 25 | }
|
|---|
| 26 |
|
|---|
| 27 | DbtPlyTrigger::~DbtPlyTrigger()
|
|---|
| 28 | {
|
|---|
| 29 | }
|
|---|
| 30 |
|
|---|
| 31 | ComponentBase::COMPONENT_CONFIGURATION DbtPlyTrigger::configureComponent(XmlComponentConfig /*config*/)
|
|---|
| 32 | {
|
|---|
| 33 | ComponentManager * mgr = ComponentManager::getInstance();
|
|---|
| 34 | // we get a pointer to the engine component
|
|---|
| 35 | mEngine = dynamic_cast<DbtPlyEngine *>(mgr->getComponent("dbiteEngine"));
|
|---|
| 36 | if (NULL == mEngine) {
|
|---|
| 37 | LOG_FATAL("cannot get a pointer of the 'dbiteEngine' component");
|
|---|
| 38 | return CONFIGURED_FAILED;
|
|---|
| 39 | }
|
|---|
| 40 | connect(this, SIGNAL(triggerSig()),
|
|---|
| 41 | mEngine,SLOT(engReceiver()),
|
|---|
| 42 | Qt::DirectConnection);
|
|---|
| 43 |
|
|---|
| 44 | return CONFIGURED_OK;
|
|---|
| 45 | }
|
|---|
| 46 |
|
|---|
| 47 | void DbtPlyTrigger::startActivity()
|
|---|
| 48 | {
|
|---|
| 49 | THREAD_ALIVE = true;
|
|---|
| 50 | start();
|
|---|
| 51 | }
|
|---|
| 52 |
|
|---|
| 53 | void DbtPlyTrigger::stopActivity()
|
|---|
| 54 | {
|
|---|
| 55 | THREAD_ALIVE = false;
|
|---|
| 56 | }
|
|---|
| 57 |
|
|---|
| 58 | // The thread is started when the user press the play button
|
|---|
| 59 | void DbtPlyTrigger::run()
|
|---|
| 60 | {
|
|---|
| 61 | #ifdef WIN32
|
|---|
| 62 | timeBeginPeriod(1);
|
|---|
| 63 | #endif
|
|---|
| 64 |
|
|---|
| 65 | while(THREAD_ALIVE) {
|
|---|
| 66 | if (mEngine->isPlaying()) {
|
|---|
| 67 | Q_EMIT triggerSig();
|
|---|
| 68 | }
|
|---|
| 69 | msleep(1);
|
|---|
| 70 | }
|
|---|
| 71 |
|
|---|
| 72 | #ifdef WIN32
|
|---|
| 73 | timeEndPeriod(1);
|
|---|
| 74 | #endif
|
|---|
| 75 | }
|
|---|
| 76 |
|
|---|
| 77 | } // namespace pacpus
|
|---|