[Bluetooth][OTP] Add base code for OTP server role
[platform/core/connectivity/bluetooth-frwk.git] / bt-core / bt-core-dbus-handler.c
old mode 100755 (executable)
new mode 100644 (file)
index b6a0e77..41f15b0
 #define BT_SERVICE_NAME                "org.projectx.bt"
 #define BT_SERVICE_PATH                "/org/projectx/bt_service"
 
-#ifdef HPS_FEATURE
+#ifdef TIZEN_FEATURE_BT_HPS
 #define BT_HPS_SERVICE_NAME "org.projectx.httpproxy"
 #define BT_HPS_OBJECT_PATH "/org/projectx/httpproxy"
 #define BT_HPS_INTERFACE_NAME "org.projectx.httpproxy_service"
 #endif
 
+#ifdef TIZEN_FEATURE_BT_OTP
+#define BT_OTP_SERVICE_NAME    "org.projectx.otp"
+#define BT_OTP_OBJECT_PATH     "/org/projectx/otp"
+#define BT_OTP_INTERFACE_NAME  "org.projectx.otp_service"
+#endif
+
 static GDBusConnection *service_gconn;
 static GDBusProxy *service_gproxy;
-#ifdef HPS_FEATURE
+#ifdef TIZEN_FEATURE_BT_HPS
 static GDBusProxy *hps_gproxy;
 #endif
 
+#ifdef TIZEN_FEATURE_BT_OTP
+static GDBusProxy *otp_gproxy;
+#endif
+
 void _bt_core_fill_garray_from_variant(GVariant *var, GArray *param)
 {
        char *data;
@@ -108,12 +118,12 @@ GDBusProxy *_bt_core_gdbus_get_service_proxy(void)
        return (service_gproxy) ? service_gproxy : __bt_core_gdbus_init_service_proxy();
 }
 
-#ifdef HPS_FEATURE
+#ifdef TIZEN_FEATURE_BT_HPS
 int _bt_core_start_httpproxy(void)
 {
        GVariant *variant = NULL;
        unsigned char enabled;
-
+       GError *err = NULL;
        BT_DBG(" ");
 
        hps_gproxy = _bt_core_gdbus_get_hps_proxy();
@@ -123,7 +133,11 @@ int _bt_core_start_httpproxy(void)
        }
 
        variant = g_dbus_proxy_call_sync(hps_gproxy, "enable",
-                               NULL, G_DBUS_CALL_FLAGS_NONE, -1, NULL, NULL);
+                               NULL, G_DBUS_CALL_FLAGS_NONE, -1, NULL, &err);
+       if (err) {
+               BT_ERR("Error : %s" , err->message);
+               g_clear_error(&err);
+       }
        if (variant) {
                g_variant_get(variant, "(y)", &enabled);
                BT_ERR("HPS enabled status 0x%x", enabled);
@@ -135,7 +149,7 @@ int _bt_core_stop_httpproxy(void)
 {
        GVariant *variant = NULL;
        unsigned char enabled;
-
+       GError *err = NULL;
        BT_DBG(" ");
 
        hps_gproxy = _bt_core_gdbus_get_hps_proxy();
@@ -145,7 +159,11 @@ int _bt_core_stop_httpproxy(void)
        }
 
        variant = g_dbus_proxy_call_sync(hps_gproxy, "disable",
-                               NULL, G_DBUS_CALL_FLAGS_NONE, -1, NULL, NULL);
+                               NULL, G_DBUS_CALL_FLAGS_NONE, -1, NULL, &err);
+       if (err) {
+               BT_ERR("Error : %s" , err->message);
+               g_clear_error(&err);
+       }
        if (variant) {
                g_variant_get(variant, "(y)", &enabled);
                BT_ERR("HPS disabled status 0x%x", enabled);
@@ -190,6 +208,69 @@ GDBusProxy *_bt_core_gdbus_get_hps_proxy(void)
 }
 #endif
 
+#ifdef TIZEN_FEATURE_BT_OTP
+static GDBusProxy *_bt_core_gdbus_init_otp_proxy(void)
+{
+       GDBusProxy *proxy;
+       GError *err = NULL;
+       GDBusConnection *conn;
+
+       BT_DBG(" ");
+
+       conn = _bt_core_get_gdbus_connection();
+       if (!conn)
+               return NULL;
+
+       proxy =  g_dbus_proxy_new_sync(conn,
+                       G_DBUS_PROXY_FLAGS_NONE, NULL,
+                       BT_OTP_SERVICE_NAME,
+                       BT_OTP_OBJECT_PATH,
+                       BT_OTP_INTERFACE_NAME,
+                       NULL, &err);
+       if (proxy == NULL) {
+               if (err) {
+                        BT_ERR("Unable to create proxy: %s", err->message);
+                        g_clear_error(&err);
+               }
+               return NULL;
+       }
+
+       otp_gproxy = proxy;
+
+       return proxy;
+}
+
+GDBusProxy *_bt_core_gdbus_get_otp_proxy(void)
+{
+       return (otp_gproxy) ? otp_gproxy : _bt_core_gdbus_init_otp_proxy();
+}
+
+int _bt_core_stop_otp(void)
+{
+       GVariant *variant = NULL;
+       unsigned char enabled;
+       GError *err = NULL;
+       BT_DBG(" ");
+
+       otp_gproxy = _bt_core_gdbus_get_otp_proxy();
+       if (!otp_gproxy) {
+               BT_DBG("Couldn't get service proxy");
+               return -1;
+       }
+
+       variant = g_dbus_proxy_call_sync(otp_gproxy, "disable",
+                               NULL, G_DBUS_CALL_FLAGS_NONE, -1, NULL, &err);
+       if (err) {
+               BT_ERR("Error : %s" , err->message);
+               g_clear_error(&err);
+       }
+       if (variant) {
+               g_variant_get(variant, "(y)", &enabled);
+               BT_ERR("OTP disabled status 0x%x", enabled);
+       }
+       return 0;
+}
+#endif
 void _bt_core_gdbus_deinit_proxys(void)
 {
        BT_DBG("");
@@ -199,13 +280,20 @@ void _bt_core_gdbus_deinit_proxys(void)
                service_gproxy = NULL;
        }
 
-#ifdef HPS_FEATURE
+#ifdef TIZEN_FEATURE_BT_HPS
        if (hps_gproxy) {
                g_object_unref(hps_gproxy);
                hps_gproxy = NULL;
        }
 #endif
 
+#ifdef TIZEN_FEATURE_BT_OTP
+       if (otp_gproxy) {
+               g_object_unref(otp_gproxy);
+               otp_gproxy = NULL;
+       }
+#endif
+
        if (service_gconn) {
                g_object_unref(service_gconn);
                service_gconn = NULL;
@@ -218,7 +306,7 @@ int _bt_core_service_request(int service_type, int service_function,
                        GArray **out_param1)
 {
        GDBusProxy  *proxy;
-       GVariant *ret;
+       GVariant *ret = NULL;
        GVariant *param1;
        GVariant *param2;
        GVariant *param3;
@@ -534,6 +622,7 @@ gboolean _bt_core_register_dbus(void)
                                        node_info->interfaces[0],
                                        &method_table,
                                        NULL, NULL, &error);
+       g_dbus_node_info_unref(node_info);
        if (obj_id == 0) {
                BT_ERR("Failed to register: %s", error->message);
                g_error_free(error);