xref: /haiku/headers/private/shared/AutoDeleterDrivers.h (revision fa766875afc584bcfd45bd4eea40bbd9b331b50c)
1553f3f23SX512 /*
2a748b72eSX512  * Copyright 2020, Haiku, Inc. All rights reserved.
3553f3f23SX512  * Distributed under the terms of the MIT License.
4553f3f23SX512  */
5553f3f23SX512 #ifndef _AUTO_DELETER_DRIVERS_H
6553f3f23SX512 #define _AUTO_DELETER_DRIVERS_H
7553f3f23SX512 
8553f3f23SX512 
9553f3f23SX512 #include <AutoDeleter.h>
10553f3f23SX512 #include <driver_settings.h>
11a748b72eSX512 
12553f3f23SX512 #if defined(_KERNEL_MODE) && !defined(_BOOT_MODE)
13553f3f23SX512 #include <vfs.h>
14553f3f23SX512 #include <fs/fd.h>
15a748b72eSX512 #include <vm/VMAddressSpace.h>
16a748b72eSX512 #include <device_manager.h>
17553f3f23SX512 #endif
18553f3f23SX512 
19553f3f23SX512 
20553f3f23SX512 namespace BPrivate {
21553f3f23SX512 
22553f3f23SX512 
23a748b72eSX512 typedef CObjectDeleter<void, status_t, unload_driver_settings>
24a748b72eSX512 	DriverSettingsUnloader;
25553f3f23SX512 
26553f3f23SX512 #if defined(_KERNEL_MODE) && !defined(_BOOT_MODE)
27553f3f23SX512 
28553f3f23SX512 typedef CObjectDeleter<struct vnode, void, vfs_put_vnode> VnodePutter;
29*fa766875SAugustin Cavalier typedef CObjectDeleter<file_descriptor, void, put_fd> FileDescriptorPutter;
30a748b72eSX512 typedef MethodDeleter<VMAddressSpace, void, &VMAddressSpace::Put>
31a748b72eSX512 	VMAddressSpacePutter;
32a748b72eSX512 
33a748b72eSX512 #if __GNUC__ >= 4
34a748b72eSX512 
35a748b72eSX512 template <device_manager_info **deviceManager>
36a748b72eSX512 using DeviceNodePutter = MethodObjectDeleter<device_node, device_manager_info,
37a748b72eSX512 	deviceManager, void, &device_manager_info::put_node>;
38a748b72eSX512 
39a748b72eSX512 #else
40a748b72eSX512 
41a748b72eSX512 template <device_manager_info **deviceManager>
42a748b72eSX512 struct DeviceNodePutter : MethodObjectDeleter<device_node, device_manager_info,
43a748b72eSX512 	deviceManager, void, &device_manager_info::put_node>
44a748b72eSX512 {
45a748b72eSX512 	typedef MethodObjectDeleter<device_node, device_manager_info,
46a748b72eSX512 		deviceManager, void, &device_manager_info::put_node> Base;
47a748b72eSX512 
DeviceNodePutterDeviceNodePutter48a748b72eSX512 	DeviceNodePutter() : Base() {}
DeviceNodePutterDeviceNodePutter49a748b72eSX512 	DeviceNodePutter(device_node* object) : Base(object) {}
50a748b72eSX512 };
51a748b72eSX512 
52a748b72eSX512 #endif
53553f3f23SX512 
54553f3f23SX512 #endif
55553f3f23SX512 
56553f3f23SX512 
57553f3f23SX512 }
58553f3f23SX512 
59553f3f23SX512 
60553f3f23SX512 using ::BPrivate::DriverSettingsUnloader;
61553f3f23SX512 
62553f3f23SX512 #if defined(_KERNEL_MODE) && !defined(_BOOT_MODE)
63553f3f23SX512 
64553f3f23SX512 using ::BPrivate::VnodePutter;
65*fa766875SAugustin Cavalier using ::BPrivate::FileDescriptorPutter;
66a748b72eSX512 using ::BPrivate::VMAddressSpacePutter;
67a748b72eSX512 using ::BPrivate::DeviceNodePutter;
68553f3f23SX512 
69553f3f23SX512 #endif
70553f3f23SX512 
71553f3f23SX512 
72553f3f23SX512 #endif	// _AUTO_DELETER_DRIVERS_H
73