#include <glib-object.h>
#include <Types.h>
+#include <DatabaseManager.h>
#include "DBusServer.h"
#include "ContextManager.h"
#include "policy/PolicyManager.h"
#include "trigger/Trigger.h"
#include "Server.h"
+#define RUN(L) g_main_loop_run((L))
+#define QUIT(L) if (g_main_loop_is_running((L)) == TRUE) g_main_loop_quit((L))
+
static GMainLoop *mainloop = NULL;
static bool started = false;
/* TODO: re-organize activation & deactivation processes */
void ctx::Server::initialize()
{
- _I("Init MainLoop");
- mainloop = g_main_loop_new(NULL, FALSE);
-
_I("Init Dbus Connection");
__dbusHandle = new(std::nothrow) ctx::DBusServer();
IF_FAIL_VOID_TAG(__dbusHandle, _E, "Memory allocation failed");
// Start the main loop
_I(CYAN("Launching Context-Service"));
- g_main_loop_run(mainloop);
+ RUN(mainloop);
}
void ctx::Server::activate()
bool result = false;
+ _I("Init Database Manager");
+ IF_FAIL_CATCH(DatabaseManager::__init());
+
_I("Init Context Manager");
__contextMgr = new(std::nothrow) ctx::ContextManager();
IF_FAIL_CATCH_TAG(__contextMgr, _E, "Memory allocation failed");
_E(RED("Launching Failed"));
// Stop the main loop
- g_main_loop_quit(mainloop);
+ QUIT(mainloop);
}
void ctx::Server::release()
{
_I(CYAN("Terminating Context-Service"));
+ started = false;
_I("Release Policy Manager");
delete __policyMgr;
if (__contextMgr)
__contextMgr->release();
- _I("Release Dbus Connection");
- if (__dbusHandle)
- __dbusHandle->__release();
-
- g_main_loop_unref(mainloop);
+ _I("Release Database Manager");
+ DatabaseManager::__release();
delete __contextTrigger;
delete __contextMgr;
_I("SIGNAL %d received", signo);
// Stop the main loop
- g_main_loop_quit(mainloop);
+ QUIT(mainloop);
}
int main(int argc, char* argv[])
g_type_init();
#endif
+ _I("Init MainLoop");
+ mainloop = g_main_loop_new(NULL, FALSE);
+
ctx::Server::initialize();
ctx::Server::release();
+ g_main_loop_unref(mainloop);
+
return EXIT_SUCCESS;
}