Devices

Important

Please note that this part of the documentation is not yet finished. It will still be revised and updated.

A device describes a single component of a Scenario or of a Setup. Generally they are container classes for a collection of Features.

Scenario-Device

A Scenario-Device is a device, that defines a subset of Features, a possible Setup-Device should have. Balder searches for matches (see also Matching process of setups and scenarios (SOLVING)), where the potential Setup-Device has an implementation for the Features of the Scenario-Device.

So when is a Device a scenario-device? - This depends one the definition location. A Device is a Scenario-Device when it is an inner-class of a Scenario.

# file `scenario_basic/scenario_basic.py`

import balder
from .features import SendFeature, RecvFeature

class ScenarioBasic(balder.Scenario):
    ...

    class MyDevice(balder.Device):
        send = SendFeature()
        recv = RecvFeature()

    ...

The shown scenario ScenarioBasic has one Scenario-Device with the name MyDevice, that requires two Features: SendFeature and RecvFeature.

Setup-Device

On the other hand, a Setup-Device is a Device, that describes what we have. These devices contains the absolute implementation of the Features, that will be used for the scenarios later. Setup-Devices looks similar to Scenario-Devices, but are defined as inner-classes in Setups of course.

# file `setup_at_home/setup_at_home.py`

import balder
# contains the absolute implementation of ``SendFeature`` and ``RecvFeature``
from .setup_features import MySendFeatureImpl, MyRecvFeatureImpl

class SetupAtHome(balder.Setup):
    ...

    class MainDevice(balder.Device):

        send = MySendFeatureImpl()
        recv = MyRecvFeatureImpl()
        ...
    ...

Often the Features of a Setup-Device implement the complete logic, while the features of the Scenario-Device only describes the abstract architecture. This can be done, because the Features of the Setup-Devices are subclasses of the scenario-device Features. You can find more information about this in the sections Features and Matching process of setups and scenarios (SOLVING).

Connect Devices

Regardless of whether is a Scenario-Device or a Setup-Device you can simply connect two devices with the @balder.connect(..) decorator.

import balder
import balder.connections as conn

class MyScenario(balder.Scenario):

    class DeviceA(balder.Device):
        ...

    @balder.connect(DeviceA, over_connection=conn.TcpConnection)
    class DeviceB(balder.Device):
        ...

    ..

Over this decorator you can define different sub Connections within the over_connection argument. For more information how the connection mechanism works, see Connections.