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