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
{
ConstDictionaryIterator i = m_Data.find(key);
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)
{
DictionaryIterator i = m_Data.find(key);
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)
{
Variant data;
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)
{
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)
{
Variant data;
return true;
}
+/**
+ * SetPropertyInteger
+ *
+ * Sets a value in the dictionary.
+ *
+ * @param key The key.
+ * @param value The value.
+ */
void Dictionary::SetPropertyInteger(string key, long 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)
{
Dictionary::Ptr dictionary;
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)
{
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)
{
Variant data;
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)
{
SetProperty(key, Variant(value));
}
+/**
+ * Begin
+ *
+ * Returns an iterator to the beginning of the dictionary.
+ *
+ * @returns An iterator.
+ */
DictionaryIterator Dictionary::Begin(void)
{
return m_Data.begin();
}
+/**
+ * End
+ *
+ * Returns an iterator to the end of the dictionary.
+ *
+ * @returns An iterator.
+ */
DictionaryIterator Dictionary::End(void)
{
return m_Data.end();
}
+/**
+ * GetLength
+ *
+ * Returns the number of elements in the dictionary.
+ *
+ * @returns Number of elements.
+ */
long Dictionary::GetLength(void) const
{
return m_Data.size();
}
+/**
+ * AddUnnamedProperty
+ *
+ * Adds an unnamed value to the dictionary.
+ *
+ * @param value The value.
+ */
void Dictionary::AddUnnamedProperty(const Variant& value)
{
map<string, Variant>::const_iterator it;
m_Data[key] = value;
}
+/**
+ * AddUnnamedPropertyString
+ *
+ * Adds an unnamed value to the dictionary.
+ *
+ * @param value The value.
+ */
void Dictionary::AddUnnamedPropertyString(const string& value)
{
AddUnnamedProperty(Variant(value));
}
+/**
+ * AddUnnamedPropertyInteger
+ *
+ * Adds an unnamed value to the dictionary.
+ *
+ * @param value The value.
+ */
void Dictionary::AddUnnamedPropertyInteger(long value)
{
AddUnnamedProperty(Variant(value));
}
+/**
+ * AddUnnamedPropertyDictionary
+ *
+ * Adds an unnamed value to the dictionary.
+ *
+ * @param value The value.
+ */
void Dictionary::AddUnnamedPropertyDictionary(const Dictionary::Ptr& value)
{
AddUnnamedProperty(Variant(value));
}
+/**
+ * AddUnnamedPropertyObject
+ *
+ * Adds an unnamed value to the dictionary.
+ *
+ * @param value The value.
+ */
void Dictionary::AddUnnamedPropertyObject(const Object::Ptr& value)
{
AddUnnamedProperty(Variant(value));
vector<DelegateType> m_Delegates;
public:
+ /**
+ * operator +=
+ *
+ * Adds a delegate to this event.
+ *
+ * @param rhs The delegate.
+ */
Event<TArgs>& operator +=(const DelegateType& rhs)
{
m_Delegates.push_back(rhs);
return *this;
}
+ /**
+ * operator -=
+ *
+ * Removes a delegate from this event.
+ *
+ * @param rhs The delegate.
+ */
Event<TArgs>& operator -=(const DelegateType& rhs)
{
m_Delegates.erase(rhs);
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)
{
typename vector<DelegateType>::iterator i;
using namespace icinga;
+/**
+ * Exception
+ *
+ * Default constructor for the Exception class.
+ */
Exception::Exception(void)
{
}
+/**
+ * Exception
+ *
+ * Constructor for the exception class.
+ *
+ * @param message A message describing the exception.
+ */
Exception::Exception(const string& message)
{
SetMessage(message);
}
+/**
+ * GetMessage
+ *
+ * Retrieves the description for the exception.
+ *
+ * @returns The description.
+ */
string Exception::GetMessage(void) const
{
return m_Message;
}
+/**
+ * SetMessage
+ *
+ * Sets the description for the exception.
+ *
+ * @param message The description.
+ */
void Exception::SetMessage(string message)
{
m_Message = message;
}
#ifdef _WIN32
+/**
+ * FormatError
+ *
+ * Formats an Win32 error code.
+ *
+ * @param code The error code.
+ * @returns A string describing the error.
+ */
string Win32Exception::FormatErrorCode(int code)
{
char *message;
}
#endif /* _WIN32 */
+/**
+ * FormatError
+ *
+ * Formats a Posix error code.
+ *
+ * @param code The error code.
+ * @returns A string describing the error.
+ */
string PosixException::FormatErrorCode(int 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)
{
const char *message = ERR_error_string(code, NULL);
using namespace icinga;
+/**
+ * FIFO
+ *
+ * Constructor for the FIFO class.
+ */
FIFO::FIFO(void)
{
m_Buffer = NULL;
m_Offset = 0;
}
+/**
+ * ~FIFO
+ *
+ * Destructor for the FIFO class.
+ */
FIFO::~FIFO(void)
{
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)
{
if (m_AllocSize >= newSize)
m_AllocSize = newSize;
}
+/**
+ * Optimize
+ *
+ * Optimizes memory usage of the FIFO buffer by reallocating
+ * and moving the buffer.
+ */
void FIFO::Optimize(void)
{
//char *newBuffer;
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
{
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
{
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)
{
count = (count <= m_DataSize) ? count : m_DataSize;
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)
{
ResizeBuffer(m_Offset + m_DataSize + *count);
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)
{
if (buffer != NULL) {
using namespace icinga;
+/**
+ * Memory
+ *
+ * Constructor for the memory class.
+ */
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 *ptr = malloc(size);
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 *new_ptr = realloc(ptr, size);
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 *new_str = strdup(str);
return new_str;
}
+/**
+ * Free
+ *
+ * Frees a memory block.
+ *
+ * @param ptr The memory block.
+ */
void Memory::Free(void *ptr)
{
if (ptr != NULL)
using namespace icinga;
+/**
+ * Mutex
+ *
+ * Constructor for the Mutex class.
+ */
Mutex::Mutex(void)
{
#ifdef _WIN32
#endif /* _WIN32 */
}
+/**
+ * ~Mutex
+ *
+ * Destructor for the Mutex class.
+ */
Mutex::~Mutex(void)
{
#ifdef _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)
{
#ifdef _WIN32
#endif /* _WIN32 */
}
+/**
+ * Enter
+ *
+ * Locks the mutex.
+ */
void Mutex::Enter(void)
{
#ifdef _WIN32
#endif /* _WIN32 */
}
+/**
+ * Exit
+ *
+ * Unlocks the mutex.
+ */
void Mutex::Exit(void)
{
#ifdef _WIN32
#endif /* _WIN32 */
}
+/**
+ * Get
+ *
+ * Retrieves the platform-specific mutex handle.
+ *
+ * @returns The platform-specific mutex handle.
+ */
#ifdef _WIN32
CRITICAL_SECTION *Mutex::Get(void)
#else /* _WIN32 */
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
+ *
+ * Constructor for the Socket class.
+ */
Socket::Socket(void)
{
m_FD = INVALID_SOCKET;
}
+/**
+ * ~Socket
+ *
+ * Destructor for the Socket class.
+ */
Socket::~Socket(void)
{
CloseInternal(true);
}
+/**
+ * Start
+ *
+ * Registers the socket and starts handling events for it.
+ */
void Socket::Start(void)
{
assert(m_FD != INVALID_SOCKET);
Sockets.push_back(static_pointer_cast<Socket>(shared_from_this()));
}
+/**
+ * Stop
+ *
+ * Unregisters the sockets and stops handling events for it.
+ */
void Socket::Stop(void)
{
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)
{
unsigned long lTrue = 1;
m_FD = fd;
}
+/**
+ * GetFD
+ *
+ * Retrieves the file descriptor for this socket object.
+ *
+ * @returns The file descriptor.
+ */
SOCKET Socket::GetFD(void) const
{
return m_FD;
}
+/**
+ * Close
+ *
+ * Closes the socket.
+ */
void Socket::Close(void)
{
CloseInternal(false);
}
+/**
+ * CloseInternal
+ *
+ * Closes the socket.
+ *
+ * @param from_dtor Whether this method was called from the destructor.
+ */
void Socket::CloseInternal(bool from_dtor)
{
if (m_FD == INVALID_SOCKET)
}
}
+/**
+ * HandleSocketError
+ *
+ * Handles a socket error by calling the OnError event.
+ */
void Socket::HandleSocketError(void)
{
int opt;
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)
{
HandleSocketError();
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
{
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
{
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)
{
char host[NI_MAXHOST];
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)
{
sockaddr_storage sin;
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)
{
sockaddr_storage sin;
using namespace icinga;
+/**
+ * MakeSocket
+ *
+ * Creates a socket.
+ *
+ * @param family The socket family for the new socket.
+ */
void TCPSocket::MakeSocket(int family)
{
assert(GetFD() == INVALID_SOCKET);
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)
{
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)
{
addrinfo hints;
time_t Timer::NextCall;
Timer::CollectionType Timer::Timers;
+/**
+ * Constructor for the Timer class.
+ */
Timer::Timer(void)
{
m_Interval = 0;
}
+/**
+ * GetNextCall
+ *
+ * Retrieves when the next timer is due.
+ *
+ * @returns Time when the next timer is due.
+ */
time_t Timer::GetNextCall(void)
{
if (NextCall < time(NULL))
return NextCall;
}
+/**
+ * RescheduleTimers
+ *
+ * Reschedules all timers, thereby updating the NextCall
+ * timestamp used by the GetNextCall() function.
+ */
void Timer::RescheduleTimers(void)
{
/* Make sure we wake up at least once every 30 seconds */
}
}
+/**
+ * CallExpiredTimers
+ *
+ * Calls all expired timers and reschedules them.
+ */
void Timer::CallExpiredTimers(void)
{
time_t now;
}
}
-/* 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)
{
TimerEventArgs tea;
OnTimerExpired(tea);
}
+/**
+ * SetInterval
+ *
+ * Sets the interval for this timer.
+ *
+ * @param interval The new interval.
+ */
void Timer::SetInterval(unsigned int interval)
{
m_Interval = interval;
}
+/**
+ * GetInterval
+ *
+ * Retrieves the interval for this timer.
+ *
+ * @returns The interval.
+ */
unsigned int Timer::GetInterval(void) const
{
return m_Interval;
}
+/**
+ * SetUserArgs
+ *
+ * Sets user arguments for the timer callback.
+ *
+ * @param userArgs The user arguments.
+ */
void Timer::SetUserArgs(const EventArgs& userArgs)
{
m_UserArgs = userArgs;
}
-
+/**
+ * GetUserArgs
+ *
+ * Retrieves the user arguments for the timer callback.
+ *
+ * @returns The user arguments.
+ */
EventArgs Timer::GetUserArgs(void) const
{
return m_UserArgs;
}
+/**
+ * Start
+ *
+ * Registers the timer and starts processing events for it.
+ */
void Timer::Start(void)
{
Timers.push_back(static_pointer_cast<Timer>(shared_from_this()));
Reschedule(time(NULL) + m_Interval);
}
+/**
+ * Stop
+ *
+ * Unregisters the timer and stops processing events for it.
+ */
void Timer::Stop(void)
{
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)
{
m_Next = next;
using namespace icinga;
+/**
+ * Sleep
+ *
+ * Sleeps for the specified amount of time.
+ *
+ * @param milliseconds The amount of time in milliseconds.
+ */
void Sleep(unsigned long milliseconds)
{
usleep(milliseconds * 1000);
}
+/**
+ * closesocket
+ *
+ * Closes a socket.
+ *
+ * @param fd The socket that is to be closed.
+ */
void closesocket(SOCKET fd)
{
close(fd);
#endif
}
+/**
+ * InitializeOpenSSL
+ *
+ * Initializes the OpenSSL library.
+ */
void Utility::InitializeOpenSSL(void)
{
if (!m_SSLInitialized) {
}
}
+/**
+ * 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)
{
InitializeOpenSSL();
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)
{
char buffer[256];
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)
{
X509 *cert;
void ConfigRpcComponent::Stop(void)
{
- // TODO: implement
+ EndpointManager::Ptr mgr = GetEndpointManager();
+
+ if (mgr)
+ mgr->UnregisterEndpoint(m_ConfigRpcEndpoint);
}
int ConfigRpcComponent::NewEndpointHandler(const NewEndpointEventArgs& ea)
using namespace icinga;
+/**
+ * GetName
+ *
+ * Returns the name of the component.
+ *
+ * @returns The name.
+ */
string DemoComponent::GetName(void) const
{
return "democomponent";
}
+/**
+ * Start
+ *
+ * Starts the component.
+ */
void DemoComponent::Start(void)
{
m_DemoEndpoint = make_shared<VirtualEndpoint>();
m_DemoTimer->Start();
}
+/**
+ * Stop
+ *
+ * Stops the component.
+ */
void DemoComponent::Stop(void)
{
IcingaApplication::Ptr app = GetIcingaApplication();
}
}
+/**
+ * DemoTimerHandler
+ *
+ * Periodically sends a demo::HelloWorld message.
+ *
+ * @param tea Event arguments for the timer.
+ * @returns 0
+ */
int DemoComponent::DemoTimerHandler(const TimerEventArgs& tea)
{
Application::Log("Sending multicast 'hello world' message.");
return 0;
}
+/**
+ * HelloWorldRequestHandler
+ *
+ * Processes demo::HelloWorld messages.
+ */
int DemoComponent::HelloWorldRequestHandler(const NewRequestEventArgs& nrea)
{
Application::Log("Got 'hello world' from address=" + nrea.Sender->GetAddress() + ", identity=" + nrea.Sender->GetIdentity());
return 0;
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();
GetEndpointManager()->UnregisterEndpoint(neea.Endpoint);