comparison dep/animia/src/fd.cc @ 198:bc1ae1810855

dep/animia: switch from using classes to global functions the old idea was ok, but sort of hackish; this method doesn't use classes at all, and this way (especially important!) we can do wayland stuff AND x11 at the same time, which wasn't really possible without stupid workarounds in the other method
author Paper <mrpapersonic@gmail.com>
date Sun, 24 Dec 2023 02:59:42 -0500
parents 54c5d80a737e
children 71832ffe425a
comparison
equal deleted inserted replaced
197:c4ca035c565d 198:bc1ae1810855
1 #include "animia/fd.h" 1 #include "animia/fd.h"
2 2
3 #ifdef WIN32 3 #ifdef WIN32
4 # include "animia/fd/win32.h" 4 # include "animia/fd/win32.h"
5 #elif defined(LINUX) || defined(FREEBSD) 5 #endif
6
7 #ifdef LINUX
6 # include "animia/fd/proc.h" 8 # include "animia/fd/proc.h"
7 #elif defined(MACOSX) 9 #endif
10
11 #ifdef MACOSX
8 # include "animia/fd/xnu.h" 12 # include "animia/fd/xnu.h"
9 #elif defined(LIBUTIL) 13 #endif
10 # include "animia/fd/libutil.h" 14
15 #ifdef LIBUTIL
16 # include "animia/fd/libutil.h"
11 #endif 17 #endif
12 18
13 namespace animia::internal { 19 namespace animia::internal {
14 20
21 bool EnumerateOpenFiles(const std::set<pid_t>& pids, open_file_proc_t open_file_proc) {
22 bool success = false;
23
15 #ifdef WIN32 24 #ifdef WIN32
16 win32::Win32FdTools os_fd; 25 success ^= win32::EnumerateOpenFiles(pids, open_file_proc);
17 #elif defined(LINUX) || defined(FREEBSD)
18 proc::ProcFdTools os_fd;
19 #elif defined(MACOSX)
20 xnu::XnuFdTools os_fd;
21 #elif defined(LIBUTIL)
22 libutil::LibutilFdTools os_fd;
23 #else
24 BaseFdTools os_fd;
25 #endif 26 #endif
26 27
27 BaseFdTools& fd = os_fd; 28 #ifdef LINUX
29 success ^= proc::EnumerateOpenFiles(pids, open_file_proc);
30 #endif
31
32 #ifdef MACOSX
33 success ^= xnu::EnumerateOpenFiles(pids, open_file_proc);
34 #endif
35
36 #ifdef LIBUTIL
37 success ^= libutil::EnumerateOpenFiles(pids, open_file_proc);
38 #endif
39
40 return success;
41 }
42
43 bool EnumerateOpenProcesses(process_proc_t process_proc) {
44 bool success = false;
45
46 #ifdef WIN32
47 success ^= win32::EnumerateOpenProcesses(process_proc);
48 #endif
49
50 #ifdef LINUX
51 success ^= proc::EnumerateOpenProcesses(process_proc);
52 #endif
53
54 #ifdef MACOSX
55 success ^= xnu::EnumerateOpenProcesses(process_proc);
56 #endif
57
58 #ifdef LIBUTIL
59 success ^= libutil::EnumerateOpenProcesses(process_proc);
60 #endif
61
62 return success;
63 }
28 64
29 } // namespace animia::internal 65 } // namespace animia::internal