Into

Modules

Documentation

classPiiDemuxOperation

#include <PiiDemuxOperation.h>

A demultiplexer.

Inherits PiiDefaultOperation

Description

A demux sends objects coming from one channel to multiple channels. The active output channel is selected by a control input.

Demultiplexer is useful in many different situations. For example, it can be used to perform different processing for different objects. In such a scenario the operation works as an analogue to the switch clause in programming languages. The picture below shows a scenario in which PiiDemuxOperation is used as a load balancer. Let us assume thet both of the HeavyProcessing operations are run in separate threads and that Control emits an alternating sequence of ones and zeros. If the machine had two processors, the HeavyProcessing operations would be executed simultaneously.

Since the outputs of a demultiplexer are active in a non-deterministic manner, there is no way to synchronize their emissions. This causes problems if you connect two or more of the outputs to a single operation either directly or indirectly. The most likely cause is that the configuration hangs. Therefore, it is advisable to always couple PiiDemuxOperation with a PiiMuxOperation that is controlled by the same control signal.

Inputs

controlselects the output channel. Accepts any numeric type in the range [0, outputCount - 1]. All numeric values are automatically converted to integers.
inputany object. Passed to the output selected by the control input.

Outputs

outputXthe output channels. X ranges from 0 to dynamicOutputCount - 1.

Properties

int

The number of output channels.

Constructors and destructor

Public member functions

int
void
(
  • int count
)

Protected member functions

virtual void

Executes one round of processing.

Property details

  • int dynamicOutputCount

    [read, write]

    The number of output channels.

    The value equals to the number of output sockets. The default value is two.

Function details

  • PiiDemuxOperation

    ()
  • int dynamicOutputCount

    ()
  • void setDynamicOutputCount

    (
    • int count
    )
  • virtual void process

    ()
    [protected, virtual]

    Executes one round of processing.

    This function is invoked by the processor if the necessary preconditions for a new processing round are met. This function does all the necessary calculations to create output objects and sends them to output sockets.

    Calls to process(), syncEvent(), and setProperty() are synchronized and cannot occur simultaneously. PiiDefaultOperation ensures this by locking processLock() for reading before calling process().

    Note: With time-consuming operations, one should occasionally check that the operation hasn't been interrupted, i.e. that state() returns Running.

    Exceptions
    PiiExecutionException

    whenever an unrecoverable error occurs during a processing round, the operation is interrupted, or finishes execution due to end of input data.

    Reimplemented from PiiDefaultOperation.

Notes (0)

Add a note

Not a single note added yet. Be the first, add yours.