Andrew Top | 2a79646 | 2018-06-29 09:04:04 -0700 | [diff] [blame] | 1 | // Copyright 2016 The Cobalt Authors. All Rights Reserved. |
David Ghandehari | 9e5b587 | 2016-07-28 09:50:04 -0700 | [diff] [blame] | 2 | // |
| 3 | // Licensed under the Apache License, Version 2.0 (the "License"); |
| 4 | // you may not use this file except in compliance with the License. |
| 5 | // You may obtain a copy of the License at |
| 6 | // |
| 7 | // http://www.apache.org/licenses/LICENSE-2.0 |
| 8 | // |
| 9 | // Unless required by applicable law or agreed to in writing, software |
| 10 | // distributed under the License is distributed on an "AS IS" BASIS, |
| 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 12 | // See the License for the specific language governing permissions and |
| 13 | // limitations under the License. |
| 14 | |
| 15 | #ifndef STARBOARD_SHARED_LINUX_DEV_INPUT_DEV_INPUT_H_ |
| 16 | #define STARBOARD_SHARED_LINUX_DEV_INPUT_DEV_INPUT_H_ |
| 17 | |
| 18 | #include "starboard/shared/internal_only.h" |
| 19 | #include "starboard/shared/starboard/application.h" |
| 20 | #include "starboard/time.h" |
| 21 | #include "starboard/window.h" |
| 22 | |
| 23 | namespace starboard { |
| 24 | namespace shared { |
| 25 | namespace dev_input { |
| 26 | |
| 27 | // A class that wraps /dev/input, providing enough functionality to be used in a |
| 28 | // Starboard Application implementation. |
| 29 | class DevInput { |
| 30 | public: |
| 31 | typedef ::starboard::shared::starboard::Application::Event Event; |
| 32 | |
| 33 | virtual ~DevInput() {} |
| 34 | |
| 35 | // Returns an event if one exists, otherwise returns NULL. The caller is |
| 36 | // responsible for deleting the returned event. |
| 37 | virtual Event* PollNextSystemEvent() = 0; |
| 38 | |
| 39 | // Waits for an event until the timeout |time| runs out. If an event occurs in |
| 40 | // this time, it is returned, otherwise NULL is returned. The caller is |
| 41 | // responsible for deleting the returned event. |
| 42 | virtual Event* WaitForSystemEventWithTimeout(SbTime duration) = 0; |
| 43 | |
| 44 | // Wakes up any thread waiting within a call to |
| 45 | // WaitForSystemEventWithTimeout(). |
| 46 | virtual void WakeSystemEventWait() = 0; |
| 47 | |
| 48 | // Creates an instance of DevInput for the given window. |
| 49 | static DevInput* Create(SbWindow window); |
| 50 | |
Andrew Top | d84d494 | 2017-08-22 17:31:32 -0700 | [diff] [blame] | 51 | // Creates an instance of DevInput for the given window. |
| 52 | // The wake_up_fd will be used in WaitForSystemEventWithTimeout() to return |
| 53 | // early when input is available on it. |
| 54 | static DevInput* Create(SbWindow window, int wake_up_fd); |
| 55 | |
David Ghandehari | 9e5b587 | 2016-07-28 09:50:04 -0700 | [diff] [blame] | 56 | protected: |
| 57 | DevInput() {} |
| 58 | }; |
| 59 | |
| 60 | } // namespace dev_input |
| 61 | } // namespace shared |
| 62 | } // namespace starboard |
| 63 | |
| 64 | #endif // STARBOARD_SHARED_LINUX_DEV_INPUT_DEV_INPUT_H_ |