[163] | 1 | #include "ConsumerExample.h"
|
---|
| 2 |
|
---|
| 3 | #include <Pacpus/kernel/ComponentFactory.h>
|
---|
| 4 | #include <Pacpus/kernel/Log.h>
|
---|
| 5 | #include <Pacpus/kernel/InputOutputInterface.h>
|
---|
| 6 |
|
---|
| 7 | using namespace pacpus;
|
---|
| 8 | using namespace std;
|
---|
| 9 |
|
---|
| 10 | DECLARE_STATIC_LOGGER("pacpus.cityvip.test.ConsumerExample");
|
---|
| 11 |
|
---|
| 12 | /// Construct the factory
|
---|
| 13 | static ComponentFactory<ConsumerExample> sFactory("ConsumerExample");
|
---|
| 14 |
|
---|
| 15 | ConsumerExample::ConsumerExample(QString name)
|
---|
| 16 | : ComponentBase(name)
|
---|
| 17 | {
|
---|
| 18 | LOG_TRACE("constructor(" << name << ")");
|
---|
| 19 |
|
---|
| 20 | LOG_INFO("Thread " << thread.currentThread());
|
---|
| 21 | LOG_INFO("Current Thread " << QThread::currentThread());
|
---|
| 22 | }
|
---|
| 23 |
|
---|
| 24 | ConsumerExample::~ConsumerExample()
|
---|
| 25 | {
|
---|
| 26 | LOG_TRACE("destructor");
|
---|
| 27 | }
|
---|
| 28 |
|
---|
| 29 | void ConsumerExample::addInputs()
|
---|
| 30 | {
|
---|
| 31 | addInput<QImage, ConsumerExample>("image", &ConsumerExample::process);
|
---|
| 32 | }
|
---|
| 33 |
|
---|
| 34 | void ConsumerExample::addOutputs()
|
---|
| 35 | {
|
---|
| 36 | // empty: no outputs
|
---|
| 37 | }
|
---|
| 38 |
|
---|
| 39 | ComponentBase::COMPONENT_CONFIGURATION
|
---|
| 40 | ConsumerExample::configureComponent(XmlComponentConfig /*config*/)
|
---|
| 41 | {
|
---|
| 42 | LOG_TRACE(Q_FUNC_INFO);
|
---|
| 43 |
|
---|
| 44 | // load XML parameters
|
---|
| 45 |
|
---|
| 46 | LOG_INFO("component '" << name() << "' configured");
|
---|
| 47 | return ComponentBase::CONFIGURED_OK;
|
---|
| 48 | }
|
---|
| 49 |
|
---|
| 50 | void ConsumerExample::startActivity()
|
---|
| 51 | {
|
---|
| 52 | LOG_TRACE(Q_FUNC_INFO);
|
---|
| 53 | moveToThread(&thread);
|
---|
[165] | 54 | m_counter = 0;
|
---|
[163] | 55 |
|
---|
[165] | 56 | static const char * outputFileName = "consumer.txt";
|
---|
[163] | 57 | m_file.open(outputFileName, std::ios_base::out | std::ios_base::app);
|
---|
| 58 | if (!m_file.is_open()) {
|
---|
| 59 | LOG_ERROR("file '" << outputFileName << "'cannot be opened");
|
---|
| 60 | }
|
---|
| 61 |
|
---|
| 62 | thread.start();
|
---|
| 63 | setState(MONITOR_OK);
|
---|
| 64 | LOG_INFO("started component '" << name() << "'");
|
---|
| 65 | }
|
---|
| 66 |
|
---|
| 67 | void ConsumerExample::stopActivity()
|
---|
| 68 | {
|
---|
| 69 | LOG_TRACE(Q_FUNC_INFO);
|
---|
| 70 |
|
---|
| 71 | QMetaObject::invokeMethod(&thread, "quit");
|
---|
| 72 | m_file.close();
|
---|
| 73 | setState(STOPPED);
|
---|
| 74 | LOG_INFO("stopped component '" << name() << "'");
|
---|
| 75 | }
|
---|
| 76 |
|
---|
| 77 | void ConsumerExample::process(const QImage& matrix)
|
---|
| 78 | {
|
---|
[165] | 79 | m_file << ++m_counter << " " << road_time() << "\n" << std::flush;
|
---|
[163] | 80 |
|
---|
[165] | 81 | LOG_INFO("Received QIMage: "
|
---|
| 82 | << "size = " << matrix.size().width()<< " x " << matrix.size().height()
|
---|
| 83 | );
|
---|
[163] | 84 |
|
---|
[165] | 85 | // DO PROCESSING
|
---|
| 86 |
|
---|
[163] | 87 | setState(MONITOR_OK);
|
---|
| 88 | }
|
---|