mirror of
https://github.com/Icinga/icinga2.git
synced 2025-07-23 21:55:03 +02:00
Merge branch 'master' of ssh://github.com/gunnarbeutner/i2test
This commit is contained in:
commit
94c7324b51
@ -17,6 +17,7 @@ libbase_la_SOURCES = \
|
|||||||
confighive.h \
|
confighive.h \
|
||||||
configobject.cpp \
|
configobject.cpp \
|
||||||
configobject.h \
|
configobject.h \
|
||||||
|
cxx11-compat.h \
|
||||||
delegate.h \
|
delegate.h \
|
||||||
event.h \
|
event.h \
|
||||||
exception.cpp \
|
exception.cpp \
|
||||||
|
@ -17,6 +17,9 @@ Application::Application(void)
|
|||||||
lt_dlinit();
|
lt_dlinit();
|
||||||
#endif /* _WIN32 */
|
#endif /* _WIN32 */
|
||||||
|
|
||||||
|
char *debugging = getenv("_DEBUG");
|
||||||
|
m_Debugging = (debugging && strtol(debugging, NULL, 10) != 0);
|
||||||
|
|
||||||
m_ShuttingDown = false;
|
m_ShuttingDown = false;
|
||||||
m_ConfigHive = make_shared<ConfigHive>();
|
m_ConfigHive = make_shared<ConfigHive>();
|
||||||
}
|
}
|
||||||
@ -30,6 +33,8 @@ Application::~Application(void)
|
|||||||
i->second->Stop();
|
i->second->Stop();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
m_Components.clear();
|
||||||
|
|
||||||
#ifdef _WIN32
|
#ifdef _WIN32
|
||||||
WSACleanup();
|
WSACleanup();
|
||||||
#else /* _WIN32 */
|
#else /* _WIN32 */
|
||||||
@ -349,3 +354,20 @@ void Application::AddComponentSearchDir(const string& componentDirectory)
|
|||||||
lt_dladdsearchdir(componentDirectory.c_str());
|
lt_dladdsearchdir(componentDirectory.c_str());
|
||||||
#endif /* _WIN32 */
|
#endif /* _WIN32 */
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool Application::IsDebugging(void) const
|
||||||
|
{
|
||||||
|
return m_Debugging;
|
||||||
|
}
|
||||||
|
|
||||||
|
void Application::SigIntHandler(int signum)
|
||||||
|
{
|
||||||
|
Application::Instance->Shutdown();
|
||||||
|
|
||||||
|
#ifndef _WIN32
|
||||||
|
struct sigaction sa;
|
||||||
|
memset(&sa, 0, sizeof(sa));
|
||||||
|
sa.sa_handler = SIG_DFL;
|
||||||
|
sigaction(SIGINT, &sa, NULL);
|
||||||
|
#endif /* _WIN32 */
|
||||||
|
}
|
||||||
|
@ -13,6 +13,7 @@ private:
|
|||||||
ConfigHive::Ptr m_ConfigHive;
|
ConfigHive::Ptr m_ConfigHive;
|
||||||
map< string, shared_ptr<Component> > m_Components;
|
map< string, shared_ptr<Component> > m_Components;
|
||||||
vector<string> m_Arguments;
|
vector<string> m_Arguments;
|
||||||
|
bool m_Debugging;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
typedef shared_ptr<Application> Ptr;
|
typedef shared_ptr<Application> Ptr;
|
||||||
@ -42,8 +43,16 @@ public:
|
|||||||
void AddComponentSearchDir(const string& componentDirectory);
|
void AddComponentSearchDir(const string& componentDirectory);
|
||||||
|
|
||||||
const string& GetExeDirectory(void);
|
const string& GetExeDirectory(void);
|
||||||
|
|
||||||
|
bool IsDebugging(void) const;
|
||||||
|
void SigIntHandler(int signum);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
inline void sigint_handler(int signum)
|
||||||
|
{
|
||||||
|
Application::Instance->SigIntHandler(signum);
|
||||||
|
}
|
||||||
|
|
||||||
template<class T>
|
template<class T>
|
||||||
int application_main(int argc, char **argv)
|
int application_main(int argc, char **argv)
|
||||||
{
|
{
|
||||||
@ -51,6 +60,13 @@ int application_main(int argc, char **argv)
|
|||||||
|
|
||||||
Application::Instance = make_shared<T>();
|
Application::Instance = make_shared<T>();
|
||||||
|
|
||||||
|
#ifndef _WIN32
|
||||||
|
struct sigaction sa;
|
||||||
|
memset(&sa, 0, sizeof(sa));
|
||||||
|
sa.sa_handler = sigint_handler;
|
||||||
|
sigaction(SIGINT, &sa, NULL);
|
||||||
|
#endif /* _WIN32 */
|
||||||
|
|
||||||
vector<string> args;
|
vector<string> args;
|
||||||
|
|
||||||
for (int i = 0; i < argc; i++)
|
for (int i = 0; i < argc; i++)
|
||||||
@ -58,11 +74,11 @@ int application_main(int argc, char **argv)
|
|||||||
|
|
||||||
Application::Instance->SetArguments(args);
|
Application::Instance->SetArguments(args);
|
||||||
|
|
||||||
#ifndef _DEBUG
|
if (Application::Instance->IsDebugging()) {
|
||||||
try {
|
result = Application::Instance->Main(args);
|
||||||
#endif /* !_DEBUG */
|
} else {
|
||||||
|
try {
|
||||||
result = Application::Instance->Main(args);
|
result = Application::Instance->Main(args);
|
||||||
#ifndef _DEBUG
|
|
||||||
} catch (const Exception& ex) {
|
} catch (const Exception& ex) {
|
||||||
cout << "---" << endl;
|
cout << "---" << endl;
|
||||||
|
|
||||||
@ -83,7 +99,7 @@ int application_main(int argc, char **argv)
|
|||||||
|
|
||||||
return EXIT_FAILURE;
|
return EXIT_FAILURE;
|
||||||
}
|
}
|
||||||
#endif /* !_DEBUG */
|
}
|
||||||
|
|
||||||
Application::Instance.reset();
|
Application::Instance.reset();
|
||||||
|
|
||||||
|
@ -11,6 +11,7 @@
|
|||||||
#include <netinet/in.h>
|
#include <netinet/in.h>
|
||||||
#include <arpa/inet.h>
|
#include <arpa/inet.h>
|
||||||
#include <pthread.h>
|
#include <pthread.h>
|
||||||
|
#include <signal.h>
|
||||||
|
|
||||||
void Sleep(unsigned long milliseconds);
|
void Sleep(unsigned long milliseconds);
|
||||||
|
|
||||||
|
@ -66,25 +66,18 @@ int ConnectionManager::NewMessageHandler(NewMessageEventArgs::Ptr nmea)
|
|||||||
|
|
||||||
void ConnectionManager::RegisterMethod(string method, function<int (NewMessageEventArgs::Ptr)> callback)
|
void ConnectionManager::RegisterMethod(string method, function<int (NewMessageEventArgs::Ptr)> callback)
|
||||||
{
|
{
|
||||||
map<string, event<NewMessageEventArgs::Ptr> >::iterator i;
|
m_Methods[method] += callback;
|
||||||
i = m_Methods.find(method);
|
|
||||||
|
|
||||||
if (i == m_Methods.end()) {
|
|
||||||
m_Methods[method] = event<NewMessageEventArgs::Ptr>();
|
|
||||||
i = m_Methods.find(method);
|
|
||||||
}
|
|
||||||
|
|
||||||
i->second += callback;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void ConnectionManager::UnregisterMethod(string method, function<int (NewMessageEventArgs::Ptr)> function)
|
void ConnectionManager::UnregisterMethod(string method, function<int (NewMessageEventArgs::Ptr)> callback)
|
||||||
{
|
{
|
||||||
// TODO: implement
|
// TODO: implement
|
||||||
|
//m_Methods[method] -= callback;
|
||||||
}
|
}
|
||||||
|
|
||||||
void ConnectionManager::SendMessage(JsonRpcMessage::Ptr message)
|
void ConnectionManager::SendMessage(JsonRpcMessage::Ptr message)
|
||||||
{
|
{
|
||||||
/* TODO: filter messages based on event subscriptions */
|
/* TODO: filter messages based on event subscriptions; also loopback message to our own handlers */
|
||||||
for (list<JsonRpcClient::Ptr>::iterator i = m_Clients.begin(); i != m_Clients.end(); i++)
|
for (list<JsonRpcClient::Ptr>::iterator i = m_Clients.begin(); i != m_Clients.end(); i++)
|
||||||
{
|
{
|
||||||
JsonRpcClient::Ptr client = *i;
|
JsonRpcClient::Ptr client = *i;
|
||||||
|
@ -24,8 +24,8 @@ public:
|
|||||||
void RegisterClient(JsonRpcClient::Ptr client);
|
void RegisterClient(JsonRpcClient::Ptr client);
|
||||||
void UnregisterClient(JsonRpcClient::Ptr client);
|
void UnregisterClient(JsonRpcClient::Ptr client);
|
||||||
|
|
||||||
void RegisterMethod(string method, function<int (NewMessageEventArgs::Ptr)> function);
|
void RegisterMethod(string method, function<int (NewMessageEventArgs::Ptr)> callback);
|
||||||
void UnregisterMethod(string method, function<int (NewMessageEventArgs::Ptr)> function);
|
void UnregisterMethod(string method, function<int (NewMessageEventArgs::Ptr)> callback);
|
||||||
|
|
||||||
void SendMessage(JsonRpcMessage::Ptr message);
|
void SendMessage(JsonRpcMessage::Ptr message);
|
||||||
};
|
};
|
||||||
|
Loading…
x
Reference in New Issue
Block a user