mirror of
				https://github.com/RGBCube/serenity
				synced 2025-10-31 12:22:44 +00:00 
			
		
		
		
	 0cede94c39
			
		
	
	
		0cede94c39
		
	
	
	
	
		
			
			Instead of using a clunky if-statement paradigm, we now have all drivers being declaring two methods for their adapter class - create and probe. These methods are linked in each PCINetworkDriverInitializer structure, in a new s_initializers static list of them. Then, when we probe for a PCI device, we use each probe method and if there's a match, then the corresponding create method is called. After the adapter instance is created, we call the virtual initialize method on it, because many drivers actually require a sort of post-construction initialization sequence to ensure the network adapter can properly function. As a result of this change, it's much more easy to add more drivers and the initialization code is more readable and it's easier to understand when and where things could fail in the whole initialization sequence.
		
			
				
	
	
		
			30 lines
		
	
	
	
		
			815 B
		
	
	
	
		
			C++
		
	
	
	
	
	
			
		
		
	
	
			30 lines
		
	
	
	
		
			815 B
		
	
	
	
		
			C++
		
	
	
	
	
	
| /*
 | |
|  * Copyright (c) 2018-2020, Andreas Kling <kling@serenityos.org>
 | |
|  *
 | |
|  * SPDX-License-Identifier: BSD-2-Clause
 | |
|  */
 | |
| 
 | |
| #pragma once
 | |
| 
 | |
| #include <Kernel/Net/NetworkAdapter.h>
 | |
| 
 | |
| namespace Kernel {
 | |
| 
 | |
| class LoopbackAdapter final : public NetworkAdapter {
 | |
| private:
 | |
|     LoopbackAdapter(NonnullOwnPtr<KString>);
 | |
| 
 | |
| public:
 | |
|     static LockRefPtr<LoopbackAdapter> try_create();
 | |
|     virtual ~LoopbackAdapter() override;
 | |
| 
 | |
|     virtual ErrorOr<void> initialize(Badge<NetworkingManagement>) override { VERIFY_NOT_REACHED(); }
 | |
| 
 | |
|     virtual void send_raw(ReadonlyBytes) override;
 | |
|     virtual StringView class_name() const override { return "LoopbackAdapter"sv; }
 | |
|     virtual bool link_up() override { return true; }
 | |
|     virtual bool link_full_duplex() override { return true; }
 | |
|     virtual int link_speed() override { return 1000; }
 | |
| };
 | |
| 
 | |
| }
 |