[bluetooth-frwk] Added listFilterFields implementation with async result 49/102849/2
authorLukasz Bardeli <l.bardeli@samsung.com>
Fri, 4 Nov 2016 10:44:01 +0000 (11:44 +0100)
committerPyun DoHyun <dh79.pyun@samsung.com>
Thu, 8 Dec 2016 00:20:09 +0000 (16:20 -0800)
[Feature] added implementation for listFilterFields method

[Verification] function checked with sample C program:
 - listing filter fields is possible

Change-Id: Ic3cb5b18df442f4a896b80941228e63e5cfa8dac
Signed-off-by: Lukasz Bardeli <l.bardeli@samsung.com>
bt-api/bt-event-handler.c
bt-api/bt-map-client.c
bt-api/bt-request-sender.c
bt-service/bt-request-handler.c
bt-service/bt-service-event-sender.c
bt-service/bt-service-map-client.c
bt-service/include/bt-service-map-client.h
include/bluetooth-api.h
include/bt-internal-types.h

index a2f3913..5a4d843 100644 (file)
@@ -2085,8 +2085,50 @@ void __bt_map_client_event_filter(GDBusConnection *connection,
                free(folders_struct.names);
 
                g_variant_unref(folder_list_var);
-       }
-       // TODO MAP place for you else 1
+
+       } else if (strcasecmp(signal_name, BT_MAP_FILTER_FIELDS_COMPLETE) == 0) {
+               BT_DBG("BT_MAP_LIST_FOLDERS_COMPLETE");
+
+               const char *session_id = NULL;
+               GVariant *value;
+               int request_id = 0;
+               int i = 0;
+               bt_map_list_filter_fields_info_t fields_info = {0,};
+
+               g_variant_get(parameters, "(ivsi)", &result, &value, &session_id, &request_id);
+
+               if (__bt_is_request_id_exist(request_id) == FALSE) {
+                       BT_ERR("Different request id!");
+                       return;
+               }
+
+               if (value) {
+                       GVariantIter *iter = NULL;
+                       g_variant_get(value, "(as)", &iter);
+                       fields_info.size  = g_variant_iter_n_children(iter);
+                       char* field = NULL;
+
+                       fields_info.fields = malloc(fields_info.size * sizeof(char*));
+                       while (g_variant_iter_loop(iter, "s", &field)) {
+                               fields_info.fields[i] = strdup(field);
+                               i++;
+                       }
+               }
+
+               _bt_common_event_cb(BLUETOOTH_EVENT_MAP_LIST_FILTER_FIELD_COMPLETE,
+                               request_id, &fields_info,
+                               event_info->cb, event_info->user_data);
+
+               while(--i >= 0) {
+                       free(fields_info.fields[i]);
+                       fields_info.fields[i] = NULL;
+               }
+               free(fields_info.fields);
+
+               __bt_remove_push_request_id(request_id);
+               g_variant_unref(value);
+       }
+
        // TODO MAP place for you else 2
        // TODO MAP place for you else 3
        // TODO MAP place for you else 4
index eb062c9..8d4610e 100644 (file)
@@ -165,12 +165,28 @@ BT_EXPORT_API int bluetooth_map_client_list_folders(
 BT_EXPORT_API int bluetooth_map_client_list_filter_fields(
     bt_map_client_session_info_s *session)
 {
-    BT_DBG("bluetooth_map_client_list_filter_fields");
-    int result = BLUETOOTH_ERROR_INTERNAL;
+       BT_DBG("bluetooth_map_client_list_filter_fields");
+       int result = BLUETOOTH_ERROR_NONE;
+       bt_user_info_t *user_info;
 
-    /* TODO: MAP */
+       BT_CHECK_ENABLED(return);
+       BT_CHECK_PARAMETER(session->session_path, return);
 
-    return result;
+       user_info = _bt_get_user_data(BT_COMMON);
+       retv_if(user_info->cb == NULL, BLUETOOTH_ERROR_INTERNAL);
+
+       BT_INIT_PARAMS();
+       BT_ALLOC_PARAMS(in_param1, in_param2, in_param3, in_param4, out_param);
+
+       g_array_append_vals(in_param1, session->session_path, strlen(session->session_path)+1);
+
+       result = _bt_send_request_async(BT_OBEX_SERVICE, BT_MAP_LIST_FILTER_FIELDS,
+               in_param1, in_param2, in_param3, in_param4,
+               user_info->cb, user_info->user_data);
+
+       BT_FREE_PARAMS(in_param1, in_param2, in_param3, in_param4, out_param);
+
+       return result;
 }
 
 BT_EXPORT_API int bluetooth_map_client_list_messages(
index 6594580..294b8ad 100644 (file)
@@ -321,6 +321,10 @@ static void __send_request_cb(GDBusProxy *proxy,
                                request_id = g_array_index(out_param1, int, 0);
                                BT_DBG("request_id : %d", request_id);
                                _bt_add_push_request_id(request_id);
+                       } else if (cb_data->service_function == BT_MAP_LIST_FILTER_FIELDS) {
+                               request_id = g_array_index(out_param1, int, 0);
+                               BT_DBG("request_id : %d", request_id);
+                               _bt_add_push_request_id(request_id);
                        }
                        // TODO MAP place for your own if 1
                        // TODO MAP place for your own if 2
index 401d17e..ba982f6 100644 (file)
@@ -2312,9 +2312,12 @@ int __bt_obexd_request(int function_name,
        case BT_MAP_LIST_FILTER_FIELDS: {
                BT_DBG("BT_MAP_LIST_FILTER_FIELDS");
 
-               /* TODO: MAP */
+               char* session_id = (char *)g_variant_get_data(in_param1);
 
-               result = BLUETOOTH_ERROR_NOT_SUPPORT;
+               result = _bt_map_client_list_filter_fields(request_id, context, session_id);
+               if (result == BLUETOOTH_ERROR_NONE) {
+                       BT_DBG("_bt_map_client_list_filter_fields succeed");
+               }
                break;
        }
 
index cc13bb8..ac53303 100644 (file)
@@ -332,7 +332,10 @@ int _bt_send_event(int event_type, int event, GVariant *param)
                signal = BT_MAP_LIST_FOLDERS_COMPLETE;
                BT_INFO_C("Completed list folders operation[MAP]");
                break;
-               // TODO MAP place for your own case 1
+       case BLUETOOTH_EVENT_MAP_LIST_FILTER_FIELD_COMPLETE:
+               signal = BT_MAP_FILTER_FIELDS_COMPLETE;
+               BT_INFO_C("Completed list filters field operation[MAP]");
+               break;
                // TODO MAP place for your own case 2
                // TODO MAP place for your own case 3
                // TODO MAP place for your own case 4
index 1ecba34..9babf6b 100644 (file)
@@ -446,11 +446,82 @@ int _bt_map_client_list_folders(int request_id, GDBusMethodInvocation *context,
        return result;
 }
 
-int _bt_map_client_list_filter_fields(const char* session_id)
+static void __bt_list_filter_fields_cb(GDBusProxy *proxy,
+                               GAsyncResult *res, gpointer user_data)
 {
        BT_DBG("+");
 
-       /* TODO: MAP */
+       GError *error = NULL;
+       GVariant *value, *in_param, *param;
+
+       int result = BLUETOOTH_ERROR_NONE;
+       int request_id;
+       char* session_id = NULL;
+       char** fields = NULL;
+       int size = 0;
+
+       in_param = (GVariant*) user_data;
+       g_variant_get(in_param, "(is)", &request_id, &session_id);
+
+       value = g_dbus_proxy_call_finish(proxy, res, &error);
+
+       if (error) {
+               BT_ERR("%s", error->message);
+               g_clear_error(&error);
+               result = BLUETOOTH_ERROR_INTERNAL;
+       }
+
+       param = g_variant_new("(ivsi)", result, value, session_id, request_id);
+
+       _bt_send_event(BT_MAP_CLIENT_EVENT, BLUETOOTH_EVENT_MAP_LIST_FILTER_FIELD_COMPLETE,
+                       param);
+
+       g_variant_unref(value);
+       g_variant_unref(in_param);
+
+       BT_DBG("-");
+}
+
+int _bt_map_client_list_filter_fields(int request_id, GDBusMethodInvocation *context, const char* session_id)
+{
+       BT_DBG("+");
+
+       GError *err = NULL;
+       GDBusConnection *g_conn;
+       GDBusProxy *message_proxy;
+       GVariantBuilder *builder;
+       GVariant *ret = NULL;
+       int result = BLUETOOTH_ERROR_NONE;
+
+       retv_if(session_id == NULL, BLUETOOTH_ERROR_INVALID_PARAM);
+
+       g_conn = _bt_gdbus_get_session_gconn();
+       retv_if(g_conn == NULL, BLUETOOTH_ERROR_INTERNAL);
+
+       GVariant *out_param = g_variant_new_from_data((const GVariantType *)"ay",
+                                                       &request_id, sizeof(int),
+                                                       TRUE, NULL, NULL);
+
+       g_dbus_method_invocation_return_value(context,
+                       g_variant_new("(iv)", result, out_param));
+
+
+       message_proxy = g_dbus_proxy_new_sync(g_conn,
+               G_DBUS_PROXY_FLAGS_NONE, NULL,
+               BT_OBEX_SERVICE_NAME, session_id,
+               BT_OBEX_MESSAGE_INTERFACE, NULL, &err);
+
+       retv_if(message_proxy == NULL, BLUETOOTH_ERROR_INTERNAL);
+
+       GVariant *param = g_variant_new("(is)",
+                       request_id, session_id);
+
+       g_dbus_proxy_call(message_proxy,
+                       "ListFilterFields", g_variant_new("()"),
+                       G_DBUS_CALL_FLAGS_NONE, -1,
+                       NULL,
+                       (GAsyncReadyCallback)__bt_list_filter_fields_cb,
+                       (void*)param);
 
        BT_DBG("-");
 
index 42eb8d2..4d9c772 100644 (file)
@@ -66,7 +66,8 @@ int _bt_destroy_session_sync(const char* session_id);
 int _bt_map_client_set_folder(const char* session_id, const char* name);
 int _bt_map_client_list_folders(int request_id, GDBusMethodInvocation *context,
                const char* session_id, int offset, int maxcount);
-int _bt_map_client_list_filter_fields(const char* session_id);
+int _bt_map_client_list_filter_fields(int request_id, GDBusMethodInvocation *context,
+               const char* session_id);
 int _bt_map_client_list_messages(
                const char* session_id,
                const char* folder,
index c81f2b5..a386950 100644 (file)
@@ -613,6 +613,7 @@ typedef enum {
        BLUETOOTH_EVENT_MAP_GET_MESSAGE_COMPLETE,
        BLUETOOTH_EVENT_MAP_GET_MESSAGE_INVALID_ARGUMENTS,
        BLUETOOTH_EVENT_MAP_GET_MESSAGE_FAILED,
+       BLUETOOTH_EVENT_MAP_LIST_FILTER_FIELD_COMPLETE,
 
        BLUETOOTH_EVENT_OBEX_SERVER_TRANSFER_AUTHORIZE = BLUETOOTH_EVENT_OBEX_SERVER_BASE,
                                                                /* Obex server authorize event*/
@@ -1276,6 +1277,13 @@ typedef struct {
 } bt_opc_transfer_info_t;
 
 /* TODO: MAP client structures, see above */
+/**
+ * Stucture to Map filter fields
+ */
+typedef struct {
+       char **fields;
+       int size;
+} bt_map_list_filter_fields_info_t;
 
 /* Obex Server transfer type */
 #define TRANSFER_PUT "PUT"
@@ -4869,6 +4877,20 @@ int bluetooth_map_client_list_folders(
     int maxcount
 );
 
+/**
+ * @fn int bluetooth_map_client_list_filter_fields(bt_map_session_info_s* session)
+ * @brief Return all available fields that can be used in Fields filter.
+ *
+ * This function is a asynchronous call.
+ *
+ * @return   BLUETOOTH_ERROR_NONE  - Success \n
+ *              BLUETOOTH_ERROR_DEVICE_NOT_ENABLED - Device is not enabled \n
+ *              BLUETOOTH_ERROR_INTERNAL - Update inbox failed \n
+ *
+ * @exception   None
+ * @param[in]  session   Information about session.
+ * @remark       None
+ */
 int bluetooth_map_client_list_filter_fields(
     bt_map_client_session_info_s *session
 );
index 0b69dcc..6bbc033 100644 (file)
@@ -502,7 +502,7 @@ typedef struct {
 #define BT_MAP_CONNECTED "MapConnected"
 #define BT_MAP_DISCONNECTED "MapDisconnected"
 #define BT_MAP_LIST_FOLDERS_COMPLETE "ListFoldersComplete"
-//  TODO MAP place for your define 1
+#define BT_MAP_FILTER_FIELDS_COMPLETE "MapListFiltersFieldComplete"
 //  TODO MAP place for your define 2
 //  TODO MAP place for your define 3
 //  TODO MAP place for your define 4