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