mirror of https://github.com/Icinga/icinga2.git
Updated documentation for some of the classes.
This commit is contained in:
parent
b844607274
commit
bef85cac1a
|
@ -2,6 +2,15 @@
|
||||||
|
|
||||||
using namespace icinga;
|
using namespace icinga;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* GetProperty
|
||||||
|
*
|
||||||
|
* Retrieves a value from the dictionary.
|
||||||
|
*
|
||||||
|
* @param key The key.
|
||||||
|
* @param value Pointer to the value.
|
||||||
|
* @returns true if the value was retrieved, false otherwise.
|
||||||
|
*/
|
||||||
bool Dictionary::GetProperty(string key, Variant *value) const
|
bool Dictionary::GetProperty(string key, Variant *value) const
|
||||||
{
|
{
|
||||||
ConstDictionaryIterator i = m_Data.find(key);
|
ConstDictionaryIterator i = m_Data.find(key);
|
||||||
|
@ -13,6 +22,14 @@ bool Dictionary::GetProperty(string key, Variant *value) const
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* SetProperty
|
||||||
|
*
|
||||||
|
* Sets a value in the dictionary.
|
||||||
|
*
|
||||||
|
* @param key The key.
|
||||||
|
* @param value The value.
|
||||||
|
*/
|
||||||
void Dictionary::SetProperty(string key, const Variant& value)
|
void Dictionary::SetProperty(string key, const Variant& value)
|
||||||
{
|
{
|
||||||
DictionaryIterator i = m_Data.find(key);
|
DictionaryIterator i = m_Data.find(key);
|
||||||
|
@ -33,6 +50,15 @@ void Dictionary::SetProperty(string key, const Variant& value)
|
||||||
OnPropertyChanged(dpce);
|
OnPropertyChanged(dpce);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* GetPropertyString
|
||||||
|
*
|
||||||
|
* Retrieves a value from the dictionary and converts it to a string.
|
||||||
|
*
|
||||||
|
* @param key The key.
|
||||||
|
* @param value Pointer to the value.
|
||||||
|
* @returns true if the value was retrieved, false otherwise.
|
||||||
|
*/
|
||||||
bool Dictionary::GetPropertyString(string key, string *value)
|
bool Dictionary::GetPropertyString(string key, string *value)
|
||||||
{
|
{
|
||||||
Variant data;
|
Variant data;
|
||||||
|
@ -44,11 +70,28 @@ bool Dictionary::GetPropertyString(string key, string *value)
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* SetPropertyString
|
||||||
|
*
|
||||||
|
* Sets a value in the dictionary.
|
||||||
|
*
|
||||||
|
* @param key The key.
|
||||||
|
* @param value The value.
|
||||||
|
*/
|
||||||
void Dictionary::SetPropertyString(string key, const string& value)
|
void Dictionary::SetPropertyString(string key, const string& value)
|
||||||
{
|
{
|
||||||
SetProperty(key, Variant(value));
|
SetProperty(key, Variant(value));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* GetPropertyInteger
|
||||||
|
*
|
||||||
|
* Retrieves a value from the dictionary and converts it to an integer.
|
||||||
|
*
|
||||||
|
* @param key The key.
|
||||||
|
* @param value Pointer to the value.
|
||||||
|
* @returns true if the value was retrieved, false otherwise.
|
||||||
|
*/
|
||||||
bool Dictionary::GetPropertyInteger(string key, long *value)
|
bool Dictionary::GetPropertyInteger(string key, long *value)
|
||||||
{
|
{
|
||||||
Variant data;
|
Variant data;
|
||||||
|
@ -60,11 +103,28 @@ bool Dictionary::GetPropertyInteger(string key, long *value)
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* SetPropertyInteger
|
||||||
|
*
|
||||||
|
* Sets a value in the dictionary.
|
||||||
|
*
|
||||||
|
* @param key The key.
|
||||||
|
* @param value The value.
|
||||||
|
*/
|
||||||
void Dictionary::SetPropertyInteger(string key, long value)
|
void Dictionary::SetPropertyInteger(string key, long value)
|
||||||
{
|
{
|
||||||
SetProperty(key, Variant(value));
|
SetProperty(key, Variant(value));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* GetPropertyDictionary
|
||||||
|
*
|
||||||
|
* Retrieves a value from the dictionary and converts it to a dictionary.
|
||||||
|
*
|
||||||
|
* @param key The key.
|
||||||
|
* @param value Pointer to the value.
|
||||||
|
* @returns true if the value was retrieved, false otherwise.
|
||||||
|
*/
|
||||||
bool Dictionary::GetPropertyDictionary(string key, Dictionary::Ptr *value)
|
bool Dictionary::GetPropertyDictionary(string key, Dictionary::Ptr *value)
|
||||||
{
|
{
|
||||||
Dictionary::Ptr dictionary;
|
Dictionary::Ptr dictionary;
|
||||||
|
@ -83,11 +143,28 @@ bool Dictionary::GetPropertyDictionary(string key, Dictionary::Ptr *value)
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* SetPropertyDictionary
|
||||||
|
*
|
||||||
|
* Sets a value in the dictionary.
|
||||||
|
*
|
||||||
|
* @param key The key.
|
||||||
|
* @param value The value.
|
||||||
|
*/
|
||||||
void Dictionary::SetPropertyDictionary(string key, const Dictionary::Ptr& value)
|
void Dictionary::SetPropertyDictionary(string key, const Dictionary::Ptr& value)
|
||||||
{
|
{
|
||||||
SetProperty(key, Variant(value));
|
SetProperty(key, Variant(value));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* GetPropertyObject
|
||||||
|
*
|
||||||
|
* Retrieves a value from the dictionary and converts it to an object.
|
||||||
|
*
|
||||||
|
* @param key The key.
|
||||||
|
* @param value Pointer to the value.
|
||||||
|
* @returns true if the value was retrieved, false otherwise.
|
||||||
|
*/
|
||||||
bool Dictionary::GetPropertyObject(string key, Object::Ptr *value)
|
bool Dictionary::GetPropertyObject(string key, Object::Ptr *value)
|
||||||
{
|
{
|
||||||
Variant data;
|
Variant data;
|
||||||
|
@ -99,26 +176,62 @@ bool Dictionary::GetPropertyObject(string key, Object::Ptr *value)
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* SetPropertyObject
|
||||||
|
*
|
||||||
|
* Sets a value in the dictionary.
|
||||||
|
*
|
||||||
|
* @param key The key.
|
||||||
|
* @param value The value.
|
||||||
|
*/
|
||||||
void Dictionary::SetPropertyObject(string key, const Object::Ptr& value)
|
void Dictionary::SetPropertyObject(string key, const Object::Ptr& value)
|
||||||
{
|
{
|
||||||
SetProperty(key, Variant(value));
|
SetProperty(key, Variant(value));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Begin
|
||||||
|
*
|
||||||
|
* Returns an iterator to the beginning of the dictionary.
|
||||||
|
*
|
||||||
|
* @returns An iterator.
|
||||||
|
*/
|
||||||
DictionaryIterator Dictionary::Begin(void)
|
DictionaryIterator Dictionary::Begin(void)
|
||||||
{
|
{
|
||||||
return m_Data.begin();
|
return m_Data.begin();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* End
|
||||||
|
*
|
||||||
|
* Returns an iterator to the end of the dictionary.
|
||||||
|
*
|
||||||
|
* @returns An iterator.
|
||||||
|
*/
|
||||||
DictionaryIterator Dictionary::End(void)
|
DictionaryIterator Dictionary::End(void)
|
||||||
{
|
{
|
||||||
return m_Data.end();
|
return m_Data.end();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* GetLength
|
||||||
|
*
|
||||||
|
* Returns the number of elements in the dictionary.
|
||||||
|
*
|
||||||
|
* @returns Number of elements.
|
||||||
|
*/
|
||||||
long Dictionary::GetLength(void) const
|
long Dictionary::GetLength(void) const
|
||||||
{
|
{
|
||||||
return m_Data.size();
|
return m_Data.size();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* AddUnnamedProperty
|
||||||
|
*
|
||||||
|
* Adds an unnamed value to the dictionary.
|
||||||
|
*
|
||||||
|
* @param value The value.
|
||||||
|
*/
|
||||||
void Dictionary::AddUnnamedProperty(const Variant& value)
|
void Dictionary::AddUnnamedProperty(const Variant& value)
|
||||||
{
|
{
|
||||||
map<string, Variant>::const_iterator it;
|
map<string, Variant>::const_iterator it;
|
||||||
|
@ -136,21 +249,49 @@ void Dictionary::AddUnnamedProperty(const Variant& value)
|
||||||
m_Data[key] = value;
|
m_Data[key] = value;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* AddUnnamedPropertyString
|
||||||
|
*
|
||||||
|
* Adds an unnamed value to the dictionary.
|
||||||
|
*
|
||||||
|
* @param value The value.
|
||||||
|
*/
|
||||||
void Dictionary::AddUnnamedPropertyString(const string& value)
|
void Dictionary::AddUnnamedPropertyString(const string& value)
|
||||||
{
|
{
|
||||||
AddUnnamedProperty(Variant(value));
|
AddUnnamedProperty(Variant(value));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* AddUnnamedPropertyInteger
|
||||||
|
*
|
||||||
|
* Adds an unnamed value to the dictionary.
|
||||||
|
*
|
||||||
|
* @param value The value.
|
||||||
|
*/
|
||||||
void Dictionary::AddUnnamedPropertyInteger(long value)
|
void Dictionary::AddUnnamedPropertyInteger(long value)
|
||||||
{
|
{
|
||||||
AddUnnamedProperty(Variant(value));
|
AddUnnamedProperty(Variant(value));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* AddUnnamedPropertyDictionary
|
||||||
|
*
|
||||||
|
* Adds an unnamed value to the dictionary.
|
||||||
|
*
|
||||||
|
* @param value The value.
|
||||||
|
*/
|
||||||
void Dictionary::AddUnnamedPropertyDictionary(const Dictionary::Ptr& value)
|
void Dictionary::AddUnnamedPropertyDictionary(const Dictionary::Ptr& value)
|
||||||
{
|
{
|
||||||
AddUnnamedProperty(Variant(value));
|
AddUnnamedProperty(Variant(value));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* AddUnnamedPropertyObject
|
||||||
|
*
|
||||||
|
* Adds an unnamed value to the dictionary.
|
||||||
|
*
|
||||||
|
* @param value The value.
|
||||||
|
*/
|
||||||
void Dictionary::AddUnnamedPropertyObject(const Object::Ptr& value)
|
void Dictionary::AddUnnamedPropertyObject(const Object::Ptr& value)
|
||||||
{
|
{
|
||||||
AddUnnamedProperty(Variant(value));
|
AddUnnamedProperty(Variant(value));
|
||||||
|
|
22
base/event.h
22
base/event.h
|
@ -19,18 +19,40 @@ private:
|
||||||
vector<DelegateType> m_Delegates;
|
vector<DelegateType> m_Delegates;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
/**
|
||||||
|
* operator +=
|
||||||
|
*
|
||||||
|
* Adds a delegate to this event.
|
||||||
|
*
|
||||||
|
* @param rhs The delegate.
|
||||||
|
*/
|
||||||
Event<TArgs>& operator +=(const DelegateType& rhs)
|
Event<TArgs>& operator +=(const DelegateType& rhs)
|
||||||
{
|
{
|
||||||
m_Delegates.push_back(rhs);
|
m_Delegates.push_back(rhs);
|
||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* operator -=
|
||||||
|
*
|
||||||
|
* Removes a delegate from this event.
|
||||||
|
*
|
||||||
|
* @param rhs The delegate.
|
||||||
|
*/
|
||||||
Event<TArgs>& operator -=(const DelegateType& rhs)
|
Event<TArgs>& operator -=(const DelegateType& rhs)
|
||||||
{
|
{
|
||||||
m_Delegates.erase(rhs);
|
m_Delegates.erase(rhs);
|
||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* operator ()
|
||||||
|
*
|
||||||
|
* Invokes each delegate that is registered for this event. Any delegates
|
||||||
|
* which return -1 are removed.
|
||||||
|
*
|
||||||
|
* @param args Event arguments.
|
||||||
|
*/
|
||||||
void operator()(const TArgs& args)
|
void operator()(const TArgs& args)
|
||||||
{
|
{
|
||||||
typename vector<DelegateType>::iterator i;
|
typename vector<DelegateType>::iterator i;
|
||||||
|
|
|
@ -2,26 +2,60 @@
|
||||||
|
|
||||||
using namespace icinga;
|
using namespace icinga;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Exception
|
||||||
|
*
|
||||||
|
* Default constructor for the Exception class.
|
||||||
|
*/
|
||||||
Exception::Exception(void)
|
Exception::Exception(void)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Exception
|
||||||
|
*
|
||||||
|
* Constructor for the exception class.
|
||||||
|
*
|
||||||
|
* @param message A message describing the exception.
|
||||||
|
*/
|
||||||
Exception::Exception(const string& message)
|
Exception::Exception(const string& message)
|
||||||
{
|
{
|
||||||
SetMessage(message);
|
SetMessage(message);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* GetMessage
|
||||||
|
*
|
||||||
|
* Retrieves the description for the exception.
|
||||||
|
*
|
||||||
|
* @returns The description.
|
||||||
|
*/
|
||||||
string Exception::GetMessage(void) const
|
string Exception::GetMessage(void) const
|
||||||
{
|
{
|
||||||
return m_Message;
|
return m_Message;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* SetMessage
|
||||||
|
*
|
||||||
|
* Sets the description for the exception.
|
||||||
|
*
|
||||||
|
* @param message The description.
|
||||||
|
*/
|
||||||
void Exception::SetMessage(string message)
|
void Exception::SetMessage(string message)
|
||||||
{
|
{
|
||||||
m_Message = message;
|
m_Message = message;
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifdef _WIN32
|
#ifdef _WIN32
|
||||||
|
/**
|
||||||
|
* FormatError
|
||||||
|
*
|
||||||
|
* Formats an Win32 error code.
|
||||||
|
*
|
||||||
|
* @param code The error code.
|
||||||
|
* @returns A string describing the error.
|
||||||
|
*/
|
||||||
string Win32Exception::FormatErrorCode(int code)
|
string Win32Exception::FormatErrorCode(int code)
|
||||||
{
|
{
|
||||||
char *message;
|
char *message;
|
||||||
|
@ -40,11 +74,27 @@ string Win32Exception::FormatErrorCode(int code)
|
||||||
}
|
}
|
||||||
#endif /* _WIN32 */
|
#endif /* _WIN32 */
|
||||||
|
|
||||||
|
/**
|
||||||
|
* FormatError
|
||||||
|
*
|
||||||
|
* Formats a Posix error code.
|
||||||
|
*
|
||||||
|
* @param code The error code.
|
||||||
|
* @returns A string describing the error.
|
||||||
|
*/
|
||||||
string PosixException::FormatErrorCode(int code)
|
string PosixException::FormatErrorCode(int code)
|
||||||
{
|
{
|
||||||
return strerror(code);
|
return strerror(code);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* FormatError
|
||||||
|
*
|
||||||
|
* Formats an OpenSSL error code.
|
||||||
|
*
|
||||||
|
* @param code The error code.
|
||||||
|
* @returns A string describing the error.
|
||||||
|
*/
|
||||||
string OpenSSLException::FormatErrorCode(int code)
|
string OpenSSLException::FormatErrorCode(int code)
|
||||||
{
|
{
|
||||||
const char *message = ERR_error_string(code, NULL);
|
const char *message = ERR_error_string(code, NULL);
|
||||||
|
|
|
@ -2,6 +2,11 @@
|
||||||
|
|
||||||
using namespace icinga;
|
using namespace icinga;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* FIFO
|
||||||
|
*
|
||||||
|
* Constructor for the FIFO class.
|
||||||
|
*/
|
||||||
FIFO::FIFO(void)
|
FIFO::FIFO(void)
|
||||||
{
|
{
|
||||||
m_Buffer = NULL;
|
m_Buffer = NULL;
|
||||||
|
@ -10,11 +15,23 @@ FIFO::FIFO(void)
|
||||||
m_Offset = 0;
|
m_Offset = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* ~FIFO
|
||||||
|
*
|
||||||
|
* Destructor for the FIFO class.
|
||||||
|
*/
|
||||||
FIFO::~FIFO(void)
|
FIFO::~FIFO(void)
|
||||||
{
|
{
|
||||||
Memory::Free(m_Buffer);
|
Memory::Free(m_Buffer);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* ResizeBuffer
|
||||||
|
*
|
||||||
|
* Resizes the FIFO's buffer so that it is at least newSize bytes long.
|
||||||
|
*
|
||||||
|
* @param newSize The minimum new size of the FIFO buffer.
|
||||||
|
*/
|
||||||
void FIFO::ResizeBuffer(size_t newSize)
|
void FIFO::ResizeBuffer(size_t newSize)
|
||||||
{
|
{
|
||||||
if (m_AllocSize >= newSize)
|
if (m_AllocSize >= newSize)
|
||||||
|
@ -26,6 +43,12 @@ void FIFO::ResizeBuffer(size_t newSize)
|
||||||
m_AllocSize = newSize;
|
m_AllocSize = newSize;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Optimize
|
||||||
|
*
|
||||||
|
* Optimizes memory usage of the FIFO buffer by reallocating
|
||||||
|
* and moving the buffer.
|
||||||
|
*/
|
||||||
void FIFO::Optimize(void)
|
void FIFO::Optimize(void)
|
||||||
{
|
{
|
||||||
//char *newBuffer;
|
//char *newBuffer;
|
||||||
|
@ -50,16 +73,40 @@ void FIFO::Optimize(void)
|
||||||
m_Offset = 0;*/
|
m_Offset = 0;*/
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* GetSize
|
||||||
|
*
|
||||||
|
* Returns the number of bytes that are contained in the FIFO.
|
||||||
|
*
|
||||||
|
* @returns The number of bytes.
|
||||||
|
*/
|
||||||
size_t FIFO::GetSize(void) const
|
size_t FIFO::GetSize(void) const
|
||||||
{
|
{
|
||||||
return m_DataSize;
|
return m_DataSize;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* GetReadBuffer
|
||||||
|
*
|
||||||
|
* Returns a pointer to the start of the read buffer.
|
||||||
|
*
|
||||||
|
* @returns Pointer to the read buffer.
|
||||||
|
*/
|
||||||
const void *FIFO::GetReadBuffer(void) const
|
const void *FIFO::GetReadBuffer(void) const
|
||||||
{
|
{
|
||||||
return m_Buffer + m_Offset;
|
return m_Buffer + m_Offset;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Read
|
||||||
|
*
|
||||||
|
* Reads data from the FIFO and places it in the specified buffer.
|
||||||
|
*
|
||||||
|
* @param buffer The buffer where the data should be placed (can be NULL if
|
||||||
|
* the reader is not interested in the data).
|
||||||
|
* @param count The number of bytes to read.
|
||||||
|
* @returns The number of bytes read which may be less than what was requested.
|
||||||
|
*/
|
||||||
size_t FIFO::Read(void *buffer, size_t count)
|
size_t FIFO::Read(void *buffer, size_t count)
|
||||||
{
|
{
|
||||||
count = (count <= m_DataSize) ? count : m_DataSize;
|
count = (count <= m_DataSize) ? count : m_DataSize;
|
||||||
|
@ -75,6 +122,15 @@ size_t FIFO::Read(void *buffer, size_t count)
|
||||||
return count;
|
return count;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* GetWriteBuffer
|
||||||
|
*
|
||||||
|
* Returns a pointer to the start of the write buffer.
|
||||||
|
*
|
||||||
|
* @param count Minimum size of the buffer; on return this parameter
|
||||||
|
* contains the actual size of the available buffer which can
|
||||||
|
* be larger than the requested size.
|
||||||
|
*/
|
||||||
void *FIFO::GetWriteBuffer(size_t *count)
|
void *FIFO::GetWriteBuffer(size_t *count)
|
||||||
{
|
{
|
||||||
ResizeBuffer(m_Offset + m_DataSize + *count);
|
ResizeBuffer(m_Offset + m_DataSize + *count);
|
||||||
|
@ -83,6 +139,16 @@ void *FIFO::GetWriteBuffer(size_t *count)
|
||||||
return m_Buffer + m_Offset + m_DataSize;
|
return m_Buffer + m_Offset + m_DataSize;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Write
|
||||||
|
*
|
||||||
|
* Writes data to the FIFO.
|
||||||
|
*
|
||||||
|
* @param buffer The data that is to be written (can be NULL if the writer has
|
||||||
|
* already filled the write buffer, e.g. via GetWriteBuffer()).
|
||||||
|
* @param count The number of bytes to write.
|
||||||
|
* @returns The number of bytes written
|
||||||
|
*/
|
||||||
size_t FIFO::Write(const void *buffer, size_t count)
|
size_t FIFO::Write(const void *buffer, size_t count)
|
||||||
{
|
{
|
||||||
if (buffer != NULL) {
|
if (buffer != NULL) {
|
||||||
|
|
|
@ -2,10 +2,24 @@
|
||||||
|
|
||||||
using namespace icinga;
|
using namespace icinga;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Memory
|
||||||
|
*
|
||||||
|
* Constructor for the memory class.
|
||||||
|
*/
|
||||||
Memory::Memory(void)
|
Memory::Memory(void)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Allocate
|
||||||
|
*
|
||||||
|
* Allocates memory. Throws an exception if no memory is available. Alignment
|
||||||
|
* guarantees are the same like for malloc().
|
||||||
|
*
|
||||||
|
* @param size The size of the requested memory block.
|
||||||
|
* @returns A new block of memory.
|
||||||
|
*/
|
||||||
void *Memory::Allocate(size_t size)
|
void *Memory::Allocate(size_t size)
|
||||||
{
|
{
|
||||||
void *ptr = malloc(size);
|
void *ptr = malloc(size);
|
||||||
|
@ -16,6 +30,15 @@ void *Memory::Allocate(size_t size)
|
||||||
return ptr;
|
return ptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Reallocate
|
||||||
|
*
|
||||||
|
* Resizes a block of memory. Throws an exception if no memory is available.
|
||||||
|
*
|
||||||
|
* @param ptr The old memory block or NULL.
|
||||||
|
* @param size The requested new size of the block.
|
||||||
|
* @returns A pointer to the new memory block.
|
||||||
|
*/
|
||||||
void *Memory::Reallocate(void *ptr, size_t size)
|
void *Memory::Reallocate(void *ptr, size_t size)
|
||||||
{
|
{
|
||||||
void *new_ptr = realloc(ptr, size);
|
void *new_ptr = realloc(ptr, size);
|
||||||
|
@ -26,6 +49,14 @@ void *Memory::Reallocate(void *ptr, size_t size)
|
||||||
return new_ptr;
|
return new_ptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* StrDup
|
||||||
|
*
|
||||||
|
* Duplicates a string. Throws an exception if no memory is available.
|
||||||
|
*
|
||||||
|
* @param str The string.
|
||||||
|
* @returns A copy of the string.
|
||||||
|
*/
|
||||||
char *Memory::StrDup(const char *str)
|
char *Memory::StrDup(const char *str)
|
||||||
{
|
{
|
||||||
char *new_str = strdup(str);
|
char *new_str = strdup(str);
|
||||||
|
@ -36,6 +67,13 @@ char *Memory::StrDup(const char *str)
|
||||||
return new_str;
|
return new_str;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Free
|
||||||
|
*
|
||||||
|
* Frees a memory block.
|
||||||
|
*
|
||||||
|
* @param ptr The memory block.
|
||||||
|
*/
|
||||||
void Memory::Free(void *ptr)
|
void Memory::Free(void *ptr)
|
||||||
{
|
{
|
||||||
if (ptr != NULL)
|
if (ptr != NULL)
|
||||||
|
|
|
@ -2,6 +2,11 @@
|
||||||
|
|
||||||
using namespace icinga;
|
using namespace icinga;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Mutex
|
||||||
|
*
|
||||||
|
* Constructor for the Mutex class.
|
||||||
|
*/
|
||||||
Mutex::Mutex(void)
|
Mutex::Mutex(void)
|
||||||
{
|
{
|
||||||
#ifdef _WIN32
|
#ifdef _WIN32
|
||||||
|
@ -11,6 +16,11 @@ Mutex::Mutex(void)
|
||||||
#endif /* _WIN32 */
|
#endif /* _WIN32 */
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* ~Mutex
|
||||||
|
*
|
||||||
|
* Destructor for the Mutex class.
|
||||||
|
*/
|
||||||
Mutex::~Mutex(void)
|
Mutex::~Mutex(void)
|
||||||
{
|
{
|
||||||
#ifdef _WIN32
|
#ifdef _WIN32
|
||||||
|
@ -20,6 +30,14 @@ Mutex::~Mutex(void)
|
||||||
#endif /* _WIN32 */
|
#endif /* _WIN32 */
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* TryEnter
|
||||||
|
*
|
||||||
|
* Tries to lock the mutex. If the mutex cannot be immediatelly
|
||||||
|
* locked the operation fails.
|
||||||
|
*
|
||||||
|
* @returns true if the operation succeeded, false otherwise.
|
||||||
|
*/
|
||||||
bool Mutex::TryEnter(void)
|
bool Mutex::TryEnter(void)
|
||||||
{
|
{
|
||||||
#ifdef _WIN32
|
#ifdef _WIN32
|
||||||
|
@ -29,6 +47,11 @@ bool Mutex::TryEnter(void)
|
||||||
#endif /* _WIN32 */
|
#endif /* _WIN32 */
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Enter
|
||||||
|
*
|
||||||
|
* Locks the mutex.
|
||||||
|
*/
|
||||||
void Mutex::Enter(void)
|
void Mutex::Enter(void)
|
||||||
{
|
{
|
||||||
#ifdef _WIN32
|
#ifdef _WIN32
|
||||||
|
@ -38,6 +61,11 @@ void Mutex::Enter(void)
|
||||||
#endif /* _WIN32 */
|
#endif /* _WIN32 */
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Exit
|
||||||
|
*
|
||||||
|
* Unlocks the mutex.
|
||||||
|
*/
|
||||||
void Mutex::Exit(void)
|
void Mutex::Exit(void)
|
||||||
{
|
{
|
||||||
#ifdef _WIN32
|
#ifdef _WIN32
|
||||||
|
@ -47,6 +75,13 @@ void Mutex::Exit(void)
|
||||||
#endif /* _WIN32 */
|
#endif /* _WIN32 */
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get
|
||||||
|
*
|
||||||
|
* Retrieves the platform-specific mutex handle.
|
||||||
|
*
|
||||||
|
* @returns The platform-specific mutex handle.
|
||||||
|
*/
|
||||||
#ifdef _WIN32
|
#ifdef _WIN32
|
||||||
CRITICAL_SECTION *Mutex::Get(void)
|
CRITICAL_SECTION *Mutex::Get(void)
|
||||||
#else /* _WIN32 */
|
#else /* _WIN32 */
|
||||||
|
|
100
base/socket.cpp
100
base/socket.cpp
|
@ -2,18 +2,39 @@
|
||||||
|
|
||||||
using namespace icinga;
|
using namespace icinga;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Socket::Sockets
|
||||||
|
*
|
||||||
|
* A collection of weak pointers to Socket objects which have been
|
||||||
|
* registered with the socket sub-system.
|
||||||
|
*/
|
||||||
Socket::CollectionType Socket::Sockets;
|
Socket::CollectionType Socket::Sockets;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Socket
|
||||||
|
*
|
||||||
|
* Constructor for the Socket class.
|
||||||
|
*/
|
||||||
Socket::Socket(void)
|
Socket::Socket(void)
|
||||||
{
|
{
|
||||||
m_FD = INVALID_SOCKET;
|
m_FD = INVALID_SOCKET;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* ~Socket
|
||||||
|
*
|
||||||
|
* Destructor for the Socket class.
|
||||||
|
*/
|
||||||
Socket::~Socket(void)
|
Socket::~Socket(void)
|
||||||
{
|
{
|
||||||
CloseInternal(true);
|
CloseInternal(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Start
|
||||||
|
*
|
||||||
|
* Registers the socket and starts handling events for it.
|
||||||
|
*/
|
||||||
void Socket::Start(void)
|
void Socket::Start(void)
|
||||||
{
|
{
|
||||||
assert(m_FD != INVALID_SOCKET);
|
assert(m_FD != INVALID_SOCKET);
|
||||||
|
@ -23,11 +44,23 @@ void Socket::Start(void)
|
||||||
Sockets.push_back(static_pointer_cast<Socket>(shared_from_this()));
|
Sockets.push_back(static_pointer_cast<Socket>(shared_from_this()));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Stop
|
||||||
|
*
|
||||||
|
* Unregisters the sockets and stops handling events for it.
|
||||||
|
*/
|
||||||
void Socket::Stop(void)
|
void Socket::Stop(void)
|
||||||
{
|
{
|
||||||
Sockets.remove_if(weak_ptr_eq_raw<Socket>(this));
|
Sockets.remove_if(weak_ptr_eq_raw<Socket>(this));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* SetFD
|
||||||
|
*
|
||||||
|
* Sets the file descriptor for this socket object.
|
||||||
|
*
|
||||||
|
* @param fd The file descriptor.
|
||||||
|
*/
|
||||||
void Socket::SetFD(SOCKET fd)
|
void Socket::SetFD(SOCKET fd)
|
||||||
{
|
{
|
||||||
unsigned long lTrue = 1;
|
unsigned long lTrue = 1;
|
||||||
|
@ -38,16 +71,35 @@ void Socket::SetFD(SOCKET fd)
|
||||||
m_FD = fd;
|
m_FD = fd;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* GetFD
|
||||||
|
*
|
||||||
|
* Retrieves the file descriptor for this socket object.
|
||||||
|
*
|
||||||
|
* @returns The file descriptor.
|
||||||
|
*/
|
||||||
SOCKET Socket::GetFD(void) const
|
SOCKET Socket::GetFD(void) const
|
||||||
{
|
{
|
||||||
return m_FD;
|
return m_FD;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Close
|
||||||
|
*
|
||||||
|
* Closes the socket.
|
||||||
|
*/
|
||||||
void Socket::Close(void)
|
void Socket::Close(void)
|
||||||
{
|
{
|
||||||
CloseInternal(false);
|
CloseInternal(false);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* CloseInternal
|
||||||
|
*
|
||||||
|
* Closes the socket.
|
||||||
|
*
|
||||||
|
* @param from_dtor Whether this method was called from the destructor.
|
||||||
|
*/
|
||||||
void Socket::CloseInternal(bool from_dtor)
|
void Socket::CloseInternal(bool from_dtor)
|
||||||
{
|
{
|
||||||
if (m_FD == INVALID_SOCKET)
|
if (m_FD == INVALID_SOCKET)
|
||||||
|
@ -67,6 +119,11 @@ void Socket::CloseInternal(bool from_dtor)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* HandleSocketError
|
||||||
|
*
|
||||||
|
* Handles a socket error by calling the OnError event.
|
||||||
|
*/
|
||||||
void Socket::HandleSocketError(void)
|
void Socket::HandleSocketError(void)
|
||||||
{
|
{
|
||||||
int opt;
|
int opt;
|
||||||
|
@ -89,6 +146,14 @@ void Socket::HandleSocketError(void)
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* ExceptionEventHandler
|
||||||
|
*
|
||||||
|
* Processes errors that have occured for the socket.
|
||||||
|
*
|
||||||
|
* @param ea Event arguments for the socket error.
|
||||||
|
* @returns 0
|
||||||
|
*/
|
||||||
int Socket::ExceptionEventHandler(const EventArgs& ea)
|
int Socket::ExceptionEventHandler(const EventArgs& ea)
|
||||||
{
|
{
|
||||||
HandleSocketError();
|
HandleSocketError();
|
||||||
|
@ -96,16 +161,37 @@ int Socket::ExceptionEventHandler(const EventArgs& ea)
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* WantsToRead
|
||||||
|
*
|
||||||
|
* Checks whether data should be read for this socket object.
|
||||||
|
*
|
||||||
|
* @returns true if the socket should be registered for reading, false otherwise.
|
||||||
|
*/
|
||||||
bool Socket::WantsToRead(void) const
|
bool Socket::WantsToRead(void) const
|
||||||
{
|
{
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* WantsToWrite
|
||||||
|
*
|
||||||
|
* Checks whether data should be written for this socket object.
|
||||||
|
*
|
||||||
|
* @returns true if the socket should be registered for writing, false otherwise.
|
||||||
|
*/
|
||||||
bool Socket::WantsToWrite(void) const
|
bool Socket::WantsToWrite(void) const
|
||||||
{
|
{
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* GetAddressFromSockaddr
|
||||||
|
*
|
||||||
|
* Formats a sockaddr in a human-readable way.
|
||||||
|
*
|
||||||
|
* @returns A string describing the sockaddr.
|
||||||
|
*/
|
||||||
string Socket::GetAddressFromSockaddr(sockaddr *address, socklen_t len)
|
string Socket::GetAddressFromSockaddr(sockaddr *address, socklen_t len)
|
||||||
{
|
{
|
||||||
char host[NI_MAXHOST];
|
char host[NI_MAXHOST];
|
||||||
|
@ -119,6 +205,13 @@ string Socket::GetAddressFromSockaddr(sockaddr *address, socklen_t len)
|
||||||
return s.str();
|
return s.str();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* GetClientAddress
|
||||||
|
*
|
||||||
|
* Returns a string describing the local address of the socket.
|
||||||
|
*
|
||||||
|
* @returns A string describing the local address.
|
||||||
|
*/
|
||||||
string Socket::GetClientAddress(void)
|
string Socket::GetClientAddress(void)
|
||||||
{
|
{
|
||||||
sockaddr_storage sin;
|
sockaddr_storage sin;
|
||||||
|
@ -133,6 +226,13 @@ string Socket::GetClientAddress(void)
|
||||||
return GetAddressFromSockaddr((sockaddr *)&sin, len);
|
return GetAddressFromSockaddr((sockaddr *)&sin, len);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* GetPeerAddress
|
||||||
|
*
|
||||||
|
* Returns a string describing the peer address of the socket.
|
||||||
|
*
|
||||||
|
* @returns A string describing the peer address.
|
||||||
|
*/
|
||||||
string Socket::GetPeerAddress(void)
|
string Socket::GetPeerAddress(void)
|
||||||
{
|
{
|
||||||
sockaddr_storage sin;
|
sockaddr_storage sin;
|
||||||
|
|
|
@ -2,6 +2,13 @@
|
||||||
|
|
||||||
using namespace icinga;
|
using namespace icinga;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* MakeSocket
|
||||||
|
*
|
||||||
|
* Creates a socket.
|
||||||
|
*
|
||||||
|
* @param family The socket family for the new socket.
|
||||||
|
*/
|
||||||
void TCPSocket::MakeSocket(int family)
|
void TCPSocket::MakeSocket(int family)
|
||||||
{
|
{
|
||||||
assert(GetFD() == INVALID_SOCKET);
|
assert(GetFD() == INVALID_SOCKET);
|
||||||
|
@ -17,11 +24,27 @@ void TCPSocket::MakeSocket(int family)
|
||||||
SetFD(fd);
|
SetFD(fd);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Bind
|
||||||
|
*
|
||||||
|
* Creates a socket and binds it to the specified service.
|
||||||
|
*
|
||||||
|
* @param service The service.
|
||||||
|
* @param family The address family for the socket.
|
||||||
|
*/
|
||||||
void TCPSocket::Bind(string service, int family)
|
void TCPSocket::Bind(string service, int family)
|
||||||
{
|
{
|
||||||
Bind(string(), service, family);
|
Bind(string(), service, family);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Bind
|
||||||
|
*
|
||||||
|
* Creates a socket and binds it to the specified node and service.
|
||||||
|
*
|
||||||
|
* @param service The service.
|
||||||
|
* @param family The address family for the socket.
|
||||||
|
*/
|
||||||
void TCPSocket::Bind(string node, string service, int family)
|
void TCPSocket::Bind(string node, string service, int family)
|
||||||
{
|
{
|
||||||
addrinfo hints;
|
addrinfo hints;
|
||||||
|
|
|
@ -7,11 +7,21 @@ using namespace icinga;
|
||||||
time_t Timer::NextCall;
|
time_t Timer::NextCall;
|
||||||
Timer::CollectionType Timer::Timers;
|
Timer::CollectionType Timer::Timers;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Constructor for the Timer class.
|
||||||
|
*/
|
||||||
Timer::Timer(void)
|
Timer::Timer(void)
|
||||||
{
|
{
|
||||||
m_Interval = 0;
|
m_Interval = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* GetNextCall
|
||||||
|
*
|
||||||
|
* Retrieves when the next timer is due.
|
||||||
|
*
|
||||||
|
* @returns Time when the next timer is due.
|
||||||
|
*/
|
||||||
time_t Timer::GetNextCall(void)
|
time_t Timer::GetNextCall(void)
|
||||||
{
|
{
|
||||||
if (NextCall < time(NULL))
|
if (NextCall < time(NULL))
|
||||||
|
@ -20,6 +30,12 @@ time_t Timer::GetNextCall(void)
|
||||||
return NextCall;
|
return NextCall;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* RescheduleTimers
|
||||||
|
*
|
||||||
|
* Reschedules all timers, thereby updating the NextCall
|
||||||
|
* timestamp used by the GetNextCall() function.
|
||||||
|
*/
|
||||||
void Timer::RescheduleTimers(void)
|
void Timer::RescheduleTimers(void)
|
||||||
{
|
{
|
||||||
/* Make sure we wake up at least once every 30 seconds */
|
/* Make sure we wake up at least once every 30 seconds */
|
||||||
|
@ -36,6 +52,11 @@ void Timer::RescheduleTimers(void)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* CallExpiredTimers
|
||||||
|
*
|
||||||
|
* Calls all expired timers and reschedules them.
|
||||||
|
*/
|
||||||
void Timer::CallExpiredTimers(void)
|
void Timer::CallExpiredTimers(void)
|
||||||
{
|
{
|
||||||
time_t now;
|
time_t now;
|
||||||
|
@ -61,8 +82,13 @@ void Timer::CallExpiredTimers(void)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Note: the timer delegate must not call Disable() on any other timers than
|
/**
|
||||||
* the timer that originally invoked the delegate */
|
* Call
|
||||||
|
*
|
||||||
|
* Calls this timer. Note: the timer delegate must not call
|
||||||
|
* Disable() on any other timers than the timer that originally
|
||||||
|
* invoked the delegate.
|
||||||
|
*/
|
||||||
void Timer::Call(void)
|
void Timer::Call(void)
|
||||||
{
|
{
|
||||||
TimerEventArgs tea;
|
TimerEventArgs tea;
|
||||||
|
@ -71,27 +97,59 @@ void Timer::Call(void)
|
||||||
OnTimerExpired(tea);
|
OnTimerExpired(tea);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* SetInterval
|
||||||
|
*
|
||||||
|
* Sets the interval for this timer.
|
||||||
|
*
|
||||||
|
* @param interval The new interval.
|
||||||
|
*/
|
||||||
void Timer::SetInterval(unsigned int interval)
|
void Timer::SetInterval(unsigned int interval)
|
||||||
{
|
{
|
||||||
m_Interval = interval;
|
m_Interval = interval;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* GetInterval
|
||||||
|
*
|
||||||
|
* Retrieves the interval for this timer.
|
||||||
|
*
|
||||||
|
* @returns The interval.
|
||||||
|
*/
|
||||||
unsigned int Timer::GetInterval(void) const
|
unsigned int Timer::GetInterval(void) const
|
||||||
{
|
{
|
||||||
return m_Interval;
|
return m_Interval;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* SetUserArgs
|
||||||
|
*
|
||||||
|
* Sets user arguments for the timer callback.
|
||||||
|
*
|
||||||
|
* @param userArgs The user arguments.
|
||||||
|
*/
|
||||||
void Timer::SetUserArgs(const EventArgs& userArgs)
|
void Timer::SetUserArgs(const EventArgs& userArgs)
|
||||||
{
|
{
|
||||||
m_UserArgs = userArgs;
|
m_UserArgs = userArgs;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* GetUserArgs
|
||||||
|
*
|
||||||
|
* Retrieves the user arguments for the timer callback.
|
||||||
|
*
|
||||||
|
* @returns The user arguments.
|
||||||
|
*/
|
||||||
EventArgs Timer::GetUserArgs(void) const
|
EventArgs Timer::GetUserArgs(void) const
|
||||||
{
|
{
|
||||||
return m_UserArgs;
|
return m_UserArgs;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Start
|
||||||
|
*
|
||||||
|
* Registers the timer and starts processing events for it.
|
||||||
|
*/
|
||||||
void Timer::Start(void)
|
void Timer::Start(void)
|
||||||
{
|
{
|
||||||
Timers.push_back(static_pointer_cast<Timer>(shared_from_this()));
|
Timers.push_back(static_pointer_cast<Timer>(shared_from_this()));
|
||||||
|
@ -99,11 +157,23 @@ void Timer::Start(void)
|
||||||
Reschedule(time(NULL) + m_Interval);
|
Reschedule(time(NULL) + m_Interval);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Stop
|
||||||
|
*
|
||||||
|
* Unregisters the timer and stops processing events for it.
|
||||||
|
*/
|
||||||
void Timer::Stop(void)
|
void Timer::Stop(void)
|
||||||
{
|
{
|
||||||
Timers.remove_if(weak_ptr_eq_raw<Timer>(this));
|
Timers.remove_if(weak_ptr_eq_raw<Timer>(this));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Reschedule
|
||||||
|
*
|
||||||
|
* Reschedules this timer.
|
||||||
|
*
|
||||||
|
* @param next The time when this timer should be called again.
|
||||||
|
*/
|
||||||
void Timer::Reschedule(time_t next)
|
void Timer::Reschedule(time_t next)
|
||||||
{
|
{
|
||||||
m_Next = next;
|
m_Next = next;
|
||||||
|
|
|
@ -5,11 +5,25 @@
|
||||||
|
|
||||||
using namespace icinga;
|
using namespace icinga;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Sleep
|
||||||
|
*
|
||||||
|
* Sleeps for the specified amount of time.
|
||||||
|
*
|
||||||
|
* @param milliseconds The amount of time in milliseconds.
|
||||||
|
*/
|
||||||
void Sleep(unsigned long milliseconds)
|
void Sleep(unsigned long milliseconds)
|
||||||
{
|
{
|
||||||
usleep(milliseconds * 1000);
|
usleep(milliseconds * 1000);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* closesocket
|
||||||
|
*
|
||||||
|
* Closes a socket.
|
||||||
|
*
|
||||||
|
* @param fd The socket that is to be closed.
|
||||||
|
*/
|
||||||
void closesocket(SOCKET fd)
|
void closesocket(SOCKET fd)
|
||||||
{
|
{
|
||||||
close(fd);
|
close(fd);
|
||||||
|
|
|
@ -43,6 +43,11 @@ void Utility::Daemonize(void) {
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* InitializeOpenSSL
|
||||||
|
*
|
||||||
|
* Initializes the OpenSSL library.
|
||||||
|
*/
|
||||||
void Utility::InitializeOpenSSL(void)
|
void Utility::InitializeOpenSSL(void)
|
||||||
{
|
{
|
||||||
if (!m_SSLInitialized) {
|
if (!m_SSLInitialized) {
|
||||||
|
@ -53,6 +58,16 @@ void Utility::InitializeOpenSSL(void)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* MakeSSLContext
|
||||||
|
*
|
||||||
|
* Initializes an SSL context using the specified certificates.
|
||||||
|
*
|
||||||
|
* @param pubkey The public key.
|
||||||
|
* @param privkey The matching private key.
|
||||||
|
* @param cakey CA certificate chain file.
|
||||||
|
* @returns An SSL context.
|
||||||
|
*/
|
||||||
shared_ptr<SSL_CTX> Utility::MakeSSLContext(string pubkey, string privkey, string cakey)
|
shared_ptr<SSL_CTX> Utility::MakeSSLContext(string pubkey, string privkey, string cakey)
|
||||||
{
|
{
|
||||||
InitializeOpenSSL();
|
InitializeOpenSSL();
|
||||||
|
@ -75,6 +90,14 @@ shared_ptr<SSL_CTX> Utility::MakeSSLContext(string pubkey, string privkey, strin
|
||||||
return sslContext;
|
return sslContext;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* GetCertificateCN
|
||||||
|
*
|
||||||
|
* Retrieves the common name for a X509 certificate.
|
||||||
|
*
|
||||||
|
* @param certificate The X509 certificate.
|
||||||
|
* @returns The common name.
|
||||||
|
*/
|
||||||
string Utility::GetCertificateCN(const shared_ptr<X509>& certificate)
|
string Utility::GetCertificateCN(const shared_ptr<X509>& certificate)
|
||||||
{
|
{
|
||||||
char buffer[256];
|
char buffer[256];
|
||||||
|
@ -87,6 +110,14 @@ string Utility::GetCertificateCN(const shared_ptr<X509>& certificate)
|
||||||
return buffer;
|
return buffer;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* GetX509Certificate
|
||||||
|
*
|
||||||
|
* Retrieves an X509 certificate from the specified file.
|
||||||
|
*
|
||||||
|
* @param pemfile The filename.
|
||||||
|
* @returns An X509 certificate.
|
||||||
|
*/
|
||||||
shared_ptr<X509> Utility::GetX509Certificate(string pemfile)
|
shared_ptr<X509> Utility::GetX509Certificate(string pemfile)
|
||||||
{
|
{
|
||||||
X509 *cert;
|
X509 *cert;
|
||||||
|
|
|
@ -43,7 +43,10 @@ void ConfigRpcComponent::Start(void)
|
||||||
|
|
||||||
void ConfigRpcComponent::Stop(void)
|
void ConfigRpcComponent::Stop(void)
|
||||||
{
|
{
|
||||||
// TODO: implement
|
EndpointManager::Ptr mgr = GetEndpointManager();
|
||||||
|
|
||||||
|
if (mgr)
|
||||||
|
mgr->UnregisterEndpoint(m_ConfigRpcEndpoint);
|
||||||
}
|
}
|
||||||
|
|
||||||
int ConfigRpcComponent::NewEndpointHandler(const NewEndpointEventArgs& ea)
|
int ConfigRpcComponent::NewEndpointHandler(const NewEndpointEventArgs& ea)
|
||||||
|
|
|
@ -2,11 +2,23 @@
|
||||||
|
|
||||||
using namespace icinga;
|
using namespace icinga;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* GetName
|
||||||
|
*
|
||||||
|
* Returns the name of the component.
|
||||||
|
*
|
||||||
|
* @returns The name.
|
||||||
|
*/
|
||||||
string DemoComponent::GetName(void) const
|
string DemoComponent::GetName(void) const
|
||||||
{
|
{
|
||||||
return "democomponent";
|
return "democomponent";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Start
|
||||||
|
*
|
||||||
|
* Starts the component.
|
||||||
|
*/
|
||||||
void DemoComponent::Start(void)
|
void DemoComponent::Start(void)
|
||||||
{
|
{
|
||||||
m_DemoEndpoint = make_shared<VirtualEndpoint>();
|
m_DemoEndpoint = make_shared<VirtualEndpoint>();
|
||||||
|
@ -23,6 +35,11 @@ void DemoComponent::Start(void)
|
||||||
m_DemoTimer->Start();
|
m_DemoTimer->Start();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Stop
|
||||||
|
*
|
||||||
|
* Stops the component.
|
||||||
|
*/
|
||||||
void DemoComponent::Stop(void)
|
void DemoComponent::Stop(void)
|
||||||
{
|
{
|
||||||
IcingaApplication::Ptr app = GetIcingaApplication();
|
IcingaApplication::Ptr app = GetIcingaApplication();
|
||||||
|
@ -33,6 +50,14 @@ void DemoComponent::Stop(void)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* DemoTimerHandler
|
||||||
|
*
|
||||||
|
* Periodically sends a demo::HelloWorld message.
|
||||||
|
*
|
||||||
|
* @param tea Event arguments for the timer.
|
||||||
|
* @returns 0
|
||||||
|
*/
|
||||||
int DemoComponent::DemoTimerHandler(const TimerEventArgs& tea)
|
int DemoComponent::DemoTimerHandler(const TimerEventArgs& tea)
|
||||||
{
|
{
|
||||||
Application::Log("Sending multicast 'hello world' message.");
|
Application::Log("Sending multicast 'hello world' message.");
|
||||||
|
@ -46,6 +71,11 @@ int DemoComponent::DemoTimerHandler(const TimerEventArgs& tea)
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* HelloWorldRequestHandler
|
||||||
|
*
|
||||||
|
* Processes demo::HelloWorld messages.
|
||||||
|
*/
|
||||||
int DemoComponent::HelloWorldRequestHandler(const NewRequestEventArgs& nrea)
|
int DemoComponent::HelloWorldRequestHandler(const NewRequestEventArgs& nrea)
|
||||||
{
|
{
|
||||||
Application::Log("Got 'hello world' from address=" + nrea.Sender->GetAddress() + ", identity=" + nrea.Sender->GetIdentity());
|
Application::Log("Got 'hello world' from address=" + nrea.Sender->GetAddress() + ", identity=" + nrea.Sender->GetIdentity());
|
||||||
|
|
|
@ -83,7 +83,7 @@ int DiscoveryComponent::CheckExistingEndpoint(Endpoint::Ptr endpoint, const NewE
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
if (endpoint->GetIdentity() == neea.Endpoint->GetIdentity()) {
|
if (endpoint->GetIdentity() == neea.Endpoint->GetIdentity()) {
|
||||||
Application::Log("Detected duplicate identity (" + endpoint->GetIdentity() + " - Disconnecting old endpoint.");
|
Application::Log("Detected duplicate identity:" + endpoint->GetIdentity() + " - Disconnecting old endpoint.");
|
||||||
|
|
||||||
neea.Endpoint->Stop();
|
neea.Endpoint->Stop();
|
||||||
GetEndpointManager()->UnregisterEndpoint(neea.Endpoint);
|
GetEndpointManager()->UnregisterEndpoint(neea.Endpoint);
|
||||||
|
|
Loading…
Reference in New Issue