diff 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
line wrap: on
line diff
--- a/dep/animia/src/animia.cc	Sun Nov 12 04:53:19 2023 -0500
+++ b/dep/animia/src/animia.cc	Sun Nov 12 16:43:07 2023 -0500
@@ -4,11 +4,35 @@
 #include <windows.h>
 
 #include "animia.h"
-#include "animia/util.h"
 #include "animia/strategies.h"
+#include "animia/types.h"
+
 #ifdef ANIMIA_ON_WIN32
-#include "animia/fd/win32.h"
+#	include "animia/fd/win32.h"
+#elif defined(ANIMIA_ON_LINUX)
+#	include "animia/fd/linux.h"
+#elif defined(ANIMIA_ON_UNIX)
+#	include "animia/fd/bsd.h"
 #endif
+
+namespace animia::internal {
+
+/* really stupid hack to get fd to point to the right
+   thing */
+#ifdef ANIMIA_ON_WIN32
+win32::Win32FdTools os_fd;
+#elif defined(ANIMIA_ON_LINUX)
+linux::LinuxFdTools os_fd;
+#elif defined(ANIMIA_ON_UNIX)
+unix::UnixFdTools os_fd;
+#else
+BaseFdTools os_fd;
+#endif
+
+BaseFdTools& fd = os_fd;
+
+}
+
 #include <iostream>
 
 namespace animia {
@@ -26,24 +50,14 @@
 }
 
 bool GetResults(const std::vector<Player>& players, std::vector<Result>& results) {
-	std::set<pid_t> pids;
+	std::set<internal::pid_t> pids;
 
-#ifdef ANIMIA_ON_WIN32
-	/* todo: make these functions also return process names in a tuple,
-	   cause the win32 api gives it to us for free! */
-	if (!internal::win32::GetAllPids(pids))
-#elif ANIMIA_ON_LINUX
-	if (!internal::linux::GetAllPids(pids))
-#elif ANIMIA_ON_UNIX
-	if (!internal::unix::GetAllPids(pids))
-#endif
+	if (!internal::fd.GetAllPids(pids))
 		return false;
 
 	for (const auto& pid : pids) {
 		std::string name;
-#ifdef ANIMIA_ON_WIN32
-		animia::internal::win32::GetProcessName(pid, name);
-#endif
+		internal::fd.GetProcessName(pid, name);
 
 		Player player;
 		if (!ProcessInPlayers(players, name, player))