From d02dd4eb0a647fcd01ec81ff11c4db2ef52a3ab0 Mon Sep 17 00:00:00 2001 From: Gunnar Beutner Date: Fri, 18 May 2012 22:53:35 +0200 Subject: [PATCH] Documentation update. Code cleanup. --- base/application.cpp | 20 +++++++++++--------- base/application.h | 6 +++++- base/base.vcxproj | 10 ---------- base/dictionary.h | 2 +- components/configfile/Makefile.am | 2 ++ components/configfile/configfile.vcxproj | 8 ++++---- components/configfile/i2-configfile.h | 1 + components/configrpc/Makefile.am | 2 -- jsonrpc/netstring.cpp | 16 +++++++++++++++- jsonrpc/netstring.h | 5 +++++ 10 files changed, 44 insertions(+), 28 deletions(-) diff --git a/base/application.cpp b/base/application.cpp index de3054477..5ed95f895 100644 --- a/base/application.cpp +++ b/base/application.cpp @@ -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) { @@ -274,18 +275,18 @@ void Application::UnregisterComponent(Component::Ptr component) * @param name The name of the component. * @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::iterator ci = m_Components.find(name); + map::const_iterator i = m_Components.find(name); - if (ci == m_Components.end()) + if (i == m_Components.end()) return Component::Ptr(); - return ci->second; + return i->second; } /** - * Logs a message. + * Writes a message to the application's log. * * @param message The message. */ @@ -408,11 +409,12 @@ bool Application::IsDebugging(void) const #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. */ -static void ApplicationSigIntHandler(int signum) +void Application::SigIntHandler(int signum) { assert(signum == SIGINT); @@ -442,7 +444,7 @@ int Application::Run(int argc, char **argv) #ifndef _WIN32 struct sigaction sa; memset(&sa, 0, sizeof(sa)); - sa.sa_handler = ApplicationSigIntHandler; + sa.sa_handler = Application::SigIntHandler; sigaction(SIGINT, &sa, NULL); sa.sa_handler = SIG_IGN; diff --git a/base/application.h b/base/application.h index 6fce49614..d6d364548 100644 --- a/base/application.h +++ b/base/application.h @@ -41,6 +41,10 @@ private: vector m_Arguments; /**< Command-line arguments */ bool m_Debugging; /**< Whether debugging is enabled. */ +#ifndef _WIN32 + static void SigIntHandler(int signum); +#endif /* _WIN32 */ + protected: void RunEventLoop(void); string GetExeDirectory(void) const; @@ -68,7 +72,7 @@ public: const ConfigObject::Ptr& componentConfig); void RegisterComponent(shared_ptr component); void UnregisterComponent(shared_ptr component); - shared_ptr GetComponent(const string& name); + shared_ptr GetComponent(const string& name) const; void AddComponentSearchDir(const string& componentDirectory); bool IsDebugging(void) const; diff --git a/base/base.vcxproj b/base/base.vcxproj index 44e415aea..59821309e 100644 --- a/base/base.vcxproj +++ b/base/base.vcxproj @@ -13,22 +13,18 @@ - - - - @@ -39,14 +35,12 @@ - - @@ -57,7 +51,6 @@ - @@ -65,9 +58,6 @@ - - - {9C92DA90-FD53-43A9-A244-90F2E8AF9677} Win32Proj diff --git a/base/dictionary.h b/base/dictionary.h index 58d35911a..83a32c3bf 100644 --- a/base/dictionary.h +++ b/base/dictionary.h @@ -44,7 +44,7 @@ public: * Retrieves a value from the dictionary. * * @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. */ template diff --git a/components/configfile/Makefile.am b/components/configfile/Makefile.am index cb2b29cde..cd38dcb1b 100644 --- a/components/configfile/Makefile.am +++ b/components/configfile/Makefile.am @@ -10,6 +10,7 @@ configfile_la_SOURCES = \ configfile_la_CXXFLAGS = \ -I${top_srcdir}/base \ + -I${top_srcdir}/icinga \ -I${top_srcdir}/jsonrpc \ -I${top_srcdir}/cJSON @@ -20,4 +21,5 @@ configfile_la_LDFLAGS = \ configfile_la_LIBADD = \ $(top_builddir)/base/libbase.la \ + $(top_builddir)/icinga/libicinga.la \ $(top_builddir)/cJSON/libcJSON.la diff --git a/components/configfile/configfile.vcxproj b/components/configfile/configfile.vcxproj index 1f8708527..61612eb00 100644 --- a/components/configfile/configfile.vcxproj +++ b/components/configfile/configfile.vcxproj @@ -45,11 +45,11 @@ - $(SolutionDir)\base;$(SolutionDir)\cJSON;$(IncludePath) + $(SolutionDir)\base;$(SolutionDir)\jsonrpc;$(SolutionDir)\icinga;$(SolutionDir)\cJSON;$(IncludePath) $(OutDir);$(LibraryPath) - $(SolutionDir)\base;$(SolutionDir)\cJSON;$(IncludePath) + $(SolutionDir)\base;$(SolutionDir)\jsonrpc;$(SolutionDir)\icinga;$(SolutionDir)\cJSON;$(IncludePath) $(OutDir);$(LibraryPath) @@ -63,7 +63,7 @@ Windows true - base.lib;jsonrpc.lib;cJSON.lib;%(AdditionalDependencies) + base.lib;jsonrpc.lib;icinga.lib;cJSON.lib;%(AdditionalDependencies) @@ -86,7 +86,7 @@ true true true - base.lib;jsonrpc.lib;cJSON.lib;%(AdditionalDependencies) + base.lib;jsonrpc.lib;icinga.lib;cJSON.lib;%(AdditionalDependencies) $(OutDir)\base.lib;$(OutDir)\jsonrpc.lib diff --git a/components/configfile/i2-configfile.h b/components/configfile/i2-configfile.h index 9a548a967..589f8d4e4 100644 --- a/components/configfile/i2-configfile.h +++ b/components/configfile/i2-configfile.h @@ -21,6 +21,7 @@ #define I2CONFIGFILECOMPONENT_H #include +#include #include "configfilecomponent.h" diff --git a/components/configrpc/Makefile.am b/components/configrpc/Makefile.am index 5661e148d..aa92bba17 100644 --- a/components/configrpc/Makefile.am +++ b/components/configrpc/Makefile.am @@ -11,7 +11,6 @@ configrpc_la_SOURCES = \ configrpc_la_CXXFLAGS = \ -I${top_srcdir}/base \ -I${top_srcdir}/jsonrpc \ - -I${top_srcdir}/cJSON \ -I${top_srcdir}/icinga configrpc_la_LDFLAGS = \ @@ -22,5 +21,4 @@ configrpc_la_LDFLAGS = \ configrpc_la_LIBADD = \ ${top_builddir}/base/libbase.la \ ${top_builddir}/jsonrpc/libjsonrpc.la \ - ${top_builddir}/cJSON/libcJSON.la \ ${top_builddir}/icinga/libicinga.la diff --git a/jsonrpc/netstring.cpp b/jsonrpc/netstring.cpp index 307f16b5d..10ab6686f 100644 --- a/jsonrpc/netstring.cpp +++ b/jsonrpc/netstring.cpp @@ -21,7 +21,15 @@ 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) { size_t buffer_length = fifo->GetSize(); @@ -66,6 +74,12 @@ bool Netstring::ReadStringFromFIFO(FIFO::Ptr fifo, string *str) 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) { unsigned long len = str.size(); diff --git a/jsonrpc/netstring.h b/jsonrpc/netstring.h index cb3154455..5fc1087eb 100644 --- a/jsonrpc/netstring.h +++ b/jsonrpc/netstring.h @@ -23,6 +23,11 @@ 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. * See http://cr.yp.to/proto/netstrings.txt for details. -- 2.40.0