Home | History | Annotate | Download | only in event_injector
      1 /*
      2 * Copyright (C) 2011 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 #include "EventInjector.h"
     17 #include "emulator-console.h"
     18 
     19 #define PRIVATE  EventInjectorPrivate
     20 
     21 class PRIVATE
     22 {
     23 public:
     24     IoLooper*         mLooper;
     25     EmulatorConsole*  mConsole;
     26 
     27     EventInjectorPrivate(int port) {
     28         mLooper = iolooper_new();
     29         mConsole = emulatorConsole_new(port, mLooper);
     30     }
     31 };
     32 
     33 EventInjector::EventInjector(int consolePort)
     34 {
     35     mPrivate = new PRIVATE(consolePort);
     36 }
     37 
     38 EventInjector::~EventInjector()
     39 {
     40     delete mPrivate;
     41 }
     42 
     43 void EventInjector::wait(int timeout_ms)
     44 {
     45     iolooper_wait(mPrivate->mLooper, timeout_ms);
     46 }
     47 
     48 void EventInjector::poll(void)
     49 {
     50     emulatorConsole_poll(mPrivate->mConsole);
     51 }
     52 
     53 void EventInjector::sendMouseDown( int x, int y )
     54 {
     55     emulatorConsole_sendMouseDown(mPrivate->mConsole, x, y);
     56 }
     57 
     58 void EventInjector::sendMouseUp( int x, int y )
     59 {
     60     emulatorConsole_sendMouseUp(mPrivate->mConsole, x, y);
     61 }
     62 
     63 void EventInjector::sendMouseMotion( int x, int y )
     64 {
     65     emulatorConsole_sendMouseMotion(mPrivate->mConsole, x, y);
     66 }
     67 
     68 void EventInjector::sendKeyDown( int keycode )
     69 {
     70     emulatorConsole_sendKey(mPrivate->mConsole, keycode, 1);
     71 }
     72 
     73 void EventInjector::sendKeyUp( int keycode )
     74 {
     75     emulatorConsole_sendKey(mPrivate->mConsole, keycode, 0);
     76 }
     77