capi: Added new CAPI to start/stop device monitor
authorSaurav Babu <saurav.babu@samsung.com>
Fri, 20 Apr 2018 04:50:34 +0000 (10:20 +0530)
committersaerome.kim <saerome.kim@samsung.com>
Mon, 2 Jul 2018 10:38:50 +0000 (19:38 +0900)
Signed-off-by: Saurav Babu <saurav.babu@samsung.com>
capi/include/companion.h
capi/src/companion.c
capi/src/companion_gdbus.xml
capi/src/companion_private.h

index 00ff83e..9928a85 100644 (file)
@@ -68,6 +68,7 @@ typedef enum {
        COMP_ERROR_ALREADY_IN_PROGRESS = TIZEN_ERROR_COMP | 0x05, /**< Operation now in progress */
        COMP_ERROR_ALREADY_INITIALIZED = TIZEN_ERROR_COMP | 0x06, /**< Already initilized */
        COMP_ERROR_NO_DATA = TIZEN_ERROR_COMP | 0x07, /**< No Data */
+       COMP_ERROR_NOT_STARTED = TIZEN_ERROR_COMP | 0x08, /**< Not Started */
        COMP_ERROR_UNKNOWN = -999,
 } comp_error_e;
 
@@ -856,6 +857,16 @@ typedef enum {
 } companion_device_type_e;
 
 /**
+ * @brief Device Status.
+ *
+ * @since_tizen 5.0
+ */
+typedef enum {
+       COMPANION_DEVICE_ADDED = 0, /**< Device Added */
+       COMPANION_DEVICE_REMOVED = 1, /**< Device Removed */
+} companion_device_status_e;
+
+/**
  * @brief Called after companion_device_find().
  * @details This function can receive a device found.
  *
@@ -916,6 +927,30 @@ typedef void (*companion_device_find_finish_cb)(int result, void *user_data);
 typedef void (*companion_device_send_data_finish_cb)(int result, char *resp_data,
                void *user_data);
 
+/**
+ * @brief Callback function pointer to be regsitered after enabling device
+ * monitor
+ *
+ * @since_tizen 5.0
+ * @privlevel public
+ * @privilege %http://tizen.org/privilege/internet
+ *
+ * @remarks The @a uuid, @arg should not be released.
+ * @remarks The @a uuid, @arg can be used only in the callback. To use outside, make a copy.
+ * @remarks The @a group_name, @arg should not be released.
+ * @remarks The @a group_name, @arg can be used only in the callback. To use outside, make a copy.
+ *
+ * @param[out] uuid Device ID
+ * @param[out] group_name Group name
+ * @param[out] status Device Status
+ * @param[out] user_data User data pointer
+ *
+ * @pre The callback must be registered with companion_request_result_callback()
+ *
+ * @see companion_device_monitor_start()
+ */
+typedef void (*companion_device_monitor_result_cb)(char *uuid, char *group_name,
+                                       companion_device_status_e status, void *user_data);
 
 /**
  * @brief Finds candidate devices to include my groups in the network.
@@ -1223,6 +1258,11 @@ int companion_device_information_get_device_type(companion_device_h device,
 int companion_device_information_get_model_name(companion_device_h device,
                char **model_name);
 
+int companion_device_monitor_start(companion_h handle,
+                                         companion_device_monitor_result_cb cb, void *user_data);
+
+int companion_device_monitor_stop(companion_h handle);
+
 /**
  * @}
  */
index f61658e..c72089c 100644 (file)
@@ -1117,3 +1117,57 @@ EXPORT_API int companion_request_result_callback(companion_h handle,
 
        return ret;
 }
+
+EXPORT_API int companion_device_monitor_start(companion_h handle,
+                                         companion_device_monitor_result_cb cb, void *user_data)
+{
+       int ret = COMP_ERROR_NONE;
+       GError *error = NULL;
+
+       CHECK_FEATURE_SUPPORTED(COMPANION_FEATURE);
+
+       comp_manager_s *_handle = handle;
+       companion_check_null_ret_error("handle", handle,
+                                                                  COMP_ERROR_INVALID_PARAMETER);
+
+       group_call_start_invited_device_monitor_sync(_handle->group_proxy, 1, &ret,
+                                                        NULL, &error);
+       if (ret != COMP_ERROR_NONE) {
+               _ERR("Failed to start monitor");
+               return ret;
+       }
+
+       _handle->monitor_result_cb.cb = cb;
+       _handle->monitor_result_cb.user_data = user_data;
+
+       return ret;
+}
+
+EXPORT_API int companion_device_monitor_stop(companion_h handle)
+{
+       int ret = COMP_ERROR_NONE;
+       GError *error = NULL;
+
+       CHECK_FEATURE_SUPPORTED(COMPANION_FEATURE);
+
+       comp_manager_s *_handle = handle;
+       companion_check_null_ret_error("handle", handle,
+                                                                  COMP_ERROR_INVALID_PARAMETER);
+
+       if (_handle->monitor_result_cb.cb == NULL) {
+               _ERR("Monitor is not started");
+               return COMP_ERROR_NOT_STARTED;
+       }
+
+       group_call_start_invited_device_monitor_sync(_handle->group_proxy, 0, &ret,
+                                                        NULL, &error);
+       if (ret != COMP_ERROR_NONE) {
+               _ERR("Failed to stop monitor");
+               return ret;
+       }
+
+       _handle->monitor_result_cb.cb = NULL;
+       _handle->monitor_result_cb.user_data = NULL;
+
+       return ret;
+}
index 94e1fa5..cb4be58 100644 (file)
                        <arg type="s" name="group_name" direction="in" />
                        <arg type="i" name="result" direction="out" />
                </method>
+               <method name="StartInvitedDeviceMonitor">
+                       <arg type="i" name="start" direction="in" />
+                       <arg type="i" name="result" direction="out" />
+               </method>
                <!-- Signal (D-Bus) definitions -->
                <signal name="GroupFound">
                        <arg type="a{sv}" name="group_info" direction="out" />
                        <arg type="(iay)" name="arg" direction="out" />
                        <arg type="i" name="result" direction="out" />
                </signal>
+               <signal name="DeviceMonitorResult">
+                       <arg type="s" name="uuid" direct="out" />
+                       <arg type="s" name="group_name" direct="out" />
+                       <arg type="s" name="status" direct="out" />
+               </signal>
        </interface>
 </node>
index 5879841..f6bbfa3 100644 (file)
@@ -144,6 +144,15 @@ typedef struct _request_result_cb_t {
 } request_result_cb_t;
 
 /**
+ * @brief Sending device monitor result callback structure
+ * @since_tizen 5.0
+ */
+typedef struct _monitor_result_cb_t {
+       companion_device_monitor_result_cb cb; /**< User callback to be called */
+       void *user_data; /**< User data pointer */
+} monitor_result_cb_t;
+
+/**
  * @brief The companion-manager context
  * @since_tizen 5.0
  */
@@ -164,6 +173,7 @@ typedef struct _comp_manager_s {
        device_eject_result_cb_t device_eject_result_cb; /**< When it called after ejecting the device done or timeout */
        send_data_finish_cb_t send_data_finish_cb; /**< When it called after sending the device done or timeout */
        request_result_cb_t request_result_cb; /**< When it called after sending private commands or timeout */
+       monitor_result_cb_t monitor_result_cb; /**< It is called after device status is changed */
 } comp_manager_s;
 
 /**