source: pacpussensors/trunk/PacpusSocket/TestPacpusSocket.hpp

Last change on this file was 21, checked in by phudelai, 11 years ago

New component for the wifibot and the dualshock 3

File size: 1.6 KB
Line 
1#ifndef TESTPACPUSSOCKET_HPP
2#define TESTPACPUSSOCKET_HPP
3
4#include "kernel/ComponentBase.h"
5#include "kernel/ComponentFactory.h"
6
7#include "PacpusSocket.hpp"
8
9#include <qtimer.h>
10#include <qstring.h>
11
12namespace pacpus {
13
14class TestPacpusSocket
15 : public QObject
16 , public ComponentBase
17{
18 Q_OBJECT
19
20public:
21 /// Constructor.
22 TestPacpusSocket(QString name)
23 : ComponentBase(name)
24 {
25 }
26
27 // Destructor
28 ~TestPacpusSocket()
29 {
30
31 }
32
33protected:
34 virtual void startActivity()
35 {
36 timer_ = new QTimer();
37 connect(timer_, SIGNAL(timeout()),
38 this, SLOT(update()));
39 timer_->start(500);
40 }
41
42 virtual void stopActivity()
43 {
44 timer_->stop();
45 delete timer_;
46 }
47
48 virtual COMPONENT_CONFIGURATION configureComponent(XmlComponentConfig config)
49 {
50 QString pacpusSocket = config.getProperty("socketComponent");
51 ComponentManager * mgr = ComponentManager::getInstance();
52 pacpusSocket_ = dynamic_cast<PacpusSocket *>(mgr->getComponent(pacpusSocket));
53 if (!pacpusSocket_)
54 {
55 qWarning() << "Failed to get component " << pacpusSocket;
56 return ComponentBase::NOT_CONFIGURED;
57 }
58
59 return ComponentBase::CONFIGURED_OK;
60 }
61
62protected slots:
63 void update()
64 {
65 QString toto = "toto";
66
67 pacpusSocket_->sendDatagrams( toto );
68 }
69
70private:
71 QTimer * timer_;
72 PacpusSocket * pacpusSocket_;
73};
74
75static ComponentFactory<TestPacpusSocket> factory("TestPacpusSocket");
76
77} // namespace pacpus
78
79#endif // TESTPACPUSSOCKET_HPP
Note: See TracBrowser for help on using the repository browser.