Updated d2d-conv-manaver.service for supporting on-demand-launch. 72/142572/1
authorSegwon <segwon.han@samsung.com>
Fri, 4 Aug 2017 09:37:13 +0000 (18:37 +0900)
committerSegwon <segwon.han@samsung.com>
Fri, 4 Aug 2017 09:37:39 +0000 (18:37 +0900)
Signed-off-by: Segwon <segwon.han@samsung.com>
Change-Id: I296467e23629452bda45cf8f54153533b18862d6

daemon/DbusServer.cpp
daemon/Server.cpp
daemon/Server.h
packaging/d2d-conv-manager.conf [deleted file]
packaging/d2d-conv-manager.service
packaging/d2d-conv-manager.spec
packaging/org.tizen.d2dconv.conf [new file with mode: 0644]
packaging/org.tizen.d2dconv.service [new file with mode: 0644]

index 288c79602821231573ebb5a773a24c5bbf8b74ca..55733ab27db2eb1cfad6c0ed525fa9a0c67e1492 100755 (executable)
@@ -18,6 +18,7 @@
 #include <glib.h>
 #include <gio/gio.h>
 #include <app_manager.h>
+#include <map>
 
 #include "Server.h"
 #include "access_control/PeerCreds.h"
@@ -25,6 +26,8 @@
 
 #define DEFAULT_APP_ID "Default"
 
+static std::map<char*, guint> dbus_disconnect_listeners;
+
 static bool connAcquired = false;
 static bool nameAcquired = false;
 static conv::DbusServer *__instance = NULL;
@@ -120,6 +123,48 @@ static void __handle_request(GDBusConnection* conn, const char *sender, GVariant
        g_variant_unref(binaryArray);
 }
 
+static void __dbusDisconnectListener(GDBusConnection* conn, const gchar* sender, const gchar* path, const gchar* iface, const gchar* name, GVariant* param, gpointer userData)
+{
+       gchar *dbus_client = reinterpret_cast<gchar *>(userData);
+       _I("Dbus client disconnected(%s)", dbus_client);
+
+       for (std::map<char*, guint>::iterator it = dbus_disconnect_listeners.begin(); it != dbus_disconnect_listeners.end(); it++) {
+               if (!strcmp(dbus_client, it->first)) {
+                       _I("Erase the dbus_disconnect_listener. dbus_client(%s), listener_id(%d)", it->first, it->second);
+                       g_dbus_connection_signal_unsubscribe(conn, it->second);
+                       dbus_disconnect_listeners.erase(it);
+                       break;
+               }
+       }
+
+       free(dbus_client);
+
+       if (dbus_disconnect_listeners.empty() == true) {
+               conv::server_kill_timer_start();
+       }
+}
+
+static void __registDbusDisconnectListener(GDBusConnection *conn, const gchar *dbus_client)
+{
+       conv::server_kill_timer_stop();
+
+       int idx = 0;
+       for(std::map<char*, guint>::iterator it = dbus_disconnect_listeners.begin(); it != dbus_disconnect_listeners.end(); it++) {
+               _I("[map %d] sender:%s, listener_id:%d", ++idx, it->first, it->second);
+               if (!strcmp(dbus_client, it->first)) {
+                       _I("This dbus client (%s) is already registed", dbus_client);
+                       return;
+               }
+       }
+
+       char *__dbus_client = strdup(dbus_client);
+       guint listener_id = g_dbus_connection_signal_subscribe(conn, "org.freedesktop.DBus", "org.freedesktop.DBus", "NameOwnerChanged", "/org/freedesktop/DBus",
+               dbus_client, G_DBUS_SIGNAL_FLAGS_NONE, __dbusDisconnectListener, __dbus_client, NULL);
+
+       dbus_disconnect_listeners[__dbus_client] = listener_id;
+       _I("Regist dbus_disconnect_listener. dbus client(%s), listener id(%d)", __dbus_client, listener_id);
+}
+
 static void __handle_method_call(GDBusConnection *conn, const gchar *sender,
                const gchar *obj_path, const gchar *iface, const gchar *method_name,
                GVariant *param, GDBusMethodInvocation *invocation, gpointer user_data)
@@ -127,6 +172,8 @@ static void __handle_method_call(GDBusConnection *conn, const gchar *sender,
        IF_FAIL_VOID_TAG(STR_EQ(obj_path, DBUS_PATH), _W, "Invalid path: %s", obj_path);
        IF_FAIL_VOID_TAG(STR_EQ(iface, DBUS_IFACE), _W, "Invalid interface: %s", obj_path);
 
+       __registDbusDisconnectListener(conn, sender);
+
        if (STR_EQ(method_name, METHOD_REQUEST))
                __handle_request(conn, sender, param, invocation);
        else if (STR_EQ(method_name, METHOD_CHK_PRIV_NETWORK_GET))
@@ -207,6 +254,8 @@ bool conv::DbusServer::init()
 
 void conv::DbusServer::release()
 {
+       dbus_disconnect_listeners.clear();
+
        if (dbusConnection){
                g_dbus_connection_flush_sync(dbusConnection, NULL, NULL);
                dbusConnection = NULL;
index ee079d2e7c75b424222657d6c2fabdde013d24f6..a9aeea88c3626b0d5e77da1cb31a84ac95bde36d 100644 (file)
@@ -27,6 +27,9 @@
 #include "ClientManager.h"
 #include "ServiceManager.h"
 #include "RequestHandler.h"
+#include "Util.h"
+
+#define PROCESS_KILL_TIMER 10
 
 using namespace std;
 
@@ -38,6 +41,33 @@ static conv::ClientManager *clientMgr = NULL;
 static conv::ServiceManager *serviceMgr = NULL;
 static conv::RequestHandler *requestMgr = NULL;
 
+static int timer_id = -1;
+
+
+void conv::server_kill_timer_stop()
+{
+       _I("process_kill_timer_stop");
+       if (timer_id == -1) return;
+       conv::util::miscStopTimer(timer_id);
+       timer_id = -1;
+}
+
+static void process_kill(void *data)
+{
+       _I("process_kill");
+       conv::server_kill_timer_stop();
+
+       if (g_main_loop_is_running(mainLoop)) {
+               g_main_loop_quit(mainLoop);
+       }
+}
+
+void conv::server_kill_timer_start()
+{
+       _I("process_kill_timer_star");
+       timer_id = conv::util::miscStartTimer(process_kill, PROCESS_KILL_TIMER, NULL);
+}
+
 void conv::initialize()
 {
        int result;
@@ -83,6 +113,8 @@ void conv::initialize()
        result = dbusHandle->init();
        IF_FAIL_CATCH_TAG(result == true, _E, "Initialization Failed");
 
+       conv::server_kill_timer_start();
+
        _I("Start main loop");
        mainLoop = g_main_loop_new(NULL, FALSE);
        g_main_loop_run(mainLoop);
index 06a9eb1cbeeee97da80c789a75a0458b8b05937c..bac059a71c98fcf91e8de86abd3b1fb07dcd08e0 100644 (file)
@@ -25,5 +25,7 @@ namespace conv {
        void initialize();
        void release();
        void sendRequest(Request* requestObj);
+       void server_kill_timer_start();
+       void server_kill_timer_stop();
 }
 #endif
diff --git a/packaging/d2d-conv-manager.conf b/packaging/d2d-conv-manager.conf
deleted file mode 100644 (file)
index 6f41cc0..0000000
+++ /dev/null
@@ -1,17 +0,0 @@
-<!DOCTYPE busconfig PUBLIC "-//freedesktop//DTD D-BUS Bus Configuration 1.0//EN" "http://www.freedesktop.org/standards/dbus/1.0/busconfig.dtd">
-<busconfig>
-       <policy user="root">
-               <allow own="org.tizen.d2dconv"/>
-               <allow send_destination="org.tizen.d2dconv" send_interface="org.tizen.d2dconv" send_member="Request"/>
-               <allow send_destination="org.tizen.d2dconv" send_interface="org.tizen.d2dconv" send_member="Respond"/>
-       </policy>
-       <policy user="owner">
-               <allow own="org.tizen.d2dconv"/>
-               <allow send_destination="org.tizen.d2dconv" send_interface="org.tizen.d2dconv" send_member="Request"/>
-               <allow send_destination="org.tizen.d2dconv" send_interface="org.tizen.d2dconv" send_member="Respond"/>
-       </policy>
-       <policy context="default">
-               <check send_destination="org.tizen.d2dconv" send_interface="org.tizen.d2dconv"
-                       send_member="ChkPrivNetworkGet" privilege="http://tizen.org/privilege/network.get"/>
-       </policy>
-</busconfig>
index 0e1799beff9fad8f8bebad958537ace662e83ebe..0f081163836030a8c6cd3c752d7d64b3e2fbe3c3 100755 (executable)
@@ -1,11 +1,10 @@
 [Unit]
 Description=D2D Convergence Manager Daemon
-After=dbus.service
 
 [Service]
+Type=dbus
+BusName=org.tizen.d2dconv
 ExecStart=/usr/bin/d2d-conv-managerd
-Restart=always
-RestartSec=1
 
 [Install]
 WantedBy=default.target
index 8a84e2b63be305d1ab909bc9416c9c696e1b0364..b56d4fe8f48f1db49f9efb756fad97fec53dcbc0 100755 (executable)
@@ -6,7 +6,8 @@ Group:      Service Framework / Convergence
 License:    Apache-2.0
 Source0:    %{name}-%{version}.tar.gz
 Source1:    %{name}.service
-Source2:    %{name}.conf
+Source2:    org.tizen.d2dconv.conf
+Source3:       org.tizen.d2dconv.service
 Source1001:    %{name}.manifest
 Source1002:    lib%{name}.manifest
 
@@ -94,6 +95,9 @@ install -m 0644 %{SOURCE1} %{buildroot}%{_unitdir_user}
 mkdir -p %{buildroot}%{_sysconfdir}/dbus-1/session.d
 install -m 0644 %{SOURCE2} %{buildroot}%{_sysconfdir}/dbus-1/session.d/
 
+mkdir -p %{buildroot}/usr/share/dbus-1/services
+install -m 0644 %{SOURCE3} %{buildroot}/usr/share/dbus-1/services/
+
 #mkdir -p %{buildroot}%{_userdatadir}
 #cp daemon/d2d-conv-manager-iotcon-server.dat %{buildroot}%{_userdatadir}
 
@@ -142,7 +146,7 @@ rm -f %{_unitdir_user}/default.target.wants/%{name}.service
 
 %files
 %manifest %{name}.manifest
-%config %{_sysconfdir}/dbus-1/session.d/d2d-conv-manager.conf
+%config %{_sysconfdir}/dbus-1/session.d/org.tizen.d2dconv.conf
 %{_unitdir_user}/%{name}.service
 %{_bindir}/%{name}d
 #%{_bindir}/msf-api-test*
@@ -150,6 +154,7 @@ rm -f %{_unitdir_user}/default.target.wants/%{name}.service
 %attr(755,root,root) %{_sysconfdir}/gumd/useradd.d/99_d2d-conv-manager.post
 /usr/share/d2d-conv-manager/*.dat
 /usr/share/d2d-conv-manager/ca_crt.pem
+/usr/share/dbus-1/services/*
 
 %files lib
 %manifest lib%{name}.manifest
diff --git a/packaging/org.tizen.d2dconv.conf b/packaging/org.tizen.d2dconv.conf
new file mode 100644 (file)
index 0000000..c8641cb
--- /dev/null
@@ -0,0 +1,17 @@
+<!DOCTYPE busconfig PUBLIC "-//freedesktop//DTD D-BUS Bus Configuration 1.0//EN" "http://www.freedesktop.org/standards/dbus/1.0/busconfig.dtd">
+<busconfig>
+       <policy user="root">
+               <allow own="org.tizen.d2dconv"/>
+               <allow send_destination="org.tizen.d2dconv" send_interface="org.tizen.d2dconv" send_member="Request"/>
+               <allow send_destination="org.tizen.d2dconv" send_interface="org.tizen.d2dconv" send_member="Respond"/>
+       </policy>
+       <policy user="owner">
+               <allow own="org.tizen.d2dconv"/>
+               <allow send_destination="org.tizen.d2dconv" send_interface="org.tizen.d2dconv" send_member="Request"/>
+               <allow send_destination="org.tizen.d2dconv" send_interface="org.tizen.d2dconv" send_member="Respond"/>
+       </policy>
+       <policy context="default">
+               <check send_destination="org.tizen.d2dconv" send_interface="org.tizen.d2dconv"
+                       send_member="ChkPrivNetworkGet" privilege="http://tizen.org/privilege/network.get"/>
+       </policy>
+</busconfig>
\ No newline at end of file
diff --git a/packaging/org.tizen.d2dconv.service b/packaging/org.tizen.d2dconv.service
new file mode 100644 (file)
index 0000000..d5018c4
--- /dev/null
@@ -0,0 +1,4 @@
+[D-BUS Service]
+Name=org.tizen.d2dconv
+Exec=/usr/bin/false
+SystemdService=d2d-conv-manager.service
\ No newline at end of file