comparison dep/animia/src/animia.cc @ 139:478f3b366199

dep/animia: separate lots of things, use base class for OS stuff
author Paper <mrpapersonic@gmail.com>
date Sun, 12 Nov 2023 16:43:07 -0500
parents 28842a8d0c6b
children 1e696863b54c
comparison
equal deleted inserted replaced
138:28842a8d0c6b 139:478f3b366199
2 #include <vector> 2 #include <vector>
3 3
4 #include <windows.h> 4 #include <windows.h>
5 5
6 #include "animia.h" 6 #include "animia.h"
7 #include "animia/util.h"
8 #include "animia/strategies.h" 7 #include "animia/strategies.h"
8 #include "animia/types.h"
9
9 #ifdef ANIMIA_ON_WIN32 10 #ifdef ANIMIA_ON_WIN32
10 #include "animia/fd/win32.h" 11 # include "animia/fd/win32.h"
12 #elif defined(ANIMIA_ON_LINUX)
13 # include "animia/fd/linux.h"
14 #elif defined(ANIMIA_ON_UNIX)
15 # include "animia/fd/bsd.h"
11 #endif 16 #endif
17
18 namespace animia::internal {
19
20 /* really stupid hack to get fd to point to the right
21 thing */
22 #ifdef ANIMIA_ON_WIN32
23 win32::Win32FdTools os_fd;
24 #elif defined(ANIMIA_ON_LINUX)
25 linux::LinuxFdTools os_fd;
26 #elif defined(ANIMIA_ON_UNIX)
27 unix::UnixFdTools os_fd;
28 #else
29 BaseFdTools os_fd;
30 #endif
31
32 BaseFdTools& fd = os_fd;
33
34 }
35
12 #include <iostream> 36 #include <iostream>
13 37
14 namespace animia { 38 namespace animia {
15 39
16 static bool ProcessInPlayers(const std::vector<Player>& players, const std::string& name, Player& player_) { 40 static bool ProcessInPlayers(const std::vector<Player>& players, const std::string& name, Player& player_) {
24 } 48 }
25 return false; 49 return false;
26 } 50 }
27 51
28 bool GetResults(const std::vector<Player>& players, std::vector<Result>& results) { 52 bool GetResults(const std::vector<Player>& players, std::vector<Result>& results) {
29 std::set<pid_t> pids; 53 std::set<internal::pid_t> pids;
30 54
31 #ifdef ANIMIA_ON_WIN32 55 if (!internal::fd.GetAllPids(pids))
32 /* todo: make these functions also return process names in a tuple,
33 cause the win32 api gives it to us for free! */
34 if (!internal::win32::GetAllPids(pids))
35 #elif ANIMIA_ON_LINUX
36 if (!internal::linux::GetAllPids(pids))
37 #elif ANIMIA_ON_UNIX
38 if (!internal::unix::GetAllPids(pids))
39 #endif
40 return false; 56 return false;
41 57
42 for (const auto& pid : pids) { 58 for (const auto& pid : pids) {
43 std::string name; 59 std::string name;
44 #ifdef ANIMIA_ON_WIN32 60 internal::fd.GetProcessName(pid, name);
45 animia::internal::win32::GetProcessName(pid, name);
46 #endif
47 61
48 Player player; 62 Player player;
49 if (!ProcessInPlayers(players, name, player)) 63 if (!ProcessInPlayers(players, name, player))
50 continue; 64 continue;
51 65