Common utilities for communication libraries.


topology.libraries.utils.stateprovider(stateclass, statename=None, initfunc=None)

Decorator to inject a library state into an enode.

  • stateclass (class) – Class that will hold all the state / attribute of the library functions.
  • statename (str) – Attribute name to save the instance of the state class in the engine node (enode). By default, the name of the state class is used like _lib_state_<stateclass> in lower case.
  • initfunc (function) – A function to create the instance the state class. It receives as arguments the enode and the state class and MUST return and instance of that class already initialized. If None, the default, this decorator will create an instance of the state class without any arguments or keyword arguments.

Basic usage:

from topology.libraries.utils import stateprovider

class MyState(object):
    def __init__(self):
        self.my_variable_one = 100

def my_library_function(enode, state, arg1, arg2, keyword_arg1=None):
    state.my_variable_one += 100

 __all__ = ['my_library_function']

In the above example the variable my_variable_one will be bound to the enode calling the library functions, and each call of that library function will increase it’s value by 100.