-rw-r--r-- | noncore/net/opietooth/lib/device.cc | 2 | ||||
-rw-r--r-- | noncore/net/opietooth/lib/manager.cc | 20 |
2 files changed, 11 insertions, 11 deletions
diff --git a/noncore/net/opietooth/lib/device.cc b/noncore/net/opietooth/lib/device.cc index f81066e..eea1178 100644 --- a/noncore/net/opietooth/lib/device.cc +++ b/noncore/net/opietooth/lib/device.cc | |||
@@ -1,157 +1,157 @@ | |||
1 | 1 | ||
2 | #include "device.h" | 2 | #include "device.h" |
3 | 3 | ||
4 | /* OPIE */ | 4 | /* OPIE */ |
5 | #include <opie2/oprocess.h> | 5 | #include <opie2/oprocess.h> |
6 | #include <opie2/odebug.h> | 6 | #include <opie2/odebug.h> |
7 | using namespace Opie::Core; | 7 | using namespace Opie::Core; |
8 | 8 | ||
9 | /* STD */ | 9 | /* STD */ |
10 | #include <signal.h> | 10 | #include <signal.h> |
11 | 11 | ||
12 | 12 | ||
13 | using namespace OpieTooth; | 13 | using namespace OpieTooth; |
14 | 14 | ||
15 | using Opie::Core::OProcess; | 15 | using Opie::Core::OProcess; |
16 | namespace { | 16 | namespace { |
17 | int parsePid( const QCString& par ){ | 17 | int parsePid( const QCString& par ){ |
18 | int id=0; | 18 | int id=0; |
19 | QString string( par ); | 19 | QString string( par ); |
20 | QStringList list = QStringList::split( '\n', string ); | 20 | QStringList list = QStringList::split( '\n', string ); |
21 | for( QStringList::Iterator it = list.begin(); it != list.end(); ++it ){ | 21 | for( QStringList::Iterator it = list.begin(); it != list.end(); ++it ){ |
22 | owarn << "parsePID: " << (*it).latin1() << oendl; | 22 | owarn << "parsePID: " << (*it).latin1() << oendl; |
23 | if( !(*it).startsWith("CSR") ){ | 23 | if( !(*it).startsWith("CSR") ){ |
24 | id = (*it).toInt(); | 24 | id = (*it).toInt(); |
25 | break; | 25 | break; |
26 | } | 26 | } |
27 | } | 27 | } |
28 | return id; | 28 | return id; |
29 | } | 29 | } |
30 | } | 30 | } |
31 | 31 | ||
32 | Device::Device(const QString &device, const QString &mode, const QString &speed ) | 32 | Device::Device(const QString &device, const QString &mode, const QString &speed ) |
33 | : QObject(0, "device") { | 33 | : QObject(0, "device") { |
34 | 34 | ||
35 | owarn << "OpieTooth::Device create" << oendl; | 35 | owarn << "OpieTooth::Device create" << oendl; |
36 | m_hci = 0; | 36 | m_hci = 0; |
37 | m_process = 0; | 37 | m_process = 0; |
38 | m_attached = false; | 38 | m_attached = false; |
39 | m_device = device; | 39 | m_device = device; |
40 | m_mode = mode; | 40 | m_mode = mode; |
41 | m_speed = speed; | 41 | m_speed = speed; |
42 | attach(); | 42 | attach(); |
43 | } | 43 | } |
44 | Device::~Device(){ | 44 | Device::~Device(){ |
45 | detach(); | 45 | detach(); |
46 | } | 46 | } |
47 | void Device::attach(){ | 47 | void Device::attach(){ |
48 | owarn << "attaching " << m_device.latin1() << " " << m_mode.latin1() << " " << m_speed.latin1() << oendl; | 48 | owarn << "attaching " << m_device.latin1() << " " << m_mode.latin1() << " " << m_speed.latin1() << oendl; |
49 | if(m_process == 0 ){ | 49 | if(m_process == 0 ){ |
50 | m_output.resize(0); | 50 | m_output.resize(0); |
51 | owarn << "new process to create" << oendl; | 51 | owarn << "new process to create" << oendl; |
52 | m_process = new OProcess(); | 52 | m_process = new OProcess(); |
53 | *m_process << "hciattach"; | 53 | *m_process << "hciattach"; |
54 | *m_process << "-p"; | 54 | *m_process << "-p"; |
55 | *m_process << m_device << m_mode << m_speed; | 55 | *m_process << m_device << m_mode << m_speed; |
56 | connect(m_process, SIGNAL( processExited(Opie::Core::OProcess*) ), | 56 | connect(m_process, SIGNAL( processExited(Opie::Core::OProcess*) ), |
57 | this, SLOT( slotExited(Opie::Core::OProcess* ) ) ); | 57 | this, SLOT( slotExited(Opie::Core::OProcess* ) ) ); |
58 | connect(m_process, SIGNAL( receivedStdout(Opie::Core::OProcess*, char*, int) ), | 58 | connect(m_process, SIGNAL( receivedStdout(Opie::Core::OProcess*, char*, int) ), |
59 | this, SLOT(slotStdOut(Opie::Core::OProcess*,char*,int ) ) ); | 59 | this, SLOT(slotStdOut(Opie::Core::OProcess*,char*,int ) ) ); |
60 | connect(m_process, SIGNAL(receivedStderr(Opie::Core::OProcess*, char*, int ) ), | 60 | connect(m_process, SIGNAL(receivedStderr(Opie::Core::OProcess*, char*, int ) ), |
61 | this, SLOT(slotStdErr(Opie::Core::OProcess*,char*,int) ) ); | 61 | this, SLOT(slotStdErr(Opie::Core::OProcess*,char*,int) ) ); |
62 | if(!m_process->start(OProcess::NotifyOnExit, OProcess::AllOutput ) ){ | 62 | if(!m_process->start(OProcess::NotifyOnExit, OProcess::AllOutput ) ){ |
63 | owarn << "Could not start" << oendl; | 63 | owarn << "Could not start" << oendl; |
64 | delete m_process; | 64 | delete m_process; |
65 | m_process = 0; | 65 | m_process = 0; |
66 | } | 66 | } |
67 | }; | 67 | }; |
68 | } | 68 | } |
69 | void Device::detach(){ | 69 | void Device::detach(){ |
70 | delete m_hci; | 70 | delete m_hci; |
71 | delete m_process; | 71 | delete m_process; |
72 | // kill the pid we got | 72 | // kill the pid we got |
73 | if(m_attached ){ | 73 | if(m_attached ){ |
74 | //kill the pid | 74 | //kill the pid |
75 | warn << "killing" << oendl; | 75 | owarn << "killing" << oendl; |
76 | kill(pid, 9); | 76 | kill(pid, 9); |
77 | } | 77 | } |
78 | owarn << "detached" << oendl; | 78 | owarn << "detached" << oendl; |
79 | } | 79 | } |
80 | bool Device::isLoaded()const{ | 80 | bool Device::isLoaded()const{ |
81 | return m_attached; | 81 | return m_attached; |
82 | } | 82 | } |
83 | QString Device::devName()const { | 83 | QString Device::devName()const { |
84 | return QString::fromLatin1("hci0"); | 84 | return QString::fromLatin1("hci0"); |
85 | }; | 85 | }; |
86 | void Device::slotExited( OProcess* proc) | 86 | void Device::slotExited( OProcess* proc) |
87 | { | 87 | { |
88 | owarn << "prcess exited" << oendl; | 88 | owarn << "prcess exited" << oendl; |
89 | if(proc== m_process ){ | 89 | if(proc== m_process ){ |
90 | owarn << "proc == m_process" << oendl; | 90 | owarn << "proc == m_process" << oendl; |
91 | if( m_process->normalExit() ){ // normal exit | 91 | if( m_process->normalExit() ){ // normal exit |
92 | owarn << "normalExit" << oendl; | 92 | owarn << "normalExit" << oendl; |
93 | int ret = m_process->exitStatus(); | 93 | int ret = m_process->exitStatus(); |
94 | if( ret == 0 ){ // attached | 94 | if( ret == 0 ){ // attached |
95 | owarn << "attached" << oendl; | 95 | owarn << "attached" << oendl; |
96 | owarn << "Output: " << m_output.data() << oendl; | 96 | owarn << "Output: " << m_output.data() << oendl; |
97 | pid = parsePid( m_output ); | 97 | pid = parsePid( m_output ); |
98 | owarn << "Pid = " << pid << oendl; | 98 | owarn << "Pid = " << pid << oendl; |
99 | // now hciconfig hci0 up ( determine hciX FIXME) | 99 | // now hciconfig hci0 up ( determine hciX FIXME) |
100 | // and call hciconfig hci0 up | 100 | // and call hciconfig hci0 up |
101 | // FIXME hardcoded to hci0 now :( | 101 | // FIXME hardcoded to hci0 now :( |
102 | m_hci = new OProcess( ); | 102 | m_hci = new OProcess( ); |
103 | *m_hci << "hciconfig"; | 103 | *m_hci << "hciconfig"; |
104 | *m_hci << "hci0 up"; | 104 | *m_hci << "hci0 up"; |
105 | connect(m_hci, SIGNAL( processExited(Opie::Core::OProcess*) ), | 105 | connect(m_hci, SIGNAL( processExited(Opie::Core::OProcess*) ), |
106 | this, SLOT( slotExited(Opie::Core::OProcess* ) ) ); | 106 | this, SLOT( slotExited(Opie::Core::OProcess* ) ) ); |
107 | if(!m_hci->start() ){ | 107 | if(!m_hci->start() ){ |
108 | owarn << "could not start" << oendl; | 108 | owarn << "could not start" << oendl; |
109 | m_attached = false; | 109 | m_attached = false; |
110 | emit device("hci0", false ); | 110 | emit device("hci0", false ); |
111 | } | 111 | } |
112 | }else{ | 112 | }else{ |
113 | owarn << "crass" << oendl; | 113 | owarn << "crass" << oendl; |
114 | m_attached = false; | 114 | m_attached = false; |
115 | emit device("hci0", false ); | 115 | emit device("hci0", false ); |
116 | 116 | ||
117 | } | 117 | } |
118 | } | 118 | } |
119 | delete m_process; | 119 | delete m_process; |
120 | m_process = 0; | 120 | m_process = 0; |
121 | }else if(proc== m_hci ){ | 121 | }else if(proc== m_hci ){ |
122 | owarn << "M HCI exited" << oendl; | 122 | owarn << "M HCI exited" << oendl; |
123 | if( m_hci->normalExit() ){ | 123 | if( m_hci->normalExit() ){ |
124 | owarn << "normal exit" << oendl; | 124 | owarn << "normal exit" << oendl; |
125 | int ret = m_hci->exitStatus(); | 125 | int ret = m_hci->exitStatus(); |
126 | if( ret == 0 ){ | 126 | if( ret == 0 ){ |
127 | owarn << "attached really really attached" << oendl; | 127 | owarn << "attached really really attached" << oendl; |
128 | m_attached = true; | 128 | m_attached = true; |
129 | emit device("hci0", true ); | 129 | emit device("hci0", true ); |
130 | }else{ | 130 | }else{ |
131 | owarn << "failed" << oendl; | 131 | owarn << "failed" << oendl; |
132 | emit device("hci0", false ); | 132 | emit device("hci0", false ); |
133 | m_attached = false; | 133 | m_attached = false; |
134 | } | 134 | } |
135 | }// normal exit | 135 | }// normal exit |
136 | delete m_hci; | 136 | delete m_hci; |
137 | m_hci = 0; | 137 | m_hci = 0; |
138 | } | 138 | } |
139 | } | 139 | } |
140 | void Device::slotStdOut(OProcess* proc, char* chars, int len) | 140 | void Device::slotStdOut(OProcess* proc, char* chars, int len) |
141 | { | 141 | { |
142 | owarn << "std out" << oendl; | 142 | owarn << "std out" << oendl; |
143 | if( len <1 ){ | 143 | if( len <1 ){ |
144 | owarn << "len < 1 " << oendl; | 144 | owarn << "len < 1 " << oendl; |
145 | return; | 145 | return; |
146 | } | 146 | } |
147 | if(proc == m_process ){ | 147 | if(proc == m_process ){ |
148 | QCString string( chars, len+1 ); // \0 == +1 | 148 | QCString string( chars, len+1 ); // \0 == +1 |
149 | owarn << "output: " << string.data() << oendl; | 149 | owarn << "output: " << string.data() << oendl; |
150 | m_output.append( string.data() ); | 150 | m_output.append( string.data() ); |
151 | } | 151 | } |
152 | } | 152 | } |
153 | void Device::slotStdErr(OProcess* proc, char* chars, int len) | 153 | void Device::slotStdErr(OProcess* proc, char* chars, int len) |
154 | { | 154 | { |
155 | owarn << "std err" << oendl; | 155 | owarn << "std err" << oendl; |
156 | slotStdOut( proc, chars, len ); | 156 | slotStdOut( proc, chars, len ); |
157 | } | 157 | } |
diff --git a/noncore/net/opietooth/lib/manager.cc b/noncore/net/opietooth/lib/manager.cc index 76d9127..53122c1 100644 --- a/noncore/net/opietooth/lib/manager.cc +++ b/noncore/net/opietooth/lib/manager.cc | |||
@@ -99,238 +99,238 @@ void Manager::removeService( const QString& name ){ | |||
99 | bo = false; | 99 | bo = false; |
100 | emit removedService( name, bo ); | 100 | emit removedService( name, bo ); |
101 | } | 101 | } |
102 | void Manager::removeServices( const QStringList& list){ | 102 | void 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 | } |
107 | void Manager::searchServices( const QString& remDevice ){ | 107 | void 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 | owarn << "search Services for " << remDevice.latin1() << oendl; | 111 | owarn << "search Services for " << remDevice.latin1() << oendl; |
112 | connect(m_sdp, SIGNAL(processExited(Opie::Core::OProcess*) ), | 112 | connect(m_sdp, SIGNAL(processExited(Opie::Core::OProcess*) ), |
113 | this, SLOT(slotSDPExited(Opie::Core::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(Opie::Core::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 | owarn << "could not start sdptool" << oendl; | 117 | owarn << "could not start sdptool" << oendl; |
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 | } |
123 | void Manager::searchServices( const RemoteDevice& dev){ | 123 | void Manager::searchServices( const RemoteDevice& dev){ |
124 | searchServices( dev.mac() ); | 124 | searchServices( dev.mac() ); |
125 | } | 125 | } |
126 | QString Manager::toDevice( const QString& /*mac*/ ){ | 126 | QString Manager::toDevice( const QString& /*mac*/ ){ |
127 | return QString::null; | 127 | return QString::null; |
128 | } | 128 | } |
129 | QString Manager::toMac( const QString &/*device*/ ){ | 129 | QString Manager::toMac( const QString &/*device*/ ){ |
130 | return QString::null; | 130 | return QString::null; |
131 | } | 131 | } |
132 | void Manager::slotProcessExited(OProcess* proc ) { | 132 | void 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; |
140 | } | 140 | } |
141 | void Manager::slotSDPOut(OProcess* proc, char* ch, int len) | 141 | void Manager::slotSDPOut(OProcess* proc, char* ch, int len) |
142 | { | 142 | { |
143 | QCString str(ch, len+1 ); | 143 | QCString str(ch, len+1 ); |
144 | owarn << "SDP:" << str.data() << oendl; | 144 | owarn << "SDP:" << str.data() << oendl; |
145 | QMap<QString, QString>::Iterator it; | 145 | QMap<QString, QString>::Iterator it; |
146 | it = m_out.find(proc->name() ); | 146 | it = m_out.find(proc->name() ); |
147 | QString string; | 147 | QString string; |
148 | if ( it != m_out.end() ) { | 148 | if ( it != m_out.end() ) { |
149 | string = it.data(); | 149 | string = it.data(); |
150 | } | 150 | } |
151 | string.append( str ); | 151 | string.append( str ); |
152 | m_out.replace( proc->name(), string ); | 152 | m_out.replace( proc->name(), string ); |
153 | 153 | ||
154 | } | 154 | } |
155 | void Manager::slotSDPExited( OProcess* proc) | 155 | void Manager::slotSDPExited( OProcess* proc) |
156 | { | 156 | { |
157 | owarn << "proc name " << proc->name() << oendl; | 157 | owarn << "proc name " << proc->name() << oendl; |
158 | Services::ValueList list; | 158 | Services::ValueList list; |
159 | if (proc->normalExit() ) { | 159 | if (proc->normalExit() ) { |
160 | QMap<QString, QString>::Iterator it = m_out.find( proc->name() ); | 160 | QMap<QString, QString>::Iterator it = m_out.find( proc->name() ); |
161 | if ( it != m_out.end() ) { | 161 | if ( it != m_out.end() ) { |
162 | owarn << "found process" << oendl; | 162 | owarn << "found process" << oendl; |
163 | list = parseSDPOutput( it.data() ); | 163 | list = parseSDPOutput( it.data() ); |
164 | m_out.remove( it ); | 164 | m_out.remove( it ); |
165 | } | 165 | } |
166 | } | 166 | } |
167 | emit foundServices( proc->name(), list ); | 167 | emit foundServices( proc->name(), list ); |
168 | delete proc; | 168 | delete proc; |
169 | } | 169 | } |
170 | Services::ValueList Manager::parseSDPOutput( const QString& out ) { | 170 | Services::ValueList Manager::parseSDPOutput( const QString& out ) { |
171 | Services::ValueList list; | 171 | Services::ValueList list; |
172 | owarn << "parsing output" << oendl; | 172 | owarn << "parsing output" << oendl; |
173 | Parser parser( out ); | 173 | Parser parser( out ); |
174 | list = parser.services(); | 174 | list = parser.services(); |
175 | return list; | 175 | return list; |
176 | } | 176 | } |
177 | 177 | ||
178 | void Manager::slotHCIExited(OProcess* proc ) { | 178 | void Manager::slotHCIExited(OProcess* proc ) { |
179 | owarn << "process exited" << oendl; | 179 | owarn << "process exited" << oendl; |
180 | RemoteDevice::ValueList list; | 180 | RemoteDevice::ValueList list; |
181 | if (proc->normalExit() ) { | 181 | if (proc->normalExit() ) { |
182 | owarn << "normalExit " << proc->name() << oendl; | 182 | owarn << "normalExit " << proc->name() << oendl; |
183 | QMap<QString, QString>::Iterator it = m_devices.find(proc->name() ); | 183 | QMap<QString, QString>::Iterator it = m_devices.find(proc->name() ); |
184 | if (it != m_devices.end() ) { | 184 | if (it != m_devices.end() ) { |
185 | owarn << "!= end ;)" << oendl; | 185 | owarn << "!= end ;)" << oendl; |
186 | list = parseHCIOutput( it.data() ); | 186 | list = parseHCIOutput( it.data() ); |
187 | m_devices.remove( it ); | 187 | m_devices.remove( it ); |
188 | } | 188 | } |
189 | } | 189 | } |
190 | emit foundDevices( proc->name(), list ); | 190 | emit foundDevices( proc->name(), list ); |
191 | delete proc; | 191 | delete proc; |
192 | } | 192 | } |
193 | void Manager::slotHCIOut(OProcess* proc, char* ch, int len) { | 193 | void Manager::slotHCIOut(OProcess* proc, char* ch, int len) { |
194 | QCString str( ch, len+1 ); | 194 | QCString str( ch, len+1 ); |
195 | owarn << "hci: " << str.data() oendl; | 195 | owarn << "hci: " << str.data() << oendl; |
196 | QMap<QString, QString>::Iterator it; | 196 | QMap<QString, QString>::Iterator it; |
197 | it = m_devices.find( proc->name() ); | 197 | it = m_devices.find( proc->name() ); |
198 | owarn << "proc->name " << proc->name() << oendl; | 198 | owarn << "proc->name " << proc->name() << oendl; |
199 | QString string; | 199 | QString string; |
200 | if (it != m_devices.end() ) { | 200 | if (it != m_devices.end() ) { |
201 | owarn << "slotHCIOut " << oendl; | 201 | owarn << "slotHCIOut " << oendl; |
202 | string = it.data(); | 202 | string = it.data(); |
203 | } | 203 | } |
204 | string.append( str ); | 204 | string.append( str ); |
205 | 205 | ||
206 | m_devices.replace( proc->name(), string ); | 206 | m_devices.replace( proc->name(), string ); |
207 | } | 207 | } |
208 | RemoteDevice::ValueList Manager::parseHCIOutput(const QString& output ) { | 208 | RemoteDevice::ValueList Manager::parseHCIOutput(const QString& output ) { |
209 | owarn << "parseHCI " << output.latin1() << oendl; | 209 | owarn << "parseHCI " << output.latin1() << oendl; |
210 | RemoteDevice::ValueList list; | 210 | RemoteDevice::ValueList list; |
211 | QStringList strList = QStringList::split('\n', output ); | 211 | QStringList strList = QStringList::split('\n', output ); |
212 | QStringList::Iterator it; | 212 | QStringList::Iterator it; |
213 | QString str; | 213 | QString str; |
214 | for ( it = strList.begin(); it != strList.end(); ++it ) { | 214 | for ( it = strList.begin(); it != strList.end(); ++it ) { |
215 | str = (*it).stripWhiteSpace(); | 215 | str = (*it).stripWhiteSpace(); |
216 | owarn << "OpieTooth " << str.latin1() << oendl; | 216 | owarn << "OpieTooth " << str.latin1() << oendl; |
217 | int pos = str.findRev(':' ); | 217 | int pos = str.findRev(':' ); |
218 | if ( pos > 0 ) { | 218 | if ( pos > 0 ) { |
219 | QString mac = str.left(17 ); | 219 | QString mac = str.left(17 ); |
220 | str.remove( 0, 17 ); | 220 | str.remove( 0, 17 ); |
221 | owarn << "mac " << mac.latin1() << oendl; | 221 | owarn << "mac " << mac.latin1() << oendl; |
222 | owarn << "rest: " << str.latin1() << oendl; | 222 | owarn << "rest: " << str.latin1() << oendl; |
223 | RemoteDevice rem( mac , str.stripWhiteSpace() ); | 223 | RemoteDevice rem( mac , str.stripWhiteSpace() ); |
224 | list.append( rem ); | 224 | list.append( rem ); |
225 | } | 225 | } |
226 | } | 226 | } |
227 | return list; | 227 | return list; |
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 | */ |
237 | void Manager::connectTo( const QString& mac) { | 237 | void 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 | ||
246 | void Manager::searchConnections() { | 246 | void Manager::searchConnections() { |
247 | owarn << "searching connections?" << oendl; | 247 | owarn << "searching connections?" << oendl; |
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( Opie::Core::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(Opie::Core::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 | } |
264 | void Manager::slotConnectionExited( OProcess* proc ) { | 264 | void 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 | } |
270 | void Manager::slotConnectionOutput(OProcess* /*proc*/, char* cha, int len) { | 270 | void 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 | } |
275 | ConnectionState::ValueList Manager::parseConnections( const QString& out ) { | 275 | ConnectionState::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; |
279 | // remove the first line ( "Connections:") | 279 | // remove the first line ( "Connections:") |
280 | it = list.begin(); | 280 | it = list.begin(); |
281 | it = list.remove( it ); | 281 | it = list.remove( it ); |
282 | for (; it != list.end(); ++it ) { | 282 | for (; it != list.end(); ++it ) { |
283 | QString row = (*it).stripWhiteSpace(); | 283 | QString row = (*it).stripWhiteSpace(); |
284 | QStringList value = QStringList::split(' ', row ); | 284 | QStringList value = QStringList::split(' ', row ); |
285 | owan << "0: %s" << value[0].latin1() << oendl; | 285 | owarn << "0: %s" << value[0].latin1() << oendl; |
286 | owan << "1: %s" << value[1].latin1() << oendl; | 286 | owarn << "1: %s" << value[1].latin1() << oendl; |
287 | owan << "2: %s" << value[2].latin1() << oendl; | 287 | owarn << "2: %s" << value[2].latin1() << oendl; |
288 | owan << "3: %s" << value[3].latin1() << oendl; | 288 | owarn << "3: %s" << value[3].latin1() << oendl; |
289 | owan << "4: %s" << value[4].latin1() << oendl; | 289 | owarn << "4: %s" << value[4].latin1() << oendl; |
290 | owan << "5: %s" << value[5].latin1() << oendl; | 290 | owarn << "5: %s" << value[5].latin1() << oendl; |
291 | owan << "6: %s" << value[6].latin1() << oendl; | 291 | owarn << "6: %s" << value[6].latin1() << oendl; |
292 | owan << "7: %s" << value[7].latin1() << oendl; | 292 | owarn << "7: %s" << value[7].latin1() << oendl; |
293 | owan << "8: %s" << value[8].latin1() << oendl; | 293 | owarn << "8: %s" << value[8].latin1() << oendl; |
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 | ||
306 | void Manager::signalStrength( const QString &mac ) { | 306 | void 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( Opie::Core::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(Opie::Core::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 | ||
326 | void Manager::slotSignalStrengthOutput(OProcess* proc, char* cha, int len) { | 326 | void 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 | ||
334 | void Manager::slotSignalStrengthExited( OProcess* proc ) { | 334 | void Manager::slotSignalStrengthExited( OProcess* proc ) { |
335 | delete proc; | 335 | delete proc; |
336 | } | 336 | } |