#include #include #include #include "visualdl/backend/logic/sdk.h" namespace py = pybind11; namespace vs = visualdl; PYBIND11_PLUGIN(core) { py::module m("core", "C++ core of VisualDL"); // m.doc() = "visualdl python core API"; py::class_(m, "Tablet") // other member setter and getter .def("record_buffer", &vs::TabletHelper::record_buffer) .def("records_size", &vs::TabletHelper::records_size) .def("buffer", &vs::TabletHelper::buffer) .def("human_readable_buffer", &vs::TabletHelper::human_readable_buffer) .def("set_buffer", (void (vs::TabletHelper::*)(const std::string&)) & vs::TabletHelper::SetBuffer) // scalar interface .def("as_int32_scalar", [](const vs::TabletHelper& self) { return vs::components::ScalarHelper(&self.data()); }) .def("as_int64_scalar", [](const vs::TabletHelper& self) { return vs::components::ScalarHelper(&self.data()); }) .def("as_float_scalar", [](const vs::TabletHelper& self) { return vs::components::ScalarHelper(&self.data()); }) .def("as_double_scalar", [](const vs::TabletHelper& self) { return vs::components::ScalarHelper(&self.data()); }); py::class_(m, "Storage") .def("timestamp", &vs::StorageHelper::timestamp) .def("dir", &vs::StorageHelper::dir) .def("set_dir", &vs::StorageHelper::SetDir) .def("tablets_size", &vs::StorageHelper::tablets_size) .def("buffer", &vs::StorageHelper::buffer) .def("human_readable_buffer", &vs::StorageHelper::human_readable_buffer) .def("set_buffer", (void (vs::StorageHelper::*)(const std::string&)) & vs::StorageHelper::SetBuffer); py::class_(m, "Im") .def("storage", &vs::ImHelper::storage) .def("tablet", &vs::ImHelper::tablet) .def("add_tablet", &vs::ImHelper::AddTablet) .def("persist_to_disk", &vs::ImHelper::PersistToDisk) .def("clear_tablets", &vs::ImHelper::ClearTablets); m.def("start_read_service", &vs::start_read_service, "global information-maintainer object."); m.def("start_write_service", &vs::start_write_service, "global information-maintainer object."); m.def("im", &vs::im); m.def("stop_threads", &vs::stop_threads); // interfaces for components #define ADD_SCALAR_TYPED_INTERFACE(T, name__) \ py::class_>(m, #name__) \ .def("add_record", &vs::components::ScalarHelper::AddRecord) \ .def("set_captions", &vs::components::ScalarHelper::SetCaptions) \ .def("get_records", &vs::components::ScalarHelper::GetRecords) \ .def("get_captions", &vs::components::ScalarHelper::GetCaptions) \ .def("get_ids", &vs::components::ScalarHelper::GetIds) \ .def("get_record_size", &vs::components::ScalarHelper::GetSize) \ .def("get_timestamps", &vs::components::ScalarHelper::GetTimestamps); ADD_SCALAR_TYPED_INTERFACE(int32_t, ScalarInt32); ADD_SCALAR_TYPED_INTERFACE(int64_t, ScalarInt64); ADD_SCALAR_TYPED_INTERFACE(float, ScalarFloat); ADD_SCALAR_TYPED_INTERFACE(double, ScalarDouble); #undef ADD_SCALAR_TYPED_INTERFACE }