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':
@@ -314,8 +314,6 @@ int Supplicant::onEapFailureEvent(SupplicantEvent *evt) { | ||
314 | 314 | } |
315 | 315 | |
316 | 316 | int Supplicant::onScanResultsEvent(SupplicantEvent *evt) { |
317 | - LOGD("onScanResultsEvent(%s)", evt->getEvent()); | |
318 | - | |
319 | 317 | if (!strcmp(evt->getEvent(), "Ready")) { |
320 | 318 | char *reply; |
321 | 319 |
@@ -38,17 +38,20 @@ public: | ||
38 | 38 | Supplicant(); |
39 | 39 | virtual ~Supplicant() {} |
40 | 40 | |
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(); | |
44 | 48 | |
45 | - virtual int triggerScan(bool active); | |
46 | 49 | |
47 | 50 | int getState() { return mState; } |
48 | 51 | |
49 | - ScanResultCollection *createLatestScanResults(); | |
50 | 52 | |
51 | 53 | // XXX: Extract these into an interface |
54 | +// handlers for SupplicantListener | |
52 | 55 | public: |
53 | 56 | virtual int onConnectedEvent(SupplicantEvent *evt); |
54 | 57 | virtual int onDisconnectedEvent(SupplicantEvent *evt); |
@@ -141,12 +141,13 @@ int WifiController::setScanMode(uint32_t mode) { | ||
141 | 141 | |
142 | 142 | if (!(mode & SCAN_ENABLE_MASK)) { |
143 | 143 | if (mCurrentScanMode & SCAN_REPEAT_MASK) |
144 | - mScanner->stopPeriodicScan(); | |
144 | + mScanner->stop(); | |
145 | 145 | } else if (mode & SCAN_REPEAT_MASK) |
146 | - rc = mScanner->startPeriodicScan(mode & SCAN_ACTIVE_MASK); | |
146 | + rc = mScanner->start(mode & SCAN_ACTIVE_MASK); | |
147 | 147 | else |
148 | 148 | rc = mSupplicant->triggerScan(mode & SCAN_ACTIVE_MASK); |
149 | - | |
149 | + | |
150 | + mCurrentScanMode = mode; | |
150 | 151 | return rc; |
151 | 152 | } |
152 | 153 |
@@ -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> | |
1 | 6 | #include <errno.h> |
2 | 7 | #include <pthread.h> |
3 | 8 |
@@ -13,28 +18,16 @@ WifiScanner::WifiScanner(Supplicant *suppl, int period) { | ||
13 | 18 | mSuppl = suppl; |
14 | 19 | mPeriod = period; |
15 | 20 | mActive = false; |
16 | - mWorkerRunning = false; | |
17 | - mAbortRequest = false; | |
18 | - pthread_mutex_init(&mAbortRequestLock, NULL); | |
19 | - pthread_mutex_init(&mWorkerLock, NULL); | |
20 | 21 | } |
21 | 22 | |
22 | -int WifiScanner::startPeriodicScan(bool active) { | |
23 | +int WifiScanner::start(bool active) { | |
23 | 24 | mActive = active; |
24 | 25 | |
25 | - pthread_mutex_lock(&mWorkerLock); | |
26 | - if (mWorkerRunning) { | |
27 | - errno = EBUSY; | |
26 | + if(pipe(mCtrlPipe)) | |
28 | 27 | return -1; |
29 | - } | |
30 | - | |
31 | - pthread_attr_t attr; | |
32 | - pthread_attr_init(&attr); | |
33 | - pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_DETACHED); | |
34 | 28 | |
35 | - if (pthread_create(&mWorker, &attr, WifiScanner::threadStart, this)) | |
29 | + if (pthread_create(&mThread, NULL, WifiScanner::threadStart, this)) | |
36 | 30 | return -1; |
37 | - | |
38 | 31 | return 0; |
39 | 32 | } |
40 | 33 |
@@ -45,52 +38,49 @@ void *WifiScanner::threadStart(void *obj) { | ||
45 | 38 | return NULL; |
46 | 39 | } |
47 | 40 | |
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; | |
53 | 43 | |
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; | |
57 | 47 | } |
58 | -} | |
59 | 48 | |
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 | + } | |
67 | 54 | |
55 | + close(mCtrlPipe[0]); | |
56 | + close(mCtrlPipe[1]); | |
68 | 57 | return 0; |
69 | 58 | } |
70 | 59 | |
71 | 60 | 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); | |
77 | 62 | |
78 | 63 | 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 | + | |
80 | 74 | if (mSuppl->triggerScan(mActive)) { |
81 | 75 | LOGW("Error triggering scan (%s)", strerror(errno)); |
82 | 76 | } |
83 | 77 | |
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 | |
96 | 86 | } |
@@ -6,12 +6,8 @@ | ||
6 | 6 | class Supplicant; |
7 | 7 | |
8 | 8 | 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]; | |
15 | 11 | Supplicant *mSuppl; |
16 | 12 | int mPeriod; |
17 | 13 | bool mActive; |
@@ -23,12 +19,11 @@ public: | ||
23 | 19 | |
24 | 20 | int getPeriod() { return mPeriod; } |
25 | 21 | |
26 | - int startPeriodicScan(bool active); | |
27 | - int stopPeriodicScan(); | |
22 | + int start(bool active); | |
23 | + int stop(); | |
28 | 24 | |
29 | 25 | private: |
30 | 26 | static void *threadStart(void *obj); |
31 | - static void threadCleanup(void *obj); | |
32 | 27 | |
33 | 28 | void run(); |
34 | 29 | }; |