mirror of
https://github.com/RGBCube/serenity
synced 2025-05-31 06:38:10 +00:00

This step would ideally not have been necessary (increases amount of refactoring and templates necessary, which in turn increases build times), but it gives us a couple of nice properties: - SpinlockProtected inside Singleton (a very common combination) can now obtain any lock rank just via the template parameter. It was not previously possible to do this with SingletonInstanceCreator magic. - SpinlockProtected's lock rank is now mandatory; this is the majority of cases and allows us to see where we're still missing proper ranks. - The type already informs us what lock rank a lock has, which aids code readability and (possibly, if gdb cooperates) lock mismatch debugging. - The rank of a lock can no longer be dynamic, which is not something we wanted in the first place (or made use of). Locks randomly changing their rank sounds like a disaster waiting to happen. - In some places, we might be able to statically check that locks are taken in the right order (with the right lock rank checking implementation) as rank information is fully statically known. This refactoring even more exposes the fact that Mutex has no lock rank capabilites, which is not fixed here.
78 lines
2 KiB
C++
78 lines
2 KiB
C++
/*
|
|
* Copyright (c) 2021, Liav A. <liavalb@hotmail.co.il>
|
|
*
|
|
* SPDX-License-Identifier: BSD-2-Clause
|
|
*/
|
|
|
|
#pragma once
|
|
|
|
#include <AK/Atomic.h>
|
|
#include <AK/CircularQueue.h>
|
|
#include <AK/Error.h>
|
|
#include <AK/Types.h>
|
|
#include <Kernel/API/KeyCode.h>
|
|
#include <Kernel/API/MousePacket.h>
|
|
#include <Kernel/Devices/HID/HIDDevice.h>
|
|
#include <Kernel/Forward.h>
|
|
#include <Kernel/Library/LockRefPtr.h>
|
|
#include <Kernel/Library/NonnullLockRefPtrVector.h>
|
|
#include <Kernel/Locking/Spinlock.h>
|
|
#include <Kernel/Locking/SpinlockProtected.h>
|
|
#include <Kernel/UnixTypes.h>
|
|
#include <LibKeyboard/CharacterMapData.h>
|
|
|
|
namespace Kernel {
|
|
|
|
extern Atomic<bool> g_caps_lock_remapped_to_ctrl;
|
|
|
|
class HIDDevice;
|
|
class I8042Controller;
|
|
class MouseDevice;
|
|
class KeyboardDevice;
|
|
class KeyboardClient;
|
|
class HIDManagement {
|
|
friend class KeyboardDevice;
|
|
friend class MouseDevice;
|
|
|
|
public:
|
|
HIDManagement();
|
|
static ErrorOr<void> initialize();
|
|
static HIDManagement& the();
|
|
|
|
ErrorOr<void> enumerate();
|
|
|
|
struct KeymapData {
|
|
KeymapData();
|
|
NonnullOwnPtr<KString> character_map_name;
|
|
Keyboard::CharacterMapData character_map;
|
|
};
|
|
|
|
SpinlockProtected<KeymapData, LockRank::None>& keymap_data() { return m_keymap_data; }
|
|
|
|
u32 get_char_from_character_map(KeyEvent) const;
|
|
|
|
void set_client(KeyboardClient* client);
|
|
void set_maps(NonnullOwnPtr<KString> character_map_name, Keyboard::CharacterMapData const& character_map);
|
|
|
|
private:
|
|
size_t generate_minor_device_number_for_mouse();
|
|
size_t generate_minor_device_number_for_keyboard();
|
|
|
|
SpinlockProtected<KeymapData, LockRank::None> m_keymap_data {};
|
|
size_t m_mouse_minor_number { 0 };
|
|
size_t m_keyboard_minor_number { 0 };
|
|
KeyboardClient* m_client { nullptr };
|
|
#if ARCH(X86_64)
|
|
LockRefPtr<I8042Controller> m_i8042_controller;
|
|
#endif
|
|
NonnullLockRefPtrVector<HIDDevice> m_hid_devices;
|
|
Spinlock<LockRank::None> m_client_lock {};
|
|
};
|
|
|
|
class KeyboardClient {
|
|
public:
|
|
virtual ~KeyboardClient() = default;
|
|
virtual void on_key_pressed(KeyEvent) = 0;
|
|
};
|
|
|
|
}
|