Add initial source codes for gtest
[platform/core/connectivity/stc-manager.git] / src / stc-manager-gdbus.c
index bf556e6..df53f9b 100755 (executable)
@@ -15,6 +15,7 @@
  */
 
 #include "stc-manager-gdbus.h"
+#include "stc-manager.h"
 #include "stc-statistics.h"
 #include "stc-restriction.h"
 #include "stc-default-connection.h"
@@ -129,6 +130,37 @@ static gboolean __stc_manager_gdbus_restriction_init(stc_s *stc)
        return ret;
 }
 
+static gboolean __stc_manager_gdbus_manager_init(stc_s *stc)
+{
+       __STC_LOG_FUNC_ENTER__;
+       gboolean ret = TRUE;
+       gchar *s = NULL;
+
+       StcObjectSkeleton *object = NULL;
+       StcManager *manager = NULL;
+       s = g_strdup_printf(STC_DBUS_SERVICE_MANAGER_PATH);
+
+       object = stc_object_skeleton_new(s);
+       g_free(s);
+
+       manager = stc_manager_skeleton_new();
+       stc_object_skeleton_set_manager(object, manager);
+       g_object_unref(manager);
+
+       g_signal_connect(manager, "handle-stop",
+                        G_CALLBACK(handle_manager_stop), stc);
+
+       g_dbus_object_manager_server_export(stc->obj_mgr,
+                                           G_DBUS_OBJECT_SKELETON(object));
+       g_object_unref(object);
+
+       stc->manager_obj = (gpointer)manager;
+
+       __STC_LOG_FUNC_EXIT__;
+       return ret;
+}
+
+
 static void __stc_manager_gdbus_on_bus_acquired(GDBusConnection *connection,
                                                const gchar *name,
                                                gpointer user_data)
@@ -143,12 +175,17 @@ static void __stc_manager_gdbus_on_bus_acquired(GDBusConnection *connection,
        stc->connection = connection;
 
        if (__stc_manager_gdbus_statistics_init(stc) == FALSE) {
-               STC_LOGE("Can not signal connect to statistics");
+               STC_LOGE("Can not signal connect to statistics"); //LCOV_EXCL_LINE
                /* Deinitialize and quit manager */
        }
 
        if (__stc_manager_gdbus_restriction_init(stc) == FALSE) {
-               STC_LOGE("Cannot signal connect to restriction");
+               STC_LOGE("Cannot signal connect to restriction"); //LCOV_EXCL_LINE
+               /* Deinitialize and quit manager */
+       }
+
+       if (__stc_manager_gdbus_manager_init(stc) == FALSE) {
+               STC_LOGE("Cannot signal connect to manager"); //LCOV_EXCL_LINE
                /* Deinitialize and quit manager */
        }
 
@@ -169,12 +206,14 @@ static void __stc_manager_gdbus_on_name_acquired(GDBusConnection *connection,
        STC_LOGD("name : %s", name);
 }
 
+//LCOV_EXCL_START
 static void __stc_manager_gdbus_on_name_lost(GDBusConnection *connection,
                                             const gchar *name,
                                             gpointer user_data)
 {
        STC_LOGD("name : %s", name);
 }
+//LCOV_EXCL_STOP
 
 void stc_manager_gdbus_init(gpointer stc_data)
 {
@@ -205,6 +244,7 @@ void stc_manager_gdbus_deinit(gpointer stc_data)
 
        stc->statistics_obj = NULL;
        stc->restriction_obj = NULL;
+       stc->manager_obj = NULL;
        __STC_LOG_FUNC_EXIT__;
 }
 
@@ -217,8 +257,8 @@ GVariant *stc_manager_gdbus_call_sync(GDBusConnection *connection,
        GVariant *reply = NULL;
 
        if (connection == NULL) {
-               STC_LOGE("Failed to get GDBusconnection");
-               return reply;
+               STC_LOGE("Failed to get GDBusconnection"); //LCOV_EXCL_LINE
+               return reply; //LCOV_EXCL_LINE
        }
 
        reply = g_dbus_connection_call_sync(connection,
@@ -235,11 +275,11 @@ GVariant *stc_manager_gdbus_call_sync(GDBusConnection *connection,
 
        if (reply == NULL) {
                if (error != NULL) {
-                       STC_LOGE("g_dbus_connection_call_sync() failed"
+                       STC_LOGE("g_dbus_connection_call_sync() failed" //LCOV_EXCL_LINE
                                 "error [%d: %s]", error->code, error->message);
-                       g_error_free(error);
+                       g_error_free(error); //LCOV_EXCL_LINE
                } else {
-                       STC_LOGE("g_dbus_connection_call_sync() failed");
+                       STC_LOGE("g_dbus_connection_call_sync() failed"); //LCOV_EXCL_LINE
                }
 
                return NULL;
@@ -260,8 +300,8 @@ guint stc_manager_gdbus_subscribe_signal(GDBusConnection *connection,
                                         GDestroyNotify user_data_free_func)
 {
        if (connection == NULL) {
-               STC_LOGE("Failed to get GDBusconnection");
-               return 0;
+               STC_LOGE("Failed to get GDBusconnection"); //LCOV_EXCL_LINE
+               return 0; //LCOV_EXCL_LINE
        }
 
        return g_dbus_connection_signal_subscribe(connection,
@@ -280,8 +320,8 @@ void stc_manager_gdbus_unsubscribe_signal(GDBusConnection *connection,
                                          guint subscription_id)
 {
        if (connection == NULL) {
-               STC_LOGE("Failed to get GDBusconnection");
-               return;
+               STC_LOGE("Failed to get GDBusconnection"); //LCOV_EXCL_LINE
+               return; //LCOV_EXCL_LINE
        }
 
        g_dbus_connection_signal_unsubscribe(connection, subscription_id);
@@ -296,8 +336,8 @@ void stc_manager_gdbus_dict_foreach(GVariantIter *iter, dbus_dict_cb cb,
        GVariant *value = NULL;
 
        if (!cb) {
-               __STC_LOG_FUNC_EXIT__;
-               return;
+               __STC_LOG_FUNC_EXIT__; //LCOV_EXCL_LINE
+               return; //LCOV_EXCL_LINE
        }
 
        while (g_variant_iter_loop(iter, "{sv}", &key, &value)) {
@@ -319,7 +359,7 @@ gboolean stc_manager_dbus_emit_signal(GDBusConnection *connection,
        GError *error = NULL;
 
        if (connection == NULL) {
-               STC_LOGE("GDBusconnection is NULL");
+               STC_LOGE("GDBusconnection is NULL"); //LCOV_EXCL_LINE
                return 0;
        }
 
@@ -333,9 +373,9 @@ gboolean stc_manager_dbus_emit_signal(GDBusConnection *connection,
                                           parameters,
                                           &error);
        if (rv != TRUE) {
-               STC_LOGE("Failed to emit signal [%s] interface [%s] Error [%s]",
+               STC_LOGE("Failed to emit signal [%s] interface [%s] Error [%s]", //LCOV_EXCL_LINE
                         signal_name, interface_name, error->message);
-               g_error_free(error);
+               g_error_free(error); //LCOV_EXCL_LINE
        } else {
                STC_LOGD("[%s] signal sent on [%s] interface", signal_name,
                         interface_name);
@@ -343,3 +383,22 @@ gboolean stc_manager_dbus_emit_signal(GDBusConnection *connection,
 
        return rv;
 }
+
+gboolean handle_manager_stop(StcManager *object,
+                              GDBusMethodInvocation *invocation)
+{
+       __STC_LOG_FUNC_ENTER__;
+       GVariant *return_parameters = NULL;
+
+       STC_LOGI("stc manager stop");
+
+       return_parameters = g_variant_new("(i)", STC_ERROR_NONE);
+
+       DEBUG_GDBUS_VARIANT("Return parameters: ", return_parameters);
+       STC_DBUS_REPLY(invocation, return_parameters);
+
+       stc_stop_manager();
+
+       __STC_LOG_FUNC_EXIT__;
+       return TRUE;
+}