| 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 | namespace po = boost::program_options;
|
|---|
| 24 | addParameters()
|
|---|
| 25 | ("output-path", po::value<std::string>(&mOutputFileName)->default_value("consumer.txt"), "set output file path")
|
|---|
| 26 | ;
|
|---|
| 27 | }
|
|---|
| 28 |
|
|---|
| 29 | ConsumerExample::~ConsumerExample()
|
|---|
| 30 | {
|
|---|
| 31 | LOG_TRACE("destructor");
|
|---|
| 32 | }
|
|---|
| 33 |
|
|---|
| 34 | void ConsumerExample::addInputs()
|
|---|
| 35 | {
|
|---|
| 36 | addInput<QImage, ConsumerExample>("image", &ConsumerExample::process);
|
|---|
| 37 | }
|
|---|
| 38 |
|
|---|
| 39 | void ConsumerExample::addOutputs()
|
|---|
| 40 | {
|
|---|
| 41 | // empty: no outputs
|
|---|
| 42 | }
|
|---|
| 43 |
|
|---|
| 44 | ComponentBase::COMPONENT_CONFIGURATION
|
|---|
| 45 | ConsumerExample::configureComponent(XmlComponentConfig /*config*/)
|
|---|
| 46 | {
|
|---|
| 47 | PACPUS_LOG_FUNCTION();
|
|---|
| 48 |
|
|---|
| 49 | // load XML parameters -- NOT NEEDED - loaded by boost::program_options (used addParameters())
|
|---|
| 50 |
|
|---|
| 51 | LOG_INFO("component '" << getName() << "' configured");
|
|---|
| 52 | return ComponentBase::CONFIGURED_OK;
|
|---|
| 53 | }
|
|---|
| 54 |
|
|---|
| 55 | void ConsumerExample::startActivity()
|
|---|
| 56 | {
|
|---|
| 57 | LOG_TRACE(Q_FUNC_INFO);
|
|---|
| 58 | moveToThread(&thread);
|
|---|
| 59 | m_counter = 0;
|
|---|
| 60 |
|
|---|
| 61 | m_file.open(mOutputFileName.c_str(), std::ios_base::out | std::ios_base::app);
|
|---|
| 62 | if (!m_file.is_open()) {
|
|---|
| 63 | LOG_ERROR("file '" << mOutputFileName << "' cannot be opened");
|
|---|
| 64 | }
|
|---|
| 65 |
|
|---|
| 66 | thread.start();
|
|---|
| 67 | setState(MONITOR_OK);
|
|---|
| 68 | LOG_INFO("started component '" << getName() << "'");
|
|---|
| 69 | }
|
|---|
| 70 |
|
|---|
| 71 | void ConsumerExample::stopActivity()
|
|---|
| 72 | {
|
|---|
| 73 | LOG_TRACE(Q_FUNC_INFO);
|
|---|
| 74 |
|
|---|
| 75 | QMetaObject::invokeMethod(&thread, "quit");
|
|---|
| 76 | m_file.close();
|
|---|
| 77 | setState(STOPPED);
|
|---|
| 78 | LOG_INFO("stopped component '" << getName() << "'");
|
|---|
| 79 | }
|
|---|
| 80 |
|
|---|
| 81 | void ConsumerExample::process(const QImage& matrix)
|
|---|
| 82 | {
|
|---|
| 83 | m_file << ++m_counter << " " << road_time() << "\n" << std::flush;
|
|---|
| 84 |
|
|---|
| 85 | LOG_INFO("Received QIMage: "
|
|---|
| 86 | << "size = " << matrix.size().width()<< " x " << matrix.size().height()
|
|---|
| 87 | );
|
|---|
| 88 |
|
|---|
| 89 | // DO PROCESSING
|
|---|
| 90 |
|
|---|
| 91 | setState(MONITOR_OK);
|
|---|
| 92 | }
|
|---|