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;
45
46 bool isSeekable() const override {
47 return false;
48 }
49
50 bool retainVfsReference() override;
51 void releaseVfsReference() override;
52
53 private:
54 static void subscriber(InputManager::InputNotification& notification);
55 void handleInput(const InputManager::InputNotification& notification);
56
57 bool isBytewise() const override {
58 return true;
59 }
60
61 const bool m_Endpoint;
62 Mutex m_Lock;
63 Buffer<uint8_t> m_Buffer;
64 size_t m_LifetimePins = 0;
65 bool m_Registered = false;
66};
67
69class EvdevFile final : public File {
70 public:
71 enum DeviceType { Keyboard, Pointer, AbsolutePointer };
72
73 EvdevFile(String name, size_t inode, Filesystem* filesystem, File* parent, DeviceType type,
74 bool endpoint = false);
75 ~EvdevFile() override;
76
77 bool initialise();
78 File* open() override;
79
80 uint64_t readBytewise(uint64_t location, uint64_t size, uintptr_t buffer,
81 bool bCanBlock = true) override;
82 uint64_t writeBytewise(uint64_t location, uint64_t size, uintptr_t buffer,
83 bool bCanBlock = true) override;
84 int select(bool bWriting = false, int timeout = 0) override;
85 bool supports(size_t command) const override;
86 int command(size_t command, void* buffer) override;
87
88 bool isSeekable() const override {
89 return false;
90 }
91
92 bool retainVfsReference() override;
93 void releaseVfsReference() override;
94
95 private:
96 static void subscriber(InputManager::InputNotification& notification);
97 void handleInput(const InputManager::InputNotification& notification);
98 void emit(const LinuxInputEvent* events, size_t count);
99
100 bool isBytewise() const override {
101 return true;
102 }
103
104 const DeviceType m_Type;
105 const bool m_Endpoint;
106 Mutex m_Lock;
107 Buffer<uint8_t> m_Buffer;
108 uint8_t m_KeyState[96];
109 bool m_ButtonState[5];
110 uint32_t m_AbsoluteX = 0;
111 uint32_t m_AbsoluteY = 0;
112 bool m_HaveAbsolute = false;
113 size_t m_LifetimePins = 0;
114 bool m_Registered = false;
115};
116
117#endif
bool isSeekable() const override
Definition InputFile.h:88
int command(size_t command, void *buffer) override
Definition InputFile.cc:384
File * open() override
Definition InputFile.cc:338
uint64_t readBytewise(uint64_t location, uint64_t size, uintptr_t buffer, bool bCanBlock=true) override
Definition InputFile.cc:350
bool supports(size_t command) const override
Definition InputFile.cc:371
uint64_t writeBytewise(uint64_t location, uint64_t size, uintptr_t buffer, bool bCanBlock=true) override
Definition InputFile.cc:359
int select(bool bWriting=false, int timeout=0) override
Definition InputFile.cc:364
bool isBytewise() const override
Definition InputFile.h:100
bool retainVfsReference() override
Definition InputFile.cc:496
void releaseVfsReference() override
Definition InputFile.cc:505
Definition File.h:74
void releaseVfsReference() override
Definition InputFile.cc:254
bool retainVfsReference() override
Definition InputFile.cc:244
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:57
int select(bool bWriting=false, int timeout=0) override
Definition InputFile.cc:237
File * open() override
Definition InputFile.cc:214
bool isSeekable() const override
Definition InputFile.h:46
uint64_t writeBytewise(uint64_t location, uint64_t size, uintptr_t buffer, bool bCanBlock=true) override
Definition InputFile.cc:232
Definition Mutex.h:56