mirror of
https://github.com/varun-r-mallya/Python-BPF.git
synced 2025-12-31 21:06:25 +00:00
Move HelperHandlerRegistry to helper_registry.py
This commit is contained in:
@ -1,4 +1,5 @@
|
|||||||
from .helper_utils import HelperHandlerRegistry, reset_scratch_pool
|
from .helper_registry import HelperHandlerRegistry
|
||||||
|
from .helper_utils import reset_scratch_pool
|
||||||
from .bpf_helper_handler import handle_helper_call
|
from .bpf_helper_handler import handle_helper_call
|
||||||
from .helpers import ktime, pid, deref, XDP_DROP, XDP_PASS
|
from .helpers import ktime, pid, deref, XDP_DROP, XDP_PASS
|
||||||
|
|
||||||
|
|||||||
@ -1,8 +1,9 @@
|
|||||||
import ast
|
import ast
|
||||||
from llvmlite import ir
|
from llvmlite import ir
|
||||||
from enum import Enum
|
from enum import Enum
|
||||||
|
|
||||||
|
from .helper_registry import HelperHandlerRegistry
|
||||||
from .helper_utils import (
|
from .helper_utils import (
|
||||||
HelperHandlerRegistry,
|
|
||||||
get_or_create_ptr_from_arg,
|
get_or_create_ptr_from_arg,
|
||||||
get_flags_val,
|
get_flags_val,
|
||||||
handle_fstring_print,
|
handle_fstring_print,
|
||||||
|
|||||||
27
pythonbpf/helper/helper_registry.py
Normal file
27
pythonbpf/helper/helper_registry.py
Normal file
@ -0,0 +1,27 @@
|
|||||||
|
from typing import Callable
|
||||||
|
|
||||||
|
|
||||||
|
class HelperHandlerRegistry:
|
||||||
|
"""Registry for BPF helpers"""
|
||||||
|
|
||||||
|
_handlers: dict[str, Callable] = {}
|
||||||
|
|
||||||
|
@classmethod
|
||||||
|
def register(cls, helper_name):
|
||||||
|
"""Decorator to register a handler function for a helper"""
|
||||||
|
|
||||||
|
def decorator(func):
|
||||||
|
cls._handlers[helper_name] = func
|
||||||
|
return func
|
||||||
|
|
||||||
|
return decorator
|
||||||
|
|
||||||
|
@classmethod
|
||||||
|
def get_handler(cls, helper_name):
|
||||||
|
"""Get the handler function for a helper"""
|
||||||
|
return cls._handlers.get(helper_name)
|
||||||
|
|
||||||
|
@classmethod
|
||||||
|
def has_handler(cls, helper_name):
|
||||||
|
"""Check if a handler function is registered for a helper"""
|
||||||
|
return helper_name in cls._handlers
|
||||||
@ -1,6 +1,5 @@
|
|||||||
import ast
|
import ast
|
||||||
import logging
|
import logging
|
||||||
from collections.abc import Callable
|
|
||||||
|
|
||||||
from llvmlite import ir
|
from llvmlite import ir
|
||||||
from pythonbpf.expr import (
|
from pythonbpf.expr import (
|
||||||
@ -13,32 +12,6 @@ from pythonbpf.expr import (
|
|||||||
logger = logging.getLogger(__name__)
|
logger = logging.getLogger(__name__)
|
||||||
|
|
||||||
|
|
||||||
class HelperHandlerRegistry:
|
|
||||||
"""Registry for BPF helpers"""
|
|
||||||
|
|
||||||
_handlers: dict[str, Callable] = {}
|
|
||||||
|
|
||||||
@classmethod
|
|
||||||
def register(cls, helper_name):
|
|
||||||
"""Decorator to register a handler function for a helper"""
|
|
||||||
|
|
||||||
def decorator(func):
|
|
||||||
cls._handlers[helper_name] = func
|
|
||||||
return func
|
|
||||||
|
|
||||||
return decorator
|
|
||||||
|
|
||||||
@classmethod
|
|
||||||
def get_handler(cls, helper_name):
|
|
||||||
"""Get the handler function for a helper"""
|
|
||||||
return cls._handlers.get(helper_name)
|
|
||||||
|
|
||||||
@classmethod
|
|
||||||
def has_handler(cls, helper_name):
|
|
||||||
"""Check if a handler function is registered for a helper"""
|
|
||||||
return helper_name in cls._handlers
|
|
||||||
|
|
||||||
|
|
||||||
class ScratchPoolManager:
|
class ScratchPoolManager:
|
||||||
"""Manage the temporary helper variables in local_sym_tab"""
|
"""Manage the temporary helper variables in local_sym_tab"""
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user