BDE 4.14.0 Production release
Loading...
Searching...
No Matches
balb_pipetaskmanager

Detailed Description

Outline

Purpose

Provide a pipe-based mechanism to process task control messages.

Classes

See also
balb_controlmanager, balb_pipecontrolchannel

Description

This component provides a mechanism, balb::PipeTaskManager, that listens on a named pipe for messages that are typically used to influence the behavior of a (running) task.

For example, a balb::PipeTaskManager might be configured to listen on a well known named pipe (e.g., myapplication.ctrl), for the control messages starting with:

The use of imperative verbs for the first field of a message is a common practice. The first field is called the message "prefix". On receipt of a message with a known prefix, a previously registered handler functor is invoked with two arguments:

  1. the prefix value, and
  2. an bsl::istream from which the rest of the message (if any) can be read. Thus, we have a mechanism by which a running task can be sent commands and, optionally, arguments for those commands.

Once the relationship between prefix and handler has been specified, the start method is used to create the named pipe (or re-open an existing named pipe) and a thread created to listen for messages.

A human user on a console might then use a command line application to send control messages to the myapplication.ctrl pipe to configure the behavior of the running task. In the example above, the handler for the LOG prefix expects additional parameters. Thus:

echo "LOG VERBOSITY 4" > $SOCKDIR/myapplication.ctrl

changes the logging verbosity of the task to level "4". See bdls_pipeutil for functions that can be invoked from C++ code to send messages to a named pipe.

Configuring the balbl::PipeTaskManager

A default constructed balbl::PipeTaskManager has no registered handlers. Users can use the exposed balb::ControlManager, to register different control message prefixes (typically "verbs") to dispatch received messages to an appropriate functor.

Alternatively, one can construct a balb::PipeTaskManager using a separately created and configured a balb::ControlManager object. Doing so allows that single balb::ControlManager to be shared among several balb::PipeTaskManagrer objects, each listening on a different named pipe.

Thread Safety

This component is thread-safe but not thread-enabled, meaning that multiple threads may safely use their own instances of balb::PipeTaskManager, but may not manipulate the same instance of balb::PipeTaskManager simultaneously. Note that the contained balb::ControlManager object is available via both const and non=const references and that object is safe for multiple threads.

Requirements for the Named Pipe

The balb::PipeTaskManger objects waits for messages from a named pipe provided to the start method. The argument to start – mapped to all lower case, if needed – determines the basename of the named pipe. The directory of that named pipe depends on the platform and environment variables.