pybind.cc 3.4 KB
Newer Older
S
superjom 已提交
1 2
#include <ctype.h>
#include <pybind11/pybind11.h>
S
superjom 已提交
3
#include <pybind11/stl.h>
S
superjom 已提交
4 5 6 7 8 9

#include "visualdl/backend/logic/sdk.h"

namespace py = pybind11;
namespace vs = visualdl;

Q
Qiao Longfei 已提交
10 11 12
PYBIND11_PLUGIN(core) {
  py::module m("core", "C++ core of VisualDL");
  //  m.doc() = "visualdl python core API";
S
superjom 已提交
13 14 15 16 17 18 19 20 21

  py::class_<vs::TabletHelper>(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&)) &
S
superjom 已提交
22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38
               vs::TabletHelper::SetBuffer)
      // scalar interface
      .def("as_int32_scalar",
           [](const vs::TabletHelper& self) {
             return vs::components::ScalarHelper<int32_t>(&self.data());
           })
      .def("as_int64_scalar",
           [](const vs::TabletHelper& self) {
             return vs::components::ScalarHelper<int64_t>(&self.data());
           })
      .def("as_float_scalar",
           [](const vs::TabletHelper& self) {
             return vs::components::ScalarHelper<float>(&self.data());
           })
      .def("as_double_scalar", [](const vs::TabletHelper& self) {
        return vs::components::ScalarHelper<double>(&self.data());
      });
S
superjom 已提交
39 40 41 42

  py::class_<vs::StorageHelper>(m, "Storage")
      .def("timestamp", &vs::StorageHelper::timestamp)
      .def("dir", &vs::StorageHelper::dir)
S
superjom 已提交
43
      .def("set_dir", &vs::StorageHelper::SetDir)
S
superjom 已提交
44 45 46 47 48 49 50 51 52 53
      .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_<vs::ImHelper>(m, "Im")
      .def("storage", &vs::ImHelper::storage)
      .def("tablet", &vs::ImHelper::tablet)
S
superjom 已提交
54 55 56
      .def("add_tablet", &vs::ImHelper::AddTablet)
      .def("persist_to_disk", &vs::ImHelper::PersistToDisk)
      .def("clear_tablets", &vs::ImHelper::ClearTablets);
S
superjom 已提交
57

S
superjom 已提交
58 59 60 61 62 63 64 65
  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::StopThreads);
S
superjom 已提交
66 67 68 69 70 71 72 73 74

// interfaces for components
#define ADD_SCALAR_TYPED_INTERFACE(T, name__)                             \
  py::class_<vs::components::ScalarHelper<T>>(m, #name__)                 \
      .def("add_record", &vs::components::ScalarHelper<T>::AddRecord)     \
      .def("set_captions", &vs::components::ScalarHelper<T>::SetCaptions) \
      .def("get_records", &vs::components::ScalarHelper<T>::GetRecords)   \
      .def("get_captions", &vs::components::ScalarHelper<T>::GetCaptions) \
      .def("get_ids", &vs::components::ScalarHelper<T>::GetIds)           \
S
superjom 已提交
75
      .def("get_record_size", &vs::components::ScalarHelper<T>::GetSize)  \
S
superjom 已提交
76 77 78 79 80 81
      .def("get_timestamps", &vs::components::ScalarHelper<T>::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
S
superjom 已提交
82
}