Added missing doc strings.

This commit is contained in:
Gunnar Beutner 2012-09-14 14:41:17 +02:00
parent 46ff4a9857
commit 063d69ed96
10 changed files with 131 additions and 0 deletions

View File

@ -212,11 +212,19 @@ bool Application::IsDebugging(void)
return m_Debugging;
}
/**
* Checks whether we're currently on the main thread.
*
* @returns true if this is the main thread, false otherwise
*/
bool Application::IsMainThread(void)
{
return (boost::this_thread::get_id() == m_MainThreadID);
}
/**
* Sets the main thread to the currently running thread.
*/
void Application::SetMainThread(void)
{
m_MainThreadID = boost::this_thread::get_id();
@ -313,6 +321,11 @@ int Application::Run(int argc, char **argv)
return result;
}
/**
* Grabs the PID file lock and updates the PID.
*
* @param filename The name of the PID file.
*/
void Application::UpdatePidFile(const String& filename)
{
ClosePidFile();
@ -344,6 +357,9 @@ void Application::UpdatePidFile(const String& filename)
fflush(m_PidFile);
}
/**
* Closes the PID file. Does nothing if the PID file is not currently open.
*/
void Application::ClosePidFile(void)
{
if (m_PidFile != NULL)

View File

@ -99,6 +99,9 @@ Component::Component(const Dictionary::Ptr& properties)
m_Impl = impl;
}
/**
* Destructor for the Component class.
*/
Component::~Component(void)
{
if (m_Impl)

View File

@ -22,6 +22,9 @@
using namespace icinga;
/**
* Compares the keys of dictionary keys using the less operator.
*/
struct DictionaryKeyLessComparer
{
bool operator()(const pair<String, Value>& a, const char *b)

View File

@ -25,14 +25,27 @@ vector<Event> Event::m_Events;
condition_variable Event::m_EventAvailable;
boost::mutex Event::m_Mutex;
/**
* Constructor for the Event class
*
* @param callback The callback function for the new event object.
*/
Event::Event(const Event::Callback& callback)
: m_Callback(callback)
{ }
/**
* Waits for events using the specified timeout value and processes
* them.
*
* @param wait_until The wait timeout.
*/
void Event::ProcessEvents(const system_time& wait_until)
{
vector<Event> events;
assert(Application::IsMainThread());
{
boost::mutex::scoped_lock lock(m_Mutex);
@ -59,6 +72,12 @@ void Event::ProcessEvents(const system_time& wait_until)
}
}
/**
* Appends an event to the event queue. Events will be processed in FIFO
* order on the main thread.
*
* @param callback The callback function for the event.
*/
void Event::Post(const Event::Callback& callback)
{
if (Application::IsMainThread()) {

View File

@ -126,6 +126,11 @@ void Logger::ForwardLogEntry(const LogEntry& entry)
StreamLogger::ProcessLogEntry(std::cout, entry);
}
/**
* Converts a severity enum value to a string.
*
* @param severity The severity value.
*/
String Logger::SeverityToString(LogSeverity severity)
{
switch (severity) {
@ -142,6 +147,11 @@ String Logger::SeverityToString(LogSeverity severity)
}
}
/**
* Converts a string to a severity enum value.
*
* @param severity The severity.
*/
LogSeverity Logger::StringToSeverity(const String& severity)
{
if (severity == "debug")

View File

@ -69,18 +69,31 @@ void Object::ClearHeldObjects(void)
m_HeldObjects.clear();
}
/**
* Returns a reference-counted pointer to this object.
*
* @returns A shared_ptr object that points to this object
*/
Object::SharedPtrHolder Object::GetSelf(void)
{
return Object::SharedPtrHolder(shared_from_this());
}
#ifdef _DEBUG
/**
* Retrieves the number of currently alive objects.
*
* @returns The number of alive objects.
*/
int Object::GetAliveObjects(void)
{
boost::mutex::scoped_lock lock(m_Mutex);
return m_AliveObjects.size();
}
/**
* Dumps a memory histogram to the "dictionaries.dump" file.
*/
void Object::PrintMemoryProfile(void)
{
map<String, int> types;

View File

@ -212,6 +212,11 @@ bool Process::RunTask(void)
return false;
}
/**
* Retrives the stdout file descriptor for the child process.
*
* @returns The stdout file descriptor.
*/
int Process::GetFD(void) const
{
return fileno(m_FP);

View File

@ -37,6 +37,9 @@ Socket::~Socket(void)
CloseInternal(true);
}
/**
* Starts I/O processing for this socket.
*/
void Socket::Start(void)
{
assert(!m_ReadThread.joinable() && !m_WriteThread.joinable());
@ -256,6 +259,10 @@ SocketException::SocketException(const String& message, int errorCode)
SetMessage(msg.CStr());
}
/**
* Read thread procedure for sockets. This function waits until the
* socket is readable and processes inbound data.
*/
void Socket::ReadThreadProc(void)
{
boost::mutex::scoped_lock lock(m_SocketMutex);
@ -310,6 +317,10 @@ void Socket::ReadThreadProc(void)
}
}
/**
* Write thread procedure for sockets. This function waits until the socket
* is writable and processes outbound data.
*/
void Socket::WriteThreadProc(void)
{
boost::mutex::scoped_lock lock(m_SocketMutex);
@ -358,16 +369,30 @@ void Socket::WriteThreadProc(void)
}
}
/**
* Sets whether the socket is fully connected.
*
* @param connected Whether the socket is connected
*/
void Socket::SetConnected(bool connected)
{
m_Connected = connected;
}
/**
* Checks whether the socket is fully connected.
*
* @returns true if the socket is connected, false otherwise
*/
bool Socket::IsConnected(void) const
{
return m_Connected;
}
/**
* Checks whether an exception is available for this socket. Should be called
* by user-supplied handlers for the OnClosed signal.
*/
void Socket::CheckException(void)
{
if (m_Exception)

View File

@ -102,6 +102,9 @@ void TcpClient::Connect(const String& node, const String& service)
throw_exception(runtime_error("Could not create a suitable socket."));
}
/**
* Processes data that is available for this socket.
*/
void TcpClient::HandleWritable(void)
{
int rc;
@ -180,6 +183,9 @@ void TcpClient::Write(const void *buffer, size_t count)
m_SendQueue->Write(buffer, count);
}
/**
* Processes data that can be written for this socket.
*/
void TcpClient::HandleReadable(void)
{
if (!IsConnected()) {

View File

@ -34,16 +34,31 @@ bool Value::IsEmpty(void) const
return (m_Value.type() == typeid(boost::blank));
}
/**
* Checks whether the variant is scalar (i.e. not an object and not empty).
*
* @returns true if the variant is scalar, false otherwise.
*/
bool Value::IsScalar(void) const
{
return !IsEmpty() && !IsObject();
}
/**
* Checks whether the variant is a non-null object.
*
* @returns true if the variant is a non-null object, false otherwise.
*/
bool Value::IsObject(void) const
{
return !IsEmpty() && (m_Value.type() == typeid(Object::Ptr));
}
/**
* Converts a JSON object into a variant.
*
* @param json The JSON object.
*/
Value Value::FromJson(cJSON *json)
{
if (json->type == cJSON_Number)
@ -62,6 +77,11 @@ Value Value::FromJson(cJSON *json)
throw_exception(invalid_argument("Unsupported JSON type."));
}
/**
* Serializes a variant into a string.
*
* @returns A string representing this variant.
*/
String Value::Serialize(void) const
{
cJSON *json = ToJson();
@ -82,6 +102,11 @@ String Value::Serialize(void) const
return result;
}
/**
* Serializes the variant.
*
* @returns A JSON object representing this variant.
*/
cJSON *Value::ToJson(void) const
{
if (m_Value.type() == typeid(long)) {
@ -105,6 +130,12 @@ cJSON *Value::ToJson(void) const
}
}
/**
* Deserializes the string representation of a variant.
*
* @params jsonString A JSON string obtained from Value::Serialize
* @returns The newly deserialized variant.
*/
Value Value::Deserialize(const String& jsonString)
{
cJSON *json = cJSON_Parse(jsonString.CStr());