Modification about smack label of db file belong to process.
[platform/framework/web/wrt-security.git] / src / main.cpp
index 8cd8c6e..dcab031 100644 (file)
  * @brief       This is main routing for Security Daemon
  */
 
+#include <systemd/sd-daemon.h>
 #include <dpl/log/log.h>
 #include <dpl/single_instance.h>
 
 #include "security_daemon.h"
+#include "privacy_manager_daemon.h"
 
 #include <pthread.h>
+#include <glib.h>
+#include <Ecore.h>
 
 static const std::string DAEMON_INSTANCE_UUID =
     "5ebf3f24-dad6-4a27-88b4-df7970efe7a9";
 
+static Ecore_Event_Handler *g_exitHandler;
+static Eina_Bool exitHandler(void */*data*/, int /*type*/, void */*event*/)
+{
+    privacy_manager_daemon_stop();
+    privacy_manager_daemon_shutdown();
+
+    auto& daemon = SecurityDaemonSingleton::Instance();
+    daemon.shutdown();                   
+
+    ecore_event_handler_del(g_exitHandler);
+
+    ecore_main_loop_quit();
+
+    return ECORE_CALLBACK_CANCEL;
+}      
+
+static Eina_Bool startHandler(void */*data*/)
+{
+    int retVal;
+       auto& daemon = SecurityDaemonSingleton::Instance();
+       
+       privacy_manager_daemon_initialize();
+
+       privacy_manager_daemon_start();
+       
+       int argc = 0;
+       char* argv = NULL;
+
+       daemon.initialize(argc, &argv);
+    retVal = daemon.execute();
+    if (retVal != 0)
+    {
+        LogError("Failed to execute daemon.");
+        ecore_main_loop_quit();
+        
+        return ECORE_CALLBACK_CANCEL;
+    }
+
+       // Notification to systemd
+       sd_notify(0, "READY=1");
+
+    return ECORE_CALLBACK_CANCEL;
+}
+
 int main(int argc, char* argv[])
 {
-    DPL::SingleInstance instance;
-    Try {
+       DPL::SingleInstance instance;
+       
+       Try {
                if (!instance.TryLock(DAEMON_INSTANCE_UUID)) {
                        LogError("Security Daemon is already running");
                        return -1;
                }
-
-               auto& daemon = SecurityDaemonSingleton::Instance();
-
-               daemon.initialize(argc, argv);
-
-               //Run daemon
-               auto retVal = daemon.execute();
-
-               daemon.shutdown();
-    
-        instance.Release();
     } Catch (DPL::SingleInstance::Exception::LockError) {
         LogError("Failed to lock/unlock Security Daemon instance.");
         return -1;
     }
-
-    return retVal;
+       
+    if (!ecore_init())
+    {
+        LogError("Ecore cannot be initialized");
+        return -1;
+    }
+       
+    ecore_timer_add(0.1, &startHandler, NULL);
+    g_exitHandler = ecore_event_handler_add(ECORE_EVENT_SIGNAL_EXIT, &exitHandler, NULL);
+    ecore_main_loop_begin();
+    ecore_shutdown();
+    
+    instance.Release();
+    
+    return 0;
 }