diff options
| author | Dianne Hackborn <hackbod@google.com> | 2010-07-07 09:14:57 -0700 |
|---|---|---|
| committer | Android Git Automerger <android-git-automerger@android.com> | 2010-07-07 09:14:57 -0700 |
| commit | 97250d5c4ab5c36dc4f7cf1d9d48157ed934615d (patch) | |
| tree | e1075093796bc528940a2159adc557e20c3b1edb /include/utils/PollLoop.h | |
| parent | 054e3d5e17378bc3419c8f80c3f204b270d733e8 (diff) | |
| parent | e24901d3adb28fff72821d4e8e2ccc25b2184550 (diff) | |
| download | frameworks_base-97250d5c4ab5c36dc4f7cf1d9d48157ed934615d.zip frameworks_base-97250d5c4ab5c36dc4f7cf1d9d48157ed934615d.tar.gz frameworks_base-97250d5c4ab5c36dc4f7cf1d9d48157ed934615d.tar.bz2 | |
am e24901d3: am 68267415: Add new native Looper API.
Merge commit 'e24901d3adb28fff72821d4e8e2ccc25b2184550'
* commit 'e24901d3adb28fff72821d4e8e2ccc25b2184550':
Add new native Looper API.
Diffstat (limited to 'include/utils/PollLoop.h')
| -rw-r--r-- | include/utils/PollLoop.h | 34 |
1 files changed, 33 insertions, 1 deletions
diff --git a/include/utils/PollLoop.h b/include/utils/PollLoop.h index a95fb17..b3651ca 100644 --- a/include/utils/PollLoop.h +++ b/include/utils/PollLoop.h @@ -22,12 +22,22 @@ #include <sys/poll.h> +#include <android/looper.h> + +struct ALooper : public android::RefBase { +protected: + virtual ~ALooper() { } + +public: + ALooper() { } +}; + namespace android { /** * A basic file descriptor polling loop based on poll() with callbacks. */ -class PollLoop : public RefBase { +class PollLoop : public ALooper { protected: virtual ~PollLoop(); @@ -83,6 +93,11 @@ public: void setCallback(int fd, int events, Callback callback, void* data = NULL); /** + * Like setCallback(), but for the NDK callback function. + */ + void setLooperCallback(int fd, int events, ALooper_callbackFunc* callback, void* data); + + /** * Removes the callback for a file descriptor, if one exists. * * When this method returns, it is safe to close the file descriptor since the poll loop @@ -100,9 +115,22 @@ public: */ bool removeCallback(int fd); + /** + * Set the given PollLoop to be associated with the + * calling thread. There must be a 1:1 relationship between + * PollLoop and thread. + */ + static void setForThread(const sp<PollLoop>& pollLoop); + + /** + * Return the PollLoop associated with the calling thread. + */ + static sp<PollLoop> getForThread(); + private: struct RequestedCallback { Callback callback; + ALooper_callbackFunc* looperCallback; void* data; }; @@ -110,6 +138,7 @@ private: int fd; int events; Callback callback; + ALooper_callbackFunc* looperCallback; void* data; }; @@ -130,8 +159,11 @@ private: void openWakePipe(); void closeWakePipe(); + void setCallbackCommon(int fd, int events, Callback callback, + ALooper_callbackFunc* looperCallback, void* data); ssize_t getRequestIndexLocked(int fd); void wakeAndLock(); + static void threadDestructor(void *st); }; } // namespace android |
