]> granicus.if.org Git - icinga2/commitdiff
Updated documentation.
authorGunnar Beutner <gunnar.beutner@netways.de>
Tue, 15 May 2012 08:58:14 +0000 (10:58 +0200)
committerGunnar Beutner <gunnar.beutner@netways.de>
Tue, 15 May 2012 08:58:14 +0000 (10:58 +0200)
Cleaned up Dictionary class.

19 files changed:
base/application.cpp
base/application.h
base/component.h
base/configcollection.h
base/confighive.h
base/configobject.h
base/dictionary.cpp
base/dictionary.h
base/event.h
base/exception.h
base/fifo.h
base/socket.h
base/tcpclient.h
base/tcpserver.h
base/tcpsocket.h
base/timer.h
base/tlsclient.h
base/variant.h
icinga-app/icinga.cpp

index c41870a1f3bf8ce1503b128613695d4d19cdd96a..5e2e4ab109573d85e8838b93e2b75066370de21c 100644 (file)
@@ -446,20 +446,18 @@ static void ApplicationSigIntHandler(int signum)
 #endif /* _WIN32 */
 
 /**
- * Runs the specified application.
+ * Runs the application.
  *
  * @param argc The number of arguments.
  * @param argv The arguments that should be passed to the application.
- * @param instance The application instance.
  * @returns The application's exit code.
  */
-int icinga::RunApplication(int argc, char **argv, Application::Ptr instance)
+int Application::Run(int argc, char **argv)
 {
        int result;
 
        assert(!Application::Instance);
-
-       Application::Instance = instance;
+       Application::Instance = static_pointer_cast<Application>(shared_from_this());
 
 #ifndef _WIN32
        struct sigaction sa;
@@ -476,14 +474,18 @@ int icinga::RunApplication(int argc, char **argv, Application::Ptr instance)
        for (int i = 0; i < argc; i++)
                args.push_back(string(argv[i]));
 
-       Application::Instance->SetArguments(args);
+       SetArguments(args);
+
+       if (IsDebugging()) {
+               result = Main(args);
 
-       if (Application::Instance->IsDebugging()) {
-               result = Application::Instance->Main(args);
+               Application::Instance.reset();
        } else {
                try {
-                       result = Application::Instance->Main(args);
+                       result = Main(args);
                } catch (const Exception& ex) {
+                       Application::Instance.reset();
+
                        Application::Log("---");
                        Application::Log("Exception: " + Utility::GetTypeName(ex));
                        Application::Log("Message: " + ex.GetMessage());
index 5ca347c887a8fd9ca23888daa79502646fd3f08d..3b3036d68003bba5cc0d291f5d9df0e0c8df8574 100644 (file)
@@ -26,6 +26,9 @@ class Component;
 
 DEFINE_EXCEPTION_CLASS(ComponentLoadException);
 
+/**
+ * Abstract base class for applications.
+ */
 class I2_BASE_API Application : public Object {
 private:
        bool m_ShuttingDown;
@@ -47,6 +50,8 @@ public:
        Application(void);
        ~Application(void);
 
+       int Run(int argc, char **argv);
+
        virtual int Main(const vector<string>& args) = 0;
 
        void SetArguments(const vector<string>& arguments);
@@ -68,8 +73,6 @@ public:
        bool IsDebugging(void) const;
 };
 
-int I2_EXPORT RunApplication(int argc, char **argv, Application::Ptr instance);
-
 }
 
 #endif /* APPLICATION_H */
index 054a5872c4fb2f95035e4556f834a86be9e68212..a1eda5e5858e202ff55643a7d874f24824757045 100644 (file)
 namespace icinga
 {
 
+/**
+ * An application extension that can be dynamically loaded
+ * at run-time.
+ */
 class I2_BASE_API Component : public Object
 {
 private:
index 7ad0f4109b05c50952914f09fba92fd44f822c66..1846453c36336d8c20ff0378a6c702095fae5978 100644 (file)
@@ -25,6 +25,9 @@ namespace icinga
 
 class ConfigHive;
 
+/**
+ * A collection of configuration objects that each have the same type.
+ */
 class I2_BASE_API ConfigCollection : public Object
 {
 private:
index 0fc9f6b4286575a91f6ca46b9e05490187b61bd0..c137cf6ca01934fb93110ffcf72d0fbd4344116f 100644 (file)
@@ -23,6 +23,9 @@
 namespace icinga
 {
 
+/**
+ * A collection of all configuration objects that belong to an application.
+ */
 class I2_BASE_API ConfigHive : public Object
 {
 public:
index f983e7af3d5713af3ec226e7a77c30667f7760e2..9f9bdeec799b1f70f6822e5756ea41c0ae084128 100644 (file)
@@ -27,6 +27,9 @@ namespace icinga
 
 class ConfigHive;
 
+/**
+ * A configuration object that has arbitrary properties.
+ */
 class I2_BASE_API ConfigObject : public Dictionary
 {
 private:
index 2da37d9bdb02c801e0a11df01f98e7bc4a2edc4e..0a6bc1dd811d349e0a28fcc6969531a91bdc1246 100644 (file)
@@ -56,13 +56,6 @@ void Dictionary::SetProperty(string key, const Variant& value)
        }
 
        m_Data[key] = value;
-
-       PropertyChangedEventArgs dpce;
-       dpce.Source = shared_from_this();
-       dpce.Property = key;
-       dpce.OldValue = oldValue;
-       dpce.NewValue = value;
-       OnPropertyChanged(dpce);
 }
 
 /**
index 985ba408727062ae9d690ade250f78e4147b57af..01cb14d9712dd2911e000ffed30e0e57377169c2 100644 (file)
@@ -26,13 +26,9 @@ namespace icinga
 typedef map<string, Variant>::const_iterator ConstDictionaryIterator;
 typedef map<string, Variant>::iterator DictionaryIterator;
 
-struct I2_BASE_API PropertyChangedEventArgs : public EventArgs
-{
-       string Property;
-       Variant OldValue;
-       Variant NewValue;
-};
-
+/**
+ * A container that holds key-value pairs.
+ */
 class I2_BASE_API Dictionary : public Object
 {
 private:
@@ -67,8 +63,6 @@ public:
        void AddUnnamedPropertyObject(const Object::Ptr& value);
 
        long GetLength(void) const;
-
-       Event<PropertyChangedEventArgs> OnPropertyChanged;
 };
 
 }
index 18aa4a2b8306f72a78dfa4e1c5754d4395bbf836..430f7b06b35c8ecd868d4949d0f73510513290f6 100644 (file)
 namespace icinga
 {
 
+/**
+ * Base class for event arguments.
+ */
 struct I2_BASE_API EventArgs
 {
-       Object::Ptr Source;
+       Object::Ptr Source; /**< The source of the event. */
 };
 
+/**
+ * An observable event.
+ */
 template<class TArgs>
 class Event
 {
 public:
-       typedef function<int (const TArgs&)> DelegateType;
+       typedef function<int (const TArgs&)> ObserverType;
 
 private:
-       vector<DelegateType> m_Delegates;
+       vector<ObserverType> m_Observers;
 
 public:
        /**
-        * Adds a delegate to this event.
+        * Adds an observer to this event.
         *
         * @param rhs The delegate.
         */
-       Event<TArgs>& operator +=(const DelegateType& rhs)
+       Event<TArgs>& operator +=(const ObserverType& rhs)
        {
-               m_Delegates.push_back(rhs);
+               m_Observers.push_back(rhs);
                return *this;
        }
 
        /**
-        * Removes a delegate from this event.
+        * Removes an observer from this event.
         *
         * @param rhs The delegate.
         */
-       Event<TArgs>& operator -=(const DelegateType& rhs)
+       Event<TArgs>& operator -=(const ObserverType& rhs)
        {
-               m_Delegates.erase(rhs);
+               m_Observers.erase(rhs);
                return *this;
        }
 
        /**
-        * Invokes each delegate that is registered for this event. Any delegates
-        * which return -1 are removed.
+        * Invokes each observer function that is registered for this event. Any
+        * observer function which returns -1 is removed.
         *
         * @param args Event arguments.
         */
        void operator()(const TArgs& args)
        {
-               typename vector<DelegateType>::iterator i;
+               typename vector<ObserverType>::iterator i;
 
-               for (i = m_Delegates.begin(); i != m_Delegates.end(); ) {
+               for (i = m_Observers.begin(); i != m_Observers.end(); ) {
                        int result = (*i)(args);
 
                        if (result == -1)
-                               i = m_Delegates.erase(i);
+                               i = m_Observers.erase(i);
                        else
                                i++;
                }
index cd3dfc7e519465822038f2257584b6a88225a0dc..21c8dd2e78e57149b3685b2b96ac816796cfbf26 100644 (file)
@@ -24,8 +24,6 @@ namespace icinga
 {
 
 /**
- * Exception
- *
  * Base class for all exceptions.
  */
 class I2_BASE_API Exception
@@ -41,7 +39,7 @@ public:
        Exception(const string& message);
 
        /**
-        * Destructor for the Exception class. Required for RTTI.
+        * Destructor for the Exception class. Must be virtual for RTTI to work.
         */
        virtual ~Exception(void)
        {
@@ -68,37 +66,82 @@ DEFINE_EXCEPTION_CLASS(NotImplementedException);
 DEFINE_EXCEPTION_CLASS(InvalidArgumentException);
 
 #ifdef _WIN32
+/**
+ * A Win32 error encapsulated in an exception.
+ */
 class Win32Exception : public Exception
 {
 public:
+       /**
+        * Constructor for the Win32Exception class.
+        *
+        * @param message An error message.
+        * @param errorCode A Win32 error code.
+        */
        inline Win32Exception(const string& message, int errorCode)
        {
                SetMessage(message + ": " + FormatErrorCode(errorCode));
        }
 
+       /**
+        * Returns a string that describes the Win32 error.
+        *
+        * @param code The Win32 error code.
+        * @returns A description of the error.
+        */
        static string FormatErrorCode(int code);
 };
 #endif /* _WIN32 */
 
+/**
+ * A Posix error encapsulated in an exception.
+ */
 class PosixException : public Exception
 {
 public:
+       /**
+        * Constructor for the PosixException class.
+        *
+        * @param message An error message.
+        * @param errorCode A Posix (errno) error code.
+        */
        inline PosixException(const string& message, int errorCode)
        {
                SetMessage(message + ": " + FormatErrorCode(errorCode));
        }
 
+       /**
+        * Returns a string that describes the Posix error.
+        *
+        * @param code The Posix error code.
+        * @returns A description of the error.
+        */
        static string FormatErrorCode(int code);
 };
 
+/**
+ * An OpenSSL error encapsulated in an exception.
+ */
 class OpenSSLException : public Exception
 {
 public:
+       /**
+        * Constructor for the OpenSSLException class.
+        *
+        * @param message An error message.
+        * @param errorCode An OpenSSL error code.
+        */
        inline OpenSSLException(const string& message, int errorCode)
        {
                SetMessage(message + ": " + FormatErrorCode(errorCode));
        }
 
+       /**
+        * Returns a string that describes the OpenSSL error.
+        *
+        * @param code The OpenSSL error code.
+        * @returns A description of the error.
+        */
        static string FormatErrorCode(int code);
 };
 
index 587cce3b463eeda3d4084084eafa5ba3a6319652..689505d8e70efc275e7a93d5559c82b8bc89cea2 100644 (file)
@@ -23,6 +23,9 @@
 namespace icinga
 {
 
+/**
+ * A byte-based FIFO buffer.
+ */
 class I2_BASE_API FIFO : public Object
 {
 private:
index 67380e776132e7498bbfd580de81249bc575b9c1..ce6b77855b97c1c469ec50ad2ace0209bb6a61e0 100644 (file)
 
 namespace icinga {
 
+/**
+ * Event arguments for socket errors.
+ */
 struct I2_BASE_API SocketErrorEventArgs : public EventArgs
 {
-       typedef shared_ptr<SocketErrorEventArgs> Ptr;
-       typedef weak_ptr<SocketErrorEventArgs> WeakPtr;
-
-       int Code;
-       string Message;
+       int Code; /**< The error code. */
+       string Message; /**< A message describing the error. */
 };
 
+/**
+ * Base class for sockets.
+ */
 class I2_BASE_API Socket : public Object
 {
 private:
-       SOCKET m_FD;
+       SOCKET m_FD; /**< The socket descriptor. */
 
        int ExceptionEventHandler(const EventArgs& ea);
 
index 746d112adc0bf7a407b8e0eaad96b6aed3d3d64b..5c36dfa336f9631464556e77cd945ea915eb75cc 100644 (file)
 namespace icinga
 {
 
+/**
+ * The role of a TCP client object.
+ */
 enum I2_BASE_API TCPClientRole
 {
-       RoleInbound,
-       RoleOutbound
+       RoleInbound, /**< inbound socket, i.e. one that was returned from accept() */
+       RoleOutbound /**< outbound socket, i.e. one that is connect()'d to a remote socket */
 };
 
+/**
+ * A TCP client connection.
+ */
 class I2_BASE_API TCPClient : public TCPSocket
 {
 private:
@@ -61,6 +67,13 @@ public:
        Event<EventArgs> OnDataAvailable;
 };
 
+/**
+ * Returns a new unconnected TCPClient object that has the specified
+ * connection role.
+ *
+ * @param role The role of the new object.
+ * @returns A new TCPClient object.
+ */
 TCPClient::Ptr TCPClientFactory(TCPClientRole role);
 
 }
index d5744b39734e134daee17e2bb16e69dc902fcc0a..d9b30190d39c86b7562e98076d34a4288726b845 100644 (file)
 namespace icinga
 {
 
+/**
+ * Event arguments for the "new client" event.
+ */
 struct I2_BASE_API NewClientEventArgs : public EventArgs
 {
-       typedef shared_ptr<NewClientEventArgs> Ptr;
-       typedef weak_ptr<NewClientEventArgs> WeakPtr;
-
-       TCPSocket::Ptr Client;
+       TCPSocket::Ptr Client; /**< The new client object. */
 };
 
+/**
+ * A TCP server that listens on a TCP port and accepts incoming
+ * client connections. */
 class I2_BASE_API TCPServer : public TCPSocket
 {
 private:
index 36bab6ff13bbe14d2f66fe8e9762d0816ca118cb..e9b729996da912f5c096080ea5d305eb29b5ffc3 100644 (file)
@@ -23,6 +23,9 @@
 namespace icinga
 {
 
+/**
+ * A TCP socket.
+ */
 class I2_BASE_API TCPSocket : public Socket
 {
 private:
index 9516bd799e9161862d847bd272bbe89ce4cede60..79f013d5380cea819e3840988801ac923118b583 100644 (file)
 
 namespace icinga {
 
+/**
+ * Event arguments for the "timer expired" event.
+ */
 struct I2_BASE_API TimerEventArgs : public EventArgs
 {
-       typedef shared_ptr<TimerEventArgs> Ptr;
-       typedef weak_ptr<TimerEventArgs> WeakPtr;
-
-       EventArgs UserArgs;
+       EventArgs UserArgs; /**< User-specified event arguments. */
 };
 
+/**
+ * A timer that periodically triggers an event.
+ */
 class I2_BASE_API Timer : public Object
 {
 private:
-       EventArgs m_UserArgs;
-       unsigned int m_Interval;
-       time_t m_Next;
+       EventArgs m_UserArgs; /**< User-specified event arguments. */
+       unsigned int m_Interval; /**< The interval of the timer. */
+       time_t m_Next; /**< When the next event should happen. */
 
-       static time_t NextCall;
+       static time_t NextCall; /**< When the next event should happen (for all timers). */
 
        static void RescheduleTimers(void);
 
index b44460fd5b10d1561e2689528ec81c27db90da7f..bf76dbe16a8d318d6de5ffda9f826515e9a4d24d 100644 (file)
 namespace icinga
 {
 
+/**
+ * Event arguments for the "SSL certificate verification" event.
+ */
 struct I2_BASE_API VerifyCertificateEventArgs : public EventArgs
 {
-       bool ValidCertificate;
-       X509_STORE_CTX *Context;
-       shared_ptr<X509> Certificate;
+       bool ValidCertificate; /**< Whether the certificate is valid, can be
+                                   changed by the event handler. */
+       X509_STORE_CTX *Context; /**< The X509 store context. */
+       shared_ptr<X509> Certificate; /**< The X509 certificate that should
+                                          ve verified. */
 };
 
+/**
+ * A TLS client connection.
+ */
 class I2_BASE_API TLSClient : public TCPClient
 {
 private:
index d22ef572cea3f2bc6e108117b0760a5e93dc1e6e..b1b047127c15940eaec7353580e1f8804930c3b2 100644 (file)
@@ -23,6 +23,9 @@
 namespace icinga
 {
 
+/**
+ * The type of a Variant object.
+ */
 enum I2_BASE_API VariantType
 {
        VariantEmpty,
@@ -31,14 +34,20 @@ enum I2_BASE_API VariantType
        VariantObject
 };
 
+/**
+ * A type that can hold an arbitrary value.
+ */
 class I2_BASE_API Variant
 {
 private:
-       mutable VariantType m_Type;
-
-       mutable long m_IntegerValue;
-       mutable string m_StringValue;
-       mutable Object::Ptr m_ObjectValue;
+       mutable VariantType m_Type; /**< The type of the Variant. */
+
+       mutable long m_IntegerValue; /**< The value of the Variant
+                                         if m_Type == VariantInteger */
+       mutable string m_StringValue; /**< The value of the Variant
+                                          if m_Type == VariantString */
+       mutable Object::Ptr m_ObjectValue; /**< The value of the Variant
+                                               if m_Type == VariantObject */
 
        void Convert(VariantType newType) const;
 
index 7ddc1e6d027de144496d1c82030038cd544289e1..d15853cb09ca30d6ad948837282645edb1c2901f 100644 (file)
 
 using namespace icinga;
 
+/**
+ * Entry point for the Icinga application.
+ *
+ * @params argc Number of command line arguments.
+ * @params argv Command line arguments.
+ * @returns The application's exit status.
+ */
 int main(int argc, char **argv)
 {
        IcingaApplication::Ptr instance = make_shared<IcingaApplication>();
-       return icinga::RunApplication(argc, argv, instance);
+       return instance->Run(argc, argv);
 }