Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Newer
Older
100644 143 lines (107 sloc) 2.767 kb
9690258 Adding Bcaster prototype
Clovis Scotti authored
1 #include "broadcasterdevice.h"
2
3 BroadcasterDevice::BroadcasterDevice(QObject *parent) :
4 PushBurtonGenericDevice(parent)
5 {
6
7 running = false;
8
9
10 xmlWriter = 0;
11
12 currConnection = 0;
13
14
15
63452f9 Rearranging source tree; Removing Deprecated code in ticks
Clovis Scotti authored
16 serverAddress = QHostAddress("192.168.0.2");
9690258 Adding Bcaster prototype
Clovis Scotti authored
17
18 serverPort = 45454;
19
20 }
21
22
23 BroadcasterDevice::~BroadcasterDevice()
24 {
25 if(currConnection)
26 currConnection->disconnectFromHost();
27 }
28
29
c35ef9d Using standard names for all devices; responsible tick disposal when …
Clovis Scotti authored
30 QString BroadcasterDevice::getName()
9690258 Adding Bcaster prototype
Clovis Scotti authored
31 {
c35ef9d Using standard names for all devices; responsible tick disposal when …
Clovis Scotti authored
32
33 return QString("push.network.broadcaster");
9690258 Adding Bcaster prototype
Clovis Scotti authored
34 }
35
36
37 bool BroadcasterDevice::start_run()
38 {
39 if(!running) {
40 running = true;
41 return true;
42 }
43 return false;
44 }
45
46 bool BroadcasterDevice::end_run()
47 {
48 if(running) {
49 running = false;
50
51 return true;
52 }
53 return false;
54 }
55
56 void BroadcasterDevice::incoming_reading(NPushLogTick * tick)
57 {
58 if(running) {
59 if(xmlWriter && currConnection->isWritable()) {
60 tick->dump_to_xml(*xmlWriter);
61 currConnection->flush();
62 }
63 }
64 }
65
66 void BroadcasterDevice::connected()
67 {
68 qDebug() << "Connected";
69 xmlWriter = new QXmlStreamWriter(currConnection);
70 qDebug() << "coupled with xml writer";
71
72 emit connectionUpdate(true);
73 }
74
75 void BroadcasterDevice::disconnected()
76 {
77 if(xmlWriter) {
78 delete xmlWriter;
79 xmlWriter = 0;
80 }
81 if(currConnection) {
82 currConnection->close();
83 currConnection->deleteLater();
84 currConnection = 0;
85 }
86 emit connectionUpdate(false);
87 }
88
89 void BroadcasterDevice::tryToConnect()
90 {
91 if(currConnection) {
92 qDebug() << "Cleaning up old connection";
93 currConnection->close();
94 currConnection->deleteLater();
95 currConnection = 0;
96 }
97
98 qDebug() << "Trying to establish new connection";
99
100 currConnection = new QTcpSocket(this);
101
102 currConnection->connectToHost(serverAddress, serverPort, QIODevice::WriteOnly);
103
104 connect(currConnection, SIGNAL(connected()),
105 this, SLOT(connected()));
106
107 connect(currConnection, SIGNAL(disconnected()),
108 this, SLOT(disconnected()));
109 }
110
111 void BroadcasterDevice::setServerAddress(const QString &addr)
112 {
113 serverAddress.setAddress(addr);
114 qDebug() << "Address set to " << serverAddress.toString();
115 }
116
117 void BroadcasterDevice::setServerPort(quint16 port)
118 {
119 serverPort = port;
120 qDebug() << "Port set to " << serverPort;
121 }
122
123 void BroadcasterDevice::tryToDisconnect()
124 {
125 if(xmlWriter) {
126 delete xmlWriter;
127 xmlWriter = 0;
128 }
129
130 if(currConnection) {
131 currConnection->close();
132 currConnection->deleteLater();
133 currConnection = 0;
134 }
135
136 emit connectionUpdate(false);
137 }
42aa391 Removed deprecated code (append_to_xml); \n Added read_from_xml(); \n…
Clovis Scotti authored
138
139 bool BroadcasterDevice::subscribesTo(PushBurtonGenericDevice * dev)
140 {
141 return dev->getName().contains(QRegExp("push.(n8|qt)"));
142 }
Something went wrong with that request. Please try again.