Kea 2.7.6
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[])
 Constructor.
 
 ~MessageInitializer ()
 Destructor.
 

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",
        :
    NULL
};
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[])

Constructor.

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

Parameters
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 message_initializer.cc.

◆ ~MessageInitializer()

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

Destructor.

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 message_initializer.cc.

Member Function Documentation

◆ clearDuplicates()

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

Clear the static duplicates list.

Empties the list returned by getDuplicates()

Definition at line 131 of file message_initializer.cc.

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

◆ getDuplicates()

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

Return Duplicates.

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

Returns
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 message_initializer.cc.

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

◆ getPendingCount()

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

Obtain pending load count.

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

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

Definition at line 94 of file message_initializer.cc.

◆ loadDictionary()

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

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.

Parameters
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 message_initializer.cc.

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: