source: pacpusframework/trunk/examples/ProducerConsumerExample/ConsumerExample.cpp@ 252

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

Major: cleaned connection interfaces.

File size: 2.5 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 namespace po = boost::program_options;
24 addParameters()
25 ("output-path", po::value<std::string>(&mOutputFileName)->default_value("consumer.txt"), "set output file path")
26 ;
27}
28
29ConsumerExample::~ConsumerExample()
30{
31 LOG_TRACE("destructor");
32}
33
34void ConsumerExample::addInputs()
35{
36 addInput<QImage, ConsumerExample>("image", &ConsumerExample::process);
37}
38
39void ConsumerExample::addOutputs()
40{
41 // empty: no outputs
42}
43
44ComponentBase::COMPONENT_CONFIGURATION
45ConsumerExample::configureComponent(XmlComponentConfig /*config*/)
46{
47 PACPUS_LOG_FUNCTION();
48
49 // load XML parameters -- NOT NEEDED - loaded by boost::program_options (used addParameters())
50
51 LOG_INFO("component '" << getName() << "' configured");
52 return ComponentBase::CONFIGURED_OK;
53}
54
55void ConsumerExample::startActivity()
56{
57 LOG_TRACE(Q_FUNC_INFO);
58 moveToThread(&thread);
59 m_counter = 0;
60
61 m_file.open(mOutputFileName.c_str(), std::ios_base::out | std::ios_base::app);
62 if (!m_file.is_open()) {
63 LOG_ERROR("file '" << mOutputFileName << "' cannot be opened");
64 }
65
66 thread.start();
67 setState(MONITOR_OK);
68 LOG_INFO("started component '" << getName() << "'");
69}
70
71void ConsumerExample::stopActivity()
72{
73 LOG_TRACE(Q_FUNC_INFO);
74
75 QMetaObject::invokeMethod(&thread, "quit");
76 m_file.close();
77 setState(STOPPED);
78 LOG_INFO("stopped component '" << getName() << "'");
79}
80
81void ConsumerExample::process(const QImage& matrix)
82{
83 m_file << ++m_counter << " " << road_time() << "\n" << std::flush;
84
85 LOG_INFO("Received QIMage: "
86 << "size = " << matrix.size().width()<< " x " << matrix.size().height()
87 );
88
89 // DO PROCESSING
90
91 setState(MONITOR_OK);
92}
93
94void testPacpusTypedEventConverts()
95{
96 PacpusTypedEvent<float> floatEvent(TYPED_EVENT, 1.0f);
97 PacpusTypedEvent<double> doubleEvent = floatEvent;
98
99 PacpusTypedEvent<int> intEvent(TYPED_EVENT, 2);
100 //PacpusTypedEvent<QImage> imageEvent = intEvent;
101}
Note: See TracBrowser for help on using the repository browser.