summaryrefslogtreecommitdiff
Unidiff
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--noncore/securityplugins/blueping/bluepingplugin.cpp86
-rw-r--r--noncore/securityplugins/blueping/bluepingplugin.h7
2 files changed, 58 insertions, 35 deletions
diff --git a/noncore/securityplugins/blueping/bluepingplugin.cpp b/noncore/securityplugins/blueping/bluepingplugin.cpp
index f5d9ad6..1c514e5 100644
--- a/noncore/securityplugins/blueping/bluepingplugin.cpp
+++ b/noncore/securityplugins/blueping/bluepingplugin.cpp
@@ -19,11 +19,13 @@ using Opie::Security::MultiauthConfigWidget;
19/// standard c'tor 19/// standard c'tor
20BluepingPlugin::BluepingPlugin() : MultiauthPluginObject(), m_ping(0), m_bluepingW(0) { 20BluepingPlugin::BluepingPlugin() : MultiauthPluginObject(), m_ping(0), m_bluepingW(0), bluetoothWasOff(false) {
21 bluetoothAlreadyRestarted = false;
22} 21}
23 22
24/// cleans m_ping if we need to 23/// cleans m_ping and m_bluepingW if we need to
25BluepingPlugin::~BluepingPlugin() { 24BluepingPlugin::~BluepingPlugin() {
26 delete m_ping; 25 odebug << "closing Blueping plugin..." << oendl;
26 if (m_ping != 0)
27 delete m_ping;
27 if (m_bluepingW != 0) 28 if (m_bluepingW != 0)
28 delete m_bluepingW; 29 delete m_bluepingW;
30 killBluetoothIfNecessary();
29} 31}
@@ -41,2 +43,3 @@ MultiauthConfigWidget * BluepingPlugin::configWidget(QWidget * parent) {
41} 43}
44
42QString BluepingPlugin::pixmapNameWidget() const { 45QString BluepingPlugin::pixmapNameWidget() const {
@@ -44,2 +47,3 @@ QString BluepingPlugin::pixmapNameWidget() const {
44} 47}
48
45QString BluepingPlugin::pixmapNameConfig() const { 49QString BluepingPlugin::pixmapNameConfig() const {
@@ -48,2 +52,16 @@ QString BluepingPlugin::pixmapNameConfig() const {
48 52
53/// If Bluetooth was off before the plugin ran, we switch it off again
54void BluepingPlugin::killBluetoothIfNecessary() {
55 if (bluetoothWasOff) {
56 OProcess killB;
57 killB << "killall" << "hciattach";
58 odebug << "killing Bluetooth... (since it was up only for Blueping)" << oendl;
59 if ( !killB.start(OProcess::Block) ) {
60 oerr << "could not kill bluetooth" << oendl;
61 }
62 } else {
63 odebug << "keeping Bluetooth on" << oendl;
64 }
65}
66
49/// Emit the MultiauthPluginObject::Success emitCode 67/// Emit the MultiauthPluginObject::Success emitCode
@@ -83,14 +101,14 @@ void BluepingPlugin::ping() {
83/// Deals with m_ping result 101/// Deals with m_ping result
84 void BluepingPlugin::pingFinished(OProcess * ping) { 102void BluepingPlugin::pingFinished(OProcess * ping) {
85 if ( ping->normalExit() && (ping->exitStatus() == 0) ) 103 if ( ping->normalExit() && (ping->exitStatus() == 0) )
86 { 104 {
87 odebug << "Successful Bluetooth ping!" << oendl; 105 odebug << "Successful Bluetooth ping!" << oendl;
88 success(); 106 success();
89 }
90 else
91 {
92 odebug << "Failed Bluetooth ping..." << oendl;
93 failure();
94 }
95 } 107 }
108 else
109 {
110 odebug << "Failed Bluetooth ping... (normalExit: " << ping->normalExit() << ", exitStatus: " << ping->exitStatus() << ")" << oendl;
111 failure();
112 }
113}
96 114
@@ -138,13 +156,16 @@ int BluepingPlugin::authenticate() {
138 156
139 // we can uncomment the following when testing 157
140 //bluetoothAlreadyRestarted = true; 158
141 if (!bluetoothAlreadyRestarted) 159 /* let's start Bluetooth if it's not running
160 */
161 OProcess checkB;
162 checkB << "pidof" << "hciattach";
163 odebug << "checking if Bluetooth is running..." << oendl;
164 // now we start bluetooth *only* if the previous command works, exits normally, and
165 // it returns a non-null exit code (which means hciattach is not running)
166 if ( checkB.start(OProcess::Block) && checkB.normalExit() && (checkB.exitStatus() != 0) )
142 { 167 {
143 // we have just started or resumed the device, so Bluetooth has to be (re)started 168 // remember to switch off Bluetooth once we're finished...
144 OProcess killB; 169 bluetoothWasOff = true;
145 killB << "killall" << "hciattach"; 170 odebug << "Bluetooth is not running, we must start it now" << oendl;
146 odebug << "killing Bluetooth..." << oendl;
147 if ( !killB.start(OProcess::Block) ) {
148 oerr << "could not kill bluetooth" << oendl;
149 }
150 171
@@ -166,3 +187,3 @@ int BluepingPlugin::authenticate() {
166 if ( !startB.start(OProcess::Block) ) { 187 if ( !startB.start(OProcess::Block) ) {
167 oerr << "could not (re)start bluetooth" << oendl; 188 oerr << "could not start Bluetooth" << oendl;
168 return MultiauthPluginObject::Skip; 189 return MultiauthPluginObject::Skip;
@@ -171,6 +192,5 @@ int BluepingPlugin::authenticate() {
171 { 192 {
172 if ( startB.normalExit() && (startB.exitStatus() == 0) ) 193 if ( (startB.normalExit()) && (startB.exitStatus() == 0) )
173 { 194 {
174 odebug << "hciattach exited normally."<< oendl; 195 odebug << "hciattach exited normally, Bluetooth is probably on now, let's wait 500 ms and ping" << oendl;
175 bluetoothAlreadyRestarted = true;
176 // 500 ms timer, so l2ping won't try to find a route before bluetooth has \em really started 196 // 500 ms timer, so l2ping won't try to find a route before bluetooth has \em really started
@@ -180,4 +200,5 @@ int BluepingPlugin::authenticate() {
180 { 200 {
181 owarn << "hciattach exited anormally (error code: " << startB.exitStatus() << ")" << oendl; 201 owarn << "hciattach exited anormally (normalExit: " << startB.normalExit() << ", exit status: " << startB.exitStatus() << ")" << oendl;
182 } // end if startBluetooth exit status == 0 202 return MultiauthPluginObject::Skip;
203 } // end if startB exited normaly
183 } // end if startBluetooth started 204 } // end if startBluetooth started
@@ -187,4 +208,5 @@ int BluepingPlugin::authenticate() {
187 // we don't need to wait, since bluetooth has been started long enough ago 208 // we don't need to wait, since bluetooth has been started long enough ago
209 odebug << "Bluetooth is already running, we can try to ping now" << oendl;
188 ping(); 210 ping();
189 } // end if bluetooth not restarted 211 } // end if Bluetooth was off
190 212
diff --git a/noncore/securityplugins/blueping/bluepingplugin.h b/noncore/securityplugins/blueping/bluepingplugin.h
index b8d6734..56ff22d 100644
--- a/noncore/securityplugins/blueping/bluepingplugin.h
+++ b/noncore/securityplugins/blueping/bluepingplugin.h
@@ -75,7 +75,8 @@ class BluepingPlugin : public QObject, public Opie::Security::MultiauthPluginObj
75 private: 75 private:
76 Opie::Core::OProcess *m_ping; 76 void killBluetoothIfNecessary();
77 Opie::Core::OProcess * m_ping;
78 Config * m_config;
77 BluepingConfigWidget * m_bluepingW; 79 BluepingConfigWidget * m_bluepingW;
78 bool bluetoothAlreadyRestarted; 80 bool bluetoothWasOff;
79 QString macToPing; 81 QString macToPing;
80
81}; 82};