InputManager.h 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110
  1. /*
  2. * Copyright (C) 2010 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. #ifndef _UI_INPUT_MANAGER_H
  17. #define _UI_INPUT_MANAGER_H
  18. /**
  19. * Native input manager.
  20. */
  21. #include "EventHub.h"
  22. #include "InputReader.h"
  23. #include "InputDispatcher.h"
  24. #include <input/Input.h>
  25. #include <input/InputTransport.h>
  26. #include <utils/Errors.h>
  27. #include <utils/Vector.h>
  28. #include <utils/Timers.h>
  29. #include <utils/RefBase.h>
  30. #include <utils/String8.h>
  31. namespace android {
  32. /*
  33. * The input manager is the core of the system event processing.
  34. *
  35. * The input manager uses two threads.
  36. *
  37. * 1. The InputReaderThread (called "InputReader") reads and preprocesses raw input events,
  38. * applies policy, and posts messages to a queue managed by the DispatcherThread.
  39. * 2. The InputDispatcherThread (called "InputDispatcher") thread waits for new events on the
  40. * queue and asynchronously dispatches them to applications.
  41. *
  42. * By design, the InputReaderThread class and InputDispatcherThread class do not share any
  43. * internal state. Moreover, all communication is done one way from the InputReaderThread
  44. * into the InputDispatcherThread and never the reverse. Both classes may interact with the
  45. * InputDispatchPolicy, however.
  46. *
  47. * The InputManager class never makes any calls into Java itself. Instead, the
  48. * InputDispatchPolicy is responsible for performing all external interactions with the
  49. * system, including calling DVM services.
  50. */
  51. class InputManagerInterface : public virtual RefBase {
  52. protected:
  53. InputManagerInterface() { }
  54. virtual ~InputManagerInterface() { }
  55. public:
  56. /* Starts the input manager threads. */
  57. virtual status_t start() = 0;
  58. /* Stops the input manager threads and waits for them to exit. */
  59. virtual status_t stop() = 0;
  60. /* Gets the input reader. */
  61. virtual sp<InputReaderInterface> getReader() = 0;
  62. /* Gets the input dispatcher. */
  63. virtual sp<InputDispatcherInterface> getDispatcher() = 0;
  64. };
  65. class InputManager : public InputManagerInterface {
  66. protected:
  67. virtual ~InputManager();
  68. public:
  69. InputManager(
  70. const sp<EventHubInterface>& eventHub,
  71. const sp<InputReaderPolicyInterface>& readerPolicy,
  72. const sp<InputDispatcherPolicyInterface>& dispatcherPolicy);
  73. // (used for testing purposes)
  74. InputManager(
  75. const sp<InputReaderInterface>& reader,
  76. const sp<InputDispatcherInterface>& dispatcher);
  77. virtual status_t start();
  78. virtual status_t stop();
  79. virtual sp<InputReaderInterface> getReader();
  80. virtual sp<InputDispatcherInterface> getDispatcher();
  81. private:
  82. sp<InputReaderInterface> mReader;
  83. sp<InputReaderThread> mReaderThread;
  84. sp<InputDispatcherInterface> mDispatcher;
  85. sp<InputDispatcherThread> mDispatcherThread;
  86. void initialize();
  87. };
  88. } // namespace android
  89. #endif // _UI_INPUT_MANAGER_H