Skip to content

resource πŸ”—

Interface to the struct vaccel_resource C object.

Resource πŸ”—

Resource(paths: list[Path] | list[str] | Path | str, type_: ResourceType)

Bases: CType

Wrapper for the struct vaccel_resource C object.

Manages the creation and initialization of a C struct vaccel_resource and provides access to it through Python properties.

Inherits

CType: Abstract base class for defining C data types.

Parameters:

Name Type Description Default

paths πŸ”—

list[Path] | list[str] | Path | str

The path(s) to the file(s) that will be represented by the resource.

required

type_ πŸ”—

ResourceType

The type of the resource.

required
Source code in vaccel/resource.py
def __init__(
    self, paths: list[Path] | list[str] | Path | str, type_: ResourceType
):
    """Initializes a new `Resource` object.

    Args:
        paths: The path(s) to the file(s) that will be represented by the
            resource.
        type_: The type of the resource.
    """
    if isinstance(paths, list):
        self._paths = [str(path) for path in paths]
    else:
        self._paths = [str(paths)]
    self._c_paths = CList(self._paths)
    self._type = type_
    self.__sessions = []
    super().__init__()

c_size property πŸ”—

c_size: int

Returns the size of the object in bytes.

id property πŸ”—

id: int

The resource identifier.

Returns:

Type Description
int

The resource's unique ID.

remote_id property πŸ”—

remote_id: int

The remote resource identifier.

Returns:

Type Description
int

The resource's remote ID.

value property πŸ”—

value: CData

Returns the value of the underlying C struct.

Returns:

Type Description
CData

The dereferenced 'struct vaccel_resource`

is_registered πŸ”—

is_registered(session: BaseSession) -> bool

Checks if the resource is registered with the session.

Parameters:

Name Type Description Default

session πŸ”—

BaseSession

The session to check for registration.

required

Returns:

Type Description
bool

True if the resource is registered with the session.

Source code in vaccel/resource.py
def is_registered(self, session: "Session") -> bool:
    """Checks if the resource is registered with the session.

    Args:
        session: The session to check for registration.

    Returns:
        True if the resource is registered with the session.
    """
    return session in self.__sessions

register πŸ”—

register(session: BaseSession) -> None

Register the resource with a session.

Parameters:

Name Type Description Default

session πŸ”—

BaseSession

The session to register the resource with.

required

Raises:

Type Description
FFIError

If resource registration fails.

Source code in vaccel/resource.py
def register(self, session: "Session") -> None:
    """Register the resource with a session.

    Args:
        session: The session to register the resource with.

    Raises:
        FFIError: If resource registration fails.
    """
    ret = lib.vaccel_resource_register(
        self._c_ptr_or_raise,
        session._c_ptr_or_raise,
    )
    if ret != 0:
        raise FFIError(
            ret,
            f"Could not register resource {self.id} "
            f"with session {session.id}",
        )
    self.__sessions.append(session)

unregister πŸ”—

unregister(session: BaseSession) -> None

Unregister the resource from a session.

Parameters:

Name Type Description Default

session πŸ”—

BaseSession

The session to unregister the resource from.

required

Raises:

Type Description
FFIError

If resource unregistration fails.

Source code in vaccel/resource.py
def unregister(self, session: "Session") -> None:
    """Unregister the resource from a session.

    Args:
        session: The session to unregister the resource from.

    Raises:
        FFIError: If resource unregistration fails.
    """
    ret = lib.vaccel_resource_unregister(
        self._c_ptr_or_raise,
        session._c_ptr_or_raise,
    )
    if ret != 0:
        raise FFIError(
            ret,
            f"Could not unregister resource {self.id} "
            f"from session {session.id}",
        )
    self.__sessions.remove(session)