-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathhost_bindings.cpp
More file actions
157 lines (128 loc) · 9.96 KB
/
host_bindings.cpp
File metadata and controls
157 lines (128 loc) · 9.96 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
// SPDX-License-Identifier: BSD-3-Clause
// Copyright (c) 2026 Fernando Sahmkow
//
// AUTOGENERATED by tools/codegen — do not edit by hand.
// Regenerate via: python -m tools.codegen.codegen host --backend pybind11
//
// Source headers and `@bind` annotations live under include/whiteout/.
//
// Include order matters here:
// 1. pybind11/pybind11.h sets up the base library
// 2. project headers define whiteout::u32 et al used inside MAKE_OPAQUE
// 3. PYBIND11_MAKE_OPAQUE opts out of stl.h's auto-conversion for our vectors
// 4. pybind11/stl.h, stl_bind.h honor the opaque declarations
#include <pybind11/pybind11.h>
#include <array>
#include <cstdint>
#include <optional>
#include <sstream>
#include <string>
#include <vector>
#include <whiteout/interfaces.h>
#include <whiteout/utils/os_file_system.h>
#include <whiteout/utils/simple_thread_pool.h>
#include <whiteout/utils/simple_http_handler.h>
#include <whiteout/utils/job_group.h>
#include <whiteout/utils/blizzard_game_finder.h>
PYBIND11_MAKE_OPAQUE(std::vector<whiteout::u8>);
PYBIND11_MAKE_OPAQUE(std::vector<whiteout::utils::BlizzardGameInfo>);
PYBIND11_MAKE_OPAQUE(std::vector<std::string>);
#include <pybind11/stl.h>
#include <pybind11/stl_bind.h>
#include <pybind11/operators.h>
#include <pybind11/numpy.h>
namespace py = pybind11;
void bind_host(py::module_& m) {
py::enum_<whiteout::utils::BlizzardGame>(m, "BlizzardGame", R"doc(Known Blizzard game identifiers.
The `Unknown` value is used for games discovered via generic heuristics (e.g. the Windows Uninstall registry scan) that don't match a known title. In that case, inspect the `name` field of the result for the display name.)doc")
.value("UNKNOWN", whiteout::utils::BlizzardGame::Unknown)
.value("WORLD_OF_WARCRAFT", whiteout::utils::BlizzardGame::WorldOfWarcraft)
.value("WORLD_OF_WARCRAFT_CLASSIC", whiteout::utils::BlizzardGame::WorldOfWarcraftClassic)
.value("WORLD_OF_WARCRAFT_CLASSIC_ERA", whiteout::utils::BlizzardGame::WorldOfWarcraftClassicEra)
.value("WARCRAFT_II_BATTLE_NET_EDITION", whiteout::utils::BlizzardGame::WarcraftIIBattleNetEdition)
.value("WARCRAFT_II_REMASTERED", whiteout::utils::BlizzardGame::WarcraftIIRemastered)
.value("WARCRAFT_III", whiteout::utils::BlizzardGame::WarcraftIII)
.value("WARCRAFT_III_REFORGED", whiteout::utils::BlizzardGame::WarcraftIIIReforged)
.value("STAR_CRAFT", whiteout::utils::BlizzardGame::StarCraft)
.value("STAR_CRAFT_REMASTERED", whiteout::utils::BlizzardGame::StarCraftRemastered)
.value("STAR_CRAFT_II", whiteout::utils::BlizzardGame::StarCraftII)
.value("DIABLO", whiteout::utils::BlizzardGame::Diablo)
.value("DIABLO_II", whiteout::utils::BlizzardGame::DiabloII)
.value("DIABLO_II_RESURRECTED", whiteout::utils::BlizzardGame::DiabloIIResurrected)
.value("DIABLO_III", whiteout::utils::BlizzardGame::DiabloIII)
.value("DIABLO_IV", whiteout::utils::BlizzardGame::DiabloIV)
.value("DIABLO_IMMORTAL", whiteout::utils::BlizzardGame::DiabloImmortal)
.value("HEROES_OF_THE_STORM", whiteout::utils::BlizzardGame::HeroesOfTheStorm)
.value("OVERWATCH2", whiteout::utils::BlizzardGame::Overwatch2)
.value("HEARTHSTONE", whiteout::utils::BlizzardGame::Hearthstone)
.value("BLIZZARD_ARCADE_COLLECTION", whiteout::utils::BlizzardGame::BlizzardArcadeCollection)
.value("BATTLE_NET", whiteout::utils::BlizzardGame::BattleNet)
;
py::class_<whiteout::utils::BlizzardGameInfo>(m, "BlizzardGameInfo", R"doc(Result entry from findBlizzardGames().)doc")
.def(py::init<>())
.def_readwrite("game", &whiteout::utils::BlizzardGameInfo::game, R"doc(Identified game. `Unknown` if not recognized.)doc")
.def_readwrite("name", &whiteout::utils::BlizzardGameInfo::name, R"doc(Human-readable display name.)doc")
.def_readwrite("path", &whiteout::utils::BlizzardGameInfo::path, R"doc(Install directory path.)doc")
;
py::class_<whiteout::interfaces::CascFileSystem>(m, "CascFileSystem", R"doc(java_package=whiteout.utils — abstract file system that resolves files by numeric data ID (e.g. CASC).)doc")
.def("read_file",
[](whiteout::interfaces::CascFileSystem& self, whiteout::u32 fileId) {
auto __v = self.readFile(fileId);
return py::bytes(
reinterpret_cast<const char*>(__v.data()), __v.size());
}, py::arg("fileId"), R"doc(Read the entire contents of a file by its numeric data ID.)doc")
.def("reserve_file_id", &whiteout::interfaces::CascFileSystem::reserveFileId, py::arg("path"), R"doc(Resolve a path to a numeric file ID (nullable).)doc")
.def("write_file", &whiteout::interfaces::CascFileSystem::writeFile, py::arg("fileId"), py::arg("data"), R"doc(Write a file by its numeric data ID. Returns true on success.)doc")
.def("file_exists", &whiteout::interfaces::CascFileSystem::fileExists, py::arg("fileId"), R"doc(Check if a file with the given data ID exists.)doc")
;
py::class_<whiteout::utils::OsFileSystem, whiteout::interfaces::VirtualPathFileSystem>(m, "OsFileSystem", R"doc(VirtualPathFileSystem implementation backed by the OS filesystem.
All paths passed to readFile() / fileExists() are resolved relative to the root directory supplied at construction time.
Example: utils::OsFileSystem fs("C:/Games/Warcraft III/Data"); auto data = fs.readFile("units/human/arthas/arthas.mdx");
java_package=whiteout.utils)doc")
.def(py::init<std::string>(), py::arg("root_path"))
.def("read_file",
[](whiteout::utils::OsFileSystem& self, const std::string& path) {
auto __v = self.readFile(path);
return py::bytes(
reinterpret_cast<const char*>(__v.data()), __v.size());
}, py::arg("path"), R"doc(Read a file at `rootPath / path`. Returns an empty vector if not found.)doc")
.def("write_file", &whiteout::utils::OsFileSystem::writeFile, py::arg("path"), py::arg("data"))
.def("file_exists", &whiteout::utils::OsFileSystem::fileExists, py::arg("path"))
;
py::class_<whiteout::utils::SimpleThreadPool, whiteout::interfaces::WorkerPool>(m, "SimpleThreadPool", R"doc(Basic CPU worker pool implementation of interfaces::WorkerPool.
Tasks are executed by a fixed number of worker threads created at construction time.)doc")
.def(py::init<size_t>(), py::arg("n_threads"))
.def("wait_idle", &whiteout::utils::SimpleThreadPool::waitIdle, R"doc(Block until the pool has no pending or running tasks.)doc")
.def("thread_count", &whiteout::utils::SimpleThreadPool::threadCount, R"doc(Number of worker threads in this pool.)doc")
;
py::class_<whiteout::utils::SimpleHttpHandler, whiteout::interfaces::HttpHandler>(m, "SimpleHttpHandler", R"doc(Basic HTTP handler with two platform backends: * Windows — WinHTTP * Other — libcurl (linked at build time)
Requests are dispatched asynchronously onto an internal thread pool; each worker owns one backend handle and keeps its connection cache warm. Thread-safe: multiple threads may call getAsync / getRangeAsync concurrently.)doc")
.def(py::init<>())
.def(py::init<size_t>(), py::arg("n_threads"))
.def("capabilities", &whiteout::utils::SimpleHttpHandler::capabilities, R"doc(Reported handler capability flags.)doc")
;
py::class_<whiteout::utils::JobGroup>(m, "JobGroup", R"doc(Thread-safe counter-based completion primitive for grouped jobs.
A JobGroup starts with zero pending jobs. Call add() before submitting work, then call done() once per completed job. wait() blocks until the pending count reaches zero.
Typical usage pattern: 1. add(N) 2. submit N tasks 3. each task calls done() on completion 4. wait() to join the group)doc")
.def(py::init<>())
.def("add", &whiteout::utils::JobGroup::add, py::arg("n") = size_t{}, R"doc(Increment the number of pending jobs.
@param n Number of jobs to add to the group.)doc")
.def("done", &whiteout::utils::JobGroup::done, R"doc(Mark one pending job as completed.
When the pending count reaches zero, all waiters are notified.
@note done() calls must be balanced with prior add() calls.)doc")
.def("await", &whiteout::utils::JobGroup::wait, R"doc(Java's Object.wait() is final so the generated wrapper would fail to compile; expose as await(). Block until all pending jobs in the group are completed.)doc")
.def("is_ready", &whiteout::utils::JobGroup::isReady, R"doc(Check whether the group has no pending jobs.
@return true if pending count is zero, false otherwise.)doc")
;
py::class_<whiteout::utils::BlizzardGameInfoList>(m, "BlizzardGameInfoList", R"doc(Opaque handle around `std::vector<BlizzardGameInfo>` returned by `BlizzardGameFinder::findAll()`. Iterate via size() + at(index).)doc")
.def(py::init<std::vector<whiteout::utils::BlizzardGameInfo>>(), py::arg("games"))
.def("size", &whiteout::utils::BlizzardGameInfoList::size, R"doc(Number of game entries in the list.)doc")
.def("at", &whiteout::utils::BlizzardGameInfoList::at, py::arg("index"), R"doc(Borrowed reference to entry at @p index. Valid until this list is destroyed.)doc")
;
py::class_<whiteout::utils::BlizzardGameFinder>(m, "BlizzardGameFinder", R"doc(Static-method facade around the free functions above so they bind through the class-method codegen path.)doc")
.def_static("find_all", &whiteout::utils::BlizzardGameFinder::findAll, R"doc(Discover installed Blizzard games. See `findBlizzardGames()`.)doc")
.def_static("from_name", &whiteout::utils::BlizzardGameFinder::fromName, py::arg("name"), R"doc(Map a display name to a BlizzardGame enum. See `blizzardGameFromName()`.)doc")
.def_static("to_name", &whiteout::utils::BlizzardGameFinder::toName, py::arg("game"), R"doc(Get the canonical display name for a known game. See `blizzardGameToName()`. Returns empty string for Unknown.)doc")
;
py::bind_vector<std::vector<whiteout::utils::BlizzardGameInfo>>(m, "VectorBlizzardGameInfo");
}