Home | History | Annotate | Download | only in android_runtime
      1 /*
      2  * Copyright (C) 2013 The Android Open Source Project
      3  *
      4  * Licensed under the Apache License, Version 2.0 (the "License");
      5  * you may not use this file except in compliance with the License.
      6  * You may obtain a copy of the License at
      7  *
      8  *      http://www.apache.org/licenses/LICENSE-2.0
      9  *
     10  * Unless required by applicable law or agreed to in writing, software
     11  * distributed under the License is distributed on an "AS IS" BASIS,
     12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
     13  * See the License for the specific language governing permissions and
     14  * limitations under the License.
     15  */
     16 
     17 #ifndef _ANDROID_VIEW_INPUTQUEUE_H
     18 #define _ANDROID_VIEW_INPUTQUEUE_H
     19 
     20 #include <input/Input.h>
     21 #include <utils/Looper.h>
     22 #include <utils/TypeHelpers.h>
     23 #include <utils/Vector.h>
     24 
     25 #include "JNIHelp.h"
     26 
     27 /*
     28  * Declare a concrete type for the NDK's AInputQueue forward declaration
     29  */
     30 struct AInputQueue{
     31 };
     32 
     33 namespace android {
     34 
     35 class InputQueue : public AInputQueue, public MessageHandler {
     36 public:
     37     virtual ~InputQueue();
     38 
     39     void attachLooper(Looper* looper, int ident, ALooper_callbackFunc callback, void* data);
     40 
     41     void detachLooper();
     42 
     43     bool hasEvents();
     44 
     45     status_t getEvent(InputEvent** outEvent);
     46 
     47     bool preDispatchEvent(InputEvent* event);
     48 
     49     void finishEvent(InputEvent* event, bool handled);
     50 
     51     KeyEvent* createKeyEvent();
     52 
     53     MotionEvent* createMotionEvent();
     54 
     55     void recycleInputEvent(InputEvent* event);
     56 
     57     void enqueueEvent(InputEvent* event);
     58 
     59     static InputQueue* createQueue(jobject inputQueueObj, const sp<Looper>& looper);
     60 
     61 protected:
     62     virtual void handleMessage(const Message& message);
     63 
     64 private:
     65     InputQueue(jobject inputQueueObj, const sp<Looper>& looper,
     66             int readDispatchFd, int writeDispatchFd);
     67 
     68     void detachLooperLocked();
     69 
     70     jobject mInputQueueWeakGlobal;
     71     int mDispatchReadFd;
     72     int mDispatchWriteFd;
     73     Vector<Looper*> mAppLoopers;
     74     sp<Looper> mDispatchLooper;
     75     sp<WeakMessageHandler> mHandler;
     76     PooledInputEventFactory mPooledInputEventFactory;
     77     // Guards the pending and finished event vectors
     78     mutable Mutex mLock;
     79     Vector<InputEvent*> mPendingEvents;
     80     Vector<key_value_pair_t<InputEvent*, bool> > mFinishedEvents;
     81 };
     82 
     83 } // namespace android
     84 
     85 #endif
     86