The Pedigree Project 0.1
InputFile.h
1/*
2 * Copyright (c) 2008-2014, Pedigree Developers
3 *
4 * Please see the CONTRIB file in the root of the source tree for a full
5 * list of contributors.
6 *
7 * Permission to use, copy, modify, and distribute this software for any
8 * purpose with or without fee is hereby granted, provided that the above
9 * copyright notice and this permission notice appear in all copies.
10 *
11 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
12 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
13 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
14 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
15 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
16 * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
17 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
18 */
19
20#ifndef POSIX_INPUTFILE_H
21#define POSIX_INPUTFILE_H
22
23#include "pedigree/kernel/machine/InputManager.h"
24#include "pedigree/kernel/process/Mutex.h"
25#include "pedigree/kernel/utilities/Buffer.h"
26
27#include "linux-input-abi.h"
28#include "modules/system/vfs/File.h"
29
31class InputFile final : public File {
32 public:
33 InputFile(String name, size_t inode, Filesystem* filesystem, File* parent, bool endpoint = false);
34 ~InputFile() override;
35
36 bool initialise();
37
38 File* open() override;
39
40 uint64_t readBytewise(uint64_t location, uint64_t size, uintptr_t buffer,
41 bool bCanBlock = true) override;
42 uint64_t writeBytewise(uint64_t location, uint64_t size, uintptr_t buffer,
43 bool bCanBlock = true) override;
44 int select(bool bWriting = false, int timeout = 0) override;
46 bool supportsReadinessNotifications() const override {
47 return true;
48 }
49
50 bool isSeekable() const override {
51 return false;
52 }
53
54 bool retainVfsReference() override;
55 void releaseVfsReference() override;
56
57 private:
58 static void subscriber(InputManager::InputNotification& notification);
59 void handleInput(const InputManager::InputNotification& notification);
60
61 bool isBytewise() const override {
62 return true;
63 }
64
65 const bool m_Endpoint;
66 Mutex m_Lock;
67 Buffer<uint8_t> m_Buffer;
68 size_t m_LifetimePins = 0;
69 bool m_Registered = false;
70};
71
73class EvdevFile final : public File {
74 public:
75 enum DeviceType { Keyboard, Pointer, AbsolutePointer };
76
77 EvdevFile(String name, size_t inode, Filesystem* filesystem, File* parent, DeviceType type,
78 bool endpoint = false);
79 ~EvdevFile() override;
80
81 bool initialise();
82 File* open() override;
83
84 uint64_t readBytewise(uint64_t location, uint64_t size, uintptr_t buffer,
85 bool bCanBlock = true) override;
86 uint64_t writeBytewise(uint64_t location, uint64_t size, uintptr_t buffer,
87 bool bCanBlock = true) override;
88 int select(bool bWriting = false, int timeout = 0) override;
90 bool supportsReadinessNotifications() const override {
91 return true;
92 }
93 bool supports(size_t command) const override;
94 int command(size_t command, void* buffer) override;
95
96 bool isSeekable() const override {
97 return false;
98 }
99
100 bool retainVfsReference() override;
101 void releaseVfsReference() override;
102
103 private:
104 static void subscriber(InputManager::InputNotification& notification);
105 void handleInput(const InputManager::InputNotification& notification);
106 void emit(const LinuxInputEvent* events, size_t count);
107
108 bool isBytewise() const override {
109 return true;
110 }
111
112 const DeviceType m_Type;
113 const bool m_Endpoint;
114 Mutex m_Lock;
115 Buffer<uint8_t> m_Buffer;
116 uint8_t m_KeyState[96];
117 bool m_ButtonState[5];
118 uint32_t m_AbsoluteX = 0;
119 uint32_t m_AbsoluteY = 0;
120 bool m_HaveAbsolute = false;
121 size_t m_LifetimePins = 0;
122 bool m_Registered = false;
123};
124
125#endif
bool isSeekable() const override
Definition InputFile.h:96
File * open() override
Definition InputFile.cc:344
uint64_t readBytewise(uint64_t location, uint64_t size, uintptr_t buffer, bool bCanBlock=true) override
Definition InputFile.cc:356
bool supportsReadinessNotifications() const override
Definition InputFile.h:90
bool supports(size_t command) const override
Definition InputFile.cc:383
uint64_t writeBytewise(uint64_t location, uint64_t size, uintptr_t buffer, bool bCanBlock=true) override
Definition InputFile.cc:365
ReadinessGenerations readinessGenerations() override
Definition InputFile.cc:377
int select(bool bWriting=false, int timeout=0) override
Definition InputFile.cc:370
bool isBytewise() const override
Definition InputFile.h:108
bool retainVfsReference() override
Definition InputFile.cc:508
void releaseVfsReference() override
Definition InputFile.cc:517
Definition File.h:75
ReadinessGenerations readinessGenerations() override
Definition InputFile.cc:244
void releaseVfsReference() override
Definition InputFile.cc:260
bool retainVfsReference() override
Definition InputFile.cc:250
uint64_t readBytewise(uint64_t location, uint64_t size, uintptr_t buffer, bool bCanBlock=true) override
Definition InputFile.cc:227
bool isBytewise() const override
Definition InputFile.h:61
int select(bool bWriting=false, int timeout=0) override
Definition InputFile.cc:237
File * open() override
Definition InputFile.cc:214
bool supportsReadinessNotifications() const override
Definition InputFile.h:46
bool isSeekable() const override
Definition InputFile.h:50
uint64_t writeBytewise(uint64_t location, uint64_t size, uintptr_t buffer, bool bCanBlock=true) override
Definition InputFile.cc:232
Definition Mutex.h:56