diff --git a/__init__.py b/__init__.py new file mode 100644 index 0000000..d679661 --- /dev/null +++ b/__init__.py @@ -0,0 +1,41 @@ +import logging +from .pylibbpf import ( + BpfObject as _BpfObject, # C++ object (internal) + BpfProgram, + BpfMap, + PerfEventArray, + StructParser, + BpfException, +) +from .wrappers import BpfObjectWrapper +from .ir_to_ctypes import convert_structs_to_ctypes, is_pythonbpf_structs + +logger = logging.getLogger(__name__) + + +class BpfObject(BpfObjectWrapper): + """BpfObject with automatic struct conversion""" + + def __init__(self, object_path: str, structs=None): + """Create a BPF object""" + if structs is None: + structs = {} + elif is_pythonbpf_structs(structs): + logger.info(f"Auto-converting {len(structs)} PythonBPF structs to ctypes") + structs = convert_structs_to_ctypes(structs) + + # Create C++ BpfObject with converted structs + cpp_obj = _BpfObject(object_path, structs) + + # Initialize wrapper + super().__init__(cpp_obj) + + +__all__ = [ + "BpfObject", + "BpfProgram", + "BpfMap", + "PerfEventArray", + "StructParser", + "BpfException", +]