summaryrefslogtreecommitdiff
path: root/noncore/net/opietooth/lib/manager.cc
Unidiff
Diffstat (limited to 'noncore/net/opietooth/lib/manager.cc') (more/less context) (show whitespace changes)
-rw-r--r--noncore/net/opietooth/lib/manager.cc18
1 files changed, 9 insertions, 9 deletions
diff --git a/noncore/net/opietooth/lib/manager.cc b/noncore/net/opietooth/lib/manager.cc
index 56156a8..7c9ea5b 100644
--- a/noncore/net/opietooth/lib/manager.cc
+++ b/noncore/net/opietooth/lib/manager.cc
@@ -24,116 +24,116 @@ Manager::Manager( Device* /*dev*/ )
24 m_hcitool = 0; 24 m_hcitool = 0;
25 m_sdp = 0; 25 m_sdp = 0;
26} 26}
27Manager::Manager() 27Manager::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}
33Manager::~Manager(){ 33Manager::~Manager(){
34 delete m_hcitool; 34 delete m_hcitool;
35 delete m_sdp; 35 delete m_sdp;
36} 36}
37void Manager::setDevice( const QString& dev ){ 37void Manager::setDevice( const QString& dev ){
38 m_device = dev; 38 m_device = dev;
39} 39}
40void Manager::setDevice( Device* /*dev*/ ){ 40void Manager::setDevice( Device* /*dev*/ ){
41 41
42} 42}
43void Manager::isAvailable( const QString& device ){ 43void 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(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
56void Manager::isAvailable( Device* /*dev*/ ){ 56void Manager::isAvailable( Device* /*dev*/ ){
57 57
58 58
59} 59}
60void Manager::searchDevices( const QString& device ){ 60void Manager::searchDevices( const QString& device ){
61 qWarning("search devices"); 61 qWarning("search devices");
62 OProcess* hcitool = new OProcess(); 62 OProcess* hcitool = new OProcess();
63 hcitool->setName( device.isEmpty() ? "hci0" : device.latin1() ); 63 hcitool->setName( device.isEmpty() ? "hci0" : device.latin1() );
64 *hcitool << "hcitool" << "scan"; 64 *hcitool << "hcitool" << "scan";
65 connect( hcitool, SIGNAL(processExited(Opie::Core::OProcess*) ) , 65 connect( hcitool, SIGNAL(processExited(Opie::Core::OProcess*) ) ,
66 this, SLOT(slotHCIExited(OProcess* ) ) ); 66 this, SLOT(slotHCIExited(Opie::Core::OProcess* ) ) );
67 connect( hcitool, SIGNAL(receivedStdout(Opie::Core::OProcess*, char*, int ) ), 67 connect( hcitool, SIGNAL(receivedStdout(Opie::Core::OProcess*, char*, int ) ),
68 this, SLOT(slotHCIOut(OProcess*, char*, int ) ) ); 68 this, SLOT(slotHCIOut(Opie::Core::OProcess*, char*, int ) ) );
69 if (!hcitool->start(OProcess::NotifyOnExit, OProcess::AllOutput) ) { 69 if (!hcitool->start(OProcess::NotifyOnExit, OProcess::AllOutput) ) {
70 qWarning("could not start"); 70 qWarning("could not start");
71 RemoteDevice::ValueList list; 71 RemoteDevice::ValueList list;
72 emit foundDevices( device, list ); 72 emit foundDevices( device, list );
73 delete hcitool; 73 delete hcitool;
74 } 74 }
75} 75}
76 76
77void Manager::searchDevices(Device* /*d*/ ){ 77void Manager::searchDevices(Device* /*d*/ ){
78 78
79 79
80} 80}
81void Manager::addService(const QString& name ){ 81void Manager::addService(const QString& name ){
82 OProcess proc; 82 OProcess proc;
83 proc << "sdptool" << "add" << name; 83 proc << "sdptool" << "add" << name;
84 bool bo = true; 84 bool bo = true;
85 if (!proc.start(OProcess::DontCare ) ) 85 if (!proc.start(OProcess::DontCare ) )
86 bo = false; 86 bo = false;
87 emit addedService( name, bo ); 87 emit addedService( name, bo );
88} 88}
89void Manager::addServices(const QStringList& list){ 89void Manager::addServices(const QStringList& list){
90 QStringList::ConstIterator it; 90 QStringList::ConstIterator it;
91 for (it = list.begin(); it != list.end(); ++it ) 91 for (it = list.begin(); it != list.end(); ++it )
92 addService( (*it) ); 92 addService( (*it) );
93} 93}
94void Manager::removeService( const QString& name ){ 94void Manager::removeService( const QString& name ){
95 OProcess prc; 95 OProcess prc;
96 prc << "sdptool" << "del" << name; 96 prc << "sdptool" << "del" << name;
97 bool bo = true; 97 bool bo = true;
98 if (!prc.start(OProcess::DontCare ) ) 98 if (!prc.start(OProcess::DontCare ) )
99 bo = false; 99 bo = false;
100 emit removedService( name, bo ); 100 emit removedService( name, bo );
101} 101}
102void Manager::removeServices( const QStringList& list){ 102void Manager::removeServices( const QStringList& list){
103 QStringList::ConstIterator it; 103 QStringList::ConstIterator it;
104 for (it = list.begin(); it != list.end(); ++it ) 104 for (it = list.begin(); it != list.end(); ++it )
105 removeService( (*it) ); 105 removeService( (*it) );
106} 106}
107void Manager::searchServices( const QString& remDevice ){ 107void Manager::searchServices( const QString& remDevice ){
108 OProcess *m_sdp =new OProcess(); 108 OProcess *m_sdp =new OProcess();
109 *m_sdp << "sdptool" << "browse" << remDevice; 109 *m_sdp << "sdptool" << "browse" << remDevice;
110 m_sdp->setName( remDevice.latin1() ); 110 m_sdp->setName( remDevice.latin1() );
111 qWarning("search Services for %s", remDevice.latin1() ); 111 qWarning("search Services for %s", remDevice.latin1() );
112 connect(m_sdp, SIGNAL(processExited(Opie::Core::OProcess*) ), 112 connect(m_sdp, SIGNAL(processExited(Opie::Core::OProcess*) ),
113 this, SLOT(slotSDPExited(OProcess* ) ) ); 113 this, SLOT(slotSDPExited(Opie::Core::OProcess* ) ) );
114 connect(m_sdp, SIGNAL(receivedStdout(Opie::Core::OProcess*, char*, int ) ), 114 connect(m_sdp, SIGNAL(receivedStdout(Opie::Core::OProcess*, char*, int ) ),
115 this, SLOT(slotSDPOut(OProcess*, char*, int) ) ); 115 this, SLOT(slotSDPOut(Opie::Core::OProcess*, char*, int) ) );
116 if (!m_sdp->start(OProcess::NotifyOnExit, OProcess::AllOutput) ) { 116 if (!m_sdp->start(OProcess::NotifyOnExit, OProcess::AllOutput) ) {
117 qWarning("could not start sdptool" ); 117 qWarning("could not start sdptool" );
118 delete m_sdp; 118 delete m_sdp;
119 Services::ValueList list; 119 Services::ValueList list;
120 emit foundServices( remDevice, list ); 120 emit foundServices( remDevice, list );
121 } 121 }
122} 122}
123void Manager::searchServices( const RemoteDevice& dev){ 123void Manager::searchServices( const RemoteDevice& dev){
124 searchServices( dev.mac() ); 124 searchServices( dev.mac() );
125} 125}
126QString Manager::toDevice( const QString& /*mac*/ ){ 126QString Manager::toDevice( const QString& /*mac*/ ){
127 return QString::null; 127 return QString::null;
128} 128}
129QString Manager::toMac( const QString &/*device*/ ){ 129QString Manager::toMac( const QString &/*device*/ ){
130 return QString::null; 130 return QString::null;
131} 131}
132void Manager::slotProcessExited(OProcess* proc ) { 132void Manager::slotProcessExited(OProcess* proc ) {
133 bool conn= false; 133 bool conn= false;
134 if (proc->normalExit() && proc->exitStatus() == 0 ) 134 if (proc->normalExit() && proc->exitStatus() == 0 )
135 conn = true; 135 conn = true;
136 136
137 QString name = QString::fromLatin1(proc->name() ); 137 QString name = QString::fromLatin1(proc->name() );
138 emit available( name, conn ); 138 emit available( name, conn );
139 delete proc; 139 delete proc;
@@ -228,51 +228,51 @@ RemoteDevice::ValueList Manager::parseHCIOutput(const QString& output ) {
228} 228}
229 229
230////// hcitool cc and hcitool con 230////// hcitool cc and hcitool con
231 231
232/** 232/**
233 * Create it on the stack as don't care 233 * Create it on the stack as don't care
234 * so we don't need to care for it 234 * so we don't need to care for it
235 * cause hcitool gets reparented 235 * cause hcitool gets reparented
236 */ 236 */
237void Manager::connectTo( const QString& mac) { 237void Manager::connectTo( const QString& mac) {
238 OProcess proc; 238 OProcess proc;
239 proc << "hcitool"; 239 proc << "hcitool";
240 proc << "cc"; 240 proc << "cc";
241 proc << mac; 241 proc << mac;
242 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
243} 243}
244 244
245 245
246void Manager::searchConnections() { 246void Manager::searchConnections() {
247 qWarning("searching connections?"); 247 qWarning("searching connections?");
248 OProcess* proc = new OProcess(); 248 OProcess* proc = new OProcess();
249 m_hcitoolCon = QString::null; 249 m_hcitoolCon = QString::null;
250 250
251 connect(proc, SIGNAL(processExited(Opie::Core::OProcess*) ), 251 connect(proc, SIGNAL(processExited(Opie::Core::OProcess*) ),
252 this, SLOT(slotConnectionExited( OProcess*) ) ); 252 this, SLOT(slotConnectionExited( Opie::Core::OProcess*) ) );
253 connect(proc, SIGNAL(receivedStdout(Opie::Core::OProcess*, char*, int) ), 253 connect(proc, SIGNAL(receivedStdout(Opie::Core::OProcess*, char*, int) ),
254 this, SLOT(slotConnectionOutput(OProcess*, char*, int) ) ); 254 this, SLOT(slotConnectionOutput(Opie::Core::OProcess*, char*, int) ) );
255 *proc << "hcitool"; 255 *proc << "hcitool";
256 *proc << "con"; 256 *proc << "con";
257 257
258 if (!proc->start(OProcess::NotifyOnExit, OProcess::AllOutput) ) { 258 if (!proc->start(OProcess::NotifyOnExit, OProcess::AllOutput) ) {
259 ConnectionState::ValueList list; 259 ConnectionState::ValueList list;
260 emit connections( list ); 260 emit connections( list );
261 delete proc; 261 delete proc;
262 } 262 }
263} 263}
264void Manager::slotConnectionExited( OProcess* proc ) { 264void Manager::slotConnectionExited( OProcess* proc ) {
265 ConnectionState::ValueList list; 265 ConnectionState::ValueList list;
266 list = parseConnections( m_hcitoolCon ); 266 list = parseConnections( m_hcitoolCon );
267 emit connections(list ); 267 emit connections(list );
268 delete proc; 268 delete proc;
269} 269}
270void Manager::slotConnectionOutput(OProcess* /*proc*/, char* cha, int len) { 270void Manager::slotConnectionOutput(OProcess* /*proc*/, char* cha, int len) {
271 QCString str(cha, len ); 271 QCString str(cha, len );
272 m_hcitoolCon.append( str ); 272 m_hcitoolCon.append( str );
273 //delete proc; 273 //delete proc;
274} 274}
275ConnectionState::ValueList Manager::parseConnections( const QString& out ) { 275ConnectionState::ValueList Manager::parseConnections( const QString& out ) {
276 ConnectionState::ValueList list2; 276 ConnectionState::ValueList list2;
277 QStringList list = QStringList::split('\n', out ); 277 QStringList list = QStringList::split('\n', out );
278 QStringList::Iterator it; 278 QStringList::Iterator it;
@@ -287,50 +287,50 @@ ConnectionState::ValueList Manager::parseConnections( const QString& out ) {
287 qWarning("2: %s", value[2].latin1() ); 287 qWarning("2: %s", value[2].latin1() );
288 qWarning("3: %s", value[3].latin1() ); 288 qWarning("3: %s", value[3].latin1() );
289 qWarning("4: %s", value[4].latin1() ); 289 qWarning("4: %s", value[4].latin1() );
290 qWarning("5: %s", value[5].latin1() ); 290 qWarning("5: %s", value[5].latin1() );
291 qWarning("6: %s", value[6].latin1() ); 291 qWarning("6: %s", value[6].latin1() );
292 qWarning("7: %s", value[7].latin1() ); 292 qWarning("7: %s", value[7].latin1() );
293 qWarning("8: %s", value[8].latin1() ); 293 qWarning("8: %s", value[8].latin1() );
294 ConnectionState con; 294 ConnectionState con;
295 con.setDirection( value[0] == QString::fromLatin1("<") ? Outgoing : Incoming ); 295 con.setDirection( value[0] == QString::fromLatin1("<") ? Outgoing : Incoming );
296 con.setConnectionMode( value[1] ); 296 con.setConnectionMode( value[1] );
297 con.setMac( value[2] ); 297 con.setMac( value[2] );
298 con.setHandle( value[4].toInt() ); 298 con.setHandle( value[4].toInt() );
299 con.setState( value[6].toInt() ); 299 con.setState( value[6].toInt() );
300 con.setLinkMode( value[8] == QString::fromLatin1("MASTER") ? Master : Client ); 300 con.setLinkMode( value[8] == QString::fromLatin1("MASTER") ? Master : Client );
301 list2.append( con ); 301 list2.append( con );
302 } 302 }
303 return list2; 303 return list2;
304} 304}
305 305
306void Manager::signalStrength( const QString &mac ) { 306void Manager::signalStrength( const QString &mac ) {
307 307
308 OProcess* sig_proc = new OProcess(); 308 OProcess* sig_proc = new OProcess();
309 309
310 connect(sig_proc, SIGNAL(processExited(Opie::Core::OProcess*) ), 310 connect(sig_proc, SIGNAL(processExited(Opie::Core::OProcess*) ),
311 this, SLOT(slotSignalStrengthExited( OProcess*) ) ); 311 this, SLOT(slotSignalStrengthExited( Opie::Core::OProcess*) ) );
312 connect(sig_proc, SIGNAL(receivedStdout(Opie::Core::OProcess*, char*, int) ), 312 connect(sig_proc, SIGNAL(receivedStdout(Opie::Core::OProcess*, char*, int) ),
313 this, SLOT(slotSignalStrengthOutput(OProcess*, char*, int) ) ); 313 this, SLOT(slotSignalStrengthOutput(Opie::Core::OProcess*, char*, int) ) );
314 *sig_proc << "hcitool"; 314 *sig_proc << "hcitool";
315 *sig_proc << "lq"; 315 *sig_proc << "lq";
316 *sig_proc << mac; 316 *sig_proc << mac;
317 317
318 sig_proc->setName( mac.latin1() ); 318 sig_proc->setName( mac.latin1() );
319 319
320 if (!sig_proc->start(OProcess::NotifyOnExit, OProcess::AllOutput) ) { 320 if (!sig_proc->start(OProcess::NotifyOnExit, OProcess::AllOutput) ) {
321 emit signalStrength( mac, "-1" ); 321 emit signalStrength( mac, "-1" );
322 delete sig_proc; 322 delete sig_proc;
323 } 323 }
324} 324}
325 325
326void Manager::slotSignalStrengthOutput(OProcess* proc, char* cha, int len) { 326void Manager::slotSignalStrengthOutput(OProcess* proc, char* cha, int len) {
327 QCString str(cha, len ); 327 QCString str(cha, len );
328 QString temp = QString(str).stripWhiteSpace(); 328 QString temp = QString(str).stripWhiteSpace();
329 QStringList value = QStringList::split(' ', temp ); 329 QStringList value = QStringList::split(' ', temp );
330 emit signalStrength( proc->name(), value[2].latin1() ); 330 emit signalStrength( proc->name(), value[2].latin1() );
331} 331}
332 332
333 333
334void Manager::slotSignalStrengthExited( OProcess* proc ) { 334void Manager::slotSignalStrengthExited( OProcess* proc ) {
335 delete proc; 335 delete proc;
336} 336}