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