Skip to content

Commit 23cafa4

Browse files
committed
Expose classes and perform struct conversion in __init__
1 parent 30021e8 commit 23cafa4

File tree

1 file changed

+41
-0
lines changed

1 file changed

+41
-0
lines changed

__init__.py

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
import logging
2+
from .pylibbpf import (
3+
BpfObject as _BpfObject, # C++ object (internal)
4+
BpfProgram,
5+
BpfMap,
6+
PerfEventArray,
7+
StructParser,
8+
BpfException,
9+
)
10+
from .wrappers import BpfObjectWrapper
11+
from .ir_to_ctypes import convert_structs_to_ctypes, is_pythonbpf_structs
12+
13+
logger = logging.getLogger(__name__)
14+
15+
16+
class BpfObject(BpfObjectWrapper):
17+
"""BpfObject with automatic struct conversion"""
18+
19+
def __init__(self, object_path: str, structs=None):
20+
"""Create a BPF object"""
21+
if structs is None:
22+
structs = {}
23+
elif is_pythonbpf_structs(structs):
24+
logger.info(f"Auto-converting {len(structs)} PythonBPF structs to ctypes")
25+
structs = convert_structs_to_ctypes(structs)
26+
27+
# Create C++ BpfObject with converted structs
28+
cpp_obj = _BpfObject(object_path, structs)
29+
30+
# Initialize wrapper
31+
super().__init__(cpp_obj)
32+
33+
34+
__all__ = [
35+
"BpfObject",
36+
"BpfProgram",
37+
"BpfMap",
38+
"PerfEventArray",
39+
"StructParser",
40+
"BpfException",
41+
]

0 commit comments

Comments
 (0)