36 lines
744 B
Python
36 lines
744 B
Python
|
|
class BaseController:
|
||
|
|
|
||
|
|
def set_stream_func(self, stream_func):
|
||
|
|
self._stream_func = stream_func
|
||
|
|
|
||
|
|
def send(self, data):
|
||
|
|
if getattr(self, "_stream_func", None) is not None:
|
||
|
|
self._stream_func(data)
|
||
|
|
|
||
|
|
def setProperty(self, params):
|
||
|
|
name = params.get("name")
|
||
|
|
value = params.get("value")
|
||
|
|
|
||
|
|
if not isinstance(name, str):
|
||
|
|
return {"error": "Property name must be a string"}
|
||
|
|
|
||
|
|
if not hasattr(self, name):
|
||
|
|
return {"error": f"Property '{name}' does not exist"}
|
||
|
|
|
||
|
|
setattr(self, name, value)
|
||
|
|
|
||
|
|
return {"success": True}
|
||
|
|
|
||
|
|
|
||
|
|
def getProperty(self, params):
|
||
|
|
|
||
|
|
name = params.get("name")
|
||
|
|
|
||
|
|
if not hasattr(self, name):
|
||
|
|
|
||
|
|
return {"error": f"Property '{name}' does not exist"}
|
||
|
|
|
||
|
|
value = getattr(self, name)
|
||
|
|
|
||
|
|
return {"value": value}
|