mirror of
				https://github.com/RGBCube/serenity
				synced 2025-10-31 11:12:45 +00:00 
			
		
		
		
	Kernel: Introduce a new super class called HIDController
Use the new class in HID code, because all other HID device controllers will be using this class as their parent class. Hence, we no longer keep a reference to any PS/2 device in HIDManagement and rely on HIDController derived classes to do this for us. It also means that we removed another instance of a LockRefPtr, which is designated to be removed and is replaced by the better pattern of SpinlockProtected<RefPtr<>> instead.
This commit is contained in:
		
							parent
							
								
									6c4a47d916
								
							
						
					
					
						commit
						d76c08c9b0
					
				
					 5 changed files with 39 additions and 25 deletions
				
			
		
							
								
								
									
										28
									
								
								Kernel/Devices/HID/Controller.h
									
										
									
									
									
										Normal file
									
								
							
							
						
						
									
										28
									
								
								Kernel/Devices/HID/Controller.h
									
										
									
									
									
										Normal file
									
								
							|  | @ -0,0 +1,28 @@ | |||
| /*
 | ||||
|  * Copyright (c) 2022, Liav A. <liavalb@hotmail.co.il> | ||||
|  * | ||||
|  * SPDX-License-Identifier: BSD-2-Clause | ||||
|  */ | ||||
| 
 | ||||
| #pragma once | ||||
| 
 | ||||
| #include <AK/AtomicRefCounted.h> | ||||
| #include <AK/IntrusiveList.h> | ||||
| 
 | ||||
| namespace Kernel { | ||||
| 
 | ||||
| class HIDManagement; | ||||
| class HIDController : public AtomicRefCounted<HIDController> { | ||||
|     friend class HIDManagement; | ||||
| 
 | ||||
| public: | ||||
|     virtual ~HIDController() = default; | ||||
| 
 | ||||
| protected: | ||||
|     HIDController() = default; | ||||
| 
 | ||||
| private: | ||||
|     IntrusiveListNode<HIDController, NonnullLockRefPtr<HIDController>> m_list_node; | ||||
| }; | ||||
| 
 | ||||
| } | ||||
|  | @ -152,13 +152,11 @@ UNMAP_AFTER_INIT ErrorOr<void> HIDManagement::enumerate() | |||
|     // Note: If we happen to not have i8042 just return "gracefully" for now.
 | ||||
|     if (!has_i8042_controller) | ||||
|         return {}; | ||||
|     m_i8042_controller = i8042_controller; | ||||
|     TRY(m_i8042_controller->detect_devices()); | ||||
|     if (m_i8042_controller->mouse()) | ||||
|         m_hid_devices.append(m_i8042_controller->mouse().release_nonnull()); | ||||
| 
 | ||||
|     if (m_i8042_controller->keyboard()) | ||||
|         m_hid_devices.append(m_i8042_controller->keyboard().release_nonnull()); | ||||
|     if (auto result_or_error = i8042_controller->detect_devices(); result_or_error.is_error()) | ||||
|         return {}; | ||||
|     m_hid_controllers.with([&](auto& list) { | ||||
|         list.append(i8042_controller); | ||||
|     }); | ||||
| #endif | ||||
|     return {}; | ||||
| } | ||||
|  |  | |||
|  | @ -12,6 +12,7 @@ | |||
| #include <AK/Types.h> | ||||
| #include <Kernel/API/KeyCode.h> | ||||
| #include <Kernel/API/MousePacket.h> | ||||
| #include <Kernel/Devices/HID/Controller.h> | ||||
| #include <Kernel/Devices/HID/Device.h> | ||||
| #include <Kernel/Forward.h> | ||||
| #include <Kernel/Library/LockRefPtr.h> | ||||
|  | @ -61,11 +62,9 @@ private: | |||
|     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 | ||||
|     Vector<NonnullLockRefPtr<HIDDevice>> m_hid_devices; | ||||
|     Spinlock<LockRank::None> m_client_lock {}; | ||||
| 
 | ||||
|     SpinlockProtected<IntrusiveList<&HIDController::m_list_node>, LockRank::None> m_hid_controllers; | ||||
|     Spinlock<LockRank::None> m_client_lock; | ||||
| }; | ||||
| 
 | ||||
| class KeyboardClient { | ||||
|  |  | |||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue
	
	 Liav A
						Liav A