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

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

Update: DbtPlyEngine uses addParameters().

File size: 2.3 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}
Note: See TracBrowser for help on using the repository browser.