source: pacpusframework/branches/2.0-beta1/src/TestComponents/test/testComponent2.cpp@ 89

Last change on this file since 89 was 89, checked in by morasjul, 11 years ago

PACPUS 2.0 Beta deployed in new branch

Major changes:
-Add communication interface between components
-Add examples for communications interface (TestComponents)
-Move to Qt5 support

  • Property svn:executable set to *
File size: 2.2 KB
Line 
1/**
2@file
3Purpose: Lidar Detection
4
5@date created 2010-06-03 16:13
6@author Julien Moras
7@author Sergio Rodriguez
8@version $Id: $
9*/
10
11#include "testComponent2.h"
12
13#include "kernel/ComponentFactory.h"
14#include "kernel/Log.h"
15
16#include "testComponent1.h"
17
18using namespace pacpus;
19using namespace std;
20
21DECLARE_STATIC_LOGGER("pacpus.cityvip.test.TestComponent2");
22
23const char * TestComponent2::COMPONENT_TYPE = "TestComponent2";
24
25/// Construct the factory
26static ComponentFactory<TestComponent2> sFactory(TestComponent2::COMPONENT_TYPE);
27
28TestComponent2::TestComponent2(QString name)
29 : ComponentBase(name)
30{
31 LOG_TRACE("constructor(" << name << ")");
32
33 addInputOutput();
34 moveToThread(&thread);
35 LOG_INFO("Thread " << thread.currentThread());
36 LOG_INFO("Current Thread " << QThread::currentThread());
37}
38
39TestComponent2::~TestComponent2()
40{
41 LOG_TRACE("destructor");
42
43}
44
45void TestComponent2::addInputOutput()
46{
47 input.insert("image",new InputInterface<QImage,TestComponent2> ("image",this,&TestComponent2::process2));
48}
49
50ComponentBase::COMPONENT_CONFIGURATION
51TestComponent2::configureComponent(XmlComponentConfig /*config*/)
52{
53 LOG_TRACE(Q_FUNC_INFO);
54
55 // load XML parameters
56
57 LOG_INFO("component '" << componentName << "' configured");
58 return ComponentBase::CONFIGURED_OK;
59}
60
61void TestComponent2::startActivity()
62{
63 LOG_TRACE(Q_FUNC_INFO);
64
65 //Q_ASSERT(input);
66 fp = fopen("test2.txt","w+");
67 i=0;
68 thread.start();
69 THREAD_ALIVE = true;
70
71 setState(MONITOR_OK);
72 LOG_INFO("started component '" << componentName << "'");
73}
74
75void TestComponent2::stopActivity()
76{
77 LOG_TRACE(Q_FUNC_INFO);
78
79 THREAD_ALIVE = false;
80 thread.quit();
81 fclose(fp);
82 setState(STOPPED);
83 LOG_INFO("stopped component '" << componentName << "'");
84}
85
86void TestComponent2::process2(const QImage& matrix)
87{
88 LOG_INFO("Size " << matrix.size().width()<< " x " << matrix.size().height());
89 //QImage matrix = a.value<QImage>();
90 unsigned int k;
91
92// for(int i=0;i<100;i++){
93// for(int j=0;j<100;j++){
94// //k=matrix.pixel(0,0);
95// }
96// }
97 fprintf(fp,"%u %lld \n",i++, get_timestamp());
98
99 setState(MONITOR_OK);
100 LOG_INFO("Processed " << k << " time " << get_timestamp());
101}
Note: See TracBrowser for help on using the repository browser.