summaryrefslogtreecommitdiff
Unidiff
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--noncore/net/opietooth/lib/manager.cc37
1 files changed, 27 insertions, 10 deletions
diff --git a/noncore/net/opietooth/lib/manager.cc b/noncore/net/opietooth/lib/manager.cc
index d65dbd4..40c1f0a 100644
--- a/noncore/net/opietooth/lib/manager.cc
+++ b/noncore/net/opietooth/lib/manager.cc
@@ -1,22 +1,23 @@
1#include <opie/oprocess.h> 1#include <opie/oprocess.h>
2 2
3#include "manager.h" 3#include "manager.h"
4 4
5 5
6using namespace OpieTooth; 6using namespace OpieTooth;
7 7
8Manager::Manager( const QString& dev ) 8Manager::Manager( const QString& dev )
9 : QObject() 9 : QObject()
10{ 10{
11 qWarning("created");
11 m_device = dev; 12 m_device = dev;
12 m_hcitool = 0; 13 m_hcitool = 0;
13 m_sdp = 0; 14 m_sdp = 0;
14} 15}
15Manager::Manager( Device* dev ) 16Manager::Manager( Device* dev )
16 : QObject() 17 : QObject()
17{ 18{
18 m_hcitool = 0; 19 m_hcitool = 0;
19 m_sdp = 0; 20 m_sdp = 0;
20} 21}
21Manager::Manager() 22Manager::Manager()
22 : QObject() 23 : QObject()
@@ -42,32 +43,34 @@ void Manager::isConnected( const QString& device ){
42 this, SLOT(slotProcessExited(OProcess*) ) ); 43 this, SLOT(slotProcessExited(OProcess*) ) );
43 if (!l2ping->start() ) { 44 if (!l2ping->start() ) {
44 emit connected( device, false ); 45 emit connected( device, false );
45 delete l2ping; 46 delete l2ping;
46 } 47 }
47 48
48} 49}
49void Manager::isConnected( Device* dev ){ 50void Manager::isConnected( Device* dev ){
50 51
51 52
52} 53}
53void Manager::searchDevices( const QString& device ){ 54void Manager::searchDevices( const QString& device ){
55 qWarning("search devices");
54 OProcess* hcitool = new OProcess(); 56 OProcess* hcitool = new OProcess();
55 hcitool->setName( device.latin1() ); 57 hcitool->setName( device.isEmpty() ? "hci0" : device.latin1() );
56 *hcitool << "hcitool" << "scan"; 58 *hcitool << "hcitool" << "scan";
57 connect( hcitool, SIGNAL(processExited(OProcess*) ) , 59 connect( hcitool, SIGNAL(processExited(OProcess*) ) ,
58 this, SLOT(slotHCIExited(OProcess* ) ) ); 60 this, SLOT(slotHCIExited(OProcess* ) ) );
59 connect( hcitool, SIGNAL(receivedStdout(OProcess*, char*, int ) ), 61 connect( hcitool, SIGNAL(receivedStdout(OProcess*, char*, int ) ),
60 this, SLOT(slotHCIOut(OProcess*, char*, int ) ) ); 62 this, SLOT(slotHCIOut(OProcess*, char*, int ) ) );
61 if (!hcitool->start() ) { 63 if (!hcitool->start(OProcess::NotifyOnExit, OProcess::AllOutput) ) {
64 qWarning("could not start");
62 RemoteDevices::ValueList list; 65 RemoteDevices::ValueList list;
63 emit foundDevices( device, list ); 66 emit foundDevices( device, list );
64 delete hcitool; 67 delete hcitool;
65 } 68 }
66} 69}
67 70
68void Manager::searchDevices(Device* d ){ 71void Manager::searchDevices(Device* d ){
69 72
70 73
71} 74}
72void Manager::addService(const QString& name ){ 75void Manager::addService(const QString& name ){
73 OProcess proc; 76 OProcess proc;
@@ -94,25 +97,25 @@ void Manager::removeServices( const QStringList& list){
94 QStringList::ConstIterator it; 97 QStringList::ConstIterator it;
95 for (it = list.begin(); it != list.end(); ++it ) 98 for (it = list.begin(); it != list.end(); ++it )
96 removeService( (*it) ); 99 removeService( (*it) );
97} 100}
98void Manager::searchServices( const QString& remDevice ){ 101void Manager::searchServices( const QString& remDevice ){
99 OProcess *m_sdp =new OProcess(); 102 OProcess *m_sdp =new OProcess();
100 *m_sdp << "sdptool" << "browse" << remDevice; 103 *m_sdp << "sdptool" << "browse" << remDevice;
101 m_sdp->setName( remDevice.latin1() ); 104 m_sdp->setName( remDevice.latin1() );
102 connect(m_sdp, SIGNAL(processExited(OProcess*) ), 105 connect(m_sdp, SIGNAL(processExited(OProcess*) ),
103 this, SLOT(slotSDPExited(OProcess* ) ) ); 106 this, SLOT(slotSDPExited(OProcess* ) ) );
104 connect(m_sdp, SIGNAL(receivedStdout(OProcess*, char*, int ) ), 107 connect(m_sdp, SIGNAL(receivedStdout(OProcess*, char*, int ) ),
105 this, SLOT(slotSDPOut(OProcess*, char*, int) ) ); 108 this, SLOT(slotSDPOut(OProcess*, char*, int) ) );
106 if (!m_sdp->start() ) { 109 if (!m_sdp->start(OProcess::NotifyOnExit, OProcess::AllOutput) ) {
107 delete m_sdp; 110 delete m_sdp;
108 Services::ValueList list; 111 Services::ValueList list;
109 emit foundServices( remDevice, list ); 112 emit foundServices( remDevice, list );
110 } 113 }
111} 114}
112void Manager::searchServices( const RemoteDevices& dev){ 115void Manager::searchServices( const RemoteDevices& dev){
113 searchServices( dev.mac() ); 116 searchServices( dev.mac() );
114} 117}
115QString Manager::toDevice( const QString& mac ){ 118QString Manager::toDevice( const QString& mac ){
116 119
117} 120}
118QString Manager::toMac( const QString &device ){ 121QString Manager::toMac( const QString &device ){
@@ -149,48 +152,62 @@ void Manager::slotSDPExited( OProcess* proc)
149 m_out.remove( it ); 152 m_out.remove( it );
150 } 153 }
151 } 154 }
152 emit foundServices( proc->name(), list ); 155 emit foundServices( proc->name(), list );
153 delete proc; 156 delete proc;
154} 157}
155Services::ValueList Manager::parseSDPOutput( const QString& out ) { 158Services::ValueList Manager::parseSDPOutput( const QString& out ) {
156 Services::ValueList list; 159 Services::ValueList list;
157 return list; 160 return list;
158} 161}
159 162
160void Manager::slotHCIExited(OProcess* proc ) { 163void Manager::slotHCIExited(OProcess* proc ) {
164 qWarning("process exited");
161 RemoteDevices::ValueList list; 165 RemoteDevices::ValueList list;
162 if (proc->normalExit() ) { 166 if (proc->normalExit() ) {
167 qWarning("normalExit %s", proc->name() );
163 QMap<QString, QString>::Iterator it = m_devices.find(proc->name() ); 168 QMap<QString, QString>::Iterator it = m_devices.find(proc->name() );
164 if (it != m_devices.end() ) { 169 if (it != m_devices.end() ) {
170 qWarning("!= end ;)");
165 list = parseHCIOutput( it.data() ); 171 list = parseHCIOutput( it.data() );
166 m_devices.remove( it ); 172 m_devices.remove( it );
167 } 173 }
168 } 174 }
169 emit foundDevices( proc->name(), list ); 175 emit foundDevices( proc->name(), list );
170 delete proc; 176 delete proc;
171} 177}
172void Manager::slotHCIOut(OProcess* proc, char* ch, int len) { 178void Manager::slotHCIOut(OProcess* proc, char* ch, int len) {
173 QCString str( ch, len+1 ); 179 QCString str( ch, len+1 );
180 qWarning("hci: %s", str.data() );
174 QMap<QString, QString>::Iterator it; 181 QMap<QString, QString>::Iterator it;
175 it = m_devices.find( proc->name() ); 182 it = m_devices.find( proc->name() );
183 qWarning("proc->name %s", proc->name() );
184 QString string;
176 if (it != m_devices.end() ) { 185 if (it != m_devices.end() ) {
177 QString string = it.data(); 186 qWarning("slotHCIOut ");
178 string.append( str ); 187 string = it.data();
179 m_devices.replace( proc->name(), string );
180 } 188 }
189 string.append( str );
190
191 m_devices.replace( proc->name(), string );
181} 192}
182RemoteDevices::ValueList Manager::parseHCIOutput(const QString& output ) { 193RemoteDevices::ValueList Manager::parseHCIOutput(const QString& output ) {
194 qWarning("parseHCI %s", output.latin1() );
183 RemoteDevices::ValueList list; 195 RemoteDevices::ValueList list;
184 QStringList strList = QStringList::split('\n', output ); 196 QStringList strList = QStringList::split('\n', output );
185 QStringList::Iterator it; 197 QStringList::Iterator it;
186 QString str; 198 QString str;
187 for ( it = strList.begin(); it != strList.end(); ++it ) { 199 for ( it = strList.begin(); it != strList.end(); ++it ) {
188 str = (*it).stripWhiteSpace(); 200 str = (*it).stripWhiteSpace();
189 qWarning("OpieTooth %s", str.latin1() ); 201 qWarning("OpieTooth %s", str.latin1() );
190 QStringList split = QStringList::split(" ", str ); 202 int pos = str.findRev(':' );
191 qWarning("Left:%s Right:%s", split[0].latin1() , split[1].latin1() ); 203 if ( pos > 0 ) {
192 RemoteDevices rem( split[0].latin1() , split[1].latin1() ); 204 QString mac = str.left(17 );
193 list.append( rem ); 205 str.remove( 0, 17 );
206 qWarning("mac %s", mac.latin1() );
207 qWarning("rest:%s", str.latin1() );
208 RemoteDevices rem( mac , str.stripWhiteSpace() );
209 list.append( rem );
210 }
194 } 211 }
195 return list; 212 return list;
196} 213}