Documentation update.

Code cleanup.
This commit is contained in:
Gunnar Beutner 2012-05-18 22:53:35 +02:00
parent 257988539a
commit d02dd4eb0a
10 changed files with 44 additions and 28 deletions

View File

@ -75,7 +75,8 @@ Application::~Application(void)
} }
/** /**
* Processes events (e.g. sockets and timers). * Processes events for registered sockets and timers and calls whatever
* handlers have been set up for these events.
*/ */
void Application::RunEventLoop(void) void Application::RunEventLoop(void)
{ {
@ -274,18 +275,18 @@ void Application::UnregisterComponent(Component::Ptr component)
* @param name The name of the component. * @param name The name of the component.
* @returns The component or a null pointer if the component could not be found. * @returns The component or a null pointer if the component could not be found.
*/ */
Component::Ptr Application::GetComponent(const string& name) Component::Ptr Application::GetComponent(const string& name) const
{ {
map<string, Component::Ptr>::iterator ci = m_Components.find(name); map<string, Component::Ptr>::const_iterator i = m_Components.find(name);
if (ci == m_Components.end()) if (i == m_Components.end())
return Component::Ptr(); return Component::Ptr();
return ci->second; return i->second;
} }
/** /**
* Logs a message. * Writes a message to the application's log.
* *
* @param message The message. * @param message The message.
*/ */
@ -408,11 +409,12 @@ bool Application::IsDebugging(void) const
#ifndef _WIN32 #ifndef _WIN32
/** /**
* Signal handler for SIGINT. * Signal handler for SIGINT. Prepares the application for cleanly
* shutting down during the next execution of the event loop.
* *
* @param signum The signal number. * @param signum The signal number.
*/ */
static void ApplicationSigIntHandler(int signum) void Application::SigIntHandler(int signum)
{ {
assert(signum == SIGINT); assert(signum == SIGINT);
@ -442,7 +444,7 @@ int Application::Run(int argc, char **argv)
#ifndef _WIN32 #ifndef _WIN32
struct sigaction sa; struct sigaction sa;
memset(&sa, 0, sizeof(sa)); memset(&sa, 0, sizeof(sa));
sa.sa_handler = ApplicationSigIntHandler; sa.sa_handler = Application::SigIntHandler;
sigaction(SIGINT, &sa, NULL); sigaction(SIGINT, &sa, NULL);
sa.sa_handler = SIG_IGN; sa.sa_handler = SIG_IGN;

View File

@ -41,6 +41,10 @@ private:
vector<string> m_Arguments; /**< Command-line arguments */ vector<string> m_Arguments; /**< Command-line arguments */
bool m_Debugging; /**< Whether debugging is enabled. */ bool m_Debugging; /**< Whether debugging is enabled. */
#ifndef _WIN32
static void SigIntHandler(int signum);
#endif /* _WIN32 */
protected: protected:
void RunEventLoop(void); void RunEventLoop(void);
string GetExeDirectory(void) const; string GetExeDirectory(void) const;
@ -68,7 +72,7 @@ public:
const ConfigObject::Ptr& componentConfig); const ConfigObject::Ptr& componentConfig);
void RegisterComponent(shared_ptr<Component> component); void RegisterComponent(shared_ptr<Component> component);
void UnregisterComponent(shared_ptr<Component> component); void UnregisterComponent(shared_ptr<Component> component);
shared_ptr<Component> GetComponent(const string& name); shared_ptr<Component> GetComponent(const string& name) const;
void AddComponentSearchDir(const string& componentDirectory); void AddComponentSearchDir(const string& componentDirectory);
bool IsDebugging(void) const; bool IsDebugging(void) const;

View File

@ -13,22 +13,18 @@
<ItemGroup> <ItemGroup>
<ClCompile Include="application.cpp" /> <ClCompile Include="application.cpp" />
<ClCompile Include="component.cpp" /> <ClCompile Include="component.cpp" />
<ClCompile Include="condvar.cpp" />
<ClCompile Include="configcollection.cpp" /> <ClCompile Include="configcollection.cpp" />
<ClCompile Include="confighive.cpp" /> <ClCompile Include="confighive.cpp" />
<ClCompile Include="configobject.cpp" /> <ClCompile Include="configobject.cpp" />
<ClCompile Include="dictionary.cpp" /> <ClCompile Include="dictionary.cpp" />
<ClCompile Include="exception.cpp" /> <ClCompile Include="exception.cpp" />
<ClCompile Include="fifo.cpp" /> <ClCompile Include="fifo.cpp" />
<ClCompile Include="lock.cpp" />
<ClCompile Include="memory.cpp" /> <ClCompile Include="memory.cpp" />
<ClCompile Include="mutex.cpp" />
<ClCompile Include="object.cpp" /> <ClCompile Include="object.cpp" />
<ClCompile Include="socket.cpp" /> <ClCompile Include="socket.cpp" />
<ClCompile Include="tcpclient.cpp" /> <ClCompile Include="tcpclient.cpp" />
<ClCompile Include="tcpserver.cpp" /> <ClCompile Include="tcpserver.cpp" />
<ClCompile Include="tcpsocket.cpp" /> <ClCompile Include="tcpsocket.cpp" />
<ClCompile Include="thread.cpp" />
<ClCompile Include="timer.cpp" /> <ClCompile Include="timer.cpp" />
<ClCompile Include="tlsclient.cpp" /> <ClCompile Include="tlsclient.cpp" />
<ClCompile Include="unix.cpp" /> <ClCompile Include="unix.cpp" />
@ -39,14 +35,12 @@
<ItemGroup> <ItemGroup>
<ClInclude Include="application.h" /> <ClInclude Include="application.h" />
<ClInclude Include="component.h" /> <ClInclude Include="component.h" />
<ClInclude Include="condvar.h" />
<ClInclude Include="configcollection.h" /> <ClInclude Include="configcollection.h" />
<ClInclude Include="confighive.h" /> <ClInclude Include="confighive.h" />
<ClInclude Include="configobject.h" /> <ClInclude Include="configobject.h" />
<ClInclude Include="cxx11-compat.h" /> <ClInclude Include="cxx11-compat.h" />
<ClInclude Include="delegate.h" /> <ClInclude Include="delegate.h" />
<ClInclude Include="dictionary.h" /> <ClInclude Include="dictionary.h" />
<ClInclude Include="lock.h" />
<ClInclude Include="observable.h" /> <ClInclude Include="observable.h" />
<ClInclude Include="exception.h" /> <ClInclude Include="exception.h" />
<ClInclude Include="fifo.h" /> <ClInclude Include="fifo.h" />
@ -57,7 +51,6 @@
<ClInclude Include="tcpclient.h" /> <ClInclude Include="tcpclient.h" />
<ClInclude Include="tcpserver.h" /> <ClInclude Include="tcpserver.h" />
<ClInclude Include="tcpsocket.h" /> <ClInclude Include="tcpsocket.h" />
<ClInclude Include="thread.h" />
<ClInclude Include="timer.h" /> <ClInclude Include="timer.h" />
<ClInclude Include="tlsclient.h" /> <ClInclude Include="tlsclient.h" />
<ClInclude Include="unix.h" /> <ClInclude Include="unix.h" />
@ -65,9 +58,6 @@
<ClInclude Include="variant.h" /> <ClInclude Include="variant.h" />
<ClInclude Include="win32.h" /> <ClInclude Include="win32.h" />
</ItemGroup> </ItemGroup>
<ItemGroup>
<None Include="mutex.h" />
</ItemGroup>
<PropertyGroup Label="Globals"> <PropertyGroup Label="Globals">
<ProjectGuid>{9C92DA90-FD53-43A9-A244-90F2E8AF9677}</ProjectGuid> <ProjectGuid>{9C92DA90-FD53-43A9-A244-90F2E8AF9677}</ProjectGuid>
<Keyword>Win32Proj</Keyword> <Keyword>Win32Proj</Keyword>

View File

@ -44,7 +44,7 @@ public:
* Retrieves a value from the dictionary. * Retrieves a value from the dictionary.
* *
* @param key The key. * @param key The key.
* @param value Pointer to the value. * @param[out] value Pointer to the value.
* @returns true if the value was retrieved, false otherwise. * @returns true if the value was retrieved, false otherwise.
*/ */
template<typename T> template<typename T>

View File

@ -10,6 +10,7 @@ configfile_la_SOURCES = \
configfile_la_CXXFLAGS = \ configfile_la_CXXFLAGS = \
-I${top_srcdir}/base \ -I${top_srcdir}/base \
-I${top_srcdir}/icinga \
-I${top_srcdir}/jsonrpc \ -I${top_srcdir}/jsonrpc \
-I${top_srcdir}/cJSON -I${top_srcdir}/cJSON
@ -20,4 +21,5 @@ configfile_la_LDFLAGS = \
configfile_la_LIBADD = \ configfile_la_LIBADD = \
$(top_builddir)/base/libbase.la \ $(top_builddir)/base/libbase.la \
$(top_builddir)/icinga/libicinga.la \
$(top_builddir)/cJSON/libcJSON.la $(top_builddir)/cJSON/libcJSON.la

View File

@ -45,11 +45,11 @@
</ImportGroup> </ImportGroup>
<PropertyGroup Label="UserMacros" /> <PropertyGroup Label="UserMacros" />
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'"> <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
<IncludePath>$(SolutionDir)\base;$(SolutionDir)\cJSON;$(IncludePath)</IncludePath> <IncludePath>$(SolutionDir)\base;$(SolutionDir)\jsonrpc;$(SolutionDir)\icinga;$(SolutionDir)\cJSON;$(IncludePath)</IncludePath>
<LibraryPath>$(OutDir);$(LibraryPath)</LibraryPath> <LibraryPath>$(OutDir);$(LibraryPath)</LibraryPath>
</PropertyGroup> </PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'"> <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
<IncludePath>$(SolutionDir)\base;$(SolutionDir)\cJSON;$(IncludePath)</IncludePath> <IncludePath>$(SolutionDir)\base;$(SolutionDir)\jsonrpc;$(SolutionDir)\icinga;$(SolutionDir)\cJSON;$(IncludePath)</IncludePath>
<LibraryPath>$(OutDir);$(LibraryPath)</LibraryPath> <LibraryPath>$(OutDir);$(LibraryPath)</LibraryPath>
</PropertyGroup> </PropertyGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'"> <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
@ -63,7 +63,7 @@
<Link> <Link>
<SubSystem>Windows</SubSystem> <SubSystem>Windows</SubSystem>
<GenerateDebugInformation>true</GenerateDebugInformation> <GenerateDebugInformation>true</GenerateDebugInformation>
<AdditionalDependencies>base.lib;jsonrpc.lib;cJSON.lib;%(AdditionalDependencies)</AdditionalDependencies> <AdditionalDependencies>base.lib;jsonrpc.lib;icinga.lib;cJSON.lib;%(AdditionalDependencies)</AdditionalDependencies>
</Link> </Link>
<Lib> <Lib>
<AdditionalDependencies> <AdditionalDependencies>
@ -86,7 +86,7 @@
<GenerateDebugInformation>true</GenerateDebugInformation> <GenerateDebugInformation>true</GenerateDebugInformation>
<EnableCOMDATFolding>true</EnableCOMDATFolding> <EnableCOMDATFolding>true</EnableCOMDATFolding>
<OptimizeReferences>true</OptimizeReferences> <OptimizeReferences>true</OptimizeReferences>
<AdditionalDependencies>base.lib;jsonrpc.lib;cJSON.lib;%(AdditionalDependencies)</AdditionalDependencies> <AdditionalDependencies>base.lib;jsonrpc.lib;icinga.lib;cJSON.lib;%(AdditionalDependencies)</AdditionalDependencies>
</Link> </Link>
<Lib> <Lib>
<AdditionalDependencies>$(OutDir)\base.lib;$(OutDir)\jsonrpc.lib</AdditionalDependencies> <AdditionalDependencies>$(OutDir)\base.lib;$(OutDir)\jsonrpc.lib</AdditionalDependencies>

View File

@ -21,6 +21,7 @@
#define I2CONFIGFILECOMPONENT_H #define I2CONFIGFILECOMPONENT_H
#include <i2-base.h> #include <i2-base.h>
#include <i2-icinga.h>
#include "configfilecomponent.h" #include "configfilecomponent.h"

View File

@ -11,7 +11,6 @@ configrpc_la_SOURCES = \
configrpc_la_CXXFLAGS = \ configrpc_la_CXXFLAGS = \
-I${top_srcdir}/base \ -I${top_srcdir}/base \
-I${top_srcdir}/jsonrpc \ -I${top_srcdir}/jsonrpc \
-I${top_srcdir}/cJSON \
-I${top_srcdir}/icinga -I${top_srcdir}/icinga
configrpc_la_LDFLAGS = \ configrpc_la_LDFLAGS = \
@ -22,5 +21,4 @@ configrpc_la_LDFLAGS = \
configrpc_la_LIBADD = \ configrpc_la_LIBADD = \
${top_builddir}/base/libbase.la \ ${top_builddir}/base/libbase.la \
${top_builddir}/jsonrpc/libjsonrpc.la \ ${top_builddir}/jsonrpc/libjsonrpc.la \
${top_builddir}/cJSON/libcJSON.la \
${top_builddir}/icinga/libicinga.la ${top_builddir}/icinga/libicinga.la

View File

@ -21,7 +21,15 @@
using namespace icinga; using namespace icinga;
/* based on https://github.com/PeterScott/netstring-c/blob/master/netstring.c */ /**
* Reads data from a FIFO in netstring format.
*
* @param fifo The FIFO to read from.
* @param[out] str The string that has been read from the FIFO.
* @returns true if a complete string was read from the FIFO, false otherwise.
* @exception InvalidNetstringException The input stream is invalid.
* @see https://github.com/PeterScott/netstring-c/blob/master/netstring.c
*/
bool Netstring::ReadStringFromFIFO(FIFO::Ptr fifo, string *str) bool Netstring::ReadStringFromFIFO(FIFO::Ptr fifo, string *str)
{ {
size_t buffer_length = fifo->GetSize(); size_t buffer_length = fifo->GetSize();
@ -66,6 +74,12 @@ bool Netstring::ReadStringFromFIFO(FIFO::Ptr fifo, string *str)
return true; return true;
} }
/**
* Writes data into a FIFO using the netstring format.
*
* @param fifo The FIFO.
* @param str The string that is to be written.
*/
void Netstring::WriteStringToFIFO(FIFO::Ptr fifo, const string& str) void Netstring::WriteStringToFIFO(FIFO::Ptr fifo, const string& str)
{ {
unsigned long len = str.size(); unsigned long len = str.size();

View File

@ -23,6 +23,11 @@
namespace icinga namespace icinga
{ {
/**
* Thrown when an invalid netstring was encountered while reading from a FIFO.
*/
DEFINE_EXCEPTION_CLASS(InvalidNetstringException);
/** /**
* Utility functions for reading/writing messages in the netstring format. * Utility functions for reading/writing messages in the netstring format.
* See http://cr.yp.to/proto/netstrings.txt for details. * See http://cr.yp.to/proto/netstrings.txt for details.