source: pacpusframework/branches/2.0-beta1/examples/ProducerConsumerExample/ProducerExample.cpp@ 163

Last change on this file since 163 was 163, checked in by Marek Kurdej, 11 years ago

Added: test component from PacpusCityVIP.
Added: PACPUS_BUILD_EXAMPLES variable.

File size: 2.4 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#include <QColor>
9
10using namespace pacpus;
11using namespace std;
12
13DECLARE_STATIC_LOGGER("pacpus.cityvip.test.ProducerExample");
14
15/// Construct the factory
16static ComponentFactory<ProducerExample> sFactory("ProducerExample");
17
18static const char * outputFileName = "producer.txt";
19
20ProducerExample::ProducerExample(QString name)
21 : ComponentBase(name)
22{
23 LOG_TRACE("constructor(" << name << ")");
24}
25
26ProducerExample::~ProducerExample()
27{
28 LOG_TRACE("destructor");
29}
30
31ComponentBase::COMPONENT_CONFIGURATION
32ProducerExample::configureComponent(XmlComponentConfig /*config*/)
33{
34 LOG_TRACE(Q_FUNC_INFO);
35
36 LOG_INFO("component '" << name() << "' configured");
37 return ComponentBase::CONFIGURED_OK;
38}
39
40void ProducerExample::addInputs()
41{
42 // empty: no inputs
43}
44
45void ProducerExample::addOutputs()
46{
47 addOutput<QImage, ProducerExample>("image");
48}
49
50void 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
62void ProducerExample::stopActivity()
63{
64 LOG_TRACE(Q_FUNC_INFO);
65
66 setActive(false);
67 setState(STOPPED);
68 LOG_INFO("stopped component '" << name() << "'");
69}
70
71void ProducerExample::run()
72{
73 unsigned int counter = 0;
74 int waitTime = 5000;
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("Size " << mat.size().width()<< " x " << mat.size().height());
90
91 if (imageOutput && imageOutput->hasConnection()) {
92 imageOutput->send(mat);
93 }
94
95 LOG_INFO("Send data " << counter << " time " << road_time());
96 file << ++counter << " " << road_time() << "\n";
97
98 usleep(waitTime);
99 ++counter;
100 setState(MONITOR_OK);
101 }
102
103 file.close();
104}
Note: See TracBrowser for help on using the repository browser.