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 |
|
---|
9 | using namespace pacpus;
|
---|
10 | using namespace std;
|
---|
11 |
|
---|
12 | DECLARE_STATIC_LOGGER("pacpus.cityvip.test.ProducerExample");
|
---|
13 |
|
---|
14 | PACPUS_REGISTER_COMPONENT(ProducerExample);
|
---|
15 |
|
---|
16 | static const char * outputFileName = "producer.txt";
|
---|
17 |
|
---|
18 | ProducerExample::ProducerExample(QString name)
|
---|
19 | : ComponentBase(name)
|
---|
20 | {
|
---|
21 | LOG_TRACE("constructor(" << name << ")");
|
---|
22 |
|
---|
23 | namespace po = boost::program_options;
|
---|
24 |
|
---|
25 | addParameters()
|
---|
26 | ("output-path", po::value<std::string>(&mOutputFileName)->default_value("producer.txt"), "set output file path")
|
---|
27 | ;
|
---|
28 | }
|
---|
29 |
|
---|
30 | ProducerExample::~ProducerExample()
|
---|
31 | {
|
---|
32 | LOG_TRACE("destructor");
|
---|
33 | }
|
---|
34 |
|
---|
35 | ComponentBase::COMPONENT_CONFIGURATION
|
---|
36 | ProducerExample::configureComponent(XmlComponentConfig /*config*/)
|
---|
37 | {
|
---|
38 | PACPUS_LOG_FUNCTION();
|
---|
39 |
|
---|
40 | LOG_INFO("component '" << getName() << "' configured");
|
---|
41 | return ComponentBase::CONFIGURED_OK;
|
---|
42 | }
|
---|
43 |
|
---|
44 | void ProducerExample::addInputs()
|
---|
45 | {
|
---|
46 | // empty: no inputs
|
---|
47 | }
|
---|
48 |
|
---|
49 | void ProducerExample::addOutputs()
|
---|
50 | {
|
---|
51 | addOutput<QImage, ProducerExample>("image");
|
---|
52 | }
|
---|
53 |
|
---|
54 | void ProducerExample::startActivity()
|
---|
55 | {
|
---|
56 | LOG_TRACE(Q_FUNC_INFO);
|
---|
57 |
|
---|
58 | start();
|
---|
59 | setActive(true);
|
---|
60 | setState(MONITOR_OK);
|
---|
61 | LOG_INFO("started component '" << getName() << "'");
|
---|
62 | }
|
---|
63 |
|
---|
64 | void ProducerExample::stopActivity()
|
---|
65 | {
|
---|
66 | LOG_TRACE(Q_FUNC_INFO);
|
---|
67 |
|
---|
68 | setActive(false);
|
---|
69 | setState(STOPPED);
|
---|
70 | LOG_INFO("stopped component '" << getName() << "'");
|
---|
71 | }
|
---|
72 |
|
---|
73 | void ProducerExample::run()
|
---|
74 | {
|
---|
75 | unsigned int counter = 1;
|
---|
76 | int waitTimeMicros = 150 * 1000;
|
---|
77 |
|
---|
78 | std::fstream file(outputFileName, std::ios_base::out | std::ios_base::app);
|
---|
79 | if (!file.is_open()) {
|
---|
80 | LOG_ERROR("file '" << outputFileName << "' cannot be opened");
|
---|
81 | }
|
---|
82 |
|
---|
83 | QImage mat(10000, 1000, QImage::Format_RGB32);
|
---|
84 | //mat.fill( qRgb(189, 149, 39));
|
---|
85 |
|
---|
86 | OutputInterface<QImage, ProducerExample> * imageOutput =
|
---|
87 | getTypedOutput<QImage, ProducerExample>("image");
|
---|
88 |
|
---|
89 | while (isActive()) {
|
---|
90 | //mat.setPixel(0,0,i);
|
---|
91 | LOG_INFO("Sent QImage: "
|
---|
92 | << "size = " << mat.size().width()<< " x " << mat.size().height()
|
---|
93 | );
|
---|
94 |
|
---|
95 | checkedSend(imageOutput, mat);
|
---|
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 | }
|
---|