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
@@ -8,6 +8,7 @@ using namespace OpieTooth;
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;
@@ -51,14 +52,16 @@ void Manager::isConnected( Device* dev ){
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;
@@ -103,7 +106,7 @@ void Manager::searchServices( const QString& remDevice ){
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 );
@@ -158,10 +161,13 @@ Services::ValueList Manager::parseSDPOutput( const QString& out ) {
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 }
@@ -171,15 +177,21 @@ void Manager::slotHCIExited(OProcess* 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;
@@ -187,10 +199,15 @@ RemoteDevices::ValueList Manager::parseHCIOutput(const QString& output ) {
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}