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