• R/O
  • HTTP
  • SSH
  • HTTPS

コミット

タグ
未設定

よく使われているワード(クリックで追加)

javac++androidlinuxc#windowsobjective-ccocoa誰得qtpythonphprubygameguibathyscaphec計画中(planning stage)翻訳omegatframeworktwitterdomtestvb.netdirectxゲームエンジンbtronarduinopreviewer

system/corennnnn


コミットメタ情報

リビジョン2ac16b7e46753238312475cf16aa910c1897c5d0 (tree)
日時2009-05-13 11:06:54
作者San Mehat <san@goog...>
コミッターThe Android Open Source Project

ログメッセージ

am e67651c: nexus: Cleanup the scanner and plug it all in so it works

Merge commit 'e67651c89d0cbb759219412d49cbc5680c17df06'

* commit 'e67651c89d0cbb759219412d49cbc5680c17df06':

nexus: Cleanup the scanner and plug it all in so it works

変更サマリ

差分

--- a/nexus/Supplicant.cpp
+++ b/nexus/Supplicant.cpp
@@ -314,8 +314,6 @@ int Supplicant::onEapFailureEvent(SupplicantEvent *evt) {
314314 }
315315
316316 int Supplicant::onScanResultsEvent(SupplicantEvent *evt) {
317- LOGD("onScanResultsEvent(%s)", evt->getEvent());
318-
319317 if (!strcmp(evt->getEvent(), "Ready")) {
320318 char *reply;
321319
--- a/nexus/Supplicant.h
+++ b/nexus/Supplicant.h
@@ -38,17 +38,20 @@ public:
3838 Supplicant();
3939 virtual ~Supplicant() {}
4040
41- virtual int start();
42- virtual int stop();
43- virtual bool isStarted();
41+ int start();
42+ int stop();
43+ bool isStarted();
44+ int triggerScan(bool active);
45+
46+ ScanResultCollection *createLatestScanResults();
47+ WifiNetworkCollection *createWifiNetworkList();
4448
45- virtual int triggerScan(bool active);
4649
4750 int getState() { return mState; }
4851
49- ScanResultCollection *createLatestScanResults();
5052
5153 // XXX: Extract these into an interface
54+// handlers for SupplicantListener
5255 public:
5356 virtual int onConnectedEvent(SupplicantEvent *evt);
5457 virtual int onDisconnectedEvent(SupplicantEvent *evt);
--- a/nexus/WifiController.cpp
+++ b/nexus/WifiController.cpp
@@ -141,12 +141,13 @@ int WifiController::setScanMode(uint32_t mode) {
141141
142142 if (!(mode & SCAN_ENABLE_MASK)) {
143143 if (mCurrentScanMode & SCAN_REPEAT_MASK)
144- mScanner->stopPeriodicScan();
144+ mScanner->stop();
145145 } else if (mode & SCAN_REPEAT_MASK)
146- rc = mScanner->startPeriodicScan(mode & SCAN_ACTIVE_MASK);
146+ rc = mScanner->start(mode & SCAN_ACTIVE_MASK);
147147 else
148148 rc = mSupplicant->triggerScan(mode & SCAN_ACTIVE_MASK);
149-
149+
150+ mCurrentScanMode = mode;
150151 return rc;
151152 }
152153
--- a/nexus/WifiScanner.cpp
+++ b/nexus/WifiScanner.cpp
@@ -1,3 +1,8 @@
1+#include <stdlib.h>
2+#include <sys/socket.h>
3+#include <sys/select.h>
4+#include <sys/time.h>
5+#include <sys/types.h>
16 #include <errno.h>
27 #include <pthread.h>
38
@@ -13,28 +18,16 @@ WifiScanner::WifiScanner(Supplicant *suppl, int period) {
1318 mSuppl = suppl;
1419 mPeriod = period;
1520 mActive = false;
16- mWorkerRunning = false;
17- mAbortRequest = false;
18- pthread_mutex_init(&mAbortRequestLock, NULL);
19- pthread_mutex_init(&mWorkerLock, NULL);
2021 }
2122
22-int WifiScanner::startPeriodicScan(bool active) {
23+int WifiScanner::start(bool active) {
2324 mActive = active;
2425
25- pthread_mutex_lock(&mWorkerLock);
26- if (mWorkerRunning) {
27- errno = EBUSY;
26+ if(pipe(mCtrlPipe))
2827 return -1;
29- }
30-
31- pthread_attr_t attr;
32- pthread_attr_init(&attr);
33- pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_DETACHED);
3428
35- if (pthread_create(&mWorker, &attr, WifiScanner::threadStart, this))
29+ if (pthread_create(&mThread, NULL, WifiScanner::threadStart, this))
3630 return -1;
37-
3831 return 0;
3932 }
4033
@@ -45,52 +38,49 @@ void *WifiScanner::threadStart(void *obj) {
4538 return NULL;
4639 }
4740
48-void WifiScanner::threadCleanup(void *obj) {
49- WifiScanner *me = reinterpret_cast<WifiScanner *>(obj);
50-
51- me->mWorkerRunning = false;
52- pthread_mutex_unlock(&me->mWorkerLock);
41+int WifiScanner::stop() {
42+ char c = 0;
5343
54- if (me->mAbortRequest) {
55- me->mAbortRequest = false;
56- pthread_mutex_unlock(&me->mAbortRequestLock);
44+ if (write(mCtrlPipe[1], &c, 1) != 1) {
45+ LOGE("Error writing to control pipe (%s)", strerror(errno));
46+ return -1;
5747 }
58-}
5948
60-int WifiScanner::stopPeriodicScan() {
61- pthread_mutex_lock(&mAbortRequestLock);
62- pthread_mutex_lock(&mWorkerLock);
63- if (mWorkerRunning)
64- mAbortRequest = true;
65- pthread_mutex_unlock(&mWorkerLock);
66- pthread_mutex_unlock(&mAbortRequestLock);
49+ void *ret;
50+ if (pthread_join(mThread, &ret)) {
51+ LOGE("Error joining to scanner thread (%s)", strerror(errno));
52+ return -1;
53+ }
6754
55+ close(mCtrlPipe[0]);
56+ close(mCtrlPipe[1]);
6857 return 0;
6958 }
7059
7160 void WifiScanner::run() {
72- LOGD("Thread started");
73-
74- mWorkerRunning = true;
75- pthread_cleanup_push(WifiScanner::threadCleanup, this);
76- pthread_mutex_unlock(&mWorkerLock);
61+ LOGD("Starting wifi scanner (active = %d)", mActive);
7762
7863 while(1) {
79- LOGD("Triggering periodic scan");
64+ fd_set read_fds;
65+ struct timeval to;
66+ int rc = 0;
67+
68+ to.tv_sec = 0;
69+ to.tv_sec = mPeriod;
70+
71+ FD_ZERO(&read_fds);
72+ FD_SET(mCtrlPipe[0], &read_fds);
73+
8074 if (mSuppl->triggerScan(mActive)) {
8175 LOGW("Error triggering scan (%s)", strerror(errno));
8276 }
8377
84- sleep(mPeriod);
85- pthread_mutex_lock(&mAbortRequestLock);
86- if (mAbortRequest) {
87- LOGD("Abort request!");
88- goto out;
89- }
90- pthread_mutex_unlock(&mAbortRequestLock);
91- }
92-
93-out:
94- pthread_cleanup_pop(1);
95- pthread_mutex_unlock(&mWorkerLock);
78+ if ((rc = select(mCtrlPipe[0] + 1, &read_fds, NULL, NULL, &to)) < 0) {
79+ LOGE("select failed (%s) - sleeping for one scanner period", strerror(errno));
80+ sleep(mPeriod);
81+ continue;
82+ } else if (!rc) {
83+ } else if (FD_ISSET(mCtrlPipe[0], &read_fds))
84+ break;
85+ } // while
9686 }
--- a/nexus/WifiScanner.h
+++ b/nexus/WifiScanner.h
@@ -6,12 +6,8 @@
66 class Supplicant;
77
88 class WifiScanner {
9- pthread_t mWorker;
10- pthread_mutex_t mWorkerLock;
11- bool mWorkerRunning;
12- bool mAbortRequest;
13- pthread_mutex_t mAbortRequestLock;
14-
9+ pthread_t mThread;
10+ int mCtrlPipe[2];
1511 Supplicant *mSuppl;
1612 int mPeriod;
1713 bool mActive;
@@ -23,12 +19,11 @@ public:
2319
2420 int getPeriod() { return mPeriod; }
2521
26- int startPeriodicScan(bool active);
27- int stopPeriodicScan();
22+ int start(bool active);
23+ int stop();
2824
2925 private:
3026 static void *threadStart(void *obj);
31- static void threadCleanup(void *obj);
3227
3328 void run();
3429 };