udpates AdditionalServerProtocol and WebServer

updates WebServer
This commit is contained in:
Mose Müller 2023-12-19 11:04:46 +01:00
parent 3186e04cc1
commit 8b78099178
2 changed files with 21 additions and 35 deletions

View File

@ -28,35 +28,27 @@ class AdditionalServerProtocol(Protocol):
any server implementing it should have an __init__ method for initialization and a any server implementing it should have an __init__ method for initialization and a
serve method for starting the server. serve method for starting the server.
Parameters: Args:
----------- data_service_observer:
service: DataService Observer for the DataService, handling state updates and communication to
The instance of DataService that the server will use. This could be the main connected clients through injected callbacks. Can be utilized to access the
application or a specific service that the server will provide. service and state manager, and to add custom state-update callbacks.
host:
port: int Hostname or IP address where the server is accessible. Commonly '0.0.0.0' to
The port number at which the server will be accessible. This should be a valid bind to all network interfaces.
port number, typically in the range 1024-65535. port:
Port number on which the server listens. Typically in the range 1024-65535
host: str (non-standard ports).
The hostname or IP address at which the server will be hosted. This could be a **kwargs:
local address (like '127.0.0.1' for localhost) or a public IP address. Any additional parameters required for initializing the server. These
parameters are specific to the server's implementation.
state_manager: StateManager
The state manager managing the state cache and persistence of the exposed
service.
**kwargs: Any
Any additional parameters required for initializing the server. These parameters
are specific to the server's implementation.
""" """
def __init__( def __init__(
self, self,
service: DataService, data_service_observer: DataServiceObserver,
port: int,
host: str, host: str,
state_manager: StateManager, port: int,
**kwargs: Any, **kwargs: Any,
) -> None: ) -> None:
... ...
@ -252,7 +244,6 @@ class Server:
service=self._service, service=self._service,
host=self._host, host=self._host,
port=server["port"], port=server["port"],
state_manager=self._state_manager,
data_service_observer=self._observer, data_service_observer=self._observer,
**server["kwargs"], **server["kwargs"],
) )
@ -268,7 +259,6 @@ class Server:
service=self._service, service=self._service,
host=self._host, host=self._host,
port=self._web_port, port=self._web_port,
state_manager=self._state_manager,
data_service_observer=self._observer, data_service_observer=self._observer,
**self._kwargs, **self._kwargs,
) )

View File

@ -10,10 +10,8 @@ from fastapi.middleware.cors import CORSMiddleware
from fastapi.responses import FileResponse from fastapi.responses import FileResponse
from fastapi.staticfiles import StaticFiles from fastapi.staticfiles import StaticFiles
from pydase import DataService
from pydase.data_service.data_service_observer import DataServiceObserver from pydase.data_service.data_service_observer import DataServiceObserver
from pydase.data_service.state_manager import StateManager from pydase.server.web_server.sio_server_wrapper import SioServerWrapper
from pydase.server.web_server.sio_server import SioServerWrapper
from pydase.version import __version__ from pydase.version import __version__
logger = logging.getLogger(__name__) logger = logging.getLogger(__name__)
@ -53,22 +51,20 @@ class WebServer:
def __init__( # noqa: PLR0913 def __init__( # noqa: PLR0913
self, self,
service: DataService, data_service_observer: DataServiceObserver,
host: str, host: str,
port: int, port: int,
state_manager: StateManager,
data_service_observer: DataServiceObserver,
css: str | Path | None = None, css: str | Path | None = None,
enable_cors: bool = True, enable_cors: bool = True,
**kwargs: Any, **kwargs: Any,
) -> None: ) -> None:
self.service = service self.observer = data_service_observer
self.state_manager = state_manager self.state_manager = self.observer.state_manager
self.service = self.state_manager.service
self.port = port self.port = port
self.host = host self.host = host
self.css = css self.css = css
self.enable_cors = enable_cors self.enable_cors = enable_cors
self.observer = data_service_observer
self._loop: asyncio.AbstractEventLoop self._loop: asyncio.AbstractEventLoop
self.setup_fastapi_app() self.setup_fastapi_app()