summaryrefslogtreecommitdiff
authorzecke <zecke>2002-06-15 22:06:57 (UTC)
committer zecke <zecke>2002-06-15 22:06:57 (UTC)
commitac6c5de1e7a15b4ca5bdf226a9eeceffb82aea94 (patch) (unidiff)
tree256f0b9d270972b30961bfae5529ab0de7fed9d6
parent9d02762b3d2e07f6db24c21621a5d577ea6acda7 (diff)
downloadopie-ac6c5de1e7a15b4ca5bdf226a9eeceffb82aea94.zip
opie-ac6c5de1e7a15b4ca5bdf226a9eeceffb82aea94.tar.gz
opie-ac6c5de1e7a15b4ca5bdf226a9eeceffb82aea94.tar.bz2
Fix the manager to find devices
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,196 +1,213 @@
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()
23{ 24{
24 m_hcitool = 0; 25 m_hcitool = 0;
25 m_sdp = 0; 26 m_sdp = 0;
26} 27}
27Manager::~Manager(){ 28Manager::~Manager(){
28 delete m_hcitool; 29 delete m_hcitool;
29 delete m_sdp; 30 delete m_sdp;
30} 31}
31void Manager::setDevice( const QString& dev ){ 32void Manager::setDevice( const QString& dev ){
32 m_device = dev; 33 m_device = dev;
33} 34}
34void Manager::setDevice( Device* dev ){ 35void Manager::setDevice( Device* dev ){
35 36
36} 37}
37void Manager::isConnected( const QString& device ){ 38void Manager::isConnected( const QString& device ){
38 OProcess* l2ping = new OProcess(); 39 OProcess* l2ping = new OProcess();
39 l2ping->setName( device.latin1() ); 40 l2ping->setName( device.latin1() );
40 *l2ping << "l2ping" << "-c1" << device; 41 *l2ping << "l2ping" << "-c1" << device;
41 connect(l2ping, SIGNAL(processExited(OProcess* ) ), 42 connect(l2ping, SIGNAL(processExited(OProcess* ) ),
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;
74 proc << "sdptool" << "add" << name; 77 proc << "sdptool" << "add" << name;
75 bool bo = true; 78 bool bo = true;
76 if (!proc.start(OProcess::DontCare ) ) 79 if (!proc.start(OProcess::DontCare ) )
77 bo = false; 80 bo = false;
78 emit addedService( name, bo ); 81 emit addedService( name, bo );
79} 82}
80void Manager::addServices(const QStringList& list){ 83void Manager::addServices(const QStringList& list){
81 QStringList::ConstIterator it; 84 QStringList::ConstIterator it;
82 for (it = list.begin(); it != list.end(); ++it ) 85 for (it = list.begin(); it != list.end(); ++it )
83 addService( (*it) ); 86 addService( (*it) );
84} 87}
85void Manager::removeService( const QString& name ){ 88void Manager::removeService( const QString& name ){
86 OProcess prc; 89 OProcess prc;
87 prc << "sdptool" << "del" << name; 90 prc << "sdptool" << "del" << name;
88 bool bo = true; 91 bool bo = true;
89 if (!prc.start(OProcess::DontCare ) ) 92 if (!prc.start(OProcess::DontCare ) )
90 bo = false; 93 bo = false;
91 emit removedService( name, bo ); 94 emit removedService( name, bo );
92} 95}
93void Manager::removeServices( const QStringList& list){ 96void 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 ){
119 122
120} 123}
121void Manager::slotProcessExited(OProcess* proc ) { 124void Manager::slotProcessExited(OProcess* proc ) {
122 bool conn= false; 125 bool conn= false;
123 if (proc->normalExit() && proc->exitStatus() == 0 ) 126 if (proc->normalExit() && proc->exitStatus() == 0 )
124 conn = true; 127 conn = true;
125 128
126 QString name = QString::fromLatin1(proc->name() ); 129 QString name = QString::fromLatin1(proc->name() );
127 emit connected( name, conn ); 130 emit connected( name, conn );
128 delete proc; 131 delete proc;
129} 132}
130void Manager::slotSDPOut(OProcess* proc, char* ch, int len) 133void Manager::slotSDPOut(OProcess* proc, char* ch, int len)
131{ 134{
132 QCString str(ch, len+1 ); 135 QCString str(ch, len+1 );
133 QMap<QString, QString>::Iterator it; 136 QMap<QString, QString>::Iterator it;
134 it = m_out.find(proc->name() ); 137 it = m_out.find(proc->name() );
135 if ( it != m_out.end() ) { 138 if ( it != m_out.end() ) {
136 QString string = it.data(); 139 QString string = it.data();
137 string.append( str ); 140 string.append( str );
138 m_out.replace( proc->name(), string ); 141 m_out.replace( proc->name(), string );
139 } 142 }
140 143
141} 144}
142void Manager::slotSDPExited( OProcess* proc) 145void Manager::slotSDPExited( OProcess* proc)
143{ 146{
144 Services::ValueList list; 147 Services::ValueList list;
145 if (proc->normalExit() ) { 148 if (proc->normalExit() ) {
146 QMap<QString, QString>::Iterator it = m_out.find( proc->name() ); 149 QMap<QString, QString>::Iterator it = m_out.find( proc->name() );
147 if ( it != m_out.end() ) { 150 if ( it != m_out.end() ) {
148 list = parseSDPOutput( it.data() ); 151 list = parseSDPOutput( it.data() );
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}