senf::emu::ApplyInterfaceDecorator< ReceiveModule, TransmitModule > Struct Template Reference

Apply additional modules to an interface. More...

#include <senf/Ext/NetEmu/InterfaceDecorator.hh>

Static Public Member Functions

static ReceiveModule & receiveModule (InterfaceDecorator &interface)
 
static ReceiveModule const & receiveModule (InterfaceDecorator const &interface)
 
static TransmitModule & transmitModule (InterfaceDecorator &interface)
 
static TransmitModule const & transmitModule (InterfaceDecorator const &interface)
 

Detailed Description

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:

// Define the decoration typedef
// Apply the typedef to a specific interface type
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.
// Example module taking a MAC address as constructor argument
class MyModule : public senf::ppi::module::Module
{
SENF_PPI_MODULE(MyModule);
public:
MyModule(senf::MACAddress const & mac) { ... }
};
// Now define the decorator group
struct MyReceiveGroup
{
senf::emu::RateAnalyzer analyzer;
MyModule module;
MyReceiveGroup(senf::emu::Interface & iface)
: module (iface.macAddress()), input (analyzer.input), output (module.output)
{
senf::ppi::connect(analyzer, module);
// Use the passed in interface to add additional commands to the interfaces
// console directory
iface.consoleDir().add("frobble", senf::membind(&MyReceiveGroup::frooble, this));
}
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:
// Create a decorated WLAN interface instance
MyDecoratedWLANInterface wlanIface;
// Generalize this to the more generic WirelessInterface
WirelessInterface::Decorator & wirelessIface (wlanIface);
// wirelessIface now provides access to the senf::emu::WirelessInterface API
wirelessIface.interface().propertyIndex(0);
// Generalize a step further to the generic Interface API
Interface::Decorator & iface (wlanIface);
// iface provides access only to the basic senf::emu::Interface API
iface.interface().canReceive();

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.
// Get the receive module of our 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.

Member Function Documentation

◆ receiveModule() [1/2]

template<class ReceiveModule = senf::mpl::nil, class TransmitModule = senf::mpl::nil>
static ReceiveModule& senf::emu::ApplyInterfaceDecorator< ReceiveModule, TransmitModule >::receiveModule ( InterfaceDecorator interface)
static

◆ receiveModule() [2/2]

template<class ReceiveModule = senf::mpl::nil, class TransmitModule = senf::mpl::nil>
static ReceiveModule const& senf::emu::ApplyInterfaceDecorator< ReceiveModule, TransmitModule >::receiveModule ( InterfaceDecorator const &  interface)
static

◆ transmitModule() [1/2]

template<class ReceiveModule = senf::mpl::nil, class TransmitModule = senf::mpl::nil>
static TransmitModule& senf::emu::ApplyInterfaceDecorator< ReceiveModule, TransmitModule >::transmitModule ( InterfaceDecorator interface)
static

◆ transmitModule() [2/2]

template<class ReceiveModule = senf::mpl::nil, class TransmitModule = senf::mpl::nil>
static TransmitModule const& senf::emu::ApplyInterfaceDecorator< ReceiveModule, TransmitModule >::transmitModule ( InterfaceDecorator const &  interface)
static

The documentation for this struct was generated from the following file: