changeset 146:d8a61e7e2a36

dep/animia: move fd stuff to a new fd.cc, don't force the user to include windows.h
author Paper <mrpapersonic@gmail.com>
date Mon, 13 Nov 2023 13:52:58 -0500
parents 8e9b71970bda
children 6fdf0632c003
files dep/animia/CMakeLists.txt dep/animia/include/animia.h dep/animia/include/animia/fd.h dep/animia/include/animia/types.h dep/animia/src/animia.cc dep/animia/src/fd.cc dep/animia/src/fd/bsd.cc dep/animia/src/player.cc
diffstat 8 files changed, 42 insertions(+), 38 deletions(-) [+]
line wrap: on
line diff
--- a/dep/animia/CMakeLists.txt	Sun Nov 12 18:38:38 2023 -0500
+++ b/dep/animia/CMakeLists.txt	Mon Nov 13 13:52:58 2023 -0500
@@ -6,6 +6,7 @@
 	src/player.cc
 	src/util.cc
 	src/strategist.cc
+	src/fd.cc
 )
 
 if(LINUX)
--- a/dep/animia/include/animia.h	Sun Nov 12 18:38:38 2023 -0500
+++ b/dep/animia/include/animia.h	Mon Nov 13 13:52:58 2023 -0500
@@ -7,8 +7,6 @@
 
 namespace animia {
 
-/* pid_t should be DWORD on windows, and defined by the system
-   anywhere else */
 struct Process {
 	internal::pid_t pid = 0;
 	std::string name;
@@ -23,7 +21,7 @@
 struct Result {
 	Player player;
 	Process process;
-	//Window window;
+	Window window; // unused with file descriptors
 	std::vector<Media> media;
 };
 
--- a/dep/animia/include/animia/fd.h	Sun Nov 12 18:38:38 2023 -0500
+++ b/dep/animia/include/animia/fd.h	Mon Nov 13 13:52:58 2023 -0500
@@ -18,7 +18,7 @@
 		virtual bool EnumerateOpenFiles(const std::set<pid_t>& pids, std::vector<std::tuple<pid_t, std::string>>& files) { return false; }
 };
 
-extern BaseFdTools& fd; // defined in animia.cc
+extern BaseFdTools& fd; // defined in fd.cc
 
 }
 
--- a/dep/animia/include/animia/types.h	Sun Nov 12 18:38:38 2023 -0500
+++ b/dep/animia/include/animia/types.h	Mon Nov 13 13:52:58 2023 -0500
@@ -1,18 +1,18 @@
 #ifndef __animia__animia__types_h
 #define __animia__animia__types_h
 
-#include "animia/os.h"
-
-#ifdef ANIMIA_ON_WIN32
-#	include <windows.h>
+/* define this as unsigned long (DWORD) on win32 so we
+   don't force the user to include <windows.h> or <IntBase.h> */
+#ifdef _WIN32
 namespace animia::internal {
-	typedef DWORD pid_t;
+	typedef unsigned long pid_t;
 }
 #else
+/* <sys/types.h> shouldn't be that big, right? */
 #	include <sys/types.h>
 namespace animia::internal {
 	typedef ::pid_t pid_t;
 }
 #endif
 
-#endif // __animia__animia__types_h
\ No newline at end of file
+#endif // __animia__animia__types_h
--- a/dep/animia/src/animia.cc	Sun Nov 12 18:38:38 2023 -0500
+++ b/dep/animia/src/animia.cc	Mon Nov 13 13:52:58 2023 -0500
@@ -1,35 +1,11 @@
 #include <string>
 #include <vector>
+#include <set>
 
 #include "animia.h"
 #include "animia/strategies.h"
 #include "animia/types.h"
-
-#ifdef ANIMIA_ON_WIN32
-#	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 "animia/fd.h"
 
 namespace animia {
 
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/dep/animia/src/fd.cc	Mon Nov 13 13:52:58 2023 -0500
@@ -0,0 +1,27 @@
+#include "animia/fd.h"
+
+#ifdef ANIMIA_ON_WIN32
+#	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;
+
+}
--- a/dep/animia/src/fd/bsd.cc	Sun Nov 12 18:38:38 2023 -0500
+++ b/dep/animia/src/fd/bsd.cc	Mon Nov 13 13:52:58 2023 -0500
@@ -25,7 +25,9 @@
 
 /* this is a cleaned up version of a function from... Apple?
    ...anyway, what it essentially does is gets the size and stuff from
-   sysctl() and reserves the space in a vector to store the PIDs */
+   sysctl() and reserves the space in a vector to store the PIDs
+
+	TODO: https://kaashif.co.uk/2015/06/18/how-to-get-a-list-of-processes-on-openbsd-in-c/ */
 bool UnixFdTools::GetAllPids(std::set<pid_t>& pids) {
 	struct kinfo_proc* result = NULL;
 	size_t length = 0;
--- a/dep/animia/src/player.cc	Sun Nov 12 18:38:38 2023 -0500
+++ b/dep/animia/src/player.cc	Mon Nov 13 13:52:58 2023 -0500
@@ -195,4 +195,4 @@
 	return ParsePlayersData(data, players);
 }
 
-}  // namespace anisthesia
\ No newline at end of file
+}  // namespace animia