Skip to content

Commit

Permalink
Rework async interface internal metaclasses
Browse files Browse the repository at this point in the history
Instead of multiple different _private attributes use only two:

* `_dbus`: contains either remote objects metadata such as service
  name, object path and attached bus or local object metadata.
* `_dbus_meta`: contains interface class metadata such as D-Bus
  member names to python attributes and the reverse.

All descriptor protocols now return different classes based on
if the D-Bus element was accessed from a proxy or local object.
However, the API should remain the same.
  • Loading branch information
igo95862 committed Dec 16, 2023
1 parent 1066153 commit 0bd93c3
Show file tree
Hide file tree
Showing 10 changed files with 653 additions and 450 deletions.
18 changes: 9 additions & 9 deletions src/sdbus/autodoc.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,12 @@

from sphinx.ext.autodoc import AttributeDocumenter, MethodDocumenter

from .dbus_proxy_async_method import DbusMethodAsyncBinded
from .dbus_proxy_async_method import DbusMethodAsyncClassBind
from .dbus_proxy_async_property import (
DbusPropertyAsync,
DbusPropertyAsyncBinded,
DbusPropertyAsyncClassBind,
)
from .dbus_proxy_async_signal import DbusSignalAsync, DbusSignalBinded
from .dbus_proxy_async_signal import DbusSignalAsync, DbusSignalAsyncClassBind

if TYPE_CHECKING:
from typing import Any, Dict
Expand All @@ -38,13 +38,13 @@

class DbusMethodDocumenter(MethodDocumenter):

objtype = 'DbusMethodAsyncBinded'
objtype = 'DbusMethodAsyncClassBind'
directivetype = 'method'
priority = 100 + MethodDocumenter.priority

@classmethod
def can_document_member(cls, member: Any, *args: Any) -> bool:
return isinstance(member, DbusMethodAsyncBinded)
return isinstance(member, DbusMethodAsyncClassBind)

def import_object(self, raiseerror: bool = False) -> bool:
self.objpath.append('dbus_method')
Expand All @@ -68,13 +68,13 @@ def add_content(self,

class DbusPropertyDocumenter(AttributeDocumenter):

objtype = 'DbusPropertyAsyncBinded'
objtype = 'DbusPropertyAsyncClassBind'
directivetype = 'attribute'
priority = 100 + AttributeDocumenter.priority

@classmethod
def can_document_member(cls, member: Any, *args: Any) -> bool:
return isinstance(member, DbusPropertyAsyncBinded)
return isinstance(member, DbusPropertyAsyncClassBind)

def import_object(self, raiseerror: bool = False) -> bool:

Expand Down Expand Up @@ -109,13 +109,13 @@ def add_content(self,

class DbusSignalDocumenter(AttributeDocumenter):

objtype = 'DbusSignalBinded'
objtype = 'DbusSignalAsyncClassBind'
directivetype = 'attribute'
priority = 100 + AttributeDocumenter.priority

@classmethod
def can_document_member(cls, member: Any, *args: Any) -> bool:
return isinstance(member, DbusSignalBinded)
return isinstance(member, DbusSignalAsyncClassBind)

def import_object(self, raiseerror: bool = False) -> bool:

Expand Down
12 changes: 11 additions & 1 deletion src/sdbus/dbus_common_elements.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
from .sd_bus_internals import is_interface_name_valid, is_member_name_valid

if TYPE_CHECKING:
from asyncio import Queue
from types import FunctionType
from typing import (
Any,
Expand All @@ -45,7 +46,7 @@

T = TypeVar('T')

from .sd_bus_internals import SdBus
from .sd_bus_internals import SdBus, SdBusInterface


class DbusSomethingCommon:
Expand Down Expand Up @@ -318,6 +319,15 @@ def __init__(
)


class DbusLocalObjectMeta:
def __init__(self) -> None:
self.activated_interfaces: List[SdBusInterface] = []
self.serving_object_path: Optional[str] = None
self.attached_bus: Optional[SdBus] = None
self.local_signal_queues: Dict[
Tuple[str, str], Set[Queue[Any]]] = {}


class DbusClassMeta:
def __init__(self) -> None:
self.dbus_member_to_python_attr: Dict[str, str] = {}
Expand Down

0 comments on commit 0bd93c3

Please sign in to comment.