reactor-c
C Runtime for Lingua Franca
|
#include <stddef.h>
#include <Python.h>
#include "python_port.h"
#include "reactor.h"
#include "api/schedule.h"
#include "api/reaction_macros.h"
Functions | |
void | python_count_decrement (void *py_object) |
PyObject * | py_port_set (PyObject *self, PyObject *args) |
PyObject * | py_port_capsule_new (PyTypeObject *type, PyObject *args, PyObject *kwds) |
PyObject * | py_port_iter (PyObject *self) |
PyObject * | py_port_iter_next (PyObject *self) |
PyObject * | py_port_capsule_get_item (PyObject *self, PyObject *key) |
int | py_port_capsule_assign_get_item (PyObject *self, PyObject *item, PyObject *value) |
Py_ssize_t | py_port_length (PyObject *self) |
int | py_port_capsule_init (generic_port_capsule_struct *self, PyObject *args, PyObject *kwds) |
Variables | |
PyTypeObject | py_port_capsule_t |
PyMappingMethods | py_port_as_mapping |
PyMemberDef | py_port_capsule_members [] |
PyMethodDef | py_port_capsule_methods [] |
Copyright (c) 2022, The University of California at Berkeley. Copyright (c) 2021, The University of Texas at Dallas.
Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
Implementation of functions defined in
int py_port_capsule_assign_get_item | ( | PyObject * | self, |
PyObject * | item, | ||
PyObject * | value ) |
This function is overloaded to prevent directly assigning to multiports. The set function currently is the only way to assign value to ports.
self | The port of type LinguaFranca.port_capsule |
item | The index (which is ignored) |
value | The value to be assigned (which is ignored) |
PyObject * py_port_capsule_get_item | ( | PyObject * | self, |
PyObject * | key ) |
Get an item from a Linugua Franca port capsule type. If a port is a not a multiport, it will have a width of -2 (
self | The port which can be a multiport or a singular port |
key | The index (key) which is used to retrieve an item from the underlying C array if the port is a multiport. |
int py_port_capsule_init | ( | generic_port_capsule_struct * | self, |
PyObject * | args, | ||
PyObject * | kwds ) |
Initialize the port capsule self with the given optional values for port, value, is_present, and num_destinations. If any of these arguments are missing, the default values are assigned
self | The port_instance PyObject that follows the generic_port_instance_struct* internal structure |
args | The optional arguments that are:
|
PyObject * py_port_capsule_new | ( | PyTypeObject * | type, |
PyObject * | args, | ||
PyObject * | kwds ) |
Create a new port_capsule. Note that a LinguaFranca.port_capsule PyObject follows the same structure as the
To initialize the port_capsule, this function first initializes a generic_port_capsule_struct* self using the tp_alloc property of port_capsule (
type | The Python type object. In this case, py_port_capsule_t |
args | The optional arguments that are:
|
kwds | Keywords ( |
PyObject * py_port_iter | ( | PyObject * | self | ) |
Return an iterator for self, which is a port. This function just have to exist to tell Python that ports are iterable.
For example to make for p in foo_multiport: p.set(42) possible in Python.
PyObject * py_port_iter_next | ( | PyObject * | self | ) |
The function that is responsible for getting the next item in the iterator for a multiport.
This would make the following code possible in the Python target: for p in foo_multiport: p.set(42)
Py_ssize_t py_port_length | ( | PyObject * | self | ) |
A function that allows the invocation of len() on a port.
self | A port of type LinguaFranca.port_capsule |
PyObject * py_port_set | ( | PyObject * | self, |
PyObject * | args ) |
Set the value and is_present field of self which is of type LinguaFranca.port_capsule
Each LinguaFranca.port_capsule includes a void* pointer of the C port (a.k.a. generic_port_instance_struct*).
This function calls the underlying _LF_SET API.
This function can be used to set any type of PyObject ranging from primitive types to complex lists and tuples. Moreover, this function is callable from Python target code by using port_name.out(value)
Some examples include port_name.out("Hello") port_name.out(5) port_name.out(["Hello", 5 , (2.8, "X")])
The port type given in the Lingua Franca is only used as a "suggestion" as per Python's duck typing principles. The end-user is responsible for appropriately handling types on the recieveing end of this port.
self | The output port (by name) or input of a contained reactor in form instance_name.port_name. |
args | contains:
|
void python_count_decrement | ( | void * | py_object | ) |
Decrease the reference count of PyObject. When the reference count hits zero, Python can free its memory.
py_object | A PyObject with count 1 or greater. |
PyMappingMethods py_port_as_mapping |
Methods that convert a LinguaFranca.port_capsule into a mapping, which allows it to be subscriptble.
PyMemberDef py_port_capsule_members[] |
PyMethodDef py_port_capsule_methods[] |
PyTypeObject py_port_capsule_t |