-rw-r--r-- | noncore/net/opietooth/lib/manager.cc | 22 |
1 files changed, 14 insertions, 8 deletions
diff --git a/noncore/net/opietooth/lib/manager.cc b/noncore/net/opietooth/lib/manager.cc index 83accf7..7311484 100644 --- a/noncore/net/opietooth/lib/manager.cc +++ b/noncore/net/opietooth/lib/manager.cc | |||
@@ -1,336 +1,342 @@ | |||
1 | 1 | ||
2 | #include "parser.h" | 2 | #include "parser.h" |
3 | #include "manager.h" | 3 | #include "manager.h" |
4 | 4 | ||
5 | #include <opie2/oprocess.h> | 5 | #include <opie2/oprocess.h> |
6 | #include <opie2/odebug.h> | 6 | #include <opie2/odebug.h> |
7 | using namespace Opie::Core; | 7 | using namespace Opie::Core; |
8 | 8 | ||
9 | 9 | ||
10 | using namespace OpieTooth; | 10 | using namespace OpieTooth; |
11 | 11 | ||
12 | using Opie::Core::OProcess; | 12 | using Opie::Core::OProcess; |
13 | Manager::Manager( const QString& dev ) | 13 | Manager::Manager( const QString& dev ) |
14 | : QObject() | 14 | : QObject() |
15 | { | 15 | { |
16 | odebug << "Manager: created" << oendl; | 16 | odebug << "Manager: created" << oendl; |
17 | m_device = dev; | 17 | m_device = dev; |
18 | m_hcitool = 0; | 18 | m_hcitool = 0; |
19 | m_sdp = 0; | 19 | m_sdp = 0; |
20 | } | 20 | } |
21 | Manager::Manager( Device* /*dev*/ ) | 21 | Manager::Manager( Device* /*dev*/ ) |
22 | : QObject() | 22 | : QObject() |
23 | { | 23 | { |
24 | m_hcitool = 0; | 24 | m_hcitool = 0; |
25 | m_sdp = 0; | 25 | m_sdp = 0; |
26 | } | 26 | } |
27 | Manager::Manager() | 27 | Manager::Manager() |
28 | : QObject() | 28 | : QObject() |
29 | { | 29 | { |
30 | m_hcitool = 0; | 30 | m_hcitool = 0; |
31 | m_sdp = 0; | 31 | m_sdp = 0; |
32 | } | 32 | } |
33 | Manager::~Manager(){ | 33 | Manager::~Manager(){ |
34 | delete m_hcitool; | 34 | delete m_hcitool; |
35 | delete m_sdp; | 35 | delete m_sdp; |
36 | } | 36 | } |
37 | void Manager::setDevice( const QString& dev ){ | 37 | void Manager::setDevice( const QString& dev ){ |
38 | m_device = dev; | 38 | m_device = dev; |
39 | } | 39 | } |
40 | void Manager::setDevice( Device* /*dev*/ ){ | 40 | void Manager::setDevice( Device* /*dev*/ ){ |
41 | 41 | ||
42 | } | 42 | } |
43 | void Manager::isAvailable( const QString& device ){ | 43 | void Manager::isAvailable( const QString& device ){ |
44 | OProcess* l2ping = new OProcess(); | 44 | OProcess* l2ping = new OProcess(); |
45 | l2ping->setName( device.latin1() ); | 45 | l2ping->setName( device.latin1() ); |
46 | *l2ping << "l2ping" << "-c1" << device; | 46 | *l2ping << "l2ping" << "-c1" << device; |
47 | connect(l2ping, SIGNAL(processExited(Opie::Core::OProcess* ) ), | 47 | connect(l2ping, SIGNAL(processExited(Opie::Core::OProcess* ) ), |
48 | this, SLOT(slotProcessExited(Opie::Core::OProcess*) ) ); | 48 | this, SLOT(slotProcessExited(Opie::Core::OProcess*) ) ); |
49 | if (!l2ping->start() ) { | 49 | if (!l2ping->start() ) { |
50 | emit available( device, false ); | 50 | emit available( device, false ); |
51 | delete l2ping; | 51 | delete l2ping; |
52 | } | 52 | } |
53 | 53 | ||
54 | } | 54 | } |
55 | 55 | ||
56 | void Manager::isAvailable( Device* /*dev*/ ){ | 56 | void Manager::isAvailable( Device* /*dev*/ ){ |
57 | 57 | ||
58 | 58 | ||
59 | } | 59 | } |
60 | void Manager::searchDevices( const QString& device ){ | 60 | void Manager::searchDevices( const QString& device ){ |
61 | odebug << "Manager: search devices" << oendl; | 61 | odebug << "Manager: search devices" << oendl; |
62 | OProcess* hcitool = new OProcess(); | 62 | m_hcitool = new OProcess(); |
63 | hcitool->setName( device.isEmpty() ? "hci0" : device.latin1() ); | 63 | m_hcitool->setName( device.isEmpty() ? "hci0" : device.latin1() ); |
64 | *hcitool << "hcitool" << "scan"; | 64 | *m_hcitool << "hcitool" << "scan"; |
65 | connect( hcitool, SIGNAL(processExited(Opie::Core::OProcess*) ) , | 65 | connect( m_hcitool, SIGNAL(processExited(Opie::Core::OProcess*) ) , |
66 | this, SLOT(slotHCIExited(Opie::Core::OProcess* ) ) ); | 66 | this, SLOT(slotHCIExited(Opie::Core::OProcess* ) ) ); |
67 | connect( hcitool, SIGNAL(receivedStdout(Opie::Core::OProcess*, char*, int ) ), | 67 | connect( m_hcitool, SIGNAL(receivedStdout(Opie::Core::OProcess*, char*, int ) ), |
68 | this, SLOT(slotHCIOut(Opie::Core::OProcess*, char*, int ) ) ); | 68 | this, SLOT(slotHCIOut(Opie::Core::OProcess*, char*, int ) ) ); |
69 | if (!hcitool->start(OProcess::NotifyOnExit, OProcess::AllOutput) ) { | 69 | if (!m_hcitool->start(OProcess::NotifyOnExit, OProcess::AllOutput) ) { |
70 | odebug << "Manager: could not start" << oendl; | 70 | odebug << "Manager: could not start" << oendl; |
71 | RemoteDevice::ValueList list; | 71 | RemoteDevice::ValueList list; |
72 | emit foundDevices( device, list ); | 72 | emit foundDevices( device, list ); |
73 | delete hcitool; | 73 | delete m_hcitool; |
74 | m_hcitool = 0; | ||
74 | } | 75 | } |
75 | } | 76 | } |
76 | 77 | ||
77 | void Manager::searchDevices(Device* /*d*/ ){ | 78 | void Manager::searchDevices(Device* /*d*/ ){ |
78 | 79 | ||
79 | 80 | ||
80 | } | 81 | } |
81 | void Manager::addService(const QString& name ){ | 82 | void Manager::addService(const QString& name ){ |
82 | OProcess proc; | 83 | OProcess proc; |
83 | proc << "sdptool" << "add" << name; | 84 | proc << "sdptool" << "add" << name; |
84 | bool bo = true; | 85 | bool bo = true; |
85 | if (!proc.start(OProcess::DontCare ) ) | 86 | if (!proc.start(OProcess::DontCare ) ) |
86 | bo = false; | 87 | bo = false; |
87 | emit addedService( name, bo ); | 88 | emit addedService( name, bo ); |
88 | } | 89 | } |
89 | void Manager::addServices(const QStringList& list){ | 90 | void Manager::addServices(const QStringList& list){ |
90 | QStringList::ConstIterator it; | 91 | QStringList::ConstIterator it; |
91 | for (it = list.begin(); it != list.end(); ++it ) | 92 | for (it = list.begin(); it != list.end(); ++it ) |
92 | addService( (*it) ); | 93 | addService( (*it) ); |
93 | } | 94 | } |
94 | void Manager::removeService( const QString& name ){ | 95 | void Manager::removeService( const QString& name ){ |
95 | OProcess prc; | 96 | OProcess prc; |
96 | prc << "sdptool" << "del" << name; | 97 | prc << "sdptool" << "del" << name; |
97 | bool bo = true; | 98 | bool bo = true; |
98 | if (!prc.start(OProcess::DontCare ) ) | 99 | if (!prc.start(OProcess::DontCare ) ) |
99 | bo = false; | 100 | bo = false; |
100 | emit removedService( name, bo ); | 101 | emit removedService( name, bo ); |
101 | } | 102 | } |
102 | void Manager::removeServices( const QStringList& list){ | 103 | void Manager::removeServices( const QStringList& list){ |
103 | QStringList::ConstIterator it; | 104 | QStringList::ConstIterator it; |
104 | for (it = list.begin(); it != list.end(); ++it ) | 105 | for (it = list.begin(); it != list.end(); ++it ) |
105 | removeService( (*it) ); | 106 | removeService( (*it) ); |
106 | } | 107 | } |
107 | void Manager::searchServices( const QString& remDevice ){ | 108 | void Manager::searchServices( const QString& remDevice ){ |
108 | OProcess *m_sdp =new OProcess(); | 109 | m_sdp =new OProcess(); |
109 | *m_sdp << "sdptool" << "browse" << remDevice; | 110 | *m_sdp << "sdptool" << "browse" << remDevice; |
110 | m_sdp->setName( remDevice.latin1() ); | 111 | m_sdp->setName( remDevice.latin1() ); |
111 | odebug << "Manager: search Services for " << remDevice.latin1() << oendl; | 112 | odebug << "Manager: search Services for " << remDevice.latin1() << oendl; |
112 | connect(m_sdp, SIGNAL(processExited(Opie::Core::OProcess*) ), | 113 | connect(m_sdp, SIGNAL(processExited(Opie::Core::OProcess*) ), |
113 | this, SLOT(slotSDPExited(Opie::Core::OProcess* ) ) ); | 114 | this, SLOT(slotSDPExited(Opie::Core::OProcess* ) ) ); |
114 | connect(m_sdp, SIGNAL(receivedStdout(Opie::Core::OProcess*, char*, int ) ), | 115 | connect(m_sdp, SIGNAL(receivedStdout(Opie::Core::OProcess*, char*, int ) ), |
115 | this, SLOT(slotSDPOut(Opie::Core::OProcess*, char*, int) ) ); | 116 | this, SLOT(slotSDPOut(Opie::Core::OProcess*, char*, int) ) ); |
116 | if (!m_sdp->start(OProcess::NotifyOnExit, OProcess::AllOutput) ) { | 117 | if (!m_sdp->start(OProcess::NotifyOnExit, OProcess::AllOutput) ) { |
117 | odebug << "Manager: could not start sdptool" << oendl; | 118 | odebug << "Manager: could not start sdptool" << oendl; |
118 | delete m_sdp; | 119 | delete m_sdp; |
120 | m_sdp = 0; | ||
119 | Services::ValueList list; | 121 | Services::ValueList list; |
120 | emit foundServices( remDevice, list ); | 122 | emit foundServices( remDevice, list ); |
121 | } | 123 | } |
122 | } | 124 | } |
123 | void Manager::searchServices( const RemoteDevice& dev){ | 125 | void Manager::searchServices( const RemoteDevice& dev){ |
124 | searchServices( dev.mac() ); | 126 | searchServices( dev.mac() ); |
125 | } | 127 | } |
126 | QString Manager::toDevice( const QString& /*mac*/ ){ | 128 | QString Manager::toDevice( const QString& /*mac*/ ){ |
127 | return QString::null; | 129 | return QString::null; |
128 | } | 130 | } |
129 | QString Manager::toMac( const QString &/*device*/ ){ | 131 | QString Manager::toMac( const QString &/*device*/ ){ |
130 | return QString::null; | 132 | return QString::null; |
131 | } | 133 | } |
132 | void Manager::slotProcessExited(OProcess* proc ) { | 134 | void Manager::slotProcessExited(OProcess* proc ) { |
133 | bool conn= false; | 135 | bool conn= false; |
134 | if (proc->normalExit() && proc->exitStatus() == 0 ) | 136 | if (proc->normalExit() && proc->exitStatus() == 0 ) |
135 | conn = true; | 137 | conn = true; |
136 | 138 | ||
137 | QString name = QString::fromLatin1(proc->name() ); | 139 | QString name = QString::fromLatin1(proc->name() ); |
138 | emit available( name, conn ); | 140 | emit available( name, conn ); |
139 | delete proc; | 141 | delete proc; |
140 | } | 142 | } |
141 | void Manager::slotSDPOut(OProcess* proc, char* ch, int len) | 143 | void Manager::slotSDPOut(OProcess* proc, char* ch, int len) |
142 | { | 144 | { |
143 | QCString str(ch, len+1 ); | 145 | QCString str(ch, len+1 ); |
144 | odebug << "Manager: SDP:" << str.data() << oendl; | 146 | odebug << "Manager: SDP:" << str.data() << oendl; |
145 | QMap<QString, QString>::Iterator it; | 147 | QMap<QString, QString>::Iterator it; |
146 | it = m_out.find(proc->name() ); | 148 | it = m_out.find(proc->name() ); |
147 | QString string; | 149 | QString string; |
148 | if ( it != m_out.end() ) { | 150 | if ( it != m_out.end() ) { |
149 | string = it.data(); | 151 | string = it.data(); |
150 | } | 152 | } |
151 | string.append( str ); | 153 | string.append( str ); |
152 | m_out.replace( proc->name(), string ); | 154 | m_out.replace( proc->name(), string ); |
153 | 155 | ||
154 | } | 156 | } |
155 | void Manager::slotSDPExited( OProcess* proc) | 157 | void Manager::slotSDPExited( OProcess* proc) |
156 | { | 158 | { |
157 | odebug << "Manager: proc name " << proc->name() << oendl; | 159 | odebug << "Manager: proc name " << proc->name() << oendl; |
158 | Services::ValueList list; | 160 | Services::ValueList list; |
159 | if (proc->normalExit() ) { | 161 | if (proc->normalExit() ) { |
160 | QMap<QString, QString>::Iterator it = m_out.find( proc->name() ); | 162 | QMap<QString, QString>::Iterator it = m_out.find( proc->name() ); |
161 | if ( it != m_out.end() ) { | 163 | if ( it != m_out.end() ) { |
162 | odebug << "Manager: found process" << oendl; | 164 | odebug << "Manager: found process" << oendl; |
163 | list = parseSDPOutput( it.data() ); | 165 | list = parseSDPOutput( it.data() ); |
164 | m_out.remove( it ); | 166 | m_out.remove( it ); |
165 | } | 167 | } |
166 | } | 168 | } |
167 | emit foundServices( proc->name(), list ); | 169 | emit foundServices( proc->name(), list ); |
170 | if (proc == m_sdp) | ||
171 | m_sdp = 0; | ||
168 | delete proc; | 172 | delete proc; |
169 | } | 173 | } |
170 | Services::ValueList Manager::parseSDPOutput( const QString& out ) { | 174 | Services::ValueList Manager::parseSDPOutput( const QString& out ) { |
171 | Services::ValueList list; | 175 | Services::ValueList list; |
172 | odebug << "Manager: parsing output" << oendl; | 176 | odebug << "Manager: parsing output" << oendl; |
173 | Parser parser( out ); | 177 | Parser parser( out ); |
174 | list = parser.services(); | 178 | list = parser.services(); |
175 | return list; | 179 | return list; |
176 | } | 180 | } |
177 | 181 | ||
178 | void Manager::slotHCIExited(OProcess* proc ) { | 182 | void Manager::slotHCIExited(OProcess* proc ) { |
179 | odebug << "Manager: process exited" << oendl; | 183 | odebug << "Manager: process exited" << oendl; |
180 | RemoteDevice::ValueList list; | 184 | RemoteDevice::ValueList list; |
181 | if (proc->normalExit() ) { | 185 | if (proc->normalExit() ) { |
182 | odebug << "Manager: normalExit " << proc->name() << oendl; | 186 | odebug << "Manager: normalExit " << proc->name() << oendl; |
183 | QMap<QString, QString>::Iterator it = m_devices.find(proc->name() ); | 187 | QMap<QString, QString>::Iterator it = m_devices.find(proc->name() ); |
184 | if (it != m_devices.end() ) { | 188 | if (it != m_devices.end() ) { |
185 | odebug << "Manager: != end ;)" << oendl; | 189 | odebug << "Manager: != end ;)" << oendl; |
186 | list = parseHCIOutput( it.data() ); | 190 | list = parseHCIOutput( it.data() ); |
187 | m_devices.remove( it ); | 191 | m_devices.remove( it ); |
188 | } | 192 | } |
189 | } | 193 | } |
190 | emit foundDevices( proc->name(), list ); | 194 | emit foundDevices( proc->name(), list ); |
195 | if (proc == m_hcitool) | ||
196 | m_hcitool = 0; | ||
191 | delete proc; | 197 | delete proc; |
192 | } | 198 | } |
193 | void Manager::slotHCIOut(OProcess* proc, char* ch, int len) { | 199 | void Manager::slotHCIOut(OProcess* proc, char* ch, int len) { |
194 | QCString str( ch, len+1 ); | 200 | QCString str( ch, len+1 ); |
195 | odebug << "Manager: hci: " << str.data() << oendl; | 201 | odebug << "Manager: hci: " << str.data() << oendl; |
196 | QMap<QString, QString>::Iterator it; | 202 | QMap<QString, QString>::Iterator it; |
197 | it = m_devices.find( proc->name() ); | 203 | it = m_devices.find( proc->name() ); |
198 | odebug << "Manager: proc->name " << proc->name() << oendl; | 204 | odebug << "Manager: proc->name " << proc->name() << oendl; |
199 | QString string; | 205 | QString string; |
200 | if (it != m_devices.end() ) { | 206 | if (it != m_devices.end() ) { |
201 | odebug << "Manager: slotHCIOut " << oendl; | 207 | odebug << "Manager: slotHCIOut " << oendl; |
202 | string = it.data(); | 208 | string = it.data(); |
203 | } | 209 | } |
204 | string.append( str ); | 210 | string.append( str ); |
205 | 211 | ||
206 | m_devices.replace( proc->name(), string ); | 212 | m_devices.replace( proc->name(), string ); |
207 | } | 213 | } |
208 | RemoteDevice::ValueList Manager::parseHCIOutput(const QString& output ) { | 214 | RemoteDevice::ValueList Manager::parseHCIOutput(const QString& output ) { |
209 | odebug << "Manager: parseHCI " << output.latin1() << oendl; | 215 | odebug << "Manager: parseHCI " << output.latin1() << oendl; |
210 | RemoteDevice::ValueList list; | 216 | RemoteDevice::ValueList list; |
211 | QStringList strList = QStringList::split('\n', output ); | 217 | QStringList strList = QStringList::split('\n', output ); |
212 | QStringList::Iterator it; | 218 | QStringList::Iterator it; |
213 | QString str; | 219 | QString str; |
214 | for ( it = strList.begin(); it != strList.end(); ++it ) { | 220 | for ( it = strList.begin(); it != strList.end(); ++it ) { |
215 | str = (*it).stripWhiteSpace(); | 221 | str = (*it).stripWhiteSpace(); |
216 | odebug << "Manager: OpieTooth " << str.latin1() << oendl; | 222 | odebug << "Manager: OpieTooth " << str.latin1() << oendl; |
217 | int pos = str.findRev(':' ); | 223 | int pos = str.findRev(':' ); |
218 | if ( pos > 0 ) { | 224 | if ( pos > 0 ) { |
219 | QString mac = str.left(17 ); | 225 | QString mac = str.left(17 ); |
220 | str.remove( 0, 17 ); | 226 | str.remove( 0, 17 ); |
221 | odebug << "Manager: mac " << mac.latin1() << oendl; | 227 | odebug << "Manager: mac " << mac.latin1() << oendl; |
222 | odebug << "Manager: rest: " << str.latin1() << oendl; | 228 | odebug << "Manager: rest: " << str.latin1() << oendl; |
223 | RemoteDevice rem( mac , QString::fromUtf8(str.stripWhiteSpace()) ); | 229 | RemoteDevice rem( mac , QString::fromUtf8(str.stripWhiteSpace()) ); |
224 | list.append( rem ); | 230 | list.append( rem ); |
225 | } | 231 | } |
226 | } | 232 | } |
227 | return list; | 233 | return list; |
228 | } | 234 | } |
229 | 235 | ||
230 | ////// hcitool cc and hcitool con | 236 | ////// hcitool cc and hcitool con |
231 | 237 | ||
232 | /** | 238 | /** |
233 | * Create it on the stack as don't care | 239 | * Create it on the stack as don't care |
234 | * so we don't need to care for it | 240 | * so we don't need to care for it |
235 | * cause hcitool gets reparented | 241 | * cause hcitool gets reparented |
236 | */ | 242 | */ |
237 | void Manager::connectTo( const QString& mac) { | 243 | void Manager::connectTo( const QString& mac) { |
238 | OProcess proc; | 244 | OProcess proc; |
239 | proc << "hcitool"; | 245 | proc << "hcitool"; |
240 | proc << "cc"; | 246 | proc << "cc"; |
241 | proc << mac; | 247 | proc << mac; |
242 | proc.start(OProcess::DontCare); // the lib does not care at this point | 248 | proc.start(OProcess::DontCare); // the lib does not care at this point |
243 | } | 249 | } |
244 | 250 | ||
245 | 251 | ||
246 | void Manager::searchConnections() { | 252 | void Manager::searchConnections() { |
247 | odebug << "Manager: searchConnections()" << oendl; | 253 | odebug << "Manager: searchConnections()" << oendl; |
248 | OProcess* proc = new OProcess(); | 254 | OProcess* proc = new OProcess(); |
249 | m_hcitoolCon = QString::null; | 255 | m_hcitoolCon = QString::null; |
250 | 256 | ||
251 | connect(proc, SIGNAL(processExited(Opie::Core::OProcess*) ), | 257 | connect(proc, SIGNAL(processExited(Opie::Core::OProcess*) ), |
252 | this, SLOT(slotConnectionExited( Opie::Core::OProcess*) ) ); | 258 | this, SLOT(slotConnectionExited( Opie::Core::OProcess*) ) ); |
253 | connect(proc, SIGNAL(receivedStdout(Opie::Core::OProcess*, char*, int) ), | 259 | connect(proc, SIGNAL(receivedStdout(Opie::Core::OProcess*, char*, int) ), |
254 | this, SLOT(slotConnectionOutput(Opie::Core::OProcess*, char*, int) ) ); | 260 | this, SLOT(slotConnectionOutput(Opie::Core::OProcess*, char*, int) ) ); |
255 | *proc << "hcitool"; | 261 | *proc << "hcitool"; |
256 | *proc << "con"; | 262 | *proc << "con"; |
257 | 263 | ||
258 | if (!proc->start(OProcess::NotifyOnExit, OProcess::AllOutput) ) { | 264 | if (!proc->start(OProcess::NotifyOnExit, OProcess::AllOutput) ) { |
259 | ConnectionState::ValueList list; | 265 | ConnectionState::ValueList list; |
260 | emit connections( list ); | 266 | emit connections( list ); |
261 | delete proc; | 267 | delete proc; |
262 | } | 268 | } |
263 | } | 269 | } |
264 | void Manager::slotConnectionExited( OProcess* proc ) { | 270 | void Manager::slotConnectionExited( OProcess* proc ) { |
265 | ConnectionState::ValueList list; | 271 | ConnectionState::ValueList list; |
266 | list = parseConnections( m_hcitoolCon ); | 272 | list = parseConnections( m_hcitoolCon ); |
267 | emit connections(list ); | 273 | emit connections(list ); |
268 | delete proc; | 274 | delete proc; |
269 | } | 275 | } |
270 | void Manager::slotConnectionOutput(OProcess* /*proc*/, char* cha, int len) { | 276 | void Manager::slotConnectionOutput(OProcess* /*proc*/, char* cha, int len) { |
271 | QCString str(cha, len ); | 277 | QCString str(cha, len ); |
272 | m_hcitoolCon.append( str ); | 278 | m_hcitoolCon.append( str ); |
273 | //delete proc; | 279 | //delete proc; |
274 | } | 280 | } |
275 | ConnectionState::ValueList Manager::parseConnections( const QString& out ) { | 281 | ConnectionState::ValueList Manager::parseConnections( const QString& out ) { |
276 | ConnectionState::ValueList list2; | 282 | ConnectionState::ValueList list2; |
277 | QStringList list = QStringList::split('\n', out ); | 283 | QStringList list = QStringList::split('\n', out ); |
278 | QStringList::Iterator it; | 284 | QStringList::Iterator it; |
279 | // remove the first line ( "Connections:") | 285 | // remove the first line ( "Connections:") |
280 | it = list.begin(); | 286 | it = list.begin(); |
281 | it = list.remove( it ); | 287 | it = list.remove( it ); |
282 | for (; it != list.end(); ++it ) { | 288 | for (; it != list.end(); ++it ) { |
283 | QString row = (*it).stripWhiteSpace(); | 289 | QString row = (*it).stripWhiteSpace(); |
284 | QStringList value = QStringList::split(' ', row ); | 290 | QStringList value = QStringList::split(' ', row ); |
285 | odebug << "Manager: 0: " << value[0].latin1() << oendl; | 291 | odebug << "Manager: 0: " << value[0].latin1() << oendl; |
286 | odebug << "Manager: 1: " << value[1].latin1() << oendl; | 292 | odebug << "Manager: 1: " << value[1].latin1() << oendl; |
287 | odebug << "Manager: 2: " << value[2].latin1() << oendl; | 293 | odebug << "Manager: 2: " << value[2].latin1() << oendl; |
288 | odebug << "Manager: 3: " << value[3].latin1() << oendl; | 294 | odebug << "Manager: 3: " << value[3].latin1() << oendl; |
289 | odebug << "Manager: 4: " << value[4].latin1() << oendl; | 295 | odebug << "Manager: 4: " << value[4].latin1() << oendl; |
290 | odebug << "Manager: 5: " << value[5].latin1() << oendl; | 296 | odebug << "Manager: 5: " << value[5].latin1() << oendl; |
291 | odebug << "Manager: 6: " << value[6].latin1() << oendl; | 297 | odebug << "Manager: 6: " << value[6].latin1() << oendl; |
292 | odebug << "Manager: 7: " << value[7].latin1() << oendl; | 298 | odebug << "Manager: 7: " << value[7].latin1() << oendl; |
293 | odebug << "Manager: 8: " << value[8].latin1() << oendl; | 299 | odebug << "Manager: 8: " << value[8].latin1() << oendl; |
294 | ConnectionState con; | 300 | ConnectionState con; |
295 | con.setDirection( value[0] == QString::fromLatin1("<") ? Outgoing : Incoming ); | 301 | con.setDirection( value[0] == QString::fromLatin1("<") ? Outgoing : Incoming ); |
296 | con.setConnectionMode( value[1] ); | 302 | con.setConnectionMode( value[1] ); |
297 | con.setMac( value[2] ); | 303 | con.setMac( value[2] ); |
298 | con.setHandle( value[4].toInt() ); | 304 | con.setHandle( value[4].toInt() ); |
299 | con.setState( value[6].toInt() ); | 305 | con.setState( value[6].toInt() ); |
300 | con.setLinkMode( value[8] == QString::fromLatin1("MASTER") ? Master : Client ); | 306 | con.setLinkMode( value[8] == QString::fromLatin1("MASTER") ? Master : Client ); |
301 | list2.append( con ); | 307 | list2.append( con ); |
302 | } | 308 | } |
303 | return list2; | 309 | return list2; |
304 | } | 310 | } |
305 | 311 | ||
306 | void Manager::signalStrength( const QString &mac ) { | 312 | void Manager::signalStrength( const QString &mac ) { |
307 | 313 | ||
308 | OProcess* sig_proc = new OProcess(); | 314 | OProcess* sig_proc = new OProcess(); |
309 | 315 | ||
310 | connect(sig_proc, SIGNAL(processExited(Opie::Core::OProcess*) ), | 316 | connect(sig_proc, SIGNAL(processExited(Opie::Core::OProcess*) ), |
311 | this, SLOT(slotSignalStrengthExited( Opie::Core::OProcess*) ) ); | 317 | this, SLOT(slotSignalStrengthExited( Opie::Core::OProcess*) ) ); |
312 | connect(sig_proc, SIGNAL(receivedStdout(Opie::Core::OProcess*, char*, int) ), | 318 | connect(sig_proc, SIGNAL(receivedStdout(Opie::Core::OProcess*, char*, int) ), |
313 | this, SLOT(slotSignalStrengthOutput(Opie::Core::OProcess*, char*, int) ) ); | 319 | this, SLOT(slotSignalStrengthOutput(Opie::Core::OProcess*, char*, int) ) ); |
314 | *sig_proc << "hcitool"; | 320 | *sig_proc << "hcitool"; |
315 | *sig_proc << "lq"; | 321 | *sig_proc << "lq"; |
316 | *sig_proc << mac; | 322 | *sig_proc << mac; |
317 | 323 | ||
318 | sig_proc->setName( mac.latin1() ); | 324 | sig_proc->setName( mac.latin1() ); |
319 | 325 | ||
320 | if (!sig_proc->start(OProcess::NotifyOnExit, OProcess::AllOutput) ) { | 326 | if (!sig_proc->start(OProcess::NotifyOnExit, OProcess::AllOutput) ) { |
321 | emit signalStrength( mac, "-1" ); | 327 | emit signalStrength( mac, "-1" ); |
322 | delete sig_proc; | 328 | delete sig_proc; |
323 | } | 329 | } |
324 | } | 330 | } |
325 | 331 | ||
326 | void Manager::slotSignalStrengthOutput(OProcess* proc, char* cha, int len) { | 332 | void Manager::slotSignalStrengthOutput(OProcess* proc, char* cha, int len) { |
327 | QCString str(cha, len ); | 333 | QCString str(cha, len ); |
328 | QString temp = QString(str).stripWhiteSpace(); | 334 | QString temp = QString(str).stripWhiteSpace(); |
329 | QStringList value = QStringList::split(' ', temp ); | 335 | QStringList value = QStringList::split(' ', temp ); |
330 | emit signalStrength( proc->name(), value[2].latin1() ); | 336 | emit signalStrength( proc->name(), value[2].latin1() ); |
331 | } | 337 | } |
332 | 338 | ||
333 | 339 | ||
334 | void Manager::slotSignalStrengthExited( OProcess* proc ) { | 340 | void Manager::slotSignalStrengthExited( OProcess* proc ) { |
335 | delete proc; | 341 | delete proc; |
336 | } | 342 | } |