summaryrefslogtreecommitdiff
path: root/docs/src/api/python/functions.md
diff options
context:
space:
mode:
authorjwijenbergh <jeroenwijenbergh@protonmail.com>2022-05-15 21:06:56 +0200
committerjwijenbergh <jeroenwijenbergh@protonmail.com>2022-05-15 21:06:56 +0200
commit8790f632fe0943f5eb616897a3072b4d182a5319 (patch)
treec5e07d5a0da5b66a95cb5f03dcc6b78d8c8bc91c /docs/src/api/python/functions.md
parent8d5d611783842d3d67604eca0fa17d24120333c0 (diff)
Docs: Document language-specific callback constructs
Diffstat (limited to 'docs/src/api/python/functions.md')
-rw-r--r--docs/src/api/python/functions.md20
1 files changed, 20 insertions, 0 deletions
diff --git a/docs/src/api/python/functions.md b/docs/src/api/python/functions.md
index 2a348cd..1d9aef5 100644
--- a/docs/src/api/python/functions.md
+++ b/docs/src/api/python/functions.md
@@ -79,3 +79,23 @@ def deregister() -> None
```
Returns nothing. Raises an exception in case of an error.
+
+# Note on Callbacks
+Some functions (e.g. [the API for getting an OpenVPN/Wireguard config](http://localhost:3000/api/overview/getconfig.html)) need a (or multiple) callbacks set. In Python, the callback function is set using decorators.
+For this, the `eduvpn.EduVPN` class has the following syntax:
+
+```python
+# Where _eduvpn is the eduvpn.EduVPN class instance
+# This gets called when the New_State_Example state is entered
+# old_state is then the old state
+@_eduvpn.event.on("New_State_Example", eduvpn.StateType.Enter)
+def example_enter(old_state: str, data: str)
+```
+```python
+# Where _eduvpn is the eduvpn.EduVPN class instance
+# This gets called when the New_State_Example state is left
+# new_state is then the new state
+@_eduvpn.event.on("New_State_Example", eduvpn.StateType.Leave)
+def example_leave(new_state: str, data: str)
+```
+To show how this can be done in practice, we will give an example in the next section.