]> granicus.if.org Git - icinga2/commitdiff
Cleaned up the code a bit.
authorGunnar Beutner <gunnar.beutner@netways.de>
Fri, 21 Sep 2012 07:43:06 +0000 (09:43 +0200)
committerGunnar Beutner <gunnar.beutner@netways.de>
Fri, 21 Sep 2012 07:43:06 +0000 (09:43 +0200)
components/checker/checkercomponent.cpp
components/checker/checkercomponent.h
components/convenience/conveniencecomponent.cpp
components/convenience/conveniencecomponent.h
components/demo/democomponent.cpp
lib/base/dynamicobject.cpp
lib/base/utility.cpp
lib/remoting/endpointmanager.cpp
lib/remoting/endpointmanager.h
lib/remoting/jsonrpcclient.cpp

index 0fb475bf1734f7061db72207b5b686b9b7801c3e..2411b45d028d6d8e1ac4f603b12dcb750d835ddc 100644 (file)
@@ -30,7 +30,7 @@ void CheckerComponent::Start(void)
        m_Endpoint->RegisterSubscription("checker");
 
        Service::OnCheckerChanged.connect(bind(&CheckerComponent::CheckerChangedHandler, this, _1));
-       DynamicObject::OnUnregistered.connect(bind(&CheckerComponent::ServiceRemovedHandler, this, _1));
+       DynamicObject::OnUnregistered.connect(bind(&CheckerComponent::ObjectRemovedHandler, this, _1));
 
        m_CheckTimer = boost::make_shared<Timer>();
        m_CheckTimer->SetInterval(1);
@@ -184,7 +184,7 @@ void CheckerComponent::CheckerChangedHandler(const Service::Ptr& service)
        }
 }
 
-void CheckerComponent::ServiceRemovedHandler(const DynamicObject::Ptr& object)
+void CheckerComponent::ObjectRemovedHandler(const DynamicObject::Ptr& object)
 {
        Service::Ptr service = dynamic_pointer_cast<Service>(object);
 
@@ -197,3 +197,4 @@ void CheckerComponent::ServiceRemovedHandler(const DynamicObject::Ptr& object)
 }
 
 EXPORT_COMPONENT(checker, CheckerComponent);
+
index b54d5d97f9ff2e55a93d9077e2603b385f0c2f0b..98a4ea92b16b820e423c3fe3096593fe8ce116f1 100644 (file)
@@ -23,6 +23,9 @@
 namespace icinga
 {
 
+/**
+ * @ingroup checker
+ */
 struct ServiceNextCheckExtractor
 {
        typedef double result_type;
@@ -71,10 +74,7 @@ private:
        void AdjustCheckTimer(void);
 
        void CheckerChangedHandler(const Service::Ptr& service);
-       void ServiceRemovedHandler(const DynamicObject::Ptr& object);
-
-       //void AssignServiceRequestHandler(const Endpoint::Ptr& sender, const RequestMessage& request);
-       //void ClearServicesRequestHandler(const Endpoint::Ptr& sender, const RequestMessage& request);
+       void ObjectRemovedHandler(const DynamicObject::Ptr& object);
 };
 
 }
index f8bf2aaa612470ac9071404280ad942bdf50abef..e4caea210b2be374d23f5e642c3265fdeb43408f 100644 (file)
@@ -26,8 +26,8 @@ using namespace icinga;
  */
 void ConvenienceComponent::Start(void)
 {
-       ConfigItem::OnCommitted.connect(boost::bind(&ConvenienceComponent::HostCommittedHandler, this, _1));
-       ConfigItem::OnRemoved.connect(boost::bind(&ConvenienceComponent::HostRemovedHandler, this, _1));
+       ConfigItem::OnCommitted.connect(boost::bind(&ConvenienceComponent::ObjectCommittedHandler, this, _1));
+       ConfigItem::OnRemoved.connect(boost::bind(&ConvenienceComponent::ObjectRemovedHandler, this, _1));
 }
 
 template<typename TDict>
@@ -68,7 +68,7 @@ static void CopyServiceAttributes(const Host::Ptr& host, TDict serviceDesc,
                    Service::ResolveDependencies(host, hostchecks));
 }
 
-void ConvenienceComponent::HostCommittedHandler(const ConfigItem::Ptr& item)
+void ConvenienceComponent::ObjectCommittedHandler(const ConfigItem::Ptr& item)
 {
        if (item->GetType() != "Host")
                return;
@@ -139,7 +139,7 @@ void ConvenienceComponent::HostCommittedHandler(const ConfigItem::Ptr& item)
        host->Set("convenience_services", newServices);
 }
 
-void ConvenienceComponent::HostRemovedHandler(const ConfigItem::Ptr& item)
+void ConvenienceComponent::ObjectRemovedHandler(const ConfigItem::Ptr& item)
 {
        if (item->GetType() != "Host")
                return;
@@ -161,3 +161,4 @@ void ConvenienceComponent::HostRemovedHandler(const ConfigItem::Ptr& item)
 }
 
 EXPORT_COMPONENT(convenience, ConvenienceComponent);
+
index 2a5807df8ccbef073c3ae3c77b00908eddc45ad8..e1d7db788ae4d631b46cc0a0a92774ae604b7ac2 100644 (file)
@@ -32,9 +32,8 @@ public:
        virtual void Start(void);
 
 private:
-       void HostAddedHandler(const ConfigItem::Ptr& item);
-       void HostCommittedHandler(const ConfigItem::Ptr& item);
-       void HostRemovedHandler(const ConfigItem::Ptr& item);
+       void ObjectCommittedHandler(const ConfigItem::Ptr& item);
+       void ObjectRemovedHandler(const ConfigItem::Ptr& item);
 };
 
 }
index 2474ed9b11ae705e26d9e1cbef086fb0c6da2c83..ebc8dd841f1bb824f56d642ac060260133bd1503 100644 (file)
@@ -28,7 +28,8 @@ void DemoComponent::Start(void)
 {
        m_Endpoint = Endpoint::MakeEndpoint("demo", true);
        m_Endpoint->RegisterTopicHandler("demo::HelloWorld",
-           boost::bind(&DemoComponent::HelloWorldRequestHandler, this, _2, _3));
+           boost::bind(&DemoComponent::HelloWorldRequestHandler, this, _2,
+           _3));
 
        m_DemoTimer = boost::make_shared<Timer>();
        m_DemoTimer->SetInterval(5);
@@ -51,20 +52,25 @@ void DemoComponent::Stop(void)
  */
 void DemoComponent::DemoTimerHandler(void)
 {
-       Logger::Write(LogInformation, "demo", "Sending multicast 'hello world' message.");
+       Logger::Write(LogInformation, "demo", "Sending multicast 'hello"
+           " world' message.");
 
        RequestMessage request;
        request.SetMethod("demo::HelloWorld");
 
-       EndpointManager::GetInstance()->SendMulticastMessage(m_Endpoint, request);
+       EndpointManager::GetInstance()->SendMulticastMessage(m_Endpoint,
+           request);
 }
 
 /**
  * Processes demo::HelloWorld messages.
  */
-void DemoComponent::HelloWorldRequestHandler(const Endpoint::Ptr& sender, const RequestMessage& request)
+void DemoComponent::HelloWorldRequestHandler(const Endpoint::Ptr& sender,
+    const RequestMessage& request)
 {
-       Logger::Write(LogInformation, "demo", "Got 'hello world' from address=" + sender->GetAddress() + ", identity=" + sender->GetName());
+       Logger::Write(LogInformation, "demo", "Got 'hello world' from"
+           " address=" + sender->GetAddress() + ", identity=" +
+           sender->GetName());
 }
 
 EXPORT_COMPONENT(demo, DemoComponent);
index 768ead8fde6756b6aeff79ef6922fcb6ab2bf083..2911a8e3cebe605e8149e6e1f5df5a071c7d7bfb 100644 (file)
@@ -85,15 +85,18 @@ Dictionary::Ptr DynamicObject::BuildUpdate(double sinceTx, int attributeTypes) c
        return update;
 }
 
-void DynamicObject::ApplyUpdate(const Dictionary::Ptr& serializedUpdate, int allowedTypes)
+void DynamicObject::ApplyUpdate(const Dictionary::Ptr& serializedUpdate,
+    int allowedTypes)
 {
        InternalApplyUpdate(serializedUpdate, allowedTypes, false);
 }
 
-void DynamicObject::InternalApplyUpdate(const Dictionary::Ptr& serializedUpdate, int allowedTypes, bool suppressEvents)
+void DynamicObject::InternalApplyUpdate(const Dictionary::Ptr& serializedUpdate,
+    int allowedTypes, bool suppressEvents)
 {
        double configTx = 0;
-       if ((allowedTypes & Attribute_Config) != 0 && serializedUpdate->Contains("configTx")) {
+       if ((allowedTypes & Attribute_Config) != 0 &&
+           serializedUpdate->Contains("configTx")) {
                configTx = serializedUpdate->Get("configTx");
 
                if (configTx > m_ConfigTx)
@@ -127,7 +130,8 @@ void DynamicObject::InternalApplyUpdate(const Dictionary::Ptr& serializedUpdate,
        }
 }
 
-void DynamicObject::RegisterAttribute(const String& name, DynamicAttributeType type)
+void DynamicObject::RegisterAttribute(const String& name,
+    DynamicAttributeType type)
 {
        DynamicAttribute attr;
        attr.Type = type;
@@ -155,7 +159,8 @@ Value DynamicObject::Get(const String& name) const
        return InternalGetAttribute(name);
 }
 
-void DynamicObject::InternalSetAttribute(const String& name, const Value& data, double tx, bool suppressEvent)
+void DynamicObject::InternalSetAttribute(const String& name, const Value& data,
+    double tx, bool suppressEvent)
 {
        DynamicAttribute attr;
        attr.Type = Attribute_Transient;
@@ -412,7 +417,8 @@ void DynamicObject::RestoreObjects(const String& filename)
        std::ifstream fp;
        fp.open(filename.CStr());
 
-       /* TODO: Fix this horrible mess. */
+       /* TODO: Fix this horrible mess by implementing a class that provides
+        * IOQueue functionality for files. */
        FIFO::Ptr fifo = boost::make_shared<FIFO>();
        while (fp) {
                char buffer[1024];
index a34512e4d88b29bd94ed2326595c4dcdfda604f6..b6c89282d78dc227e5cb2e27bafce83a44a58681 100644 (file)
@@ -145,10 +145,12 @@ String Utility::GetCertificateCN(const shared_ptr<X509>& certificate)
 {
        char buffer[256];
 
-       int rc = X509_NAME_get_text_by_NID(X509_get_subject_name(certificate.get()), NID_commonName, buffer, sizeof(buffer));
+       int rc = X509_NAME_get_text_by_NID(X509_get_subject_name(certificate.get()),
+           NID_commonName, buffer, sizeof(buffer));
 
        if (rc == -1)
-               throw_exception(OpenSSLException("X509 certificate has no CN attribute", ERR_get_error()));
+               throw_exception(OpenSSLException("X509 certificate has no CN"
+                   " attribute", ERR_get_error()));
 
        return buffer;
 }
@@ -165,14 +167,17 @@ shared_ptr<X509> Utility::GetX509Certificate(String pemfile)
        BIO *fpcert = BIO_new(BIO_s_file());
 
        if (fpcert == NULL)
-               throw_exception(OpenSSLException("BIO_new failed", ERR_get_error()));
+               throw_exception(OpenSSLException("BIO_new failed",
+                   ERR_get_error()));
 
        if (BIO_read_filename(fpcert, pemfile.CStr()) < 0)
-               throw_exception(OpenSSLException("BIO_read_filename failed", ERR_get_error()));
+               throw_exception(OpenSSLException("BIO_read_filename failed",
+                   ERR_get_error()));
 
        cert = PEM_read_bio_X509_AUX(fpcert, NULL, NULL, NULL);
        if (cert == NULL)
-               throw_exception(OpenSSLException("PEM_read_bio_X509_AUX failed", ERR_get_error()));
+               throw_exception(OpenSSLException("PEM_read_bio_X509_AUX failed",
+                   ERR_get_error()));
 
        BIO_free(fpcert);
 
@@ -210,7 +215,8 @@ String Utility::DirName(const String& path)
 #else /* _WIN32 */
        if (!PathRemoveFileSpec(dir)) {
                free(dir);
-               throw_exception(Win32Exception("PathRemoveFileSpec() failed", GetLastError()));
+               throw_exception(Win32Exception("PathRemoveFileSpec() failed",
+                   GetLastError()));
        }
 
        result = dir;
index fbf13c0d541abc2d13ea8b7ab54441c11df94d6f..080f46aa0296e178ac4a6dfab82f2c861fd4878f 100644 (file)
@@ -258,25 +258,9 @@ void EndpointManager::SendMulticastMessage(const Endpoint::Ptr& sender,
        }
 }
 
-/**
- * Calls the specified callback function for each registered endpoint.
- *
- * @param callback The callback function.
- */
-//void EndpointManager::ForEachEndpoint(function<void (const EndpointManager::Ptr&, const Endpoint::Ptr&)> callback)
-//{
-//     map<String, Endpoint::Ptr>::iterator prev, i;
-//     for (i = m_Endpoints.begin(); i != m_Endpoints.end(); ) {
-//             prev = i;
-//             i++;
-//
-//             callback(GetSelf(), prev->second);
-//     }
-//}
-
 void EndpointManager::SendAPIMessage(const Endpoint::Ptr& sender, const Endpoint::Ptr& recipient,
     RequestMessage& message,
-    function<void(const EndpointManager::Ptr&, const Endpoint::Ptr, const RequestMessage&, const ResponseMessage&, bool TimedOut)> callback, double timeout)
+    const EndpointManager::APICallback& callback, double timeout)
 {
        m_NextMessageID++;
 
@@ -355,7 +339,8 @@ void EndpointManager::RequestTimerHandler(void)
        map<String, PendingRequest>::iterator it;
        for (it = m_Requests.begin(); it != m_Requests.end(); it++) {
                if (it->second.HasTimedOut()) {
-                       it->second.Callback(GetSelf(), Endpoint::Ptr(), it->second.Request, ResponseMessage(), true);
+                       it->second.Callback(GetSelf(), Endpoint::Ptr(),
+                           it->second.Request, ResponseMessage(), true);
 
                        m_Requests.erase(it);
 
@@ -364,7 +349,8 @@ void EndpointManager::RequestTimerHandler(void)
        }
 }
 
-void EndpointManager::ProcessResponseMessage(const Endpoint::Ptr& sender, const ResponseMessage& message)
+void EndpointManager::ProcessResponseMessage(const Endpoint::Ptr& sender,
+    const ResponseMessage& message)
 {
        String id;
        if (!message.GetID(&id))
@@ -381,16 +367,6 @@ void EndpointManager::ProcessResponseMessage(const Endpoint::Ptr& sender, const
        m_Requests.erase(it);
 }
 
-//EndpointManager::Iterator EndpointManager::Begin(void)
-//{
-//     return m_Endpoints.begin();
-//}
-
-//EndpointManager::Iterator EndpointManager::End(void)
-//{
-//     return m_Endpoints.end();
-//}
-
 EndpointManager::Ptr EndpointManager::GetInstance(void)
 {
        static EndpointManager::Ptr instance;
index 878cf368e8e89ed9b096d3dddbe6ce5afeffe3db..72c0ba910292de6d3d5505681c07b584c863c7be 100644 (file)
@@ -51,8 +51,10 @@ public:
        void SendAnycastMessage(const Endpoint::Ptr& sender, const RequestMessage& message);
        void SendMulticastMessage(const Endpoint::Ptr& sender, const RequestMessage& message);
 
+       typedef function<void(const EndpointManager::Ptr&, const Endpoint::Ptr, const RequestMessage&, const ResponseMessage&, bool TimedOut)> APICallback;
+
        void SendAPIMessage(const Endpoint::Ptr& sender, const Endpoint::Ptr& recipient, RequestMessage& message,
-           function<void(const EndpointManager::Ptr&, const Endpoint::Ptr, const RequestMessage&, const ResponseMessage&, bool TimedOut)> callback, double timeout = 30);
+           const APICallback& callback, double timeout = 30);
 
        void ProcessResponseMessage(const Endpoint::Ptr& sender, const ResponseMessage& message);
 
index 5da414da31a64821ba47ce0824e4851a057d802a..4fd3497468687c2f9684b12b92eb8e00eafa8069 100644 (file)
@@ -30,7 +30,8 @@ using namespace icinga;
 JsonRpcClient::JsonRpcClient(TcpClientRole role, shared_ptr<SSL_CTX> sslContext)
        : TlsClient(role, sslContext)
 {
-       OnDataAvailable.connect(boost::bind(&JsonRpcClient::DataAvailableHandler, this));
+       OnDataAvailable.connect(boost::bind(&JsonRpcClient::DataAvailableHandler,
+           this));
 }
 
 /**
@@ -59,12 +60,16 @@ void JsonRpcClient::DataAvailableHandler(void)
                try {
                        Value value = Value::Deserialize(jsonString);
 
-                       if (!value.IsObjectType<Dictionary>())
-                               throw_exception(invalid_argument("JSON-RPC message must be a dictionary."));
+                       if (!value.IsObjectType<Dictionary>()) {
+                               throw_exception(invalid_argument("JSON-RPC"
+                                   " message must be a dictionary."));
+                       }
 
                        OnNewMessage(GetSelf(), MessagePart(value));
                } catch (const exception& ex) {
-                       Logger::Write(LogCritical, "jsonrpc", "Exception while processing message from JSON-RPC client: " + String(ex.what()));
+                       Logger::Write(LogCritical, "remoting", "Exception"
+                           " while processing message from JSON-RPC client: " +
+                           String(ex.what()));
                }
        }
 }
@@ -77,9 +82,11 @@ void JsonRpcClient::DataAvailableHandler(void)
  * @param sslContext SSL context for the TLS connection.
  * @returns A new JSON-RPC client.
  */
-JsonRpcClient::Ptr icinga::JsonRpcClientFactory(SOCKET fd, TcpClientRole role, shared_ptr<SSL_CTX> sslContext)
+JsonRpcClient::Ptr icinga::JsonRpcClientFactory(SOCKET fd, TcpClientRole role,
+    shared_ptr<SSL_CTX> sslContext)
 {
-       JsonRpcClient::Ptr client = boost::make_shared<JsonRpcClient>(role, sslContext);
+       JsonRpcClient::Ptr client = boost::make_shared<JsonRpcClient>(role,
+           sslContext);
        client->SetFD(fd);
        return client;
 }