Add basic class along with exception and attach

Signed-off-by: varun-r-mallya <varunrmallya@gmail.com>
This commit is contained in:
2025-09-21 14:27:07 +05:30
parent ecefff6b81
commit 3c8c6deb68
8 changed files with 156 additions and 53 deletions

44
src/bindings/main.cpp Normal file
View 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
}