CAPI/OPP: Implement function bt_opp_server_initialize/deinitialize() 26/23026/1
authorWu Jiangbo <jiangbox.wu@intel.com>
Thu, 12 Jun 2014 09:07:13 +0000 (17:07 +0800)
committerWu Jiangbo <jiangbox.wu@intel.com>
Mon, 16 Jun 2014 09:13:39 +0000 (17:13 +0800)
Change-Id: I35a681cdb601868e58ca97fd244dc9804f270e52
Signed-off-by: Wu Jiangbo <jiangbox.wu@intel.com>
capi/bluetooth-obex.c
include/bluetooth.h

index 0197cc0..290e959 100644 (file)
@@ -35,7 +35,7 @@
 static struct {
        char *root_folder;
        char *pending_name;
-       bt_opp_server_push_requested_cb requested_cb;
+       bt_opp_server_push_file_requested_cb requested_cb;
        void *user_data;
        obex_transfer_t *pending_transfer;
        GDBusMethodInvocation *pending_invocation;
@@ -225,7 +225,7 @@ static int register_agent(void)
 }
 
 int bt_opp_register_server(const char *dir,
-                       bt_opp_server_push_requested_cb push_requested_cb,
+                       bt_opp_server_push_file_requested_cb push_requested_cb,
                        void *user_data)
 {
        if (dir == NULL || push_requested_cb == NULL)
@@ -457,3 +457,70 @@ int bt_opp_deinit(void)
 
        return 0;
 }
+
+/* Deprecate OPP APIs.
+ * Always implement using NEW OPP APIs*/
+struct opp_server_push_cb_node {
+       bt_opp_server_push_requested_cb callback;
+       void *user_data;
+};
+
+struct opp_server_push_cb_node *opp_server_push_node;
+
+void server_push_requested_cb(const char *remote_address, const char *name,
+                                       uint64_t size, void *user_data)
+{
+       if (opp_server_push_node)
+               opp_server_push_node->callback(name, size,
+                               opp_server_push_node->user_data);
+}
+
+int bt_opp_server_initialize(const char *destination,
+                       bt_opp_server_push_requested_cb push_requested_cb,
+                       void *user_data)
+{
+       int ret;
+
+       ret = bt_opp_init();
+       if (ret != BT_SUCCESS)
+               return ret;
+
+       if (!destination || !push_requested_cb)
+               return BT_ERROR_INVALID_PARAMETER;
+
+       if (opp_server_push_node) {
+               ERROR("Already registered");
+               return BT_ERROR_OPERATION_FAILED;
+       }
+
+       opp_server_push_node = g_new0(struct opp_server_push_cb_node, 1);
+       if (opp_server_push_node == NULL) {
+               ERROR("no memroy");
+               return BT_ERROR_OUT_OF_MEMORY;
+       }
+
+       ret = bt_opp_register_server(destination,
+                               server_push_requested_cb, NULL);
+       if (ret != BT_SUCCESS) {
+               g_free(opp_server_push_node);
+               opp_server_push_node = NULL;
+       }
+
+       return ret;
+}
+
+int bt_opp_server_deinitialize(void)
+{
+       int ret;
+
+       if (opp_server_push_node) {
+               g_free(opp_server_push_node);
+               opp_server_push_node = NULL;
+       }
+
+       ret = bt_opp_deinit();
+       if (ret != BT_SUCCESS)
+               return ret;
+
+       return bt_opp_unregister_server();
+}
index 0caf335..78f6309 100644 (file)
@@ -2043,12 +2043,101 @@ int bt_socket_set_connection_state_changed_cb(bt_socket_connection_state_changed
  */
 int bt_socket_unset_connection_state_changed_cb(void);
 
-/* OPP */
+/**
+ * @ingroup CAPI_NETWORK_BLUETOOTH_OPP_SERVER_MODULE
+ * @brief  Called when the push is requested.
+ * @details You must call bt_opp_server_accept() if you want to accept.
+ * Otherwise, you must call bt_opp_server_reject().
+ * @param[in] file  The path of file to be pushed
+ * @param[in] size The file size (bytes)
+ * @param[in] user_data The user data passed from the callback registration function
+ * @see bt_opp_server_initialize()
+ */
+typedef void (*bt_opp_server_push_requested_cb)(const char *file, int size, void *user_data);
+
+/**
+ * @ingroup CAPI_NETWORK_BLUETOOTH_OPP_SERVER_MODULE
+ * @brief  Called when an OPP connection is requested.
+ * @details You must call bt_opp_server_accept_connection() if you want to accept.
+ * Otherwise, you must call bt_opp_server_reject_connection().
+ * @param[in] remote_address  The address of remote device
+ * @param[in] user_data The user data passed from the callback registration function
+ * @see bt_opp_server_initialize()
+ * @see bt_opp_server_accept_connection()
+ * @see bt_opp_server_reject_connection()
+ */
+typedef void (*bt_opp_server_connection_requested_cb)(const char *remote_address, void *user_data);
+
+/**
+ * @ingroup CAPI_NETWORK_BLUETOOTH_OPP_SERVER_MODULE
+ * @brief Initializes the Bluetooth OPP server requested by bt_opp_server_push_requested_cb().
+ * @details The popup appears when an OPP connection is requested from a remote device.
+ * If you accept the request, then connection will be established and bt_opp_server_push_requested_cb() will be called.
+ * At that time, you can call either bt_opp_server_accept() or bt_opp_server_reject().
+ * @remarks This function must be called to start Bluetooth OPP server. You must free all resources of the Bluetooth service
+ * by calling bt_opp_server_deinitialize() if Bluetooth OPP service is no longer needed.
+ * @param[in] destination  The destination path
+ * @param[in] push_requested_cb  The callback called when a push is requested
+ * @param[in] user_data The user data to be passed to the callback function
+ * @return 0 on success, otherwise a negative error value.
+ * @retval #BT_ERROR_NONE  Successful
+ * @retval #BT_ERROR_NOT_INITIALIZED  Not initialized
+ * @retval #BT_ERROR_NOT_ENABLED  Not enabled
+ * @retval #BT_ERROR_INVALID_PARAMETER  Invalid parameter
+ * @retval #BT_ERROR_RESOURCE_BUSY  Device or resource busy
+ * @retval #BT_ERROR_OPERATION_FAILED  Operation failed
+ * @see  bt_opp_server_push_requested_cb()
+ * @see  bt_opp_server_deinitialize()
+ * @see  bt_opp_server_accept()
+ * @see  bt_opp_server_reject()
+ */
+int bt_opp_server_initialize(const char *destination, bt_opp_server_push_requested_cb push_requested_cb, void *user_data);
+
+/**
+ * @ingroup CAPI_NETWORK_BLUETOOTH_OPP_SERVER_MODULE
+ * @brief Initializes the Bluetooth OPP server requested by bt_opp_server_connection_requested_cb().
+ * @details No popup appears when an OPP connection is requested from a remote device.
+ * Instead, @a connection_requested_cb() will be called.
+ * At that time, you can call either bt_opp_server_accept() or bt_opp_server_reject().
+ * @remarks This function must be called to start Bluetooth OPP server. \n
+ * You must free all resources of the Bluetooth service by calling bt_opp_server_deinitialize() if Bluetooth OPP service is no longer needed.
+ * @param[in] destination  The destination path
+ * @param[in] connection_requested_cb  The callback called when an OPP connection is requested
+ * @param[in] user_data The user data to be passed to the callback function
+ * @return 0 on success, otherwise a negative error value.
+ * @retval #BT_ERROR_NONE  Successful
+ * @retval #BT_ERROR_NOT_INITIALIZED  Not initialized
+ * @retval #BT_ERROR_NOT_ENABLED  Not enabled
+ * @retval #BT_ERROR_INVALID_PARAMETER  Invalid parameter
+ * @retval #BT_ERROR_RESOURCE_BUSY  Device or resource busy
+ * @retval #BT_ERROR_OPERATION_FAILED  Operation failed
+ * @see  bt_opp_server_connection_requested_cb()
+ * @see  bt_opp_server_deinitialize()
+ * @see  bt_opp_server_accept_connection()
+ * @see  bt_opp_server_reject_connection()
+ */
+int bt_opp_server_initialize_by_connection_request(const char *destination, bt_opp_server_connection_requested_cb connection_requested_cb, void *user_data);
+
+/**
+ * @ingroup CAPI_NETWORK_BLUETOOTH_OPP_SERVER_MODULE
+ * @brief Denitializes the Bluetooth OPP server.
+ * @return 0 on success, otherwise a negative error value.
+ * @retval #BT_ERROR_NONE  Successful
+ * @retval #BT_ERROR_NOT_INITIALIZED  Not initialized
+ * @retval #BT_ERROR_NOT_ENABLED  Not enabled
+ * @retval #BT_ERROR_OPERATION_FAILED  Operation failed
+ * @see  bt_opp_server_initialize()
+ * @see  bt_opp_server_deinitialize()
+ * @see  bt_opp_server_initialize()
+ */
+int bt_opp_server_deinitialize(void);
+
+/* New OPP API*/
 int bt_opp_init(void);
 
 int bt_opp_deinit(void);
 
-typedef void (*bt_opp_server_push_requested_cb)(
+typedef void (*bt_opp_server_push_file_requested_cb)(
                        const char *remote_address,
                        const char *name,
                        uint64_t size,
@@ -2056,7 +2145,7 @@ typedef void (*bt_opp_server_push_requested_cb)(
 
 int bt_opp_register_server(
                        const char *dir,
-                       bt_opp_server_push_requested_cb push_requested_cb,
+                       bt_opp_server_push_file_requested_cb push_requested_cb,
                        void *user_data);
 
 int bt_opp_unregister_server(void);