1 | #include "ProducerExample.h"
|
---|
2 |
|
---|
3 | #include <fstream>
|
---|
4 | #include <Pacpus/kernel/ComponentFactory.h>
|
---|
5 | #include <Pacpus/kernel/ComponentManager.h>
|
---|
6 | #include <Pacpus/kernel/InputOutputInterface.h>
|
---|
7 | #include <Pacpus/kernel/Log.h>
|
---|
8 | #include <QColor>
|
---|
9 |
|
---|
10 | using namespace pacpus;
|
---|
11 | using namespace std;
|
---|
12 |
|
---|
13 | DECLARE_STATIC_LOGGER("pacpus.cityvip.test.ProducerExample");
|
---|
14 |
|
---|
15 | /// Construct the factory
|
---|
16 | static ComponentFactory<ProducerExample> sFactory("ProducerExample");
|
---|
17 |
|
---|
18 | static const char * outputFileName = "producer.txt";
|
---|
19 |
|
---|
20 | ProducerExample::ProducerExample(QString name)
|
---|
21 | : ComponentBase(name)
|
---|
22 | {
|
---|
23 | LOG_TRACE("constructor(" << name << ")");
|
---|
24 | }
|
---|
25 |
|
---|
26 | ProducerExample::~ProducerExample()
|
---|
27 | {
|
---|
28 | LOG_TRACE("destructor");
|
---|
29 | }
|
---|
30 |
|
---|
31 | ComponentBase::COMPONENT_CONFIGURATION
|
---|
32 | ProducerExample::configureComponent(XmlComponentConfig /*config*/)
|
---|
33 | {
|
---|
34 | LOG_TRACE(Q_FUNC_INFO);
|
---|
35 |
|
---|
36 | LOG_INFO("component '" << name() << "' configured");
|
---|
37 | return ComponentBase::CONFIGURED_OK;
|
---|
38 | }
|
---|
39 |
|
---|
40 | void ProducerExample::addInputs()
|
---|
41 | {
|
---|
42 | // empty: no inputs
|
---|
43 | }
|
---|
44 |
|
---|
45 | void ProducerExample::addOutputs()
|
---|
46 | {
|
---|
47 | addOutput<QImage, ProducerExample>("image");
|
---|
48 | }
|
---|
49 |
|
---|
50 | void ProducerExample::startActivity()
|
---|
51 | {
|
---|
52 | LOG_TRACE(Q_FUNC_INFO);
|
---|
53 |
|
---|
54 | //Q_ASSERT(input);
|
---|
55 |
|
---|
56 | start();
|
---|
57 | setActive(true);
|
---|
58 | setState(MONITOR_OK);
|
---|
59 | LOG_INFO("started component '" << name() << "'");
|
---|
60 | }
|
---|
61 |
|
---|
62 | void ProducerExample::stopActivity()
|
---|
63 | {
|
---|
64 | LOG_TRACE(Q_FUNC_INFO);
|
---|
65 |
|
---|
66 | setActive(false);
|
---|
67 | setState(STOPPED);
|
---|
68 | LOG_INFO("stopped component '" << name() << "'");
|
---|
69 | }
|
---|
70 |
|
---|
71 | void ProducerExample::run()
|
---|
72 | {
|
---|
73 | unsigned int counter = 1;
|
---|
74 | int waitTimeMicros = 150 * 1000;
|
---|
75 |
|
---|
76 | std::fstream file(outputFileName, std::ios_base::out | std::ios_base::app);
|
---|
77 | if (!file.is_open()) {
|
---|
78 | LOG_ERROR("file '" << outputFileName << "'cannot be opened");
|
---|
79 | }
|
---|
80 |
|
---|
81 | QImage mat(10000, 1000, QImage::Format_RGB32);
|
---|
82 | //mat.fill( qRgb(189, 149, 39));
|
---|
83 |
|
---|
84 | OutputInterface<QImage, ProducerExample> * imageOutput =
|
---|
85 | getTypedOutput<QImage, ProducerExample>("image");
|
---|
86 |
|
---|
87 | while (isActive()) {
|
---|
88 | //mat.setPixel(0,0,i);
|
---|
89 | LOG_INFO("Sent QImage: "
|
---|
90 | << "size = " << mat.size().width()<< " x " << mat.size().height()
|
---|
91 | );
|
---|
92 |
|
---|
93 | if (imageOutput && imageOutput->hasConnection()) {
|
---|
94 | imageOutput->send(mat);
|
---|
95 | }
|
---|
96 |
|
---|
97 | LOG_INFO("Sent data=" << counter << ", time=" << road_time());
|
---|
98 | file << counter << " " << road_time() << "\n" << std::flush;
|
---|
99 |
|
---|
100 | usleep(waitTimeMicros);
|
---|
101 | ++counter;
|
---|
102 | setState(MONITOR_OK);
|
---|
103 | }
|
---|
104 |
|
---|
105 | file.close();
|
---|
106 | }
|
---|