|
BDE 4.39.x Production Release
|
Provide a mechanism for mapping control messages to callbacks.
Provide a mechanism for mapping control messages to callbacks.
The balb::ControlManager mechanism provided by this component maps control messages to callback functions on the basis of message prefixes.
The prefix (case-insensitive) "HELP" is reserved for use by the registerUsageHandler.
Functions registered as callbacks for messages must be invokable as void(*)(const bsl::string&, bsl::istream&). (This signature is balb::ControlManager::ControlHandler). When the function is invoked, the first argument is the message prefix, and the second is a stream on the remainder of the message.
This component is thread-safe and thread-enabled: it is safe to access and manipulate multiple distinct instances from different threads, and it is safe to access and manipulate a single shared instance from different threads.
The balb::ControlManager ignores messages having (case-insensitive) prefixes that have not been previously registered. Optionally, users can install a (default) handler for messages messages with un-registered prefixes. Note that "default" refers to the message prefix – there is no such handler unless the user explicitly installs one using the setDefaultHandler method.
This section illustrates intended use of this component.
First define a trivial callback to be invoked when an "ECHO" message is received:
Now create a balb::ControlManager object and register a handler for "ECHO". Also register a handler for HELP to observe the auto-generated documentation for ECHO: