mirror of
https://github.com/varun-r-mallya/pylibbpf.git
synced 2025-12-31 20:36:26 +00:00
Expose classes and perform struct conversion in __init__
This commit is contained in:
41
__init__.py
Normal file
41
__init__.py
Normal file
@ -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",
|
||||
]
|
||||
Reference in New Issue
Block a user