[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());
|
---|
[176] | 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 | ;
|
---|
[163] | 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 | {
|
---|
[176] | 47 | PACPUS_LOG_FUNCTION();
|
---|
[163] | 48 |
|
---|
[176] | 49 | // load XML parameters -- NOT NEEDED - loaded by boost::program_options (used addParameters())
|
---|
[163] | 50 |
|
---|
[176] | 51 | LOG_INFO("component '" << getName() << "' configured");
|
---|
[163] | 52 | return ComponentBase::CONFIGURED_OK;
|
---|
| 53 | }
|
---|
| 54 |
|
---|
| 55 | void ConsumerExample::startActivity()
|
---|
| 56 | {
|
---|
| 57 | LOG_TRACE(Q_FUNC_INFO);
|
---|
| 58 | moveToThread(&thread);
|
---|
[165] | 59 | m_counter = 0;
|
---|
[163] | 60 |
|
---|
[176] | 61 | m_file.open(mOutputFileName.c_str(), std::ios_base::out | std::ios_base::app);
|
---|
[163] | 62 | if (!m_file.is_open()) {
|
---|
[176] | 63 | LOG_ERROR("file '" << mOutputFileName << "' cannot be opened");
|
---|
[163] | 64 | }
|
---|
| 65 |
|
---|
| 66 | thread.start();
|
---|
| 67 | setState(MONITOR_OK);
|
---|
[176] | 68 | LOG_INFO("started component '" << getName() << "'");
|
---|
[163] | 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);
|
---|
[176] | 78 | LOG_INFO("stopped component '" << getName() << "'");
|
---|
[163] | 79 | }
|
---|
| 80 |
|
---|
| 81 | void ConsumerExample::process(const QImage& matrix)
|
---|
| 82 | {
|
---|
[165] | 83 | m_file << ++m_counter << " " << road_time() << "\n" << std::flush;
|
---|
[163] | 84 |
|
---|
[165] | 85 | LOG_INFO("Received QIMage: "
|
---|
| 86 | << "size = " << matrix.size().width()<< " x " << matrix.size().height()
|
---|
| 87 | );
|
---|
[163] | 88 |
|
---|
[165] | 89 | // DO PROCESSING
|
---|
| 90 |
|
---|
[163] | 91 | setState(MONITOR_OK);
|
---|
| 92 | }
|
---|
[206] | 93 |
|
---|
| 94 | void testPacpusTypedEventConverts()
|
---|
| 95 | {
|
---|
| 96 | PacpusTypedEvent<float> floatEvent(TYPED_EVENT, 1.0f);
|
---|
| 97 | PacpusTypedEvent<double> doubleEvent = floatEvent;
|
---|
| 98 |
|
---|
| 99 | PacpusTypedEvent<int> intEvent(TYPED_EVENT, 2);
|
---|
| 100 | //PacpusTypedEvent<QImage> imageEvent = intEvent;
|
---|
| 101 | }
|
---|