source: pacpusframework/trunk/examples/ProducerConsumerExample/ProducerExample.cpp@ 288

Last change on this file since 288 was 288, checked in by Marek Kurdej, 10 years ago

Using boost::shared_ptr for storing components.

File size: 2.5 KB
Line 
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
9using namespace pacpus;
10using namespace std;
11
12DECLARE_STATIC_LOGGER("pacpus.cityvip.test.ProducerExample");
13
14PACPUS_REGISTER_COMPONENT(ProducerExample);
15
16static const char * outputFileName = "producer.txt";
17
18ProducerExample::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
30ProducerExample::~ProducerExample()
31{
32 LOG_TRACE("destructor");
33}
34
35ComponentBase::COMPONENT_CONFIGURATION
36ProducerExample::configureComponent(XmlComponentConfig /*config*/)
37{
38 PACPUS_LOG_FUNCTION();
39
40 LOG_INFO("component '" << getName() << "' configured");
41 return ComponentBase::CONFIGURED_OK;
42}
43
44void ProducerExample::addInputs()
45{
46 // empty: no inputs
47}
48
49void ProducerExample::addOutputs()
50{
51 addOutput<QImage, ProducerExample>("image");
52}
53
54void 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
64void ProducerExample::stopActivity()
65{
66 LOG_TRACE(Q_FUNC_INFO);
67
68 setActive(false);
69 setState(STOPPED);
70 LOG_INFO("stopped component '" << getName() << "'");
71}
72
73void 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}
Note: See TracBrowser for help on using the repository browser.