BDE 4.39.x Production Release
Loading...
Searching...
No Matches
balb::ControlManager Class Reference

#include <balb_controlmanager.h>

Detailed Description

Dispatch control messages to callbacks by name.

See balb_controlmanager

Public Types

typedef bsl::function< void(const bsl::string &prefix, bsl::istream &stream)> ControlHandler
 

Public Member Functions

 BSLMF_NESTED_TRAIT_DECLARATION (ControlManager, bslma::UsesBslmaAllocator)
 
 ControlManager (bslma::Allocator *basicAllocator=0)
 
 ~ControlManager ()
 
int registerHandler (const bsl::string_view &prefix, const bsl::string_view &arguments, const bsl::string_view &description, const ControlHandler &handler)
 
int registerUsageHandler (bsl::ostream &stream)
 
int registerDefaultHandler (const ControlHandler &hander)
 
int deregisterHandler (const bsl::string_view &prefix)
 
int deregisterUsageHandler ()
 
int deregisterDefaultHandler ()
 
int dispatchMessage (const bsl::string_view &message) const
 
int dispatchMessage (const bsl::string &prefix, bsl::istream &stream) const
 
bool hasDefaultHandler () const
 
void printUsage (bsl::ostream &stream, const bsl::string_view &preamble) const
 
void printUsageHelper (bsl::ostream *stream, const bsl::string_view &preamble) const
 
bslma::Allocatorallocator () const
 

Member Typedef Documentation

◆ ControlHandler

typedef bsl::function<void(const bsl::string& prefix, bsl::istream& stream)> balb::ControlManager::ControlHandler

Defines a type alias for the function called to handle control messages. The prefix argument is the first space-delimited word read from the message, and the stream argument is the bsl::istream containing the remainder of the message.

Constructor & Destructor Documentation

◆ ControlManager()

balb::ControlManager::ControlManager ( bslma::Allocator basicAllocator = 0)
explicit

Create a control manager object. Optionally specify a basicAllocator used to supply memory. If basicAllocator is 0, the currently installed default allocator is used.

◆ ~ControlManager()

balb::ControlManager::~ControlManager ( )

Destroy this object.

Member Function Documentation

◆ allocator()

bslma::Allocator * balb::ControlManager::allocator ( ) const
inline

Return the allocator used by this object to supply memory.

Note
Note that if no allocator was supplied at construction the default allocator in effect at construction is used.

◆ BSLMF_NESTED_TRAIT_DECLARATION()

balb::ControlManager::BSLMF_NESTED_TRAIT_DECLARATION ( ControlManager  ,
bslma::UsesBslmaAllocator   
)

◆ deregisterDefaultHandler()

int balb::ControlManager::deregisterDefaultHandler ( )

Deregister the callback function previously registered (see registerDefaultHandler) to handle messages with unregistered prefixes. Return 0 on success or a non-zero value otherwise.

◆ deregisterHandler()

int balb::ControlManager::deregisterHandler ( const bsl::string_view prefix)

Deregister the callback function previously registered to handle the specified prefix. Return 0 on success or a non-zero value otherwise.

◆ deregisterUsageHandler()

int balb::ControlManager::deregisterUsageHandler ( )
inline

◆ dispatchMessage() [1/2]

int balb::ControlManager::dispatchMessage ( const bsl::string prefix,
bsl::istream &  stream 
) const

Dispatch the message contained in the specified stream to the callback associated with the specified prefix. Return 0 on success, and a non-zero value otherwise; in particular return non-zero if no registered callback could be found for the case-insensitive prefix and no default handler is installed.

◆ dispatchMessage() [2/2]

int balb::ControlManager::dispatchMessage ( const bsl::string_view message) const

Parse the specified complete message and dispatch it. Return 0 on success, and a non-zero value otherwise; in particular return non-zero if no registered callback could be found for the case-insensitive prefix in message and no default handler is installed.

◆ hasDefaultHandler()

bool balb::ControlManager::hasDefaultHandler ( ) const

Return true if this control manager has a default message handler installed, and false otherwise.

◆ printUsage()

void balb::ControlManager::printUsage ( bsl::ostream &  stream,
const bsl::string_view preamble 
) const

Print to the specified stream the specified preamble text, followed by the registered commands and documentation for this control manager.

Note
Note that a newline is appended to preamble in the output.

◆ printUsageHelper()

void balb::ControlManager::printUsageHelper ( bsl::ostream *  stream,
const bsl::string_view preamble 
) const
inline

Invoke printUsage passing the specified *stream and preamble. Suitable for binding using the bdlf::BindUtil package.

◆ registerDefaultHandler()

int balb::ControlManager::registerDefaultHandler ( const ControlHandler hander)

Register the specified handler to be invoked whenever a control message having an unregistered (case-insensitive) prefix is received by this control manager. Return a positive value if an existing callback was replaced, return 0 if no replacement occurred, and return a negative value otherwise.

◆ registerHandler()

int balb::ControlManager::registerHandler ( const bsl::string_view prefix,
const bsl::string_view arguments,
const bsl::string_view description,
const ControlHandler handler 
)

Register the specified handler to be invoked whenever a control message having the specified case-insensitive prefix is received by this control manager. Also register the specified arguments string to describe the arguments accepted by the message, and the specified description to describe its operation; these are printed by printUsage. Return a positive value if an existing callback was replaced, return 0 if no replacement occurred, and return a negative value otherwise.

◆ registerUsageHandler()

int balb::ControlManager::registerUsageHandler ( bsl::ostream &  stream)

Register a handler that, on receipt of a (case-insensitive) "HELP" message, prints to the specified stream a list of this ControlManagers registered commands and their documentation. Return a positive value if an existing callback was replaced, return 0 if no replacement occurred, and return a negative value otherwise.


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