capi: Change callback function called after request functions
authorsaerome.kim <saerome.kim@samsung.com>
Tue, 3 Apr 2018 11:50:33 +0000 (20:50 +0900)
committersaerome.kim <saerome.kim@samsung.com>
Mon, 2 Jul 2018 10:38:49 +0000 (19:38 +0900)
capi/demo/comp-manager.c
capi/demo/main.c
capi/doc/companion_doc.h [changed mode: 0644->0755]
capi/include/companion.h
capi/include/companion_internal.h [new file with mode: 0644]
capi/src/companion.c

index cbb9e50..a32adb1 100644 (file)
@@ -49,29 +49,32 @@ void receive_request_result(char *cmd, char *arg, int ret, void *user_data)
 {
        msg("_request_result_cb is called");
 
-       if (cmd != NULL) {
-               if (strcmp("1", cmd) == 0) {
-                       msgp("[CMD] Request Create Group [%s(0x%X)]", comp_error_to_string(ret), ret);
-                       if (ret == 0 && arg != NULL) {
-                               msgb("Created Group name is %s", arg);
-                               run_group_find(NULL, NULL);
-                               run_devices_find(NULL, NULL);
-                       }
-               } else if (strcmp("2", cmd) == 0) {
-                       msgp("[CMD] Request Invite [%s(0x%X)]", comp_error_to_string(ret), ret);
-                       if (ret == 0 && arg != NULL)
-                               msgb("Invited Device ID is %s", arg);
-               } else if (strcmp("3", cmd) == 0) {
-                       msgp("[CMD] Request Eject [%s(0x%X)]", comp_error_to_string(ret), ret);
-                       if (ret == 0 && arg != NULL)
-                               msgb("Ejected Device ID is %s", arg);
-               } else if (strcmp("4", cmd) == 0) {
-                       msgp("[CMD] Request Delete Group [%s(0x%X)]", comp_error_to_string(ret), ret);
-                       if (ret == 0 && arg != NULL)
-                               msgb("Deleted Group name is %s", arg);
-               } else {
-                       msgp("[Recv][%d] %s", strlen(arg), arg);
+       if (cmd == NULL) {
+               msgp("cmd is null [%s(0x%X)]", comp_error_to_string(ret), ret);
+               return;
+       }
+
+       if (strcmp("1", cmd) == 0) {
+               msgp("[CMD] Request Create Group [%s(0x%X)]", comp_error_to_string(ret), ret);
+               if (ret == COMP_ERROR_NONE && arg != NULL) {
+                       msgb("Created Group name is %s", arg);
+                       run_group_find(NULL, NULL);
+                       run_devices_find(NULL, NULL);
                }
+       } else if (strcmp("2", cmd) == 0) {
+               msgp("[CMD] Request Invite [%s(0x%X)]", comp_error_to_string(ret), ret);
+               if (ret == COMP_ERROR_NONE && arg != NULL)
+                       msgb("Invited Device ID is %s", arg);
+       } else if (strcmp("3", cmd) == 0) {
+               msgp("[CMD] Request Eject [%s(0x%X)]", comp_error_to_string(ret), ret);
+               if (ret == COMP_ERROR_NONE && arg != NULL)
+                       msgb("Ejected Device ID is %s", arg);
+       } else if (strcmp("4", cmd) == 0) {
+               msgp("[CMD] Request Delete Group [%s(0x%X)]", comp_error_to_string(ret), ret);
+               if (ret == COMP_ERROR_NONE && arg != NULL)
+                       msgb("Deleted Group name is %s", arg);
+       } else {
+               msgp("[Recv][%d] %s", strlen(arg), arg);
        }
 }
 
@@ -568,11 +571,6 @@ int run_device_show_my_device(MManager *mm, struct menu_data *menu)
        return RET_SUCCESS;
 }
 
-static void _group_leave_finish_cb(int result, void *user_data)
-{
-       msgb("\rleave operation finished");
-}
-
 static int run_group_leave(MManager *mm, struct menu_data *menu)
 {
        int ret;
@@ -597,7 +595,7 @@ static int run_group_leave(MManager *mm, struct menu_data *menu)
                }
        }
 
-       ret = companion_request_leave_group (handle, group, _group_leave_finish_cb, NULL);
+       ret = companion_request_leave_group (handle, group, receive_request_result, NULL);
        if (COMP_ERROR_NONE != ret) {
                msgr("Failed to Leave Group: [%s(0x%X)]", comp_error_to_string(ret), ret);
                return RET_FAILURE;
@@ -646,11 +644,6 @@ static int run_group_show(MManager *mm, struct menu_data *menu)
        return RET_SUCCESS;
 }
 
-static void _group_join_finish_cb(int result, void *user_data)
-{
-       msgp("\rjoin operation finished");
-}
-
 static int run_group_join(MManager *mm, struct menu_data *menu)
 {
        int ret;
@@ -675,7 +668,7 @@ static int run_group_join(MManager *mm, struct menu_data *menu)
                }
        }
 
-       ret = companion_request_join_group(handle, group, _group_join_finish_cb, NULL);
+       ret = companion_request_join_group(handle, group, receive_request_result, NULL);
        if (COMP_ERROR_NONE != ret) {
                msgr("Failed to Join Group: [%s(0x%X)]", comp_error_to_string(ret), ret);
                return RET_FAILURE;
@@ -967,11 +960,6 @@ int run_device_show_mowned_device(MManager *mm, struct menu_data *menu)
        return RET_SUCCESS;
 }
 
-static void _group_create_finish_cb(int result, void *user_data)
-{
-       msgb("\rCreate operation finished");
-}
-
 static int run_request_create_group(MManager *mm, struct menu_data *menu)
 {
        int ret = 0;
@@ -1005,7 +993,7 @@ static int run_request_create_group(MManager *mm, struct menu_data *menu)
        }
 
        ret = companion_request_create_group(handle, device, request_groupid,
-               _group_create_finish_cb, NULL);
+               receive_request_result, NULL);
        if (COMP_ERROR_NONE != ret) {
                msgr("Failed to Request Create Group: [%s(0x%X)]",
                        comp_error_to_string(ret), ret);
@@ -1018,11 +1006,6 @@ static int run_request_create_group(MManager *mm, struct menu_data *menu)
        return RET_SUCCESS;
 }
 
-static void _group_invite_finish_cb(int result, void *user_data)
-{
-       msgb("\rInvite operation finished");
-}
-
 static int run_request_invite(MManager *mm, struct menu_data *menu)
 {
        int ret = 0;
@@ -1074,7 +1057,7 @@ static int run_request_invite(MManager *mm, struct menu_data *menu)
        }
 
        ret = companion_request_invite_device(handle, group, device, pin,
-               _group_invite_finish_cb, NULL);
+               receive_request_result, NULL);
        if (COMP_ERROR_NONE != ret) {
                msgr("Failed to Request Invite: [%s(0x%X)]", comp_error_to_string(ret), ret);
                return RET_FAILURE;
@@ -1086,11 +1069,6 @@ static int run_request_invite(MManager *mm, struct menu_data *menu)
        return RET_SUCCESS;
 }
 
-static void _group_eject_finish_cb(int result, void *user_data)
-{
-       msgb("\rEject operation finished");
-}
-
 static int run_request_eject(MManager *mm, struct menu_data *menu)
 {
        int ret = 0;
@@ -1141,7 +1119,7 @@ static int run_request_eject(MManager *mm, struct menu_data *menu)
                }
        }
 
-       ret = companion_request_eject_device(handle, group, device, _group_eject_finish_cb,
+       ret = companion_request_eject_device(handle, group, device, receive_request_result,
                NULL);
        if (COMP_ERROR_NONE != ret) {
                msgr("Failed to Request Eject: [%s(0x%X)]", comp_error_to_string(ret), ret);
@@ -1153,11 +1131,6 @@ static int run_request_eject(MManager *mm, struct menu_data *menu)
        return RET_SUCCESS;
 }
 
-static void _group_delete_finish_cb(int result, void *user_data)
-{
-       msgb("\rDelete operation finished");
-}
-
 static int run_request_delete_group(MManager *mm, struct menu_data *menu)
 {
        int ret = 0;
@@ -1188,7 +1161,7 @@ static int run_request_delete_group(MManager *mm, struct menu_data *menu)
                }
        }
 
-       ret = companion_request_delete_group(handle, group, _group_delete_finish_cb, NULL);
+       ret = companion_request_delete_group(handle, group, receive_request_result, NULL);
        if (COMP_ERROR_NONE != ret) {
                msgr("Failed to Request Delete Group: [%s(0x%X)]",
                        comp_error_to_string(ret), ret);
index 4dca2d6..b2c1c37 100644 (file)
@@ -81,7 +81,6 @@ static int __init_func(MManager *mm, struct menu_data *menu)
                                comp_error_to_string(ret), ret);
                return RET_FAILURE;
        }
-       companion_request_result_callback(handle, receive_request_result, NULL);
 
        return RET_SUCCESS;
 }
old mode 100644 (file)
new mode 100755 (executable)
index e4829b0..6b460a4
@@ -46,7 +46,7 @@
  */
 
 /**
- * @defgroup CAPI_NETWORK_COMPANION_GROUP_MODULE Local Group Management
+ * @defgroup CAPI_NETWORK_COMPANION_GROUP_MODULE Group Management
  * @brief The Companion API provides functions for device management.
  * @ingroup CAPI_NETWORK_COMPANION_MODULE
  *
index 890bdad..638af2e 100644 (file)
@@ -490,22 +490,26 @@ int companion_group_eject_device(companion_h handle, companion_group_h group,
  */
 
 /**
- * @brief Callback function potiner to be regsitered by calling request to remote groups.
+ * @brief Callback function potiner to be regsitered after sending requests.
  *
  * @since_tizen 5.0
  * @privlevel public
  * @privilege %http://tizen.org/privilege/internet
  *
+ * @remarks The @a cmd, @arg should not be released.
+ * @remarks The @a cmd, @arg can be used only in the callback. To use outside, make a copy.
  *
- * @param[out] result Return code
+ * @param[out] cmd Command
+ * @param[out] arg Argument
+ * @param[out] ret Return code
  * @param[out] user_data User data pointer
  *
- * @see companion_request_join_group()
- * @see companion_request_leave_group()
- * @see companion_device_send_data()
- * @see companion_device_send_data()
+ * @pre The callback must be registered with companion_request_result_callback()
+ *
+ * @see companion_request_result_callback()
  */
-typedef void (*companion_request_done_cb)(int result, void *user_data);
+typedef void (*companion_request_result_cb)(char *cmd, char *arg, int ret,
+               void *user_data);
 
 /**
  * @brief Requests my device to be joined to remote group.
@@ -534,7 +538,7 @@ typedef void (*companion_request_done_cb)(int result, void *user_data);
  *
  */
 int companion_request_join_group(companion_h handle, companion_group_h group,
-               companion_request_done_cb cb, void *user_data);
+               companion_request_result_cb cb, void *user_data);
 
 /**
  * @brief Requests my device to be exit from remote group.
@@ -563,7 +567,7 @@ int companion_request_join_group(companion_h handle, companion_group_h group,
  *
  */
 int companion_request_leave_group (companion_h handle, companion_group_h group,
-               companion_request_done_cb cb, void *user_data);
+               companion_request_result_cb cb, void *user_data);
 
 /**
  * @brief Requests to create a group.
@@ -593,7 +597,7 @@ int companion_request_leave_group (companion_h handle, companion_group_h group,
  *
  */
 int companion_request_create_group(companion_h handle,
-       companion_device_h device, char *group_name, companion_request_done_cb cb,
+       companion_device_h device, char *group_name, companion_request_result_cb cb,
        void *user_data);
 
 /**
@@ -626,7 +630,7 @@ int companion_request_create_group(companion_h handle,
  *
  */
 int companion_request_invite_device(companion_h handle, companion_group_h group,
-               companion_device_h device, char *PIN, companion_request_done_cb cb,
+               companion_device_h device, char *PIN, companion_request_result_cb cb,
                void *user_data);
 
 /**
@@ -656,7 +660,7 @@ int companion_request_invite_device(companion_h handle, companion_group_h group,
  *
  */
 int companion_request_eject_device(companion_h handle, companion_group_h group,
-       companion_device_h device, companion_request_done_cb cb, void *user_data);
+       companion_device_h device, companion_request_result_cb cb, void *user_data);
 
 /**
  * @brief Requests to delete the group.
@@ -684,56 +688,7 @@ int companion_request_eject_device(companion_h handle, companion_group_h group,
  *
  */
 int companion_request_delete_group(companion_h handle, companion_group_h group,
-               companion_request_done_cb cb, void *user_data);
-
-/**
- * @brief Callback function potiner to be regsitered by calling
- * companion_request_result_callback().
- *
- * @since_tizen 5.0
- * @privlevel public
- * @privilege %http://tizen.org/privilege/internet
- *
- * @remarks The @a cmd, @arg should not be released.
- * @remarks The @a cmd, @arg can be used only in the callback. To use outside, make a copy.
- *
- * @param[out] cmd Command
- * @param[out] arg Argument
- * @param[out] ret Return code
- * @param[out] user_data User data pointer
- *
- * @pre The callback must be registered with companion_request_result_callback()
- *
- * @see companion_request_result_callback()
- */
-typedef void (*companion_request_result_cb)(char *cmd, char *arg, int ret,
-               void *user_data);
-
-/**
- * @brief Registers request result callback funtion.
- * @details This function registers the callback function for requested group management
- * functions and receive processing results after the request complete.
- *
- * @since_tizen 5.0
- *
- * @param[in] handle The companion manager handle
- * @param[in] callback Callback function pointer
- * @param[in] user_data User data pointer
- *
- *
- * @return 0 on success, otherwise a negative error value.
- * @retval #COMP_ERROR_NONE Successful
- * @retval #COMP_ERROR_INVALID_PARAMETER Invalid parameter
- *
- * @see companion_request_create_group()
- * @see companion_request_invite_device()
- * @see companion_request_eject_device()
- * @see companion_request_delete_group()
- * @see companion_device_send_data()
- *
- */
-int companion_request_result_callback(companion_h handle,
-               companion_request_result_cb callback, void *user_data);
+               companion_request_result_cb cb, void *user_data);
 
 /**
  * @}
@@ -745,30 +700,6 @@ int companion_request_result_callback(companion_h handle,
  */
 
 /**
- * @brief Creates a group handle.
- *
- * @since_tizen 5.0
- *
- * @remarks The @a group should be released using companion_group_information_destroy().
- *
- * @param[in] group Group handle
- *
- * @return 0 on success, otherwise a negative error value.
- * @retval #COMP_ERROR_NONE Successful
- * @retval #COMP_ERROR_INVALID_PARAMETER Invalid parameter
- *
- * @see companion_group_information_clone()
- * @see companion_group_information_destroy()
- * @see companion_group_information_get_type()
- * @see companion_group_information_get_resource_type()
- * @see companion_group_information_get_uri_path()
- * @see companion_group_information_get_name()
- * @see companion_group_information_get_host_addr()
- *
- */
-int companion_group_information_create(companion_group_h* group);
-
-/**
  * @brief Clones the group handle.
  *
  * @since_tizen 5.0
@@ -1178,27 +1109,6 @@ int companion_device_send_data(companion_h handle, companion_device_h device, ch
  * @{
  */
 
-/**
- * @brief Creates a device handle.
- *
- * @since_tizen 5.0
- *
- * @remarks The @a device should be released using companion_device_information_destroy().
- *
- * @param[out] device Device handle
- *
- * @return 0 on success, otherwise a negative error value.
- * @retval #COMP_ERROR_NONE Successful
- * @retval #COMP_ERROR_INVALID_PARAMETER Invalid parameter
- *
- * @see companion_device_information_clone()
- * @see companion_device_information_destroy()
- * @see companion_device_information_get_device_id()
- * @see companion_device_information_get_ip()
- * @see companion_device_information_get_device_type()
- *
- */
-int companion_device_information_create(companion_device_h* device);
 
 /**
  * @brief Clones the device handle.
diff --git a/capi/include/companion_internal.h b/capi/include/companion_internal.h
new file mode 100644 (file)
index 0000000..e970fe8
--- /dev/null
@@ -0,0 +1,105 @@
+/*
+ * Network Configuration Module
+ *
+ * Copyright (c) 2017 Samsung Electronics Co., Ltd. All rights reserved.
+ *
+ * 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 __TIZEN_NETWORK_COMPANION_INTERNAL_H__
+#define __TIZEN_NETWORK_COMPANION_INTERNAL_H__
+
+#include <companion.h>
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+/**
+ * @brief Creates a group handle.
+ *
+ * @since_tizen 5.0
+ *
+ * @remarks The @a group should be released using companion_group_information_destroy().
+ *
+ * @param[in] group Group handle
+ *
+ * @return 0 on success, otherwise a negative error value.
+ * @retval #COMP_ERROR_NONE Successful
+ * @retval #COMP_ERROR_INVALID_PARAMETER Invalid parameter
+ *
+ * @see companion_group_information_clone()
+ * @see companion_group_information_destroy()
+ * @see companion_group_information_get_type()
+ * @see companion_group_information_get_resource_type()
+ * @see companion_group_information_get_uri_path()
+ * @see companion_group_information_get_name()
+ * @see companion_group_information_get_host_addr()
+ *
+ */
+int companion_group_information_create(companion_group_h* group);
+
+
+/**
+ * @brief Creates a device handle.
+ *
+ * @since_tizen 5.0
+ *
+ * @remarks The @a device should be released using companion_device_information_destroy().
+ *
+ * @param[out] device Device handle
+ *
+ * @return 0 on success, otherwise a negative error value.
+ * @retval #COMP_ERROR_NONE Successful
+ * @retval #COMP_ERROR_INVALID_PARAMETER Invalid parameter
+ *
+ * @see companion_device_information_clone()
+ * @see companion_device_information_destroy()
+ * @see companion_device_information_get_device_id()
+ * @see companion_device_information_get_ip()
+ * @see companion_device_information_get_device_type()
+ *
+ */
+int companion_device_information_create(companion_device_h* device);
+
+/**
+ * @brief Registers request result callback funtion.
+ * @details This function registers the callback function for requested group management
+ * functions and receive processing results after the request complete.
+ *
+ * @since_tizen 5.0
+ *
+ * @param[in] handle The companion manager handle
+ * @param[in] callback Callback function pointer
+ * @param[in] user_data User data pointer
+ *
+ *
+ * @return 0 on success, otherwise a negative error value.
+ * @retval #COMP_ERROR_NONE Successful
+ * @retval #COMP_ERROR_INVALID_PARAMETER Invalid parameter
+ *
+ * @see companion_request_create_group()
+ * @see companion_request_invite_device()
+ * @see companion_request_eject_device()
+ * @see companion_request_delete_group()
+ * @see companion_device_send_data()
+ *
+ */
+int companion_request_result_callback(companion_h handle,
+               companion_request_result_cb callback, void *user_data);
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* __TIZEN_NETWORK_COMPANION_INTERNAL_H__ */
index 74c10ca..e368e60 100644 (file)
@@ -255,36 +255,6 @@ EXPORT_API int companion_group_get_found_groups(companion_h handle,
        return ret;
 }
 
-EXPORT_API int companion_request_join_group(companion_h handle, companion_group_h group,
-       companion_group_find_finish_cb callback, void *user_data)
-{
-       int ret = COMP_ERROR_NONE;
-
-       CHECK_FEATURE_SUPPORTED(COMPANION_FEATURE);
-
-       NOTUSED(handle);
-       NOTUSED(group);
-       NOTUSED(callback);
-       NOTUSED(user_data);
-
-       return ret;
-}
-
-EXPORT_API int companion_request_leave_group (companion_h handle,
-       companion_group_h group, companion_group_find_finish_cb callback, void *user_data)
-{
-       int ret = COMP_ERROR_NONE;
-
-       CHECK_FEATURE_SUPPORTED(COMPANION_FEATURE);
-
-       NOTUSED(handle);
-       NOTUSED(group);
-       NOTUSED(callback);
-       NOTUSED(user_data);
-
-       return ret;
-}
-
 EXPORT_API int companion_device_find(companion_h handle, int timeout,
        companion_device_found_cb found_cb, companion_device_find_finish_cb finish_cb,
        void *user_data)
@@ -943,7 +913,7 @@ EXPORT_API int companion_device_information_get_device_type(
 }
 
 EXPORT_API int companion_request_create_group(companion_h handle,
-       companion_device_h device, char *group_name, companion_request_done_cb cb,
+       companion_device_h device, char *group_name, companion_request_result_cb cb,
        void *user_data)
 {
        int ret = COMP_ERROR_NONE;
@@ -970,9 +940,39 @@ EXPORT_API int companion_request_create_group(companion_h handle,
        return ret;
 }
 
+EXPORT_API int companion_request_join_group(companion_h handle, companion_group_h group,
+       companion_request_result_cb callback, void *user_data)
+{
+       int ret = COMP_ERROR_NONE;
+
+       CHECK_FEATURE_SUPPORTED(COMPANION_FEATURE);
+
+       NOTUSED(handle);
+       NOTUSED(group);
+       NOTUSED(callback);
+       NOTUSED(user_data);
+
+       return ret;
+}
+
+EXPORT_API int companion_request_leave_group (companion_h handle,
+       companion_group_h group, companion_request_result_cb callback, void *user_data)
+{
+       int ret = COMP_ERROR_NONE;
+
+       CHECK_FEATURE_SUPPORTED(COMPANION_FEATURE);
+
+       NOTUSED(handle);
+       NOTUSED(group);
+       NOTUSED(callback);
+       NOTUSED(user_data);
+
+       return ret;
+}
+
 EXPORT_API int companion_request_invite_device(companion_h handle,
        companion_group_h group, companion_device_h device, char *PIN,
-       companion_request_done_cb cb, void *user_data)
+       companion_request_result_cb cb, void *user_data)
 {
        int ret = COMP_ERROR_NONE;
 
@@ -1001,7 +1001,7 @@ EXPORT_API int companion_request_invite_device(companion_h handle,
 }
 
 EXPORT_API int companion_request_eject_device(companion_h handle,
-       companion_group_h group, companion_device_h device, companion_request_done_cb cb,
+       companion_group_h group, companion_device_h device, companion_request_result_cb cb,
        void *user_data)
 {
        int ret = COMP_ERROR_NONE;
@@ -1031,7 +1031,7 @@ EXPORT_API int companion_request_eject_device(companion_h handle,
 }
 
 EXPORT_API int companion_request_delete_group(companion_h handle,
-       companion_group_h group, companion_request_done_cb cb, void *user_data)
+       companion_group_h group, companion_request_result_cb cb, void *user_data)
 {
        int ret = COMP_ERROR_NONE;