Kea 2.6.0
isc::log::MessageInitializer Class Reference

Initialize Message Dictionary. More...

#include <message_initializer.h>

+ Inheritance diagram for isc::log::MessageInitializer:

Public Member Functions

 MessageInitializer (const char *values[])
 ~MessageInitializer ()

Static Public Member Functions

static void clearDuplicates ()
 Clear the static duplicates list.
static const std::list< std::string > & getDuplicates ()
 Return Duplicates.
static size_t getPendingCount ()
 Obtain pending load count.
static void loadDictionary (bool ignore_duplicates=false)
 Run-Time Initialization.

Detailed Description

Initialize Message Dictionary.

This is a helper class to add a set of message IDs and associated text to the global dictionary.

It should be declared outside an execution unit and initialized with an array of values, alternating identifier, associated text and ending with a NULL, e.g.

static const char* values[] = {
    "IDENT1", "message for ident 1",
    "IDENT2", "message for ident 2",
MessageInitializer xyz(values);

All that needed is for the module containing the definitions to be included in the execution unit.

Dynamically loaded modules should call the initializer as well on the moment they are instantiated.

To avoid static initialization fiasco problems, the containers shared by all instances of this class are dynamically allocated on first use, and held in the smart pointers which are de-allocated only when all instances of the class are destructed. After the object has been created with the constructor, the MessageInitializer::loadDictionary static function is called to populate the messages defined in various instances of the MessageInitializer class to the global dictionary.

When messages are added to the dictionary, the are added via the MessageDictionary::add() method, so any duplicates are stored in the global dictionary's overflow lince whence they can be retrieved at run-time.

Definition at line 72 of file message_initializer.h.

Constructor & Destructor Documentation

◆ MessageInitializer()

isc::log::MessageInitializer::MessageInitializer ( const char *  values[])


Adds a pointer to the array of messages to the global array of pointers to message arrays.

valuesNULL-terminated array of alternating identifier strings and associated message text. N.B. This object stores a pointer to the passed array; the array MUST remain valid at least until loadDictionary() has been called.

Definition at line 50 of file

◆ ~MessageInitializer()

isc::log::MessageInitializer::~MessageInitializer ( )


Removes pending messages from the array or loaded messages from the global dictionary.

If the messages initialized with the destructed have already been loaded to the global dictionary the destructor will remove these messages and preserve messages loaded by other instances of the MessageInitializer. If there are any duplicates, only the instance of the duplicated message initialized by the destructed object will be removed.

Definition at line 58 of file

Member Function Documentation

◆ clearDuplicates()

void isc::log::MessageInitializer::clearDuplicates ( )

Clear the static duplicates list.

Empties the list returned by getDuplicates()

Definition at line 131 of file

Referenced by isc::log::LoggerManager::logDuplicatedMessages().

◆ getDuplicates()

const std::list< std::string > & isc::log::MessageInitializer::getDuplicates ( )

Return Duplicates.

When messages are added to the global dictionary, any duplicates are recorded. They can later be output through the logging system.

List of duplicate message IDs when the global dictionary was loaded. Note that the duplicates list itself may contain duplicates.

Definition at line 125 of file

Referenced by isc::log::LoggerManager::logDuplicatedMessages().

◆ getPendingCount()

size_t isc::log::MessageInitializer::getPendingCount ( )

Obtain pending load count.

Returns the number of message arrays that will be loaded by the next call to loadDictionary().

Number of registered message arrays. This is reset to zero when loadDictionary() is called.

Definition at line 94 of file

◆ loadDictionary()

void isc::log::MessageInitializer::loadDictionary ( bool  ignore_duplicates = false)

Run-Time Initialization.

Loops through the internal array of pointers to message arrays and adds the messages to the internal dictionary. This is called during run-time initialization.

ignore_duplicatesIf true, duplicate IDs, and IDs already loaded, are ignored instead of stored in the global duplicates list.

Definition at line 102 of file

References isc::log::MessageDictionary::globalDictionary().

Referenced by isc::log::LoggerManager::init(), and isc::hooks::LibraryManager::loadLibrary().

+ Here is the call graph for this function:

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