source: pacpusframework/branches/0.1.x/examples/ProducerConsumerExample/ConsumerExample.cpp@ 204

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

Major: changed plugins section name to plugings. Parameters section will be used for something else.

File size: 2.0 KB
Line 
1#include "ConsumerExample.h"
2
3#include <Pacpus/kernel/ComponentFactory.h>
4#include <Pacpus/kernel/Log.h>
5#include <Pacpus/kernel/InputOutputInterface.h>
6
7using namespace pacpus;
8using namespace std;
9
10DECLARE_STATIC_LOGGER("pacpus.cityvip.test.ConsumerExample");
11
12/// Construct the factory
13static ComponentFactory<ConsumerExample> sFactory("ConsumerExample");
14
15ConsumerExample::ConsumerExample(QString name)
16 : ComponentBase(name)
17{
18 LOG_TRACE("constructor(" << name << ")");
19
20 LOG_INFO("Thread " << thread.currentThread());
21 LOG_INFO("Current Thread " << QThread::currentThread());
22}
23
24ConsumerExample::~ConsumerExample()
25{
26 LOG_TRACE("destructor");
27}
28
29void ConsumerExample::addInputs()
30{
31 addInput<QImage, ConsumerExample>("image", &ConsumerExample::process);
32}
33
34void ConsumerExample::addOutputs()
35{
36 // empty: no outputs
37}
38
39ComponentBase::COMPONENT_CONFIGURATION
40ConsumerExample::configureComponent(XmlComponentConfig /*config*/)
41{
42 LOG_TRACE(Q_FUNC_INFO);
43
44 // load XML parameters
45
46 LOG_INFO("component '" << name() << "' configured");
47 return ComponentBase::CONFIGURED_OK;
48}
49
50void ConsumerExample::startActivity()
51{
52 LOG_TRACE(Q_FUNC_INFO);
53 moveToThread(&thread);
54 m_counter = 0;
55
56 static const char * outputFileName = "consumer.txt";
57 m_file.open(outputFileName, std::ios_base::out | std::ios_base::app);
58 if (!m_file.is_open()) {
59 LOG_ERROR("file '" << outputFileName << "'cannot be opened");
60 }
61
62 thread.start();
63 setState(MONITOR_OK);
64 LOG_INFO("started component '" << name() << "'");
65}
66
67void ConsumerExample::stopActivity()
68{
69 LOG_TRACE(Q_FUNC_INFO);
70
71 QMetaObject::invokeMethod(&thread, "quit");
72 m_file.close();
73 setState(STOPPED);
74 LOG_INFO("stopped component '" << name() << "'");
75}
76
77void ConsumerExample::process(const QImage& matrix)
78{
79 m_file << ++m_counter << " " << road_time() << "\n" << std::flush;
80
81 LOG_INFO("Received QIMage: "
82 << "size = " << matrix.size().width()<< " x " << matrix.size().height()
83 );
84
85 // DO PROCESSING
86
87 setState(MONITOR_OK);
88}
Note: See TracBrowser for help on using the repository browser.