lokinet/pybind/llarp/tooling/router_hive.cpp

56 lines
1.9 KiB
C++
Raw Normal View History

#include <common.hpp>
#include <pybind11/stl.h>
#include <pybind11/iostream.h>
2020-03-03 00:42:06 +00:00
#include <llarp/tooling/router_hive.hpp>
#include <llarp/router/abstractrouter.hpp>
#include <llarp.hpp>
2020-02-27 21:30:45 +00:00
namespace tooling
{
void
RouterHive_Init(py::module& mod)
{
using RouterHive_ptr = std::shared_ptr<RouterHive>;
using Context_ptr = RouterHive::Context_ptr;
using ContextVisitor = std::function<void(Context_ptr)>;
py::class_<RouterHive, RouterHive_ptr>(mod, "RouterHive")
2020-02-27 21:30:45 +00:00
.def(py::init<>())
.def("AddRelay", &RouterHive::AddRelay)
.def("AddClient", &RouterHive::AddClient)
.def("StartRelays", &RouterHive::StartRelays)
.def("StartClients", &RouterHive::StartClients)
.def("StopAll", &RouterHive::StopRouters)
.def(
"ForEachRelay",
[](RouterHive& hive, ContextVisitor visit) {
hive.ForEachRelay([visit](Context_ptr ctx) {
py::gil_scoped_acquire acquire;
visit(std::move(ctx));
});
})
.def(
"ForEachClient",
[](RouterHive& hive, ContextVisitor visit) {
hive.ForEachClient([visit](Context_ptr ctx) {
py::gil_scoped_acquire acquire;
visit(std::move(ctx));
});
})
.def(
"ForEachRouter",
[](RouterHive& hive, ContextVisitor visit) {
hive.ForEachRouter([visit](Context_ptr ctx) {
py::gil_scoped_acquire acquire;
visit(std::move(ctx));
});
})
2020-03-03 00:42:06 +00:00
.def("GetNextEvent", &RouterHive::GetNextEvent)
.def("GetAllEvents", &RouterHive::GetAllEvents)
.def("RelayConnectedRelays", &RouterHive::RelayConnectedRelays)
.def("GetRelayRCs", &RouterHive::GetRelayRCs)
.def("GetRelay", &RouterHive::GetRelay);
2020-02-27 21:30:45 +00:00
}
2020-03-07 01:20:11 +00:00
} // namespace tooling