comparison dep/animia/src/animia.cc @ 138:28842a8d0c6b

dep/animia: huge refactor (again...) but this time, it actually compiles! and it WORKS! (on win32... not sure about other platforms...) configuring players is still not supported: at some point I'll prune something up...
author Paper <mrpapersonic@gmail.com>
date Sun, 12 Nov 2023 04:53:19 -0500
parents 69db40272acd
children 478f3b366199
comparison
equal deleted inserted replaced
137:69db40272acd 138:28842a8d0c6b
1 #include <string>
2 #include <vector>
3
4 #include <windows.h>
5
6 #include "animia.h"
7 #include "animia/util.h"
8 #include "animia/strategies.h"
9 #ifdef ANIMIA_ON_WIN32
10 #include "animia/fd/win32.h"
11 #endif
12 #include <iostream>
13
14 namespace animia {
15
16 static bool ProcessInPlayers(const std::vector<Player>& players, const std::string& name, Player& player_) {
17 for (const auto& player : players) {
18 for (const auto& exe : player.executables) {
19 if (exe == name.substr(0, name.rfind(".exe"))) {
20 player_ = player;
21 return true;
22 }
23 }
24 }
25 return false;
26 }
27
28 bool GetResults(const std::vector<Player>& players, std::vector<Result>& results) {
29 std::set<pid_t> pids;
30
31 #ifdef ANIMIA_ON_WIN32
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;
41
42 for (const auto& pid : pids) {
43 std::string name;
44 #ifdef ANIMIA_ON_WIN32
45 animia::internal::win32::GetProcessName(pid, name);
46 #endif
47
48 Player player;
49 if (!ProcessInPlayers(players, name, player))
50 continue;
51
52 Result result;
53 result.process.pid = pid;
54 result.process.name = name;
55 result.player = player;
56 results.push_back(result);
57 }
58
59 return internal::ApplyStrategies(results);
60 }
61
62 }