mirror of
https://github.com/varun-r-mallya/pylibbpf.git
synced 2025-12-31 20:36:26 +00:00
Add basic class along with exception and attach
Signed-off-by: varun-r-mallya <varunrmallya@gmail.com>
This commit is contained in:
44
src/bindings/main.cpp
Normal file
44
src/bindings/main.cpp
Normal file
@ -0,0 +1,44 @@
|
||||
#include <pybind11/pybind11.h>
|
||||
#define STRINGIFY(x) #x
|
||||
#define MACRO_STRINGIFY(x) STRINGIFY(x)
|
||||
|
||||
extern "C" {
|
||||
#include "libbpf.h"
|
||||
}
|
||||
#include "core/bpf_program.h"
|
||||
#include "core/bpf_exception.h"
|
||||
|
||||
namespace py = pybind11;
|
||||
|
||||
PYBIND11_MODULE(pylibbpf, m) {
|
||||
m.doc() = R"pbdoc(
|
||||
Pylibbpf - libbpf bindings for Python
|
||||
-----------------------
|
||||
|
||||
.. currentmodule:: pylibbpf
|
||||
|
||||
.. autosummary::
|
||||
:toctree: _generate
|
||||
|
||||
BpfProgram
|
||||
BpfException
|
||||
)pbdoc";
|
||||
|
||||
// Register the custom exception
|
||||
py::register_exception<BpfException>(m, "BpfException");
|
||||
|
||||
py::class_<BpfProgram>(m, "BpfProgram")
|
||||
.def(py::init<const std::string&>())
|
||||
.def(py::init<const std::string&, const std::string&>())
|
||||
.def("load", &BpfProgram::load)
|
||||
.def("attach", &BpfProgram::attach)
|
||||
// .def("detach", &BpfProgram::detach)
|
||||
.def("is_loaded", &BpfProgram::is_loaded)
|
||||
.def("is_attached", &BpfProgram::is_attached);
|
||||
|
||||
#ifdef VERSION_INFO
|
||||
m.attr("__version__") = MACRO_STRINGIFY(VERSION_INFO);
|
||||
#else
|
||||
m.attr("__version__") = "dev";
|
||||
#endif
|
||||
}
|
||||
Reference in New Issue
Block a user