✨ SwitcherIO: API improvements
This merge request integrates the new Switcher IO API.
Features
bundles
attribute for pySwitch
instances to manage bundles
A new >>> from pyquid import Switcher, Bundle
>>> sw = Switcher('bundles')
>>> bundle = Bundle("MyBundle", "my pipeline command", { "description": "my doc.description"})
>>> bundle
<Bundle 'MyBundle'>
>>> sw.bundles.append(bundle)
>>> sw.bundles
<BundleManager [<Bundle 'MyBundle'>]>
>>> sw.bundles.create("EasyBundle", "my pipeline command", { "description": "my doc.description"})
>>> sw.bundles
<BundleManager [<Bundle 'MyBundle'>, <Bundle 'EasyBundle'>]>
>>> quid = sw.create("MyBundle")
logger
attribute for pySwitch
instances
A new This leverages the new spdlog implementation of Switcher
so that it can be used by pyquid
and therefore switcherio
.
>>> from pyquid import Switcher
>>> sw = Switcher('logging_test', debug=True)
2021-12-15 05:08:33.226|logging-test|20137bdb-5e66-4767-a107-8dc1f42bc1e7|10131|10131|debug: file /home/opsocket/.config/switcher/global.json does not exist|configuration.cpp:120
2021-12-15 05:08:33.232|logging-test|20137bdb-5e66-4767-a107-8dc1f42bc1e7|10131|10131|debug: loading module /usr/local/switcher-3.0/plugins/libsoapserver.so|factory.cpp:90
...
2021-12-15 05:08:33.268|logging-test|20137bdb-5e66-4767-a107-8dc1f42bc1e7|10131|10131|debug: loading module /usr/local/switcher-3.0/plugins/libwebrtc.so|factory.cpp:90
>>> print(sw.logger)
<pyLogger object at 0x7f5c3060df90>
>>> dir(sw.logger)
['__class__', '__delattr__', '__dir__', '__doc__', '__eq__', '__format__', '__ge__', '__getattribute__', '__gt__', '__hash__', '__init__', '__init_subclass__', '__le__', '__lt__', '__ne__', '__new__', '__reduce__', '__reduce_ex__', '__repr__', '__setattr__', '__sizeof__', '__str__', '__subclasshook__', 'critical', 'debug', 'error', 'info', 'trace', 'warn']
>>> sw.logger.debug("test log line 1")
2021-12-15 05:09:03.905|logging-test|20137bdb-5e66-4767-a107-8dc1f42bc1e7|10131|10131|debug: test log line 1|:
True
>>> sw.logger.critical("test log line 2")
2021-12-15 05:09:17.796|logging-test|20137bdb-5e66-4767-a107-8dc1f42bc1e7|10131|10131|critical: test log line 2|:
True
switcherio
handler to stream logs to Switcher
A new sio.emit("switcher.log", data=("debug", "Some important debugging text"))
pyQuiddity
attributes props
& signals
Two new Properties management
>>> from pyquid import Switcher
>>> sw = Switcher('props')
>>> quid = sw.create('videotestsrc')
>>> quid.props
{'started': False, 'resolution': '1', 'width': 1920, 'height': 1080, 'framerate': '3', 'format': '0', 'pattern': '0'}
>>> type(quid.props)
<class '__main__.PropsDescriptor'>
>>> quid.props["started"] = True
>>> quid.props
{'started': True, 'resolution': '1', 'width': 1920, 'height': 1080, 'framerate': '3', 'format': '0', 'pattern': '0'}
Signals management
>>> from pyquid import Switcher
>>> sw = Switcher('props')
>>> quid = sw.create('videotestsrc')
>>> quid.signals
{'quiddity_updated': []}
>>> type(quid.signals)
<class '__main__.SignalsDescriptor'>
>>> type(quid.signals["quiddity_updated"])
<class '__main__.SignalRegistry'>
>>> dir(quid.signals)
['_SignalsDescriptor__data', '__class__', '__delattr__', '__dict__', '__dir__', '__doc__', '__eq__', '__format__', '__ge__', '__get__', '__getattribute__', '__getitem__', '__gt__', '__hash__', '__init__', '__init_subclass__', '__le__', '__lt__', '__module__', '__ne__', '__new__', '__reduce__', '__reduce_ex__', '__repr__', '__setattr__', '__sizeof__', '__str__', '__subclasshook__', '__weakref__', 'subscribe', 'unsubscribe']
>>> dir(quid.signals["quiddity_updated"])
['_SignalRegistry__data', '__class__', '__delattr__', '__dict__', '__dir__', '__doc__', '__eq__', '__format__', '__ge__', '__getattribute__', '__gt__', '__hash__', '__init__', '__init_subclass__', '__iter__', '__le__', '__len__', '__lt__', '__module__', '__ne__', '__new__', '__reduce__', '__reduce_ex__', '__repr__', '__setattr__', '__sizeof__', '__str__', '__subclasshook__', '__weakref__', 'append', 'clear', 'index', 'pop']
In short, the SignalDescriptor
is initialized with key-value pairs for each pyquid specific signals using the signal name as a key and SignalRegistry
as a value which is a special list restricted to signal callback functions
pyquid
specific signaling interface
A Here's an example script leveraging this interface to emit a signal whenever a given quiddity had its properties updated.
test.py
import pyquid
import time
sw = pyquid.Switcher('test')
quid = sw.create('videotestsrc')
def func(quid, updated):
time.sleep(5)
print('quiddity_updated function', quid.id(), updated)
print(quid.props)
quid.subscribe('quiddity_updated', func)
print(quid.props)
quid.update({
"started": True,
"resolution": "2"
})
print("non blocked print")
print(quid.props)
Below is the output from gdb
ubuntu@vmubuntu:~/sw$ gdb --args python3 test.py
GNU gdb (Ubuntu 9.2-0ubuntu1~20.04) 9.2
Copyright (C) 2020 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.
Type "show copying" and "show warranty" for details.
This GDB was configured as "x86_64-linux-gnu".
Type "show configuration" for configuration details.
For bug reporting instructions, please see:
<http://www.gnu.org/software/gdb/bugs/>.
Find the GDB manual and other documentation resources online at:
<http://www.gnu.org/software/gdb/documentation/>.
For help, type "help".
Type "apropos word" to search for commands related to "word"...
Reading symbols from python3...
(No debugging symbols found in python3)
(gdb) r
Starting program: /usr/bin/python3 test.py
[Thread debugging using libthread_db enabled]
Using host libthread_db library "/lib/x86_64-linux-gnu/libthread_db.so.1".
[Detaching after fork from child process 53000]
[New Thread 0x7ffff656d700 (LWP 53001)]
[New Thread 0x7ffff5d6c700 (LWP 53002)]
[New Thread 0x7fffed629700 (LWP 53003)]
{'started': False, 'resolution': '1', 'width': 1920, 'height': 1080, 'framerate': '3', 'format': '0', 'pattern': '0'}
[New Thread 0x7fffecda8700 (LWP 53004)]
[New Thread 0x7fffe653e700 (LWP 53005)]
[New Thread 0x7fffe553c700 (LWP 53007)]
[New Thread 0x7fffe5d3d700 (LWP 53006)]
non blocked print
{'started': False, 'resolution': '1', 'width': 1920, 'height': 1080, 'framerate': '3', 'format': '0', 'pattern': '0'}
[New Thread 0x7fffe4d3b700 (LWP 53008)]
quiddity_updated function 1 {'started': True, 'resolution': '2'}
{'started': True, 'resolution': '2', 'width': 1920, 'height': 1080, 'framerate': '3', 'format': '0', 'pattern': '0'}
[Thread 0x7fffe553c700 (LWP 53007) exited]
[Thread 0x7fffe5d3d700 (LWP 53006) exited]
[Thread 0x7fffe653e700 (LWP 53005) exited]
[Thread 0x7fffecda8700 (LWP 53004) exited]
[Thread 0x7fffed629700 (LWP 53003) exited]
[Thread 0x7ffff5d6c700 (LWP 53002) exited]
[Thread 0x7ffff656d700 (LWP 53001) exited]
[Thread 0x7ffff7bf0740 (LWP 52996) exited]
[Inferior 1 (process 52996) exited normally]
(gdb) q
future updates
things that are postponed in another issues:
-
#65 (closed) (unifying the update method the the
quiddity
API) - #84 (closed) (adding new tests to update properties and signals during runtime)
-
#83 (validating bundles when they are sent from
switcher.bundles
API) -
#89 (closed) (documenting the features and the behaviour of
swio
) -
#63 (closed) (documenting the API of
swio
with the OpenAPI tool)
also, it seems there is a couple of issues that should be checked and maybe closed after merging this one:
-
#47 (closed) (testing the bundle API of
swio
) -
#46 (closed) (testing the configuration API of
swio
)
in addition, the !418 (closed) is adding the swctrl
tool on top of this mr and should be analysed, improved minimally in order to stabilise this command line across new couple of issues/mr:
-
#49 (closed) (implementing the bundle API with
swctrl
)
also, the update feature of swio
is not stable and complete as it doesn't implement the update of the userTree
efficiently and should be improved in another mr linked with #65 (closed).
all these issues are gathered into the milestone %Switcher-io