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);
}
}
-void CheckerComponent::ServiceRemovedHandler(const DynamicObject::Ptr& object)
+void CheckerComponent::ObjectRemovedHandler(const DynamicObject::Ptr& object)
{
Service::Ptr service = dynamic_pointer_cast<Service>(object);
}
EXPORT_COMPONENT(checker, CheckerComponent);
+
namespace icinga
{
+/**
+ * @ingroup checker
+ */
struct ServiceNextCheckExtractor
{
typedef double result_type;
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);
};
}
*/
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>
Service::ResolveDependencies(host, hostchecks));
}
-void ConvenienceComponent::HostCommittedHandler(const ConfigItem::Ptr& item)
+void ConvenienceComponent::ObjectCommittedHandler(const ConfigItem::Ptr& item)
{
if (item->GetType() != "Host")
return;
host->Set("convenience_services", newServices);
}
-void ConvenienceComponent::HostRemovedHandler(const ConfigItem::Ptr& item)
+void ConvenienceComponent::ObjectRemovedHandler(const ConfigItem::Ptr& item)
{
if (item->GetType() != "Host")
return;
}
EXPORT_COMPONENT(convenience, ConvenienceComponent);
+
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);
};
}
{
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);
*/
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);
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)
}
}
-void DynamicObject::RegisterAttribute(const String& name, DynamicAttributeType type)
+void DynamicObject::RegisterAttribute(const String& name,
+ DynamicAttributeType type)
{
DynamicAttribute attr;
attr.Type = type;
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;
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];
{
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;
}
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);
#else /* _WIN32 */
if (!PathRemoveFileSpec(dir)) {
free(dir);
- throw_exception(Win32Exception("PathRemoveFileSpec() failed", GetLastError()));
+ throw_exception(Win32Exception("PathRemoveFileSpec() failed",
+ GetLastError()));
}
result = dir;
}
}
-/**
- * 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++;
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);
}
}
-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))
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;
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);
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));
}
/**
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()));
}
}
}
* @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;
}