template<class ReceiveModule = senf::mpl::nil, class TransmitModule = senf::mpl::nil>
struct senf::emu::ApplyInterfaceDecorator< ReceiveModule, TransmitModule >
Apply additional modules to an interface.
Interface decoration allows to add arbitrary additional modules to the input or output chain of an interface. Decorated interfaces share a generic API and provide fine-grained access to the underlying interface API at every level of specialization (Interface, WirelessInterface, WiredInterface etc).
However, a decorated interface is not an interface itself. Since the input and output decoration are each optional, it is possible to convert any interface into the decorated interface API by a null-wrapping. The decorated interface can thus be used as a generic, extensible and wrappable interface API.
Adding decoration to an interface is performed in two steps: First the decoration is defined as a typedef, then this decoration is applied to a specific type of interface:
MyDecoratedWLANInterface;
This way, the type of decoration can easily be declared in a generic way and be applied to
any number of different interface types.
If \a InterfaceType is receive-only, only the \a ReceiveModule will be applied. In the same
way, if \a InterfaceType is transmit-only, only the \a TransmitModule will be applied.
Receive and Transmit module/group
The decorator groups \a ReceiveModule and \a TransmitModule are arbitrary Modules or group
which take an interface reference as constructor argument. The concrete (derived) argument
type depends on the type of interface wrapped.
{
public:
};
struct MyReceiveGroup
{
senf::emu::RateAnalyzer analyzer;
: module (iface.macAddress()), input (analyzer.input), output (module.output)
{
senf::ppi::connect(analyzer, module);
}
void frobble() { ... };
};
This group can be applied to any type of interface since the constructor argument is
senf::emu::Interface &.
API access
Interface API
Every decorated interface inherits from senf::emu::InterfaceDecorator. This class provides
access to the basic senf::emu::Interface API and to the input and output connector (when
enabled depending on the \c canReceive() and \c canTransmit() properties of the underlying
interface).
If you need access to a more derived interface API (e.g. senf::emu::WirelessInterface), this
access is provided by corresponding senf::emu::TypedInterfaceDecorator classes. You do not
need to define these yourself, each Interface API class has a \c Decorator type member with
the correct decorator type. Thus, in above case all the following conversions are valid:
MyDecoratedWLANInterface wlanIface;
wirelessIface.interface().propertyIndex(0);
Wrapper modules
To access the wrapper modules, the decoration typedef (\c MyDecoration in this example) has
additional members which access the transmit and/or receive module of a wrapped interface.
MyReceiveGroup & group (MyDecoration::receiveModule(iface));
Here \a iface can be an \e arbitrary interface wrapped with \c MyDecoration. If the
interface is transmit-only or is not wrapped with \c MyDecoration, the above command will
throw \c std::bad_cast. The transmit module/group works the same.
\see senf::emu::InterfaceDecoratorImplementation / <b>List of all members</b> for a
documentation of the decorated interface API.
Definition at line 417 of file InterfaceDecorator.hh.