Reduce the predefined logic (PredefinedPreprocessor)
[platform/core/connectivity/bluetooth-frwk.git] / bt-api / bt-event-handler.c
index c08f6ec..79ce01a 100644 (file)
@@ -559,6 +559,23 @@ static void __bt_mesh_event_filter(GDBusConnection *connection,
                _bt_mesh_event_cb(BLUETOOTH_EVENT_MESH_NODE_KEY_CONFIGURED,
                                result, info,
                                event_info->cb, event_info->user_data);
+       } else if (strcasecmp(signal_name, BT_MESH_MODEL_APPKEY_CONFIGURED) == 0) {
+               int result;
+               GVariant *param = NULL;
+               GArray *dbus_data = NULL;
+               bluetooth_mesh_model_configure_t *info = NULL;
+
+               g_variant_get(parameters, "(iv)", &result, &param);
+               dbus_data = g_array_new(TRUE, TRUE, sizeof(gchar));
+
+               __bt_fill_garray_from_variant(param, dbus_data);
+               g_variant_unref(param);
+
+               info = &g_array_index(dbus_data, bluetooth_mesh_model_configure_t, 0);
+
+               _bt_mesh_event_cb(BLUETOOTH_EVENT_MESH_MODEL_APPKEY_BIND,
+                               result, info,
+                               event_info->cb, event_info->user_data);
        } else if (strcasecmp(signal_name, BT_MESH_MODEL_APPKEY_LIST) == 0) {
                int result;
                GVariantIter *iter = NULL;
@@ -571,7 +588,7 @@ static void __bt_mesh_event_filter(GDBusConnection *connection,
                uint16_t appkey_idx;
                int i;
 
-               g_variant_get(parameters, "(i&sqiui(ay))", &result, &net_uuid,
+               g_variant_get(parameters, "(i&sqiui(aq))", &result, &net_uuid,
                                &node_unicast, &elem_idx, &model, &total, &iter);
 
                memset(&info, 0x00, sizeof(bluetooth_mesh_model_configure_t));
@@ -580,7 +597,7 @@ static void __bt_mesh_event_filter(GDBusConnection *connection,
                info.elem_index = elem_idx;
                info.model = model;
                info.appkeylist_count = total;
-
+               BT_INFO("Mesh: Total appkeys bound to model [%d]", total);
                if (total) {
                        info.appkey_list = (uint16_t**)g_malloc0(sizeof(uint16_t*) * total);
 
@@ -594,11 +611,13 @@ static void __bt_mesh_event_filter(GDBusConnection *connection,
                                result, &info,
                                event_info->cb, event_info->user_data);
 
-               if (total) {
-                       for (i = 0; i < total; i++)
-                               g_free(info.appkey_list[i]);
+               for (i = 0; i < total; i++)
+                       g_free(info.appkey_list[i]);
+               if (info.appkey_list) {
+                       g_free(info.appkey_list);
                        g_variant_iter_free(iter);
                }
+
        } else if (strcasecmp(signal_name, BT_MESH_MODEL_SUB_LIST) == 0) {
                int result;
                GVariantIter *iter = NULL;
@@ -611,7 +630,7 @@ static void __bt_mesh_event_filter(GDBusConnection *connection,
                uint16_t sub_addr;
                int i;
 
-               g_variant_get(parameters, "(i&sqiui(ay))", &result, &net_uuid,
+               g_variant_get(parameters, "(i&sqiui(aq))", &result, &net_uuid,
                                &node_unicast, &elem_idx, &model, &total, &iter);
 
                memset(&info, 0x00, sizeof(bluetooth_mesh_model_configure_t));
@@ -621,11 +640,13 @@ static void __bt_mesh_event_filter(GDBusConnection *connection,
                info.model = model;
                info.sublist_count = total;
 
+               BT_INFO("Mesh: Total Subscriptions Bound to model [%d]", total);
                if (total) {
                        info.sub_list = (uint16_t**)g_malloc0(sizeof(uint16_t*) * total);
                        for (i = 0; i < total && g_variant_iter_loop(iter, "q", &sub_addr); ++i) {
                                info.sub_list[i] = g_malloc0(sizeof(uint16_t));
                                *info.sub_list[i] = sub_addr;
+                               BT_INFO("Mesh: Subscription Address [0x%2.2x]", sub_addr);
                        }
                }
 
@@ -633,9 +654,10 @@ static void __bt_mesh_event_filter(GDBusConnection *connection,
                                result, &info,
                                event_info->cb, event_info->user_data);
 
-               if (total) {
-                       for (i = 0; i < total; i++)
-                               g_free(info.sub_list[i]);
+               for (i = 0; i < total; i++)
+                       g_free(info.sub_list[i]);
+               if (info.appkey_list) {
+                       g_free(info.sub_list);
                        g_variant_iter_free(iter);
                }
        } else if (strcasecmp(signal_name, BT_MESH_NODE_TTL_CONFIGURED) == 0) {
@@ -723,6 +745,23 @@ static void __bt_mesh_event_filter(GDBusConnection *connection,
                _bt_mesh_event_cb(BLUETOOTH_EVENT_MESH_MODEL_PUBLICATION_STATUS,
                                result, info,
                                event_info->cb, event_info->user_data);
+       } else if (strcasecmp(signal_name, BT_MESH_MODEL_MSG_EXECUTED) == 0) {
+               int result;
+               GVariant *param = NULL;
+               GArray *dbus_data = NULL;
+               bluetooth_mesh_model_msg_t *info = NULL;
+
+               g_variant_get(parameters, "(iv)", &result, &param);
+               dbus_data = g_array_new(TRUE, TRUE, sizeof(gchar));
+
+               __bt_fill_garray_from_variant(param, dbus_data);
+               g_variant_unref(param);
+
+               info = &g_array_index(dbus_data, bluetooth_mesh_model_msg_t, 0);
+
+               _bt_mesh_event_cb(BLUETOOTH_EVENT_MESH_MODEL_MSG_EXECUTED,
+                               result, info,
+                               event_info->cb, event_info->user_data);
        }
        BT_INFO("Mesh event handler Exit <<");
 }
@@ -1205,7 +1244,7 @@ void __bt_device_event_filter(GDBusConnection *connection,
 #endif
 
        ret_if(signal_name == NULL);
-#ifdef TIZEN_GATT_CLIENT
+
        if (strcasecmp(signal_name, BT_GATT_SERVER_CONNECTED) == 0) {
                const char *address = NULL;
                bluetooth_device_address_t dev_address = { {0} };
@@ -1246,28 +1285,6 @@ void __bt_device_event_filter(GDBusConnection *connection,
                _bt_common_event_cb(BLUETOOTH_EVENT_GATT_CLIENT_DISCONNECTED,
                                result, &dev_address,
                                event_info->cb, event_info->user_data);
-#else
-       if (strcasecmp(signal_name, BT_GATT_CONNECTED) == 0) {
-               const char *address = NULL;
-               bluetooth_device_address_t dev_address = { {0} };
-               BT_DBG("BT_GATT_CONNECTED");
-               g_variant_get(parameters, "(i&s)", &result, &address);
-
-               _bt_convert_addr_string_to_type(dev_address.addr, address);
-               _bt_common_event_cb(BLUETOOTH_EVENT_GATT_CONNECTED,
-                               result, &dev_address,
-                               event_info->cb, event_info->user_data);
-       } else if (strcasecmp(signal_name, BT_GATT_DISCONNECTED) == 0) {
-               const char *address = NULL;
-               bluetooth_device_address_t dev_address = { {0} };
-               BT_DBG("BT_GATT_DISCONNECTED");
-               g_variant_get(parameters, "(i&s)", &result, &address);
-
-               _bt_convert_addr_string_to_type(dev_address.addr, address);
-               _bt_common_event_cb(BLUETOOTH_EVENT_GATT_DISCONNECTED,
-                               result, &dev_address,
-                               event_info->cb, event_info->user_data);
-#endif
        } else if (strcasecmp(signal_name, BT_GATT_REQ_ATT_MTU_CHANGED) == 0) {
                const char *address = NULL;
                bluetooth_device_address_t dev_address = { {0} };
@@ -1716,7 +1733,6 @@ void __bt_headset_event_filter(GDBusConnection *connection,
                _bt_headset_event_cb(BLUETOOTH_EVENT_AG_MIC_GAIN,
                                result, &gain,
                                event_info->cb, event_info->user_data);
-#ifdef TIZEN_FEATURE_BT_AVC_TARGET
        } else if (strcasecmp(signal_name, BT_AUDIO_AVC_MODE_CHANGED) == 0) {
                bool mode;
 
@@ -1733,7 +1749,6 @@ void __bt_headset_event_filter(GDBusConnection *connection,
                                result, &volume,
                                event_info->cb, event_info->user_data);
        }
-#endif
 }
 
 void __bt_hid_device_event_filter(GDBusConnection *connection,
@@ -3898,7 +3913,6 @@ static void __bt_event_data_free(void *data)
        g_free(cb_data);
 }
 
-#ifdef TIZEN_GATT_CLIENT
 static void __bt_gatt_client_event_filter(GDBusConnection *connection,
                const gchar *sender_name,
                const gchar *object_path,
@@ -4190,9 +4204,6 @@ static void __bt_gatt_client_event_filter(GDBusConnection *connection,
        }
 }
 
-#endif
-
-
 #ifndef GATT_DIRECT
 static void __bt_gatt_server_event_filter(GDBusConnection *connection,
                const gchar *sender_name,
@@ -4209,31 +4220,8 @@ static void __bt_gatt_server_event_filter(GDBusConnection *connection,
 
        event_info = (bt_event_info_t *)user_data;
        ret_if(event_info == NULL);
-#ifdef TIZEN_GATT_CLIENT
-       if (strcasecmp(signal_name, BT_GATT_VALUE_CHANGED) == 0) {
-#else
-       if (strcasecmp(signal_name, BT_GATT_CONNECTED) == 0) {
-               const char *address = NULL;
-               bluetooth_device_address_t dev_address = { {0} };
-               BT_DBG("BT_GATT_CONNECTED");
-               g_variant_get(parameters, "(i&s)", &result, &address);
 
-               _bt_convert_addr_string_to_type(dev_address.addr, address);
-               _bt_gatt_server_event_cb(BLUETOOTH_EVENT_GATT_CONNECTED,
-                               result, &dev_address,
-                               event_info->cb, event_info->user_data);
-       } else if (strcasecmp(signal_name, BT_GATT_DISCONNECTED) == 0) {
-               const char *address = NULL;
-               bluetooth_device_address_t dev_address = { {0} };
-               BT_DBG("BT_GATT_DISCONNECTED");
-               g_variant_get(parameters, "(i&s)", &result, &address);
-
-               _bt_convert_addr_string_to_type(dev_address.addr, address);
-               _bt_gatt_server_event_cb(BLUETOOTH_EVENT_GATT_DISCONNECTED,
-                               result, &dev_address,
-                               event_info->cb, event_info->user_data);
-       } else if (strcasecmp(signal_name, BT_GATT_VALUE_CHANGED) == 0) {
-#endif
+       if (strcasecmp(signal_name, BT_GATT_VALUE_CHANGED) == 0) {
                const char *address = NULL;
                GVariant *data_var = NULL;
                bluetooth_device_address_t dev_address = { {0} };
@@ -4498,13 +4486,10 @@ int _bt_register_event(int event_type, void *event_cb, void *user_data)
                path = BT_GATT_SERVER_PATH;
                break;
 #endif
-
-#ifdef TIZEN_GATT_CLIENT
        case BT_GATT_CLIENT_EVENT:
                event_func = __bt_gatt_client_event_filter;
                path = BT_GATT_CLIENT_PATH;
                break;
-#endif
        case BT_MESH_EVENT:
                event_func = __bt_mesh_event_filter;
                path = BT_MESH_PATH;