modify account daemon as on-demand/deactivate deamon. 42/60442/1 accepted/tizen/mobile/20160226.101029 accepted/tizen/tv/20160226.101106 accepted/tizen/wearable/20160226.101143 submit/tizen_mobile/20160226.090304 submit/tizen_tv/20160226.090334 submit/tizen_wearable/20160226.090322
authorjiseob.jang <jiseob.jang@samsung.com>
Fri, 26 Feb 2016 07:57:33 +0000 (16:57 +0900)
committerjiseob.jang <jiseob.jang@samsung.com>
Fri, 26 Feb 2016 07:57:33 +0000 (16:57 +0900)
Change-Id: I5291ae7e18eb51c2572d5aa2206fb4812bf3b570
Signed-off-by: jiseob.jang <jiseob.jang@samsung.com>
packaging/account-manager.spec
packaging/accounts-service.service
packaging/org.tizen.account.manager.service
server/CMakeLists.txt
server/include/lifecycle.h [new file with mode: 0644]
server/src/account-server.c
server/src/lifecycle.c [new file with mode: 0644]

index ee43ba6..03bc917 100644 (file)
@@ -1,7 +1,7 @@
 
 Name:       account-manager
 Summary:    Account Manager
-Version:    0.1.3
+Version:    0.1.4
 Release:    1
 Group:      Social & Content/Other
 License:    Apache-2.0
index 2545cf6..41eabef 100644 (file)
@@ -6,8 +6,8 @@ Requires=tizen-runtime.target
 [Service]
 #User=system
 #Gruop=system
-#SmackProcessLabel=libaccounts-svc
-#Type=simple
+Type=dbus
+BusName=org.tizen.account.manager
 ExecStart=/usr/bin/account-svcd
 #Restart=always
 #RestartSec=1
index 3ec2ce0..50e4af2 100644 (file)
@@ -4,3 +4,5 @@ Description=Account Service D-BUS
 [D-BUS Service]
 Name=org.tizen.account.manager
 Exec=/usr/bin/account-svcd
+User=root
+Group=root
index 5eb85d3..048051b 100644 (file)
@@ -22,6 +22,7 @@ ENDFOREACH(flag)
 SET(SERVER_SRCS
        src/account-server.c
        src/account-server-db.c
+       src/lifecycle.c
 )
 
 INCLUDE_DIRECTORIES(${CMAKE_SOURCE_DIR}/server/include)
diff --git a/server/include/lifecycle.h b/server/include/lifecycle.h
new file mode 100644 (file)
index 0000000..18dbae1
--- /dev/null
@@ -0,0 +1,24 @@
+/*
+ *
+ * Copyright (c) 2012 - 2013 Samsung Electronics Co., Ltd. All rights reserved.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+
+#ifndef __LIFECYCLE_H__
+
+void lifecycle_method_call_active();
+void lifecycle_method_call_inactive();
+
+#endif //__LIFECYCLE_H__
index c3561b0..1c38a52 100644 (file)
@@ -36,6 +36,7 @@
 #include <account_err.h>
 
 #include "account-server-db.h"
+#include "lifecycle.h"
 #define _PRIVILEGE_ACCOUNT_READ "http://tizen.org/privilege/account.read"
 #define _PRIVILEGE_ACCOUNT_WRITE "http://tizen.org/privilege/account.write"
 
@@ -44,6 +45,8 @@ static guint owner_id = 0;
 GDBusObjectManagerServer *account_mgr_server_mgr = NULL;
 static AccountManager* account_mgr_server_obj = NULL;
 
+static GMainLoop *mainloop = NULL;
+
 static cynara *p_cynara;
 
 //static gboolean has_owner = FALSE;
@@ -242,6 +245,8 @@ int _check_priviliege_account_write(GDBusMethodInvocation *invocation)
 gboolean account_manager_account_add(AccountManager *obj, GDBusMethodInvocation *invocation, GVariant* account_data, gint uid, gpointer user_data)
 {
        _INFO("account_manager_account_add start");
+       lifecycle_method_call_active();
+
        int db_id = -1;
        account_s* account = NULL;
 
@@ -308,7 +313,6 @@ RETURN:
        {
                account_manager_complete_account_add(obj, invocation, db_id);
        }
-       _INFO("account_manager_account_add end");
 
        return_code = _account_db_close();
        if (return_code != _ACCOUNT_ERROR_NONE)
@@ -326,12 +330,15 @@ RETURN:
 
        _account_free_account_with_items(account);
 
+       lifecycle_method_call_inactive();
+       _INFO("account_manager_account_add end");
        return true;
 }
 
 gboolean account_manager_account_query_all(AccountManager *obj, GDBusMethodInvocation *invocation, gint uid)
 {
        _INFO("account_manager_account_query_all start");
+       lifecycle_method_call_active();
 
        GVariant* account_list_variant = NULL;
 
@@ -391,7 +398,6 @@ RETURN:
        {
                account_manager_complete_account_query_all(obj, invocation, account_list_variant);
        }
-       _INFO("account_manager_account_query_all end");
 
        return_code = _account_db_close();
        if (return_code != _ACCOUNT_ERROR_NONE)
@@ -407,12 +413,15 @@ RETURN:
                return_code = _ACCOUNT_ERROR_NONE;
        }
 
+       lifecycle_method_call_inactive();
+       _INFO("account_manager_account_query_all end");
        return true;
 }
 
 gboolean account_manager_account_type_query_all(AccountManager *obj, GDBusMethodInvocation *invocation, gint uid)
 {
        _INFO("account_manager_account_query_all start");
+       lifecycle_method_call_active();
 
        GVariant* account_type_list_variant = NULL;
        guint pid = _get_client_pid(invocation);
@@ -471,7 +480,6 @@ RETURN:
        {
                account_manager_complete_account_type_query_all(obj, invocation, account_type_list_variant);
        }
-       _INFO("account_manager_account_query_all end");
 
        return_code = _account_db_close();
        if (return_code != _ACCOUNT_ERROR_NONE)
@@ -487,16 +495,19 @@ RETURN:
                return_code = _ACCOUNT_ERROR_NONE;
        }
 
+       lifecycle_method_call_inactive();
+       _INFO("account_manager_account_query_all end");
        return true;
 }
 
 gboolean account_manager_account_type_add(AccountManager *obj, GDBusMethodInvocation *invocation, GVariant *account_type_data, gint uid, gpointer user_data)
 {
+       _INFO("account_manager_account_type_add start");
+       lifecycle_method_call_active();
+
        int db_id = -1;
        account_type_s* account_type = NULL;
 
-       _INFO("account_manager_account_type_add start");
-
        guint pid = _get_client_pid(invocation);
        _INFO("client Id = [%u]", pid);
 
@@ -558,7 +569,6 @@ RETURN:
        {
                account_manager_complete_account_type_add(obj, invocation, db_id);
        }
-       _INFO("account_manager_account_type_add end");
 
        return_code = _account_db_close();
        if (return_code != _ACCOUNT_ERROR_NONE)
@@ -575,6 +585,9 @@ RETURN:
        }
 
        _account_type_free_account_type_with_items(account_type);
+
+       lifecycle_method_call_inactive();
+       _INFO("account_manager_account_type_add end");
        return true;
 }
 
@@ -584,6 +597,7 @@ gboolean account_manager_account_delete_from_db_by_id(AccountManager *object,
                                                                                         gint uid)
 {
        _INFO("account_manager_account_delete_from_db_by_id start");
+       lifecycle_method_call_active();
 
        guint pid = _get_client_pid(invocation);
        _INFO("client Id = [%u]", pid);
@@ -639,7 +653,6 @@ RETURN:
        {
                account_manager_complete_account_delete_from_db_by_id(object, invocation);
        }
-       _INFO("account_manager_account_delete_from_db_by_id end");
 
        return_code = _account_db_close();
        if (return_code != _ACCOUNT_ERROR_NONE)
@@ -655,6 +668,8 @@ RETURN:
                return_code = _ACCOUNT_ERROR_NONE;
        }
 
+       lifecycle_method_call_inactive();
+       _INFO("account_manager_account_delete_from_db_by_id end");
        return true;
 }
 
@@ -665,6 +680,7 @@ gboolean account_manager_account_delete_from_db_by_user_name(AccountManager *obj
                                                                                                                         gint uid)
 {
        _INFO("account_manager_account_delete_from_db_by_user_name start");
+       lifecycle_method_call_active();
 
        guint pid = _get_client_pid(invocation);
        _INFO("client Id = [%u]", pid);
@@ -720,7 +736,6 @@ RETURN:
        {
                account_manager_complete_account_delete_from_db_by_id(object, invocation);
        }
-       _INFO("account_manager_account_delete_from_db_by_user_name end");
 
        return_code = _account_db_close();
        if (return_code != _ACCOUNT_ERROR_NONE)
@@ -736,6 +751,8 @@ RETURN:
                return_code = _ACCOUNT_ERROR_NONE;
        }
 
+       lifecycle_method_call_inactive();
+       _INFO("account_manager_account_delete_from_db_by_user_name end");
        return true;
 }
 
@@ -746,6 +763,8 @@ gboolean account_manager_account_delete_from_db_by_package_name(AccountManager *
                                                                                                                         gint uid)
 {
        _INFO("account_manager_account_delete_from_db_by_package_name start");
+       lifecycle_method_call_active();
+
        int return_code = _ACCOUNT_ERROR_NONE;
 
        guint pid = _get_client_pid(invocation);
@@ -803,7 +822,6 @@ RETURN:
        {
                account_manager_complete_account_delete_from_db_by_package_name(object, invocation);
        }
-       _INFO("account_manager_account_delete_from_db_by_package_name end");
 
        return_code = _account_db_close();
        if (return_code != _ACCOUNT_ERROR_NONE)
@@ -819,6 +837,8 @@ RETURN:
                return_code = _ACCOUNT_ERROR_NONE;
        }
 
+       lifecycle_method_call_inactive();
+       _INFO("account_manager_account_delete_from_db_by_package_name end");
        return true;
 }
 
@@ -829,6 +849,8 @@ gboolean account_manager_account_update_to_db_by_id(AccountManager *object,
                                                                                                                        gint uid)
 {
        _INFO("account_manager_account_update_to_db_by_id start");
+       lifecycle_method_call_active();
+
        account_s* account = NULL;
 
        guint pid = _get_client_pid(invocation);
@@ -893,7 +915,6 @@ RETURN:
        {
                account_manager_complete_account_update_to_db_by_id(object, invocation);
        }
-       _INFO("account_manager_account_update_to_db_by_id end");
 
        return_code = _account_db_close();
        if (return_code != _ACCOUNT_ERROR_NONE)
@@ -911,6 +932,8 @@ RETURN:
 
        _account_free_account_with_items(account);
 
+       lifecycle_method_call_inactive();
+       _INFO("account_manager_account_update_to_db_by_id end");
        return true;
 }
 
@@ -922,6 +945,8 @@ gboolean account_manager_handle_account_update_to_db_by_user_name(AccountManager
                                                                                                                        gint uid)
 {
        _INFO("account_manager_handle_account_update_to_db_by_user_name start");
+       lifecycle_method_call_active();
+
        account_s* account = NULL;
 
        guint pid = _get_client_pid(invocation);
@@ -986,7 +1011,6 @@ RETURN:
        {
                account_manager_complete_account_update_to_db_by_id(object, invocation);
        }
-       _INFO("account_manager_handle_account_update_to_db_by_user_name end");
 
        return_code = _account_db_close();
        if (return_code != _ACCOUNT_ERROR_NONE)
@@ -1004,6 +1028,8 @@ RETURN:
 
        _account_free_account_with_items(account);
 
+       lifecycle_method_call_inactive();
+       _INFO("account_manager_handle_account_update_to_db_by_user_name end");
        return true;
 }
 
@@ -1015,6 +1041,8 @@ account_manager_handle_account_type_query_label_by_locale(AccountManager *object
                                                                                                                        gint uid)
 {
        _INFO("account_manager_handle_account_type_query_label_by_locale start");
+       lifecycle_method_call_active();
+
        guint pid = _get_client_pid(invocation);
 
        _INFO("client Id = [%u]", pid);
@@ -1064,7 +1092,6 @@ RETURN:
        {
                account_manager_complete_account_type_query_label_by_locale(object, invocation, label_name);
        }
-       _INFO("account_manager_handle_account_type_query_label_by_locale end");
 
        return_code = _account_db_close();
        if (return_code != _ACCOUNT_ERROR_NONE)
@@ -1080,6 +1107,8 @@ RETURN:
                return_code = _ACCOUNT_ERROR_NONE;
        }
 
+       lifecycle_method_call_inactive();
+       _INFO("account_manager_handle_account_type_query_label_by_locale end");
        return true;
 }
 
@@ -1090,6 +1119,8 @@ account_manager_handle_account_type_query_by_provider_feature(AccountManager *ob
                                                                                                                        gint uid)
 {
        _INFO("account_manager_handle_account_type_query_by_provider_feature start");
+       lifecycle_method_call_active();
+
        GVariant* account_type_list_variant = NULL;
 
        guint pid = _get_client_pid(invocation);
@@ -1159,7 +1190,6 @@ RETURN:
        {
                account_manager_complete_account_type_query_by_provider_feature(obj, invocation, account_type_list_variant);
        }
-       _INFO("account_manager_handle_account_type_query_by_provider_feature end");
 
        return_code = _account_db_close();
        if (return_code != _ACCOUNT_ERROR_NONE)
@@ -1175,12 +1205,16 @@ RETURN:
                return_code = _ACCOUNT_ERROR_NONE;
        }
 
+       lifecycle_method_call_inactive();
+       _INFO("account_manager_handle_account_type_query_by_provider_feature end");
        return true;
 }
 
 gboolean account_manager_account_get_total_count_from_db(AccountManager *object, GDBusMethodInvocation *invocation, gboolean include_hidden, gint uid)
 {
        _INFO("account_manager_account_get_total_count_from_db start");
+       lifecycle_method_call_active();
+
        guint pid = _get_client_pid(invocation);
 
        _INFO("client Id = [%u]", pid);
@@ -1231,7 +1265,6 @@ RETURN:
        {
                account_manager_complete_account_get_total_count_from_db(object, invocation, count);
        }
-       _INFO("account_manager_account_get_total_count_from_db end");
 
        return_code = _account_db_close();
        if (return_code != _ACCOUNT_ERROR_NONE)
@@ -1247,6 +1280,8 @@ RETURN:
                return_code = _ACCOUNT_ERROR_NONE;
        }
 
+       lifecycle_method_call_inactive();
+       _INFO("account_manager_account_get_total_count_from_db end");
        return true;
 }
 
@@ -1254,6 +1289,8 @@ gboolean account_manager_handle_account_query_account_by_account_id(AccountManag
                gint account_db_id, gint uid)
 {
        _INFO("account_manager_handle_account_query_account_by_account_id start");
+       lifecycle_method_call_active();
+
        GVariant* account_variant = NULL;
        account_s* account_data = NULL;
 
@@ -1317,7 +1354,6 @@ RETURN:
        {
                account_manager_complete_account_query_account_by_account_id(object, invocation, account_variant);
        }
-       _INFO("account_manager_handle_account_query_account_by_account_id end");
 
        return_code = _account_db_close();
        if (return_code != _ACCOUNT_ERROR_NONE)
@@ -1335,6 +1371,8 @@ RETURN:
 
        _account_free_account_with_items(account_data);
 
+       lifecycle_method_call_inactive();
+       _INFO("account_manager_handle_account_query_account_by_account_id end");
        return true;
 }
 
@@ -1345,6 +1383,7 @@ account_manager_handle_account_query_account_by_user_name(AccountManager *obj,
                                                                                                                  gint uid)
 {
        _INFO("account_manager_handle_account_query_account_by_user_name start");
+       lifecycle_method_call_active();
 
        GVariant* account_list_variant = NULL;
        guint pid = _get_client_pid(invocation);
@@ -1409,7 +1448,6 @@ RETURN:
        {
                account_manager_complete_account_query_account_by_user_name(obj, invocation, account_list_variant);
        }
-       _INFO("account_manager_handle_account_query_account_by_user_name end");
 
        return_code = _account_db_close();
        if (return_code != _ACCOUNT_ERROR_NONE)
@@ -1425,6 +1463,8 @@ RETURN:
                return_code = _ACCOUNT_ERROR_NONE;
        }
 
+       lifecycle_method_call_inactive();
+       _INFO("account_manager_handle_account_query_account_by_user_name end");
        return true;
 }
 
@@ -1435,6 +1475,7 @@ account_manager_handle_account_query_account_by_package_name(AccountManager *obj
                                                                                                                  gint uid)
 {
        _INFO("account_manager_handle_account_query_account_by_package_name start");
+       lifecycle_method_call_active();
 
        GVariant* account_list_variant = NULL;
        guint pid = _get_client_pid(invocation);
@@ -1515,6 +1556,8 @@ RETURN:
                return_code = _ACCOUNT_ERROR_NONE;
        }
 
+       lifecycle_method_call_inactive();
+       _INFO("account_manager_handle_account_query_account_by_package_name start");
        return true;
 }
 
@@ -1526,6 +1569,7 @@ account_manager_handle_account_query_account_by_capability(AccountManager *obj,
                                                                                                                  gint uid)
 {
        _INFO("account_manager_handle_account_query_account_by_capability start");
+       lifecycle_method_call_active();
 
        GVariant* account_list_variant = NULL;
 
@@ -1592,7 +1636,6 @@ RETURN:
        {
                account_manager_complete_account_query_account_by_capability(obj, invocation, account_list_variant);
        }
-       _INFO("account_manager_handle_account_query_account_by_capability end");
 
        return_code = _account_db_close();
        if (return_code != _ACCOUNT_ERROR_NONE)
@@ -1608,6 +1651,8 @@ RETURN:
                return_code = _ACCOUNT_ERROR_NONE;
        }
 
+       lifecycle_method_call_inactive();
+       _INFO("account_manager_handle_account_query_account_by_capability end");
        return true;
 }
 
@@ -1618,6 +1663,7 @@ account_manager_handle_account_query_account_by_capability_type(AccountManager *
                                                                                                                  gint uid)
 {
        _INFO("account_manager_handle_account_query_account_by_capability_type start");
+       lifecycle_method_call_active();
 
        GVariant* account_list_variant = NULL;
 
@@ -1684,7 +1730,6 @@ RETURN:
        {
                account_manager_complete_account_query_account_by_capability(obj, invocation, account_list_variant);
        }
-       _INFO("account_manager_handle_account_query_account_by_capability_type end");
 
        return_code = _account_db_close();
        if (return_code != _ACCOUNT_ERROR_NONE)
@@ -1700,6 +1745,8 @@ RETURN:
                return_code = _ACCOUNT_ERROR_NONE;
        }
 
+       lifecycle_method_call_inactive();
+       _INFO("account_manager_handle_account_query_account_by_capability_type end");
        return true;
 }
 
@@ -1710,6 +1757,7 @@ account_manager_handle_account_query_capability_by_account_id(AccountManager *ob
                                                                                                                  gint uid)
 {
        _INFO("account_manager_handle_account_query_capability_by_account_id start");
+       lifecycle_method_call_active();
 
        GVariant* capability_list_variant = NULL;
 
@@ -1776,7 +1824,6 @@ RETURN:
        {
                account_manager_complete_account_query_capability_by_account_id(obj, invocation, capability_list_variant);
        }
-       _INFO("account_manager_handle_account_query_capability_by_account_id end");
 
        return_code = _account_db_close();
        if (return_code != _ACCOUNT_ERROR_NONE)
@@ -1792,6 +1839,8 @@ RETURN:
                return_code = _ACCOUNT_ERROR_NONE;
        }
 
+       lifecycle_method_call_inactive();
+       _INFO("account_manager_handle_account_query_capability_by_account_id end");
        return true;
 }
 
@@ -1802,6 +1851,8 @@ gboolean account_manager_handle_account_update_sync_status_by_id(AccountManager
                                                                                                                        gint uid)
 {
        _INFO("account_manager_handle_account_update_sync_status_by_id start");
+       lifecycle_method_call_active();
+
        guint pid = _get_client_pid(invocation);
 
        _INFO("client Id = [%u]", pid);
@@ -1857,7 +1908,6 @@ RETURN:
        {
                account_manager_complete_account_update_sync_status_by_id(object, invocation);
        }
-       _INFO("account_manager_handle_account_update_sync_status_by_id end");
 
        return_code = _account_db_close();
        if (return_code != _ACCOUNT_ERROR_NONE)
@@ -1873,6 +1923,8 @@ RETURN:
                return_code = _ACCOUNT_ERROR_NONE;
        }
 
+       lifecycle_method_call_inactive();
+       _INFO("account_manager_handle_account_update_sync_status_by_id end");
        return true;
 }
 
@@ -1881,11 +1933,12 @@ gboolean account_manager_handle_account_type_query_provider_feature_by_app_id(Ac
                                                                                                                        const gchar* app_id,
                                                                                                                        gint uid)
 {
+       _INFO("account_manager_handle_account_type_query_provider_feature_by_app_id start");
+       lifecycle_method_call_active();
+
        GSList* feature_record_list = NULL;
        GVariant* feature_record_list_variant = NULL;
 
-       _INFO("account_manager_handle_account_type_query_provider_feature_by_app_id start");
-
        guint pid = _get_client_pid(invocation);
 
        _INFO("client Id = [%u]", pid);
@@ -1944,7 +1997,6 @@ RETURN:
                _INFO("Calling account_manager_complete_account_type_query_provider_feature_by_app_id");
                account_manager_complete_account_type_query_provider_feature_by_app_id(obj, invocation, feature_record_list_variant);
        }
-       _INFO("account_manager_handle_account_type_query_provider_feature_by_app_id end");
 
        return_code = _account_db_close();
        if (return_code != _ACCOUNT_ERROR_NONE)
@@ -1960,6 +2012,8 @@ RETURN:
                return_code = _ACCOUNT_ERROR_NONE;
        }
 
+       lifecycle_method_call_inactive();
+       _INFO("account_manager_handle_account_type_query_provider_feature_by_app_id end");
        return true;
 }
 
@@ -1969,9 +2023,10 @@ gboolean account_manager_handle_account_type_query_supported_feature(AccountMana
                                                                                                                        const gchar* capability,
                                                                                                                        gint uid)
 {
-       int is_supported = 0;
-
        _INFO("account_manager_handle_account_type_query_supported_feature start");
+       lifecycle_method_call_active();
+
+       int is_supported = 0;
        guint pid = _get_client_pid(invocation);
 
        _INFO("client Id = [%u]", pid);
@@ -2020,7 +2075,6 @@ RETURN:
                _INFO("Calling account_manager_complete_account_type_query_provider_feature_by_app_id");
                account_manager_complete_account_type_query_supported_feature(obj, invocation, is_supported);
        }
-       _INFO("account_manager_handle_account_type_query_supported_feature end");
 
        return_code = _account_db_close();
        if (return_code != _ACCOUNT_ERROR_NONE)
@@ -2036,6 +2090,8 @@ RETURN:
                return_code = _ACCOUNT_ERROR_NONE;
        }
 
+       lifecycle_method_call_inactive();
+       _INFO("account_manager_handle_account_type_query_supported_feature end");
        return true;
 }
 
@@ -2046,6 +2102,8 @@ gboolean account_manager_handle_account_type_update_to_db_by_app_id (AccountMana
                                                                                                                        gint uid)
 {
        _INFO("account_manager_handle_account_type_update_to_db_by_app_id start");
+       lifecycle_method_call_active();
+
        account_type_s* account_type = NULL;
 
        guint pid = _get_client_pid(invocation);
@@ -2104,7 +2162,6 @@ RETURN:
                _INFO("Calling account_manager_complete_account_type_update_to_db_by_app_id");
                account_manager_complete_account_type_update_to_db_by_app_id(obj, invocation);
        }
-       _INFO("account_manager_handle_account_type_update_to_db_by_app_id end");
 
        return_code = _account_db_close();
        if (return_code != _ACCOUNT_ERROR_NONE)
@@ -2122,6 +2179,8 @@ RETURN:
 
        _account_type_free_account_type_with_items(account_type);
 
+       lifecycle_method_call_inactive();
+       _INFO("account_manager_handle_account_type_update_to_db_by_app_id end");
        return true;
 }
 
@@ -2131,6 +2190,7 @@ gboolean account_manager_handle_account_type_delete_by_app_id (AccountManager *o
                                                                                                                        gint uid)
 {
        _INFO("account_manager_handle_account_type_delete_by_app_id start");
+       lifecycle_method_call_active();
 
        guint pid = _get_client_pid(invocation);
 
@@ -2186,7 +2246,6 @@ RETURN:
                _ERR("Calling account_manager_complete_account_type_update_to_db_by_app_id");
                account_manager_complete_account_type_delete_by_app_id (obj, invocation);
        }
-       _INFO("account_manager_handle_account_type_delete_by_app_id end");
 
        return_code = _account_db_close();
        if (return_code != _ACCOUNT_ERROR_NONE)
@@ -2202,6 +2261,8 @@ RETURN:
                return_code = _ACCOUNT_ERROR_NONE;
        }
 
+       lifecycle_method_call_inactive();
+       _INFO("account_manager_handle_account_type_delete_by_app_id end");
        return true;
 }
 
@@ -2211,6 +2272,8 @@ gboolean account_manager_handle_account_type_query_label_by_app_id (AccountManag
                                                                                                                        gint uid)
 {
        _INFO("account_manager_handle_account_type_query_label_by_app_id start");
+       lifecycle_method_call_active();
+
        GSList* label_list = NULL;
        GVariant* label_list_variant = NULL;
 
@@ -2264,7 +2327,6 @@ RETURN:
                _ERR("Calling account_manager_complete_account_type_query_label_by_app_id");
                account_manager_complete_account_type_query_label_by_app_id (obj, invocation, label_list_variant);
        }
-       _INFO("account_manager_handle_account_type_query_label_by_app_id end");
 
        return_code = _account_db_close();
        if (return_code != _ACCOUNT_ERROR_NONE)
@@ -2280,6 +2342,8 @@ RETURN:
                return_code = _ACCOUNT_ERROR_NONE;
        }
 
+       lifecycle_method_call_inactive();
+       _INFO("account_manager_handle_account_type_query_label_by_app_id end");
        return true;
 }
 
@@ -2289,6 +2353,8 @@ gboolean account_manager_handle_account_type_query_by_app_id (AccountManager *ob
                                                                                                                        gint uid)
 {
        _INFO("account_manager_handle_account_type_query_by_app_id start");
+       lifecycle_method_call_active();
+
        GVariant* account_type_variant = NULL;
 
        guint pid = _get_client_pid(invocation);
@@ -2349,7 +2415,6 @@ RETURN:
                _INFO("Calling account_manager_complete_account_type_query_by_app_id");
                account_manager_complete_account_type_query_by_app_id (obj, invocation, account_type_variant);
        }
-       _INFO("account_manager_handle_account_type_query_by_app_id end");
 
        return_code = _account_db_close();
        if (return_code != _ACCOUNT_ERROR_NONE)
@@ -2367,6 +2432,8 @@ RETURN:
 
        _account_type_free_account_type_with_items(account_type);
 
+       lifecycle_method_call_inactive();
+       _INFO("account_manager_handle_account_type_query_by_app_id end");
        return true;
 }
 
@@ -2376,6 +2443,8 @@ gboolean account_manager_handle_account_type_query_app_id_exist (AccountManager
                                                                                                                        gint uid)
 {
        _INFO("account_manager_handle_account_type_query_app_id_exist start");
+       lifecycle_method_call_active();
+
        guint pid = _get_client_pid(invocation);
 
        _INFO("client Id = [%u]", pid);
@@ -2425,7 +2494,6 @@ RETURN:
                _INFO("Calling account_manager_complete_account_type_query_by_app_id_exist");
                account_manager_complete_account_type_query_app_id_exist (obj, invocation);
        }
-       _INFO("account_manager_handle_account_type_query_app_id_exist end");
 
        return_code = _account_db_close();
        if (return_code != _ACCOUNT_ERROR_NONE)
@@ -2441,6 +2509,8 @@ RETURN:
                return_code = _ACCOUNT_ERROR_NONE;
        }
 
+       lifecycle_method_call_inactive();
+       _INFO("account_manager_handle_account_type_query_app_id_exist end");
        return true;
 }
 
@@ -2451,6 +2521,8 @@ gboolean account_manager_handle_account_update_to_db_by_id_ex (AccountManager *o
                                                                                                                        gint uid)
 {
        _INFO("account_manager_handle_account_update_to_db_by_id_ex start");
+       lifecycle_method_call_active();
+
        account_s* account = NULL;
        guint pid = _get_client_pid(invocation);
 
@@ -2515,7 +2587,6 @@ RETURN:
                _INFO("Calling account_manager_complete_account_update_to_db_by_id_ex");
                account_manager_complete_account_update_to_db_by_id_ex (obj, invocation);
        }
-       _INFO("in account_manager_handle_account_update_to_db_by_id_ex_p end");
 
        return_code = _account_db_close();
        if (return_code != _ACCOUNT_ERROR_NONE)
@@ -2533,6 +2604,8 @@ RETURN:
 
        _account_free_account_with_items(account);
 
+       lifecycle_method_call_inactive();
+       _INFO("in account_manager_handle_account_update_to_db_by_id_ex_p end");
        return true;
 }
 
@@ -2650,6 +2723,14 @@ on_bus_acquired (GDBusConnection *connection, const gchar *name, gpointer user_d
                _INFO("on_bus_acquired end [%s]", name);
 }
 
+void terminate_main_loop()
+{
+       if (mainloop)
+               g_main_loop_quit(mainloop);
+       else
+               _ERR("account manager's g_mainloop is NULL");
+}
+
 static void
 on_name_acquired (GDBusConnection *connection,
                                                const gchar     *name,
@@ -2693,6 +2774,12 @@ static bool _initialize_dbus()
        return true;
 }
 
+static void _terminate_server_by_timeout()
+{
+       lifecycle_method_call_active();
+       lifecycle_method_call_inactive();
+}
+
 static void _initialize()
 {
 #if !GLIB_CHECK_VERSION(2,35,0)
@@ -2712,12 +2799,12 @@ static void _initialize()
                _ERR("CYNARA Initialization fail");
                exit(1);
        }
+
+       _terminate_server_by_timeout();
 }
 
 int main()
 {
-       GMainLoop *mainloop = NULL;
-
        _INFO("Starting Accounts SVC");
 
        mainloop = g_main_loop_new(NULL, FALSE);
diff --git a/server/src/lifecycle.c b/server/src/lifecycle.c
new file mode 100644 (file)
index 0000000..f1786fe
--- /dev/null
@@ -0,0 +1,102 @@
+/*
+ *
+ * Copyright (c) 2012 - 2013 Samsung Electronics Co., Ltd. All rights reserved.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+
+#include <unistd.h>
+#include <stdbool.h>
+#include <glib.h>
+#include <pthread.h>
+#include <dlog.h>
+#include <dbg.h>
+
+#define TIMEOUT 20
+
+static int method_call_count = 0;
+static int timer_count = 0;
+static bool is_running_timer = false;
+static pthread_mutex_t lifecycle_mutex = PTHREAD_MUTEX_INITIALIZER;
+
+void terminate_main_loop();
+
+void *lifecycle_termination_timer()
+{
+       while (TIMEOUT >= timer_count) {
+               pthread_mutex_lock(&lifecycle_mutex);
+               timer_count++;
+               pthread_mutex_unlock(&lifecycle_mutex);
+               _INFO("while timer_count = [%d]", timer_count);
+               sleep(1);
+       }
+
+       if (method_call_count <= 0)
+               terminate_main_loop();
+       else
+               _ERR("account method_call_count > 0");
+
+       pthread_detach(pthread_self());
+
+       pthread_mutex_lock(&lifecycle_mutex);
+       is_running_timer = false;
+       pthread_mutex_unlock(&lifecycle_mutex);
+       pthread_exit(NULL);
+}
+
+
+void lifecycle_method_call_active()
+{
+       pthread_mutex_lock(&lifecycle_mutex);
+
+       method_call_count++;
+       _INFO("account lifecycle_method_call_active method_call_count = [%d]", method_call_count);
+
+       pthread_mutex_unlock(&lifecycle_mutex);
+}
+
+void lifecycle_method_call_inactive()
+{
+       pthread_t curThread;
+
+       pthread_mutex_lock(&lifecycle_mutex);
+
+       method_call_count--;
+       _INFO("account lifecycle_method_call_inactive method_call_count = [%d]", method_call_count);
+       pthread_mutex_unlock(&lifecycle_mutex);
+
+       if (method_call_count <= 0) {
+
+               if (!is_running_timer) {
+                       pthread_mutex_lock(&lifecycle_mutex);
+                       pthread_mutex_unlock(&lifecycle_mutex);
+                       int ret = pthread_create(&curThread, NULL, lifecycle_termination_timer, NULL);
+                       _INFO("account create timer thread");
+                       if(ret != 0)
+                               _ERR("account pthread_create fail!");
+                       else {
+                               pthread_mutex_lock(&lifecycle_mutex);
+                               is_running_timer = true;
+                               pthread_mutex_unlock(&lifecycle_mutex);
+                       }
+               } else {
+                       pthread_mutex_lock(&lifecycle_mutex);
+                       timer_count = 0;
+                       _INFO("account timer thread already is running. set timer_count = 0");
+                       pthread_mutex_unlock(&lifecycle_mutex);
+               }
+       }
+}
+
+