diff options
author | Dianne Hackborn <hackbod@google.com> | 2010-07-02 18:52:01 -0700 |
---|---|---|
committer | Dianne Hackborn <hackbod@google.com> | 2010-07-02 18:57:02 -0700 |
commit | efa10850665c8d60e562f3a488ae65e225614707 (patch) | |
tree | 716669410b52fd7dc61aa72926b729c891876c1d /include | |
parent | bf83375c73f0dcde5d97b36273e3fd971411e866 (diff) | |
download | frameworks_native-efa10850665c8d60e562f3a488ae65e225614707.zip frameworks_native-efa10850665c8d60e562f3a488ae65e225614707.tar.gz frameworks_native-efa10850665c8d60e562f3a488ae65e225614707.tar.bz2 |
Add new native Looper API.
This allows us to avoid exposing the file descriptor of
the event queue; instead, you attach an event queue to
a looper. This will also should allow native apps to be
written without the need for a separate thread, by attaching
the event queue to the main thread's looper and scheduling
their own messages there.
Change-Id: I38489282635895ae2cbfacb88599c1b1cad9b239
Diffstat (limited to 'include')
-rw-r--r-- | include/ui/InputTransport.h | 5 | ||||
-rw-r--r-- | include/utils/PollLoop.h | 34 |
2 files changed, 38 insertions, 1 deletions
diff --git a/include/ui/InputTransport.h b/include/ui/InputTransport.h index 2dfe2a8..11714d5 100644 --- a/include/ui/InputTransport.h +++ b/include/ui/InputTransport.h @@ -33,6 +33,7 @@ #include <semaphore.h> #include <ui/Input.h> #include <utils/Errors.h> +#include <utils/PollLoop.h> #include <utils/Timers.h> #include <utils/RefBase.h> #include <utils/String8.h> @@ -345,11 +346,15 @@ public: android::status_t consume(android::InputEvent** event); + void setPollLoop(const android::sp<android::PollLoop>& pollLoop) { mPollLoop = pollLoop; } + const android::sp<android::PollLoop> getPollLoop() const { return mPollLoop; } + virtual void doDefaultKey(android::KeyEvent* keyEvent) = 0; private: android::InputConsumer mConsumer; android::PreallocatedInputEventFactory mInputEventFactory; + android::sp<android::PollLoop> mPollLoop; }; #endif // _UI_INPUT_TRANSPORT_H 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 |