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