Skip to content

resource πŸ”—

Interface to the struct vaccel_resource C object.

Resource πŸ”—

Resource(path: str | Path, 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

path πŸ”—

str | Path

The path to the file 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, path: str | Path, type_: ResourceType):
    """Initializes a new `Resource` object.

    Args:
        path: The path to the file that will be represented by the resource.
        type_: The type of the resource.
    """
    # TODO: Allow the use of lists for path  # noqa: FIX002
    self._path = str(path)
    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
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.
    """
    ret = lib.vaccel_resource_register(
        self._c_obj,
        session._c_ptr,
    )
    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
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.
    """
    ret = lib.vaccel_resource_unregister(
        self._c_obj,
        session._c_ptr,
    )
    if ret != 0:
        raise FFIError(
            ret,
            f"Could not unregister resource {self.id()} "
            f"from session {session.id()}",
        )
    self.__sessions.remove(session)