# If the GENERATE_LATEX tag is set to YES (the default) Doxygen will
# generate Latex output.
-GENERATE_LATEX = NO
+GENERATE_LATEX = YES
# The LATEX_OUTPUT tag is used to specify where the LaTeX docs will be put.
# If a relative path is entered the value of OUTPUT_DIRECTORY will be
using namespace icinga;
-Application::Ptr I2_EXPORT Application::Instance;
+Application::Ptr I2_EXPORT Application::m_Instance;
/**
* Constructor for the Application class.
#endif /* _WIN32 */
}
+/**
+ * Retrieves a pointer to the application singleton object.
+ *
+ * @returns The application object.
+ */
+Application::Ptr Application::GetInstance(void)
+{
+ return m_Instance;
+}
+
/**
* Processes events for registered sockets and timers and calls whatever
* handlers have been set up for these events.
*/
void Application::RegisterComponent(Component::Ptr component)
{
- component->SetApplication(static_pointer_cast<Application>(shared_from_this()));
m_Components[component->GetName()] = component;
component->Start();
{
assert(signum == SIGINT);
- Application::Instance->Shutdown();
+ Application::GetInstance()->Shutdown();
struct sigaction sa;
memset(&sa, 0, sizeof(sa));
sa.sa_handler = SIG_DFL;
sigaction(SIGINT, &sa, NULL);
}
+#else /* _WIN32 */
+/**
+ * Console control handler. Prepares the application for cleanly
+ * shutting down during the next execution of the event loop.
+ */
+BOOL WINAPI Application::CtrlHandler(DWORD type)
+{
+ Application::GetInstance()->Shutdown();
+ SetConsoleCtrlHandler(NULL, FALSE);
+ return TRUE;
+}
#endif /* _WIN32 */
/**
{
int result;
- assert(!Application::Instance);
- Application::Instance = static_pointer_cast<Application>(shared_from_this());
+ assert(!Application::m_Instance);
+ Application::m_Instance = static_pointer_cast<Application>(shared_from_this());
#ifndef _WIN32
struct sigaction sa;
memset(&sa, 0, sizeof(sa));
- sa.sa_handler = Application::SigIntHandler;
+ sa.sa_handler = &Application::SigIntHandler;
sigaction(SIGINT, &sa, NULL);
sa.sa_handler = SIG_IGN;
sigaction(SIGPIPE, &sa, NULL);
+#else
+ SetConsoleCtrlHandler(&Application::CtrlHandler, TRUE);
#endif /* _WIN32 */
m_Arguments.clear();
if (IsDebugging()) {
result = Main(m_Arguments);
- Application::Instance.reset();
+ Application::m_Instance.reset();
} else {
try {
result = Main(m_Arguments);
} catch (const exception& ex) {
- Application::Instance.reset();
+ Application::m_Instance.reset();
Application::Log("---");
Application::Log("Exception: " + Utility::GetTypeName(ex));
* @ingroup base
*/
class I2_BASE_API Application : public Object {
+public:
+ typedef shared_ptr<Application> Ptr;
+ typedef weak_ptr<Application> WeakPtr;
+
private:
+ static Application::Ptr m_Instance;
+
bool m_ShuttingDown; /**< Whether the application is in the process of
shutting down. */
ConfigHive::Ptr m_ConfigHive; /**< The application's configuration. */
#ifndef _WIN32
static void SigIntHandler(int signum);
+#else /* _WIN32 */
+ static BOOL WINAPI CtrlHandler(DWORD type);
#endif /* _WIN32 */
protected:
string GetExeDirectory(void) const;
public:
- typedef shared_ptr<Application> Ptr;
- typedef weak_ptr<Application> WeakPtr;
-
- static Application::Ptr Instance;
-
Application(void);
~Application(void);
+ static Application::Ptr GetInstance(void);
+
int Run(int argc, char **argv);
virtual int Main(const vector<string>& args) = 0;
using namespace icinga;
-/**
- * Sets the application this component belongs to.
- *
- * @param application The application.
- */
-void Component::SetApplication(const Application::WeakPtr& application)
-{
- m_Application = application;
-}
-
-/**
- * Retrieves the application this component belongs to.
- *
- * @returns The application.
- */
-Application::Ptr Component::GetApplication(void) const
-{
- return m_Application.lock();
-}
-
/**
* Sets the configuration for this component.
*
class I2_BASE_API Component : public Object
{
private:
- Application::WeakPtr m_Application;
ConfigObject::Ptr m_Config;
public:
typedef shared_ptr<Component> Ptr;
typedef weak_ptr<Component> WeakPtr;
- void SetApplication(const Application::WeakPtr& application);
- Application::Ptr GetApplication(void) const;
-
void SetConfig(const ConfigObject::Ptr& componentConfig);
ConfigObject::Ptr GetConfig(void) const;
/**
* Invokes the specified callback for each object contained in this hive.
*
+ * @param type The config object type.
* @param callback The callback.
*/
void ConfigHive::ForEachObject(const string& type,
void AddObject(const ConfigObject::Ptr& object);
void RemoveObject(const ConfigObject::Ptr& object);
- ConfigObject::Ptr GetObject(const string& collection,
+ ConfigObject::Ptr GetObject(const string& type,
const string& name = string());
- ConfigCollection::Ptr GetCollection(const string& collection);
+ ConfigCollection::Ptr GetCollection(const string& type);
void ForEachObject(const string& type,
function<int (const EventArgs&)> callback);
typedef weak_ptr<Object> WeakPtr;
};
+/**
+ * Compares a weak pointer with a raw pointer.
+ */
template<class T>
-struct weak_ptr_eq_raw
+struct WeakPtrEqual
{
private:
const void *m_Ref;
public:
- weak_ptr_eq_raw(const void *ref) : m_Ref(ref) { }
+ WeakPtrEqual(const void *ref) : m_Ref(ref) { }
+ /**
+ * Compares the two pointers.
+ *
+ * @param wref The weak pointer.
+ * @returns true if the pointers point to the same object, false otherwise.
+ */
bool operator()(const weak_ptr<T>& wref) const
{
return (wref.lock().get() == (const T *)m_Ref);
*/
void Socket::Stop(void)
{
- Sockets.remove_if(weak_ptr_eq_raw<Socket>(this));
+ Sockets.remove_if(WeakPtrEqual<Socket>(this));
}
/**
*/
void Timer::Stop(void)
{
- Timers.remove_if(weak_ptr_eq_raw<Timer>(this));
+ Timers.remove_if(WeakPtrEqual<Timer>(this));
}
/**
if (fp.fail())
throw ConfigParserException("Could not open config file");
- GetApplication()->Log("Reading config file: " + filename);
+ GetIcingaApplication()->Log("Reading config file: " + filename);
while (!fp.eof()) {
size_t bufferSize = 1024;
}
}
- GetApplication()->GetConfigHive()->AddObject(cfgobj);
+ GetConfigHive()->AddObject(cfgobj);
}
}
int ConfigRpcComponent::SessionEstablishedHandler(const EventArgs& ea)
{
- RpcRequest request;
+ RequestMessage request;
request.SetMethod("config::FetchObjects");
Endpoint::Ptr endpoint = static_pointer_cast<Endpoint>(ea.Source);
return 0;
}
-RpcRequest ConfigRpcComponent::MakeObjectMessage(const ConfigObject::Ptr& object, string method, bool includeProperties)
+RequestMessage ConfigRpcComponent::MakeObjectMessage(const ConfigObject::Ptr& object, string method, bool includeProperties)
{
- RpcRequest msg;
+ RequestMessage msg;
msg.SetMethod(method);
MessagePart params;
if (!ShouldReplicateObject(object))
continue;
- RpcRequest request = MakeObjectMessage(object, "config::ObjectCreated", true);
+ RequestMessage request = MakeObjectMessage(object, "config::ObjectCreated", true);
GetEndpointManager()->SendUnicastMessage(m_ConfigRpcEndpoint, client, request);
}
int ConfigRpcComponent::RemoteObjectCommittedHandler(const NewRequestEventArgs& ea)
{
- RpcRequest message = ea.Request;
+ RequestMessage message = ea.Request;
bool was_null = false;
MessagePart params;
int ConfigRpcComponent::RemoteObjectRemovedHandler(const NewRequestEventArgs& ea)
{
- RpcRequest message = ea.Request;
+ RequestMessage message = ea.Request;
MessagePart params;
if (!message.GetParams(¶ms))
int RemoteObjectCommittedHandler(const NewRequestEventArgs& ea);
int RemoteObjectRemovedHandler(const NewRequestEventArgs& ea);
- static RpcRequest MakeObjectMessage(const ConfigObject::Ptr& object,
+ static RequestMessage MakeObjectMessage(const ConfigObject::Ptr& object,
string method, bool includeProperties);
static bool ShouldReplicateObject(const ConfigObject::Ptr& object);
{
Application::Log("Sending multicast 'hello world' message.");
- RpcRequest request;
+ RequestMessage request;
request.SetMethod("demo::HelloWorld");
EndpointManager::Ptr endpointManager = GetIcingaApplication()->GetEndpointManager();
// we assume the other component _always_ wants
// discovery::Welcome messages from us
endpoint->RegisterSubscription("discovery::Welcome");
- RpcRequest request;
+ RequestMessage request;
request.SetMethod("discovery::Welcome");
GetEndpointManager()->SendUnicastMessage(m_DiscoveryEndpoint, endpoint, request);
*/
void DiscoveryComponent::SendDiscoveryMessage(string method, string identity, Endpoint::Ptr recipient)
{
- RpcRequest request;
+ RequestMessage request;
request.SetMethod(method);
DiscoveryMessage params;
if (!roles)
return false;
- ConfigHive::Ptr configHive = GetApplication()->GetConfigHive();
+ ConfigHive::Ptr configHive = GetConfigHive();
ConfigCollection::Ptr roleCollection = configHive->GetCollection("role");
for (DictionaryIterator ip = roles->Begin(); ip != roles->End(); ip++) {
message.GetNode(&info->Node);
message.GetService(&info->Service);
- ConfigHive::Ptr configHive = GetApplication()->GetConfigHive();
+ ConfigHive::Ptr configHive = GetConfigHive();
ConfigCollection::Ptr endpointCollection = configHive->GetCollection("endpoint");
ConfigObject::Ptr endpointConfig = endpointCollection->GetObject(identity);
time(&now);
/* check whether we have to reconnect to one of our upstream endpoints */
- ConfigCollection::Ptr endpointCollection = GetApplication()->GetConfigHive()->GetCollection("endpoint");
+ ConfigCollection::Ptr endpointCollection = GetConfigHive()->GetCollection("endpoint");
endpointCollection->ForEachObject(bind(&DiscoveryComponent::EndpointConfigHandler, this, _1));
map<string, ComponentDiscoveryInfo::Ptr>::iterator curr, i;
virtual bool IsLocal(void) const = 0;
virtual bool IsConnected(void) const = 0;
- virtual void ProcessRequest(Endpoint::Ptr sender, const RpcRequest& message) = 0;
- virtual void ProcessResponse(Endpoint::Ptr sender, const RpcResponse& message) = 0;
+ virtual void ProcessRequest(Endpoint::Ptr sender, const RequestMessage& message) = 0;
+ virtual void ProcessResponse(Endpoint::Ptr sender, const ResponseMessage& message) = 0;
virtual void Stop(void) = 0;
* @param message The message.
*/
void EndpointManager::SendAnycastMessage(Endpoint::Ptr sender,
- const RpcRequest& message)
+ const RequestMessage& message)
{
throw NotImplementedException();
}
* @param message The message.
*/
void EndpointManager::SendMulticastMessage(Endpoint::Ptr sender,
- const RpcRequest& message)
+ const RequestMessage& message)
{
string id;
if (message.GetID(&id))
void UnregisterEndpoint(Endpoint::Ptr endpoint);
void SendUnicastMessage(Endpoint::Ptr sender, Endpoint::Ptr recipient, const MessagePart& message);
- void SendAnycastMessage(Endpoint::Ptr sender, const RpcRequest& message);
- void SendMulticastMessage(Endpoint::Ptr sender, const RpcRequest& message);
+ void SendAnycastMessage(Endpoint::Ptr sender, const RequestMessage& message);
+ void SendMulticastMessage(Endpoint::Ptr sender, const RequestMessage& message);
void ForEachEndpoint(function<int (const NewEndpointEventArgs&)> callback);
IcingaApplication::Ptr IcingaComponent::GetIcingaApplication(void) const
{
- return static_pointer_cast<IcingaApplication>(GetApplication());
+ Application::Ptr application = Application::GetInstance();
+ return static_pointer_cast<IcingaApplication>(application);
}
EndpointManager::Ptr IcingaComponent::GetEndpointManager(void) const
return (bool)m_Client;
}
-void JsonRpcEndpoint::ProcessRequest(Endpoint::Ptr sender, const RpcRequest& message)
+void JsonRpcEndpoint::ProcessRequest(Endpoint::Ptr sender, const RequestMessage& message)
{
if (IsConnected()) {
string id;
}
}
-void JsonRpcEndpoint::ProcessResponse(Endpoint::Ptr sender, const RpcResponse& message)
+void JsonRpcEndpoint::ProcessResponse(Endpoint::Ptr sender, const ResponseMessage& message)
{
if (IsConnected())
m_Client->SendMessage(message);
if (!HasPublication(method))
return 0;
- RpcRequest request = message;
+ RequestMessage request = message;
string id;
if (request.GetID(&id))
else
GetEndpointManager()->SendMulticastMessage(sender, request);
} else {
- RpcResponse response = message;
+ ResponseMessage response = message;
// TODO: deal with response messages
throw NotImplementedException();
virtual bool IsLocal(void) const;
virtual bool IsConnected(void) const;
- virtual void ProcessRequest(Endpoint::Ptr sender, const RpcRequest& message);
- virtual void ProcessResponse(Endpoint::Ptr sender, const RpcResponse& message);
+ virtual void ProcessRequest(Endpoint::Ptr sender, const RequestMessage& message);
+ virtual void ProcessResponse(Endpoint::Ptr sender, const ResponseMessage& message);
virtual void Stop(void);
};
throw NotImplementedException();
}
-void VirtualEndpoint::ProcessRequest(Endpoint::Ptr sender, const RpcRequest& request)
+void VirtualEndpoint::ProcessRequest(Endpoint::Ptr sender, const RequestMessage& request)
{
string method;
if (!request.GetMethod(&method))
i->second(nrea);
}
-void VirtualEndpoint::ProcessResponse(Endpoint::Ptr sender, const RpcResponse& response)
+void VirtualEndpoint::ProcessResponse(Endpoint::Ptr sender, const ResponseMessage& response)
{
// TODO: figure out which request this response belongs to and notify the caller
throw NotImplementedException();
struct I2_ICINGA_API NewRequestEventArgs : public EventArgs
{
Endpoint::Ptr Sender;
- RpcRequest Request;
+ RequestMessage Request;
};
/**
virtual bool IsLocal(void) const;
virtual bool IsConnected(void) const;
- virtual void ProcessRequest(Endpoint::Ptr sender, const RpcRequest& message);
- virtual void ProcessResponse(Endpoint::Ptr sender, const RpcResponse& message);
+ virtual void ProcessRequest(Endpoint::Ptr sender, const RequestMessage& message);
+ virtual void ProcessResponse(Endpoint::Ptr sender, const ResponseMessage& message);
virtual void Stop(void);
};
messagepart.h \
netstring.cpp \
netstring.h \
- rpcrequest.cpp \
- rpcrequest.h \
- rpcresponse.cpp \
- rpcresponse.h
+ requestmessage.cpp \
+ requestmessage.h \
+ responsemessage.cpp \
+ responsemessage.h
libjsonrpc_la_CXXFLAGS = \
-DI2_JSONRPC_BUILD \
#endif /* I2_JSONRPC_BUILD */
#include "messagepart.h"
-#include "rpcrequest.h"
-#include "rpcresponse.h"
+#include "requestmessage.h"
+#include "responsemessage.h"
#include "netstring.h"
#include "jsonrpcclient.h"
#include "jsonrpcserver.h"
<ItemGroup>
<ClInclude Include="i2-jsonrpc.h" />
<ClInclude Include="jsonrpcclient.h" />
- <ClInclude Include="rpcrequest.h" />
- <ClInclude Include="rpcresponse.h" />
+ <ClInclude Include="requestmessage.h" />
+ <ClInclude Include="responsemessage.h" />
<ClInclude Include="jsonrpcserver.h" />
<ClInclude Include="messagepart.h" />
<ClInclude Include="netstring.h" />
</ItemGroup>
<ItemGroup>
<ClCompile Include="jsonrpcclient.cpp" />
- <ClCompile Include="rpcrequest.cpp" />
- <ClCompile Include="rpcresponse.cpp" />
+ <ClCompile Include="requestmessage.cpp" />
+ <ClCompile Include="responsemessage.cpp" />
<ClCompile Include="jsonrpcserver.cpp" />
<ClCompile Include="messagepart.cpp" />
<ClCompile Include="netstring.cpp" />
<ClCompile Include="jsonrpcclient.cpp" />
<ClCompile Include="jsonrpcserver.cpp" />
<ClCompile Include="netstring.cpp" />
- <ClCompile Include="rpcrequest.cpp" />
- <ClCompile Include="rpcresponse.cpp" />
<ClCompile Include="messagepart.cpp" />
+ <ClCompile Include="requestmessage.cpp" />
+ <ClCompile Include="responsemessage.cpp" />
</ItemGroup>
<ItemGroup>
<ClInclude Include="i2-jsonrpc.h" />
<ClInclude Include="jsonrpcclient.h" />
<ClInclude Include="jsonrpcserver.h" />
<ClInclude Include="netstring.h" />
- <ClInclude Include="rpcrequest.h" />
- <ClInclude Include="rpcresponse.h" />
<ClInclude Include="messagepart.h" />
+ <ClInclude Include="requestmessage.h" />
+ <ClInclude Include="responsemessage.h" />
</ItemGroup>
</Project>
\ No newline at end of file
char *jsonString;
string result;
-#ifdef _DEBUG
- jsonString = cJSON_Print(json);
-#else /* _DEBUG */
- jsonString = cJSON_PrintUnformatted(json);
-#endif /* _DEBUG */
+ if (!Application::GetInstance()->IsDebugging())
+ jsonString = cJSON_Print(json);
+ else
+ jsonString = cJSON_PrintUnformatted(json);
cJSON_Delete(json);
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA. *
******************************************************************************/
-#ifndef RPCREQUEST_H
-#define RPCREQUEST_H
+#ifndef REQUESTMESSAGE_H
+#define REQUESTMESSAGE_H
namespace icinga
{
*
* @ingroup jsonrpc
*/
-class I2_JSONRPC_API RpcRequest : public MessagePart
+class I2_JSONRPC_API RequestMessage : public MessagePart
{
public:
/**
- * Constructor for the RpcRequest class.
+ * Constructor for the RequestMessage class.
*/
- RpcRequest(void) : MessagePart() {
+ RequestMessage(void) : MessagePart() {
SetVersion("2.0");
}
/**
- * Copy-constructor for the RpcRequest class.
+ * Copy-constructor for the RequestMessage class.
*
* @param message The message that is to be copied.
*/
- RpcRequest(const MessagePart& message) : MessagePart(message) { }
+ RequestMessage(const MessagePart& message) : MessagePart(message) { }
/**
* Retrieves the version of the JSON-RPC protocol.
}
-#endif /* RPCREQUEST_H */
+#endif /* REQUESTMESSAGE_H */
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA. *
******************************************************************************/
-#ifndef RPCRESPONSE_H
-#define RPCRESPONSE_H
+#ifndef RESPONSEMESSAGE_H
+#define RESPONSEMESSAGE_H
namespace icinga
{
*
* @ingroup jsonrpc
*/
-class I2_JSONRPC_API RpcResponse : public MessagePart
+class I2_JSONRPC_API ResponseMessage : public MessagePart
{
public:
/**
- * Constructor for the RpcResponse class.
+ * Constructor for the ResponseMessage class.
*/
- RpcResponse(void) : MessagePart() {
+ ResponseMessage(void) : MessagePart() {
SetVersion("2.0");
}
/**
- * Copy-constructor for the RpcResponse class.
+ * Copy-constructor for the ResponseMessage class.
*
* @param message The message that should be copied.
*/
- RpcResponse(const MessagePart& message) : MessagePart(message) { }
+ ResponseMessage(const MessagePart& message) : MessagePart(message) { }
/**
* Retrieves the version of the JSON-RPC protocol.
}
-#endif /* RPCRESPONSE_H */
+#endif /* RESPONSEMESSAGE_H */