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