ua-daemon: Add support for product API's 92/253392/1 submit/tizen/20210210.041708
authorAbhay Agarwal <ay.agarwal@samsung.com>
Tue, 9 Feb 2021 06:18:59 +0000 (11:48 +0530)
committerAbhay Agarwal <ay.agarwal@samsung.com>
Tue, 9 Feb 2021 10:50:06 +0000 (16:20 +0530)
This patch adds support in ua-daemon to handle product API's.

Change-Id: Ic37f326f04bbcdd6c67734ae5ae7f48ab677afa7
Signed-off-by: Abhay Agarwal <ay.agarwal@samsung.com>
packaging/ua-manager.conf
ua-daemon/CMakeLists.txt
ua-daemon/include/ua-manager-common.h
ua-daemon/product/include/ua-manager-common-product.h [new file with mode: 0644]
ua-daemon/product/include/ua-manager-core-product.h [new file with mode: 0644]
ua-daemon/product/ua-manager-common-product.c [new file with mode: 0644]
ua-daemon/product/ua-manager-core-product.c [new file with mode: 0755]
ua-daemon/product/ua-manager-event-sender-product.c [new file with mode: 0644]
ua-daemon/product/ua-manager-request-handler-product.c [new file with mode: 0755]
ua-daemon/src/ua-manager-main.c
ua-daemon/src/ua-manager-request-handler.c

index d4eacda..fc03da1 100644 (file)
@@ -5,15 +5,22 @@
     <policy user="root">
         <allow own="net.uamd"/>
         <allow send_destination="net.uamd"/>
+        <allow own="net.uamd_product"/>
+        <allow send_destination="net.uamd_product"/>
     </policy>
     <policy user="network_fw">
         <allow own="net.uamd"/>
         <allow send_destination="net.uamd"/>
+        <allow own="net.uamd_product"/>
+        <allow send_destination="net.uamd_product"/>
     </policy>
     <policy context="default">
         <deny own="net.uamd"/>
         <deny send_destination="net.uamd"/>
+        <deny own="net.uamd_product"/>
+        <deny send_destination="net.uamd_product"/>
         <allow send_destination="net.uamd" send_interface="org.freedesktop.DBus.Properties" send_member="GetAll" />
+        <allow send_destination="net.uamd_product" send_interface="org.freedesktop.DBus.Properties" send_member="GetAll" />
     </policy>
 </busconfig>
 
index 8ae9d3d..5078005 100644 (file)
@@ -24,6 +24,10 @@ SET(SRCS
        src/pm/ua-cloud-plugin-handler.c
        src/pm/ua-vendor-plugin-manager.c
        src/pm/ua-vendor-plugin-handler.c
+       product/ua-manager-common-product.c
+       product/ua-manager-request-handler-product.c
+       product/ua-manager-event-sender-product.c
+       product/ua-manager-core-product.c
 )
 
 IF("${CMAKE_BUILD_TYPE}" STREQUAL "")
@@ -33,7 +37,9 @@ MESSAGE("Build type: ${CMAKE_BUILD_TYPE}")
 
 INCLUDE_DIRECTORIES(${CMAKE_SOURCE_DIR}/include)
 INCLUDE_DIRECTORIES(${CMAKE_SOURCE_DIR}/ua-plugins/include)
+INCLUDE_DIRECTORIES(${CMAKE_SOURCE_DIR}/include/product)
 INCLUDE_DIRECTORIES(${CMAKE_CURRENT_SOURCE_DIR}/include)
+INCLUDE_DIRECTORIES(${CMAKE_CURRENT_SOURCE_DIR}/product/include)
 
 SET(PKG_MODULES
        dlog
index 612ce34..7ed1738 100644 (file)
@@ -82,6 +82,12 @@ do { \
                *ptr = NULL; \
 } while (0)
 
+#define UAM_PRIVLEVEL_PUBLIC   0
+#define UAM_PRIVLEVEL_PLATFORM 1
+
+#define UAM_SYNC_FUNCTION      0
+#define UAM_ASYNC_FUNCTION     1
+
 typedef struct {
        int result;
        int function;
@@ -107,6 +113,9 @@ GSList **_uam_manager_get_sender_apps(void);
 
 void _uam_get_sender_from_app_num(const int app_num, char **dest);
 
+int __sender_to_app_num_operations(unsigned int *app_num,
+                                       const char *sender);
+
 void _uam_manager_remove_req_ctxt_from_list(
                uam_request_context_t *req_info);
 
diff --git a/ua-daemon/product/include/ua-manager-common-product.h b/ua-daemon/product/include/ua-manager-common-product.h
new file mode 100644 (file)
index 0000000..1fb2eb2
--- /dev/null
@@ -0,0 +1,69 @@
+/*
+ * Copyright (c) 2021 Samsung Electronics Co., Ltd. All rights reserved.
+ *
+ * Author: Abhay Agarwal <ay.agarwal@samsung.com>
+ *
+ * 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 __UAM_MANAGER_COMMON_PRODUCT_H__
+#define __UAM_MANAGER_COMMON_PRODUCT_H__
+
+#include <dlog.h>
+#include <glib.h>
+#include <gio/gio.h>
+#include <tzplatform_config.h>
+#include <ua-api-product.h>
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+#define UAM_PRODUCT_SYNC_FUNCTION      0
+#define UAM_PRODUCT_ASYNC_FUNCTION     1
+
+typedef struct {
+       int result;
+       int function;
+       char *sender;
+       unsigned int tid;
+       GDBusMethodInvocation *context;
+       gpointer data;
+} uam_product_request_context_t;
+
+int _uam_manager_product_register(void);
+
+void _uam_manager_product_unregister(void);
+
+void _uam_manager_product_method_return(
+               GDBusMethodInvocation *invocation,
+               GArray *out_param, int result);
+
+void _uam_manager_product_method_return(
+               GDBusMethodInvocation *invocation,
+               GArray *out_param, int result);
+
+int _uam_manager_product_send_event(
+               const char *dest, int event, GVariant *param);
+
+GDBusConnection *_uam_manager_product_get_gdbus_conn(void);
+
+const char *_uam_manager_product_request_to_str(unsigned int req);
+
+const char *_uam_manager_product_event_to_str(unsigned int event);
+
+#ifdef __cplusplus
+}
+#endif
+#endif /* __UAM_MANAGER_COMMON_PRODUCT_H__ */
diff --git a/ua-daemon/product/include/ua-manager-core-product.h b/ua-daemon/product/include/ua-manager-core-product.h
new file mode 100644 (file)
index 0000000..b1f37c4
--- /dev/null
@@ -0,0 +1,37 @@
+/*
+ * Copyright (c) 2021 Samsung Electronics Co., Ltd. All rights reserved.
+ *
+ * Author: Abhay Agarwal <ay.agarwal@samsung.com>
+ *
+ * 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 __UAM_MANAGER_CORE_PRODUCT_H__
+#define __UAM_MANAGER_CORE_PRODUCT_H__
+
+#include <dlog.h>
+#include <glib.h>
+#include <gio/gio.h>
+#include <ua-api-product.h>
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+int _uam_product_core_test();
+
+#ifdef __cplusplus
+}
+#endif
+#endif /* __UAM_MANAGER_CORE_PRODUCT_H__ */
diff --git a/ua-daemon/product/ua-manager-common-product.c b/ua-daemon/product/ua-manager-common-product.c
new file mode 100644 (file)
index 0000000..560be22
--- /dev/null
@@ -0,0 +1,104 @@
+/*
+ * Copyright (c) 2021 Samsung Electronics Co., Ltd. All rights reserved.
+ *
+ * Author: Abhay Agarwal <ay.agarwal@samsung.com>
+ *
+ * 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 <error.h>
+#include <sys/stat.h>
+#include <sys/time.h>
+
+#include "ua-manager-common.h"
+#include "ua-plugin.h"
+#include "ua-api-product.h"
+#include "ua-internal-product.h"
+#include "ua-manager-common-product.h"
+
+static const char *request_string[] = {
+       FOREACH_PRODUCT_REQUEST(GENERATE_PRODUCT_REQUEST_STRING)
+};
+
+static GDBusConnection *g_dbus_conn = NULL;
+
+static GDBusConnection *__uam_manager_product_get_shared_g_dbus_conn(void)
+{
+       FUNC_ENTRY;
+       GError *error = NULL;
+       GDBusConnection *shared_conn = NULL;
+
+       shared_conn = g_bus_get_sync(G_BUS_TYPE_SYSTEM, NULL, &error);
+       if (!shared_conn) {
+               UAM_ERR("Unable to connect to dbus");
+               if (error) {
+                       UAM_ERR("Error: %s", error->message);
+                       g_clear_error(&error);
+               }
+               return NULL;
+       }
+
+       FUNC_EXIT;
+       return shared_conn;
+}
+
+GDBusConnection *_uam_manager_product_get_gdbus_conn(void)
+{
+       FUNC_ENTRY;
+
+       if (g_dbus_conn) {
+               if (g_dbus_connection_is_closed(g_dbus_conn))
+                       g_dbus_conn = __uam_manager_product_get_shared_g_dbus_conn();
+
+               FUNC_EXIT;
+               return g_dbus_conn;
+       }
+
+       g_dbus_conn = __uam_manager_product_get_shared_g_dbus_conn();
+       FUNC_EXIT;
+       return g_dbus_conn;
+}
+
+const char *_uam_manager_product_request_to_str(unsigned int req)
+{
+       retv_if(UAM_PRODUCT_REQUEST_MAX <= req, NULL);
+
+       return request_string[req];
+}
+
+const char *_uam_manager_product_event_to_str(unsigned int event)
+{
+       retv_if(UAM_PRODUCT_EVENT_MAX <= event, NULL);
+
+       switch (event) {
+       CASE_TO_STR(UAM_PRODUCT_EVENT_TEST)
+       default:
+               return "UNKNOWN ERROR";
+       }
+}
+
+void _uam_manager_product_method_return(
+               GDBusMethodInvocation *invocation, GArray *out_param, int result)
+{
+       FUNC_ENTRY;
+       GVariant *out_var = NULL;
+       GVariant *return_var = NULL;
+       out_var = g_variant_new_from_data((const GVariantType *)"ay",
+                       out_param->data, out_param->len, TRUE, NULL, NULL);
+
+       return_var = g_variant_new("(iv)", result, out_var);
+
+       g_dbus_method_invocation_return_value(invocation, return_var);
+
+       FUNC_EXIT;
+}
diff --git a/ua-daemon/product/ua-manager-core-product.c b/ua-daemon/product/ua-manager-core-product.c
new file mode 100755 (executable)
index 0000000..d92fdff
--- /dev/null
@@ -0,0 +1,36 @@
+/*
+ * Copyright (c) 2021 Samsung Electronics Co., Ltd. All rights reserved.
+ *
+ * Author: Abhay Agarwal <ay.agarwal@samsung.com>
+ *
+ * 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 <time.h>
+
+#include "ua-api-product.h"
+#include "ua-internal-product.h"
+#include "ua-plugin-manager.h"
+#include "ua-manager-common-product.h"
+
+int _uam_product_core_test()
+{
+       FUNC_ENTRY;
+
+       _uam_manager_product_send_event(NULL, UAM_PRODUCT_EVENT_TEST,
+                               g_variant_new("(i)", UAM_ERROR_NONE));
+
+       FUNC_EXIT;
+       return UAM_ERROR_NONE;
+}
diff --git a/ua-daemon/product/ua-manager-event-sender-product.c b/ua-daemon/product/ua-manager-event-sender-product.c
new file mode 100644 (file)
index 0000000..871a2ce
--- /dev/null
@@ -0,0 +1,74 @@
+/*
+ * Copyright (c) 2021 Samsung Electronics Co., Ltd. All rights reserved.
+ *
+ * Author: Abhay Agarwal <ay.agarwal@samsung.com>
+ *
+ * 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 "ua-manager-common.h"
+#include "ua-api-product.h"
+#include "ua-internal-product.h"
+#include "ua-manager-common-product.h"
+
+#define UA_PRODUCT_EVENT "UA_PRODUCT_EVENT"
+
+#define CASE_TO_STR(x) case x: return #x;
+
+const char* __uam_product_event_str(int event)
+{
+       switch (event) {
+       CASE_TO_STR(UAM_PRODUCT_EVENT_TEST)
+       default :
+               return "Unknown Event";
+       }
+}
+
+int _uam_manager_product_send_event(const char *dest, int event, GVariant *param)
+{
+       FUNC_ENTRY;
+       char *signal;
+       GError *error = NULL;
+       GDBusConnection *conn;
+
+       conn = _uam_manager_product_get_gdbus_conn();
+       retv_if(conn == NULL, UAM_ERROR_INTERNAL);
+
+       switch (event) {
+       case UAM_PRODUCT_EVENT_TEST:
+               signal = UAM_PRODUCT_SIGNAL_TEST;
+               break;
+       default:
+               UAM_ERR("Unhandled event");
+               return UAM_ERROR_INTERNAL;
+       }
+
+       UAM_INFO_C("Destination: [%s], event: [%s], signal: [%s]",
+                       dest, _uam_manager_product_event_to_str(event), signal);
+
+       if (!g_dbus_connection_emit_signal(conn, dest, UAM_PRODUCT_EVENT_PATH,
+                       UAM_PRODUCT_EVENT_INTERFACE, signal, param, &error)) {
+               UAM_ERR("Error while sending Signal: %s", signal);
+               if (error) {
+                       UAM_ERR("Error Code [%d], Error Message [%s]",
+                                       error->code, error->message);
+                       g_clear_error(&error);
+               }
+
+               return UAM_ERROR_INTERNAL;
+       }
+
+       FUNC_EXIT;
+       return UAM_ERROR_NONE;
+}
diff --git a/ua-daemon/product/ua-manager-request-handler-product.c b/ua-daemon/product/ua-manager-request-handler-product.c
new file mode 100755 (executable)
index 0000000..b246323
--- /dev/null
@@ -0,0 +1,348 @@
+/*
+ * Copyright (c) 2021 Samsung Electronics Co., Ltd. All rights reserved.
+ *
+ * Author: Abhay Agarwal <ay.agarwal@samsung.com>
+ *
+ * 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 "ua-internal.h"
+#include "ua-manager-common.h"
+#include "ua-internal-product.h"
+#include "ua-manager-common-product.h"
+#include "ua-manager-core-product.h"
+
+static GDBusConnection *uam_manager_product_conn;
+static guint g_dbus_object_id = 0;
+static guint owner_id = 0;
+static guint owner_sig_id = 0;
+
+static const gchar uam_manager_product_introspection_xml[] =
+"<node name='/net/uamd_product'>"
+"      <interface name='net.uamd_product'>"
+"              <method name='uam_product_request'>"
+"                      <arg type='i' name='request_function' direction='in' />"
+"                      <arg type='ay' name='input_param1' direction='in' />"
+"                      <arg type='ay' name='input_param2' direction='in' />"
+"                      <arg type='ay' name='input_param3' direction='in' />"
+"                      <arg type='ay' name='input_param4' direction='in' />"
+"                      <arg type='i' name='output_param1' direction='out' />"
+"                      <arg type='v' name='output_param2' direction='out' />"
+"              </method>"
+"      </interface>"
+"</node>";
+
+typedef struct {
+       uam_product_request_e request;
+       int priv_level;
+       int function_type;
+} uam_product_request_table_s;
+
+
+static uam_product_request_table_s request_table[] = {
+       { UAM_PRODUCT_REQUEST_TEST, UAM_PRIVLEVEL_PLATFORM, UAM_PRODUCT_SYNC_FUNCTION },
+};
+
+static int __uam_manager_product_sync_request_handler(
+               GDBusMethodInvocation *context,
+               int function,
+               GVariant *in_param1,
+               GVariant *in_param2,
+               GVariant *in_param3,
+               GVariant *in_param4,
+               GArray **out_param1)
+{
+       FUNC_ENTRY;
+       int result = UAM_ERROR_NOT_SUPPORTED;
+       char *sender = NULL;
+       unsigned int app_num = 0;
+
+       sender = (char*)g_dbus_method_invocation_get_sender(context);
+
+       __sender_to_app_num_operations(&app_num, sender);
+       UAM_DBG("sender[%s], app_num[%u]", sender, app_num);
+
+       if (app_num <= 0)
+               UAM_ERR("app_num[%d] is invalid", app_num);
+
+       switch (function) {
+       case UAM_PRODUCT_REQUEST_TEST: {
+
+               result = _uam_product_core_test();
+               break;
+       }
+       default:
+               UAM_WARN("UnSupported function [%s(0x%4.4X)]",
+                               _uam_manager_product_request_to_str(function), function);
+               result = UAM_ERROR_NOT_SUPPORTED;
+               break;
+       }
+
+       FUNC_EXIT;
+       return result;
+}
+
+static int __uam_manager_product_async_request_handler(
+               GDBusMethodInvocation *context,
+               int function,
+               GVariant *in_param1,
+               GVariant *in_param2,
+               GVariant *in_param3,
+               GVariant *in_param4,
+               GArray **out_param1)
+{
+       FUNC_ENTRY;
+       int result = UAM_ERROR_NOT_SUPPORTED;
+       char *sender = NULL;
+       unsigned int app_num = 0;
+
+       sender = (char*)g_dbus_method_invocation_get_sender(context);
+
+       __sender_to_app_num_operations(&app_num, sender);
+       UAM_DBG("sender[%s], app_num[%u]", sender, app_num);
+
+       switch (function) {
+       default:
+               UAM_WARN("UnSupported function [%s(0x%4.4X)]",
+                               _uam_manager_product_request_to_str(function), function);
+               result = UAM_ERROR_NOT_SUPPORTED;
+               break;
+       }
+
+       FUNC_EXIT;
+       return result;
+}
+
+static int __uam_manager_product_get_function_type(int function)
+{
+       return request_table[function].function_type;
+}
+
+static void __uam_manager_product_method(
+               GDBusConnection *connection,
+               const gchar *sender,
+               const gchar *object_path,
+               const gchar *interface_name,
+               const gchar *method_name,
+               GVariant *parameters,
+               GDBusMethodInvocation *invocation,
+               gpointer user_data)
+{
+       FUNC_ENTRY;
+       int result = UAM_ERROR_NONE;
+
+       UAM_DBG("Sender[%s] Method[%s] Path[%s] Interface[%s]",
+                       sender, method_name, object_path, interface_name);
+
+       if (0 == g_strcmp0(method_name, "uam_product_request")) {
+               int function;
+
+               GVariant *in_param1 = NULL;
+               GVariant *in_param2 = NULL;
+               GVariant *in_param3 = NULL;
+               GVariant *in_param4 = NULL;
+               GArray *out_param1 = NULL;
+
+               g_variant_get(parameters, "(i@ay@ay@ay@ay)", &function,
+                               &in_param1, &in_param2, &in_param3, &in_param4);
+
+               out_param1 = g_array_new(FALSE, FALSE, sizeof(gchar));
+
+               UAM_DBG("Request function = [%s (0x%4.4X)]",
+                               _uam_manager_product_request_to_str(function), function);
+
+               if (UAM_PRODUCT_SYNC_FUNCTION ==
+                       __uam_manager_product_get_function_type(function)) {
+
+                       result = __uam_manager_product_sync_request_handler(
+                                       invocation, function, in_param1, in_param2,
+                                                       in_param3, in_param4, &out_param1);
+               } else {
+                       result = __uam_manager_product_async_request_handler(
+                                       invocation, function, in_param1, in_param2,
+                                                       in_param3, in_param4, &out_param1);
+
+                       if (UAM_ERROR_NONE == result) {
+                               UAM_DBG("Request context is saved, do not send reply over dbus");
+                               goto done;
+                       }
+               }
+
+               if (UAM_ERROR_NONE != result) {
+                       UAM_ERR("Request [%s (0x%4.4X)] is failed with [%s (0x%4.4X])",
+                                       _uam_manager_product_request_to_str(function), function,
+                                       _uam_manager_error_to_str(result), result);
+               }
+
+               _uam_manager_product_method_return(invocation, out_param1, result);
+
+done:
+               g_variant_unref(in_param1);
+               g_variant_unref(in_param2);
+               g_variant_unref(in_param3);
+               g_variant_unref(in_param4);
+               g_array_unref(out_param1);
+       }
+
+       FUNC_EXIT;
+       return;
+}
+
+static GDBusNodeInfo *__uam_manager_product_create_method_node_info(
+               const gchar *introspection_data)
+{
+       FUNC_ENTRY;
+       GError *err = NULL;
+       GDBusNodeInfo *node_info = NULL;
+
+       if (introspection_data == NULL) {
+               UAM_ERR("Introspection XML not present");
+               return NULL;
+       }
+
+       node_info = g_dbus_node_info_new_for_xml(introspection_data, &err);
+       if (err) {
+               UAM_ERR("Unable to create node: %s", err->message);
+               g_clear_error(&err);
+       }
+
+       FUNC_EXIT;
+       return node_info;
+}
+
+static const GDBusInterfaceVTable uam_method_table = {
+       __uam_manager_product_method,
+       NULL,
+       NULL,
+       {0}
+};
+
+static int __uam_manager_product_register_object(
+               GDBusConnection *conn, GDBusNodeInfo *node_info)
+{
+       FUNC_ENTRY;
+       GError *error = NULL;
+
+       retv_if(NULL == node_info, UAM_ERROR_INTERNAL);
+
+       g_dbus_object_id = g_dbus_connection_register_object(conn,
+                       UAM_PRODUCT_DAEMON_PATH,
+                       node_info->interfaces[0],
+                       &uam_method_table,
+                       NULL, NULL, &error);
+       retv_if(0 == g_dbus_object_id, UAM_ERROR_INTERNAL);
+
+       FUNC_EXIT;
+       return UAM_ERROR_NONE;
+}
+
+static int __uam_manager_product_unregister_object(GDBusConnection *conn)
+{
+       FUNC_ENTRY;
+
+       if (g_dbus_object_id > 0) {
+               g_dbus_connection_unregister_object(
+                               conn, g_dbus_object_id);
+               g_dbus_object_id = 0;
+       }
+
+       FUNC_EXIT;
+       return UAM_ERROR_NONE;
+}
+
+static void __uam_manager_product_name_acquired_cb(
+               GDBusConnection *connection, const gchar *name, gpointer user_data)
+{
+       UAM_INFO("DBus name [%s] acquired", name);
+}
+
+static void __uam_manager_product_name_lost_cb(
+               GDBusConnection *connection, const gchar *name, gpointer user_data)
+{
+       if (NULL == connection) {
+               UAM_ERR("connection to the bus can't be made");
+               return;
+       }
+
+       UAM_ERR("DBus name [%s] lost", name);
+}
+
+
+static void __uam_manager_product_bus_acquired_cb(
+               GDBusConnection *connection, const gchar *name, gpointer user_data)
+{
+       FUNC_ENTRY;
+
+       UAM_INFO("DBus %s bus acquired", name);
+
+       GDBusNodeInfo *node_info = NULL;
+
+       UAM_INFO("DBus bus acquired");
+
+       ret_if(connection == NULL);
+
+       node_info = __uam_manager_product_create_method_node_info(
+                       uam_manager_product_introspection_xml);
+       ret_if(node_info == NULL);
+
+       __uam_manager_product_register_object(connection, node_info);
+       g_dbus_node_info_unref(node_info);
+
+       uam_manager_product_conn = connection;
+       g_object_ref(uam_manager_product_conn);
+       FUNC_EXIT;
+}
+
+int _uam_manager_product_register(void)
+{
+       FUNC_ENTRY;
+
+       owner_id = g_bus_own_name(G_BUS_TYPE_SYSTEM,
+                       UAM_PRODUCT_DBUS_NAME,
+                       G_BUS_NAME_OWNER_FLAGS_REPLACE,
+                       __uam_manager_product_bus_acquired_cb,
+                       __uam_manager_product_name_acquired_cb,
+                       __uam_manager_product_name_lost_cb,
+                       NULL, NULL);
+       if (0 == owner_id)
+               goto fail;
+
+       UAM_DBG("owner_id is [%d]", owner_id);
+
+       FUNC_EXIT;
+       return UAM_ERROR_NONE;
+
+fail:
+       if (uam_manager_product_conn) {
+               g_object_unref(uam_manager_product_conn);
+               uam_manager_product_conn = NULL;
+       }
+       return UAM_ERROR_INTERNAL;
+}
+
+void _uam_manager_product_unregister(void)
+{
+       FUNC_ENTRY;
+
+       if (uam_manager_product_conn) {
+               g_dbus_connection_signal_unsubscribe(uam_manager_product_conn, owner_sig_id);
+               __uam_manager_product_unregister_object(uam_manager_product_conn);
+               g_bus_unown_name(owner_id);
+               g_dbus_connection_flush_sync(uam_manager_product_conn, NULL, NULL);
+               g_object_unref(uam_manager_product_conn);
+               uam_manager_product_conn = NULL;
+       }
+
+       FUNC_EXIT;
+}
index f05caec..3e1e03e 100644 (file)
@@ -20,6 +20,7 @@
 #include "ua-api.h"
 #include "ua-internal.h"
 #include "ua-manager-common.h"
+#include "ua-manager-common-product.h"
 #include "ua-plugin-manager.h"
 
 GMainLoop *main_loop;
@@ -37,6 +38,9 @@ static void __uam_manager_cleanup(void)
                /* Deinit plugins */
                _uam_pm_deinit();
 
+               /* unregister ua-manager product*/
+               _uam_manager_product_unregister();
+
                /* unregister ua-manager*/
                _uam_manager_unregister();
        }
@@ -169,6 +173,9 @@ static int __uam_manager_init(void)
        result = _uam_manager_register();
        retv_if(UAM_ERROR_NONE != result, result);
 
+       result = _uam_manager_product_register();
+       retv_if(UAM_ERROR_NONE != result, result);
+
        result = _uam_pm_init();
        if (UAM_ERROR_NONE != result) {
                _uam_manager_unregister();
index 671a640..2a740ea 100755 (executable)
 #include <cynara-creds-gdbus.h>
 #include <aul.h>
 
-#define UAM_PRIVLEVEL_PUBLIC   0
-#define UAM_PRIVLEVEL_PLATFORM 1
-
-#define UAM_SYNC_FUNCTION      0
-#define UAM_ASYNC_FUNCTION     1
-
 extern GMainLoop *main_loop;
 
 /* For maintaining Application Sync API call requests */
@@ -338,7 +332,7 @@ void _uam_get_sender_from_app_num(const int app_num, char **sender)
        FUNC_EXIT;
 }
 
-static int __sender_to_app_num_operations(unsigned int *app_num, const char *sender)
+int __sender_to_app_num_operations(unsigned int *app_num, const char *sender)
 {
        FUNC_ENTRY;
        GSList * l1 = NULL;