annotate dep/animia/src/animia.cc @ 140:1e696863b54c

dep/animia: remove superfluous includes #include <windows.h> in the main file LMFAO
author Paper <mrpapersonic@gmail.com>
date Sun, 12 Nov 2023 16:54:58 -0500
parents 478f3b366199
children d8a61e7e2a36
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
138
28842a8d0c6b dep/animia: huge refactor (again...)
Paper <mrpapersonic@gmail.com>
parents: 137
diff changeset
1 #include <string>
28842a8d0c6b dep/animia: huge refactor (again...)
Paper <mrpapersonic@gmail.com>
parents: 137
diff changeset
2 #include <vector>
28842a8d0c6b dep/animia: huge refactor (again...)
Paper <mrpapersonic@gmail.com>
parents: 137
diff changeset
3
28842a8d0c6b dep/animia: huge refactor (again...)
Paper <mrpapersonic@gmail.com>
parents: 137
diff changeset
4 #include "animia.h"
28842a8d0c6b dep/animia: huge refactor (again...)
Paper <mrpapersonic@gmail.com>
parents: 137
diff changeset
5 #include "animia/strategies.h"
139
478f3b366199 dep/animia: separate lots of things, use base class for OS stuff
Paper <mrpapersonic@gmail.com>
parents: 138
diff changeset
6 #include "animia/types.h"
478f3b366199 dep/animia: separate lots of things, use base class for OS stuff
Paper <mrpapersonic@gmail.com>
parents: 138
diff changeset
7
138
28842a8d0c6b dep/animia: huge refactor (again...)
Paper <mrpapersonic@gmail.com>
parents: 137
diff changeset
8 #ifdef ANIMIA_ON_WIN32
139
478f3b366199 dep/animia: separate lots of things, use base class for OS stuff
Paper <mrpapersonic@gmail.com>
parents: 138
diff changeset
9 # include "animia/fd/win32.h"
478f3b366199 dep/animia: separate lots of things, use base class for OS stuff
Paper <mrpapersonic@gmail.com>
parents: 138
diff changeset
10 #elif defined(ANIMIA_ON_LINUX)
478f3b366199 dep/animia: separate lots of things, use base class for OS stuff
Paper <mrpapersonic@gmail.com>
parents: 138
diff changeset
11 # include "animia/fd/linux.h"
478f3b366199 dep/animia: separate lots of things, use base class for OS stuff
Paper <mrpapersonic@gmail.com>
parents: 138
diff changeset
12 #elif defined(ANIMIA_ON_UNIX)
478f3b366199 dep/animia: separate lots of things, use base class for OS stuff
Paper <mrpapersonic@gmail.com>
parents: 138
diff changeset
13 # include "animia/fd/bsd.h"
138
28842a8d0c6b dep/animia: huge refactor (again...)
Paper <mrpapersonic@gmail.com>
parents: 137
diff changeset
14 #endif
139
478f3b366199 dep/animia: separate lots of things, use base class for OS stuff
Paper <mrpapersonic@gmail.com>
parents: 138
diff changeset
15
478f3b366199 dep/animia: separate lots of things, use base class for OS stuff
Paper <mrpapersonic@gmail.com>
parents: 138
diff changeset
16 namespace animia::internal {
478f3b366199 dep/animia: separate lots of things, use base class for OS stuff
Paper <mrpapersonic@gmail.com>
parents: 138
diff changeset
17
478f3b366199 dep/animia: separate lots of things, use base class for OS stuff
Paper <mrpapersonic@gmail.com>
parents: 138
diff changeset
18 /* really stupid hack to get fd to point to the right
478f3b366199 dep/animia: separate lots of things, use base class for OS stuff
Paper <mrpapersonic@gmail.com>
parents: 138
diff changeset
19 thing */
478f3b366199 dep/animia: separate lots of things, use base class for OS stuff
Paper <mrpapersonic@gmail.com>
parents: 138
diff changeset
20 #ifdef ANIMIA_ON_WIN32
478f3b366199 dep/animia: separate lots of things, use base class for OS stuff
Paper <mrpapersonic@gmail.com>
parents: 138
diff changeset
21 win32::Win32FdTools os_fd;
478f3b366199 dep/animia: separate lots of things, use base class for OS stuff
Paper <mrpapersonic@gmail.com>
parents: 138
diff changeset
22 #elif defined(ANIMIA_ON_LINUX)
478f3b366199 dep/animia: separate lots of things, use base class for OS stuff
Paper <mrpapersonic@gmail.com>
parents: 138
diff changeset
23 linux::LinuxFdTools os_fd;
478f3b366199 dep/animia: separate lots of things, use base class for OS stuff
Paper <mrpapersonic@gmail.com>
parents: 138
diff changeset
24 #elif defined(ANIMIA_ON_UNIX)
478f3b366199 dep/animia: separate lots of things, use base class for OS stuff
Paper <mrpapersonic@gmail.com>
parents: 138
diff changeset
25 unix::UnixFdTools os_fd;
478f3b366199 dep/animia: separate lots of things, use base class for OS stuff
Paper <mrpapersonic@gmail.com>
parents: 138
diff changeset
26 #else
478f3b366199 dep/animia: separate lots of things, use base class for OS stuff
Paper <mrpapersonic@gmail.com>
parents: 138
diff changeset
27 BaseFdTools os_fd;
478f3b366199 dep/animia: separate lots of things, use base class for OS stuff
Paper <mrpapersonic@gmail.com>
parents: 138
diff changeset
28 #endif
478f3b366199 dep/animia: separate lots of things, use base class for OS stuff
Paper <mrpapersonic@gmail.com>
parents: 138
diff changeset
29
478f3b366199 dep/animia: separate lots of things, use base class for OS stuff
Paper <mrpapersonic@gmail.com>
parents: 138
diff changeset
30 BaseFdTools& fd = os_fd;
478f3b366199 dep/animia: separate lots of things, use base class for OS stuff
Paper <mrpapersonic@gmail.com>
parents: 138
diff changeset
31
478f3b366199 dep/animia: separate lots of things, use base class for OS stuff
Paper <mrpapersonic@gmail.com>
parents: 138
diff changeset
32 }
478f3b366199 dep/animia: separate lots of things, use base class for OS stuff
Paper <mrpapersonic@gmail.com>
parents: 138
diff changeset
33
138
28842a8d0c6b dep/animia: huge refactor (again...)
Paper <mrpapersonic@gmail.com>
parents: 137
diff changeset
34 namespace animia {
28842a8d0c6b dep/animia: huge refactor (again...)
Paper <mrpapersonic@gmail.com>
parents: 137
diff changeset
35
28842a8d0c6b dep/animia: huge refactor (again...)
Paper <mrpapersonic@gmail.com>
parents: 137
diff changeset
36 static bool ProcessInPlayers(const std::vector<Player>& players, const std::string& name, Player& player_) {
28842a8d0c6b dep/animia: huge refactor (again...)
Paper <mrpapersonic@gmail.com>
parents: 137
diff changeset
37 for (const auto& player : players) {
28842a8d0c6b dep/animia: huge refactor (again...)
Paper <mrpapersonic@gmail.com>
parents: 137
diff changeset
38 for (const auto& exe : player.executables) {
28842a8d0c6b dep/animia: huge refactor (again...)
Paper <mrpapersonic@gmail.com>
parents: 137
diff changeset
39 if (exe == name.substr(0, name.rfind(".exe"))) {
28842a8d0c6b dep/animia: huge refactor (again...)
Paper <mrpapersonic@gmail.com>
parents: 137
diff changeset
40 player_ = player;
28842a8d0c6b dep/animia: huge refactor (again...)
Paper <mrpapersonic@gmail.com>
parents: 137
diff changeset
41 return true;
28842a8d0c6b dep/animia: huge refactor (again...)
Paper <mrpapersonic@gmail.com>
parents: 137
diff changeset
42 }
28842a8d0c6b dep/animia: huge refactor (again...)
Paper <mrpapersonic@gmail.com>
parents: 137
diff changeset
43 }
28842a8d0c6b dep/animia: huge refactor (again...)
Paper <mrpapersonic@gmail.com>
parents: 137
diff changeset
44 }
28842a8d0c6b dep/animia: huge refactor (again...)
Paper <mrpapersonic@gmail.com>
parents: 137
diff changeset
45 return false;
28842a8d0c6b dep/animia: huge refactor (again...)
Paper <mrpapersonic@gmail.com>
parents: 137
diff changeset
46 }
28842a8d0c6b dep/animia: huge refactor (again...)
Paper <mrpapersonic@gmail.com>
parents: 137
diff changeset
47
28842a8d0c6b dep/animia: huge refactor (again...)
Paper <mrpapersonic@gmail.com>
parents: 137
diff changeset
48 bool GetResults(const std::vector<Player>& players, std::vector<Result>& results) {
139
478f3b366199 dep/animia: separate lots of things, use base class for OS stuff
Paper <mrpapersonic@gmail.com>
parents: 138
diff changeset
49 std::set<internal::pid_t> pids;
138
28842a8d0c6b dep/animia: huge refactor (again...)
Paper <mrpapersonic@gmail.com>
parents: 137
diff changeset
50
139
478f3b366199 dep/animia: separate lots of things, use base class for OS stuff
Paper <mrpapersonic@gmail.com>
parents: 138
diff changeset
51 if (!internal::fd.GetAllPids(pids))
138
28842a8d0c6b dep/animia: huge refactor (again...)
Paper <mrpapersonic@gmail.com>
parents: 137
diff changeset
52 return false;
28842a8d0c6b dep/animia: huge refactor (again...)
Paper <mrpapersonic@gmail.com>
parents: 137
diff changeset
53
28842a8d0c6b dep/animia: huge refactor (again...)
Paper <mrpapersonic@gmail.com>
parents: 137
diff changeset
54 for (const auto& pid : pids) {
28842a8d0c6b dep/animia: huge refactor (again...)
Paper <mrpapersonic@gmail.com>
parents: 137
diff changeset
55 std::string name;
139
478f3b366199 dep/animia: separate lots of things, use base class for OS stuff
Paper <mrpapersonic@gmail.com>
parents: 138
diff changeset
56 internal::fd.GetProcessName(pid, name);
138
28842a8d0c6b dep/animia: huge refactor (again...)
Paper <mrpapersonic@gmail.com>
parents: 137
diff changeset
57
28842a8d0c6b dep/animia: huge refactor (again...)
Paper <mrpapersonic@gmail.com>
parents: 137
diff changeset
58 Player player;
28842a8d0c6b dep/animia: huge refactor (again...)
Paper <mrpapersonic@gmail.com>
parents: 137
diff changeset
59 if (!ProcessInPlayers(players, name, player))
28842a8d0c6b dep/animia: huge refactor (again...)
Paper <mrpapersonic@gmail.com>
parents: 137
diff changeset
60 continue;
28842a8d0c6b dep/animia: huge refactor (again...)
Paper <mrpapersonic@gmail.com>
parents: 137
diff changeset
61
28842a8d0c6b dep/animia: huge refactor (again...)
Paper <mrpapersonic@gmail.com>
parents: 137
diff changeset
62 Result result;
28842a8d0c6b dep/animia: huge refactor (again...)
Paper <mrpapersonic@gmail.com>
parents: 137
diff changeset
63 result.process.pid = pid;
28842a8d0c6b dep/animia: huge refactor (again...)
Paper <mrpapersonic@gmail.com>
parents: 137
diff changeset
64 result.process.name = name;
28842a8d0c6b dep/animia: huge refactor (again...)
Paper <mrpapersonic@gmail.com>
parents: 137
diff changeset
65 result.player = player;
28842a8d0c6b dep/animia: huge refactor (again...)
Paper <mrpapersonic@gmail.com>
parents: 137
diff changeset
66 results.push_back(result);
28842a8d0c6b dep/animia: huge refactor (again...)
Paper <mrpapersonic@gmail.com>
parents: 137
diff changeset
67 }
28842a8d0c6b dep/animia: huge refactor (again...)
Paper <mrpapersonic@gmail.com>
parents: 137
diff changeset
68
28842a8d0c6b dep/animia: huge refactor (again...)
Paper <mrpapersonic@gmail.com>
parents: 137
diff changeset
69 return internal::ApplyStrategies(results);
28842a8d0c6b dep/animia: huge refactor (again...)
Paper <mrpapersonic@gmail.com>
parents: 137
diff changeset
70 }
28842a8d0c6b dep/animia: huge refactor (again...)
Paper <mrpapersonic@gmail.com>
parents: 137
diff changeset
71
140
1e696863b54c dep/animia: remove superfluous includes
Paper <mrpapersonic@gmail.com>
parents: 139
diff changeset
72 }