mirror of
https://github.com/tiqi-group/pydase.git
synced 2025-04-23 17:40:02 +02:00
move ProxyClass into separate file
This commit is contained in:
parent
e3b95a8076
commit
6db1652dd3
@ -6,8 +6,8 @@ from typing import TypedDict, cast
|
|||||||
|
|
||||||
import socketio # type: ignore
|
import socketio # type: ignore
|
||||||
|
|
||||||
import pydase.components
|
from pydase.client.proxy_class import ProxyClass
|
||||||
from pydase.client.proxy_loader import ProxyClassMixin, ProxyLoader
|
from pydase.client.proxy_loader import ProxyLoader
|
||||||
from pydase.utils.serialization.deserializer import loads
|
from pydase.utils.serialization.deserializer import loads
|
||||||
from pydase.utils.serialization.types import SerializedDataService, SerializedObject
|
from pydase.utils.serialization.types import SerializedDataService, SerializedObject
|
||||||
|
|
||||||
@ -34,47 +34,6 @@ def asyncio_loop_thread(loop: asyncio.AbstractEventLoop) -> None:
|
|||||||
loop.run_forever()
|
loop.run_forever()
|
||||||
|
|
||||||
|
|
||||||
class ProxyClass(ProxyClassMixin, pydase.components.DeviceConnection):
|
|
||||||
"""
|
|
||||||
A proxy class that serves as the interface for interacting with device connections
|
|
||||||
via a socket.io client in an asyncio environment.
|
|
||||||
|
|
||||||
Args:
|
|
||||||
sio_client:
|
|
||||||
The socket.io client instance used for asynchronous communication with the
|
|
||||||
pydase service server.
|
|
||||||
loop:
|
|
||||||
The event loop in which the client operations are managed and executed.
|
|
||||||
|
|
||||||
This class is used to create a proxy object that behaves like a local representation
|
|
||||||
of a remote pydase service, facilitating direct interaction as if it were local
|
|
||||||
while actually communicating over network protocols.
|
|
||||||
It can also be used as an attribute of a pydase service itself, e.g.
|
|
||||||
|
|
||||||
```python
|
|
||||||
import pydase
|
|
||||||
|
|
||||||
|
|
||||||
class MyService(pydase.DataService):
|
|
||||||
proxy = pydase.Client(
|
|
||||||
hostname="...", port=8001, block_until_connected=False
|
|
||||||
).proxy
|
|
||||||
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
|
||||||
service = MyService()
|
|
||||||
server = pydase.Server(service, web_port=8002).run()
|
|
||||||
```
|
|
||||||
"""
|
|
||||||
|
|
||||||
def __init__(
|
|
||||||
self, sio_client: socketio.AsyncClient, loop: asyncio.AbstractEventLoop
|
|
||||||
) -> None:
|
|
||||||
super().__init__()
|
|
||||||
pydase.components.DeviceConnection.__init__(self)
|
|
||||||
self._initialise(sio_client=sio_client, loop=loop)
|
|
||||||
|
|
||||||
|
|
||||||
class Client:
|
class Client:
|
||||||
"""
|
"""
|
||||||
A client for connecting to a remote pydase service using socket.io. This client
|
A client for connecting to a remote pydase service using socket.io. This client
|
||||||
|
50
src/pydase/client/proxy_class.py
Normal file
50
src/pydase/client/proxy_class.py
Normal file
@ -0,0 +1,50 @@
|
|||||||
|
import asyncio
|
||||||
|
import logging
|
||||||
|
|
||||||
|
import socketio # type: ignore
|
||||||
|
|
||||||
|
import pydase.components
|
||||||
|
from pydase.client.proxy_loader import ProxyClassMixin
|
||||||
|
|
||||||
|
logger = logging.getLogger(__name__)
|
||||||
|
|
||||||
|
|
||||||
|
class ProxyClass(ProxyClassMixin, pydase.components.DeviceConnection):
|
||||||
|
"""
|
||||||
|
A proxy class that serves as the interface for interacting with device connections
|
||||||
|
via a socket.io client in an asyncio environment.
|
||||||
|
|
||||||
|
Args:
|
||||||
|
sio_client:
|
||||||
|
The socket.io client instance used for asynchronous communication with the
|
||||||
|
pydase service server.
|
||||||
|
loop:
|
||||||
|
The event loop in which the client operations are managed and executed.
|
||||||
|
|
||||||
|
This class is used to create a proxy object that behaves like a local representation
|
||||||
|
of a remote pydase service, facilitating direct interaction as if it were local
|
||||||
|
while actually communicating over network protocols.
|
||||||
|
It can also be used as an attribute of a pydase service itself, e.g.
|
||||||
|
|
||||||
|
```python
|
||||||
|
import pydase
|
||||||
|
|
||||||
|
|
||||||
|
class MyService(pydase.DataService):
|
||||||
|
proxy = pydase.Client(
|
||||||
|
hostname="...", port=8001, block_until_connected=False
|
||||||
|
).proxy
|
||||||
|
|
||||||
|
|
||||||
|
if __name__ == "__main__":
|
||||||
|
service = MyService()
|
||||||
|
server = pydase.Server(service, web_port=8002).run()
|
||||||
|
```
|
||||||
|
"""
|
||||||
|
|
||||||
|
def __init__(
|
||||||
|
self, sio_client: socketio.AsyncClient, loop: asyncio.AbstractEventLoop
|
||||||
|
) -> None:
|
||||||
|
super().__init__()
|
||||||
|
pydase.components.DeviceConnection.__init__(self)
|
||||||
|
self._initialise(sio_client=sio_client, loop=loop)
|
Loading…
x
Reference in New Issue
Block a user