From: Gunnar Beutner Date: Fri, 21 Sep 2012 07:43:06 +0000 (+0200) Subject: Cleaned up the code a bit. X-Git-Tag: v0.0.1~80^2 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=97829fbfcd479ce779c91d678fe5ada5d2e014c0;p=icinga2 Cleaned up the code a bit. --- diff --git a/components/checker/checkercomponent.cpp b/components/checker/checkercomponent.cpp index 0fb475bf1..2411b45d0 100644 --- a/components/checker/checkercomponent.cpp +++ b/components/checker/checkercomponent.cpp @@ -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(); 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(object); @@ -197,3 +197,4 @@ void CheckerComponent::ServiceRemovedHandler(const DynamicObject::Ptr& object) } EXPORT_COMPONENT(checker, CheckerComponent); + diff --git a/components/checker/checkercomponent.h b/components/checker/checkercomponent.h index b54d5d97f..98a4ea92b 100644 --- a/components/checker/checkercomponent.h +++ b/components/checker/checkercomponent.h @@ -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); }; } diff --git a/components/convenience/conveniencecomponent.cpp b/components/convenience/conveniencecomponent.cpp index f8bf2aaa6..e4caea210 100644 --- a/components/convenience/conveniencecomponent.cpp +++ b/components/convenience/conveniencecomponent.cpp @@ -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 @@ -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); + diff --git a/components/convenience/conveniencecomponent.h b/components/convenience/conveniencecomponent.h index 2a5807df8..e1d7db788 100644 --- a/components/convenience/conveniencecomponent.h +++ b/components/convenience/conveniencecomponent.h @@ -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); }; } diff --git a/components/demo/democomponent.cpp b/components/demo/democomponent.cpp index 2474ed9b1..ebc8dd841 100644 --- a/components/demo/democomponent.cpp +++ b/components/demo/democomponent.cpp @@ -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(); 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); diff --git a/lib/base/dynamicobject.cpp b/lib/base/dynamicobject.cpp index 768ead8fd..2911a8e3c 100644 --- a/lib/base/dynamicobject.cpp +++ b/lib/base/dynamicobject.cpp @@ -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(); while (fp) { char buffer[1024]; diff --git a/lib/base/utility.cpp b/lib/base/utility.cpp index a34512e4d..b6c89282d 100644 --- a/lib/base/utility.cpp +++ b/lib/base/utility.cpp @@ -145,10 +145,12 @@ String Utility::GetCertificateCN(const shared_ptr& 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 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; diff --git a/lib/remoting/endpointmanager.cpp b/lib/remoting/endpointmanager.cpp index fbf13c0d5..080f46aa0 100644 --- a/lib/remoting/endpointmanager.cpp +++ b/lib/remoting/endpointmanager.cpp @@ -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 callback) -//{ -// map::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 callback, double timeout) + const EndpointManager::APICallback& callback, double timeout) { m_NextMessageID++; @@ -355,7 +339,8 @@ void EndpointManager::RequestTimerHandler(void) map::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; diff --git a/lib/remoting/endpointmanager.h b/lib/remoting/endpointmanager.h index 878cf368e..72c0ba910 100644 --- a/lib/remoting/endpointmanager.h +++ b/lib/remoting/endpointmanager.h @@ -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 APICallback; + void SendAPIMessage(const Endpoint::Ptr& sender, const Endpoint::Ptr& recipient, RequestMessage& message, - function callback, double timeout = 30); + const APICallback& callback, double timeout = 30); void ProcessResponseMessage(const Endpoint::Ptr& sender, const ResponseMessage& message); diff --git a/lib/remoting/jsonrpcclient.cpp b/lib/remoting/jsonrpcclient.cpp index 5da414da3..4fd349746 100644 --- a/lib/remoting/jsonrpcclient.cpp +++ b/lib/remoting/jsonrpcclient.cpp @@ -30,7 +30,8 @@ using namespace icinga; JsonRpcClient::JsonRpcClient(TcpClientRole role, shared_ptr 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()) - throw_exception(invalid_argument("JSON-RPC message must be a dictionary.")); + if (!value.IsObjectType()) { + 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 sslContext) +JsonRpcClient::Ptr icinga::JsonRpcClientFactory(SOCKET fd, TcpClientRole role, + shared_ptr sslContext) { - JsonRpcClient::Ptr client = boost::make_shared(role, sslContext); + JsonRpcClient::Ptr client = boost::make_shared(role, + sslContext); client->SetFD(fd); return client; }