int mdg_device_unregist_channel(mdg_h handle, char *channel_id);
/* Client Side */
-//int mdg_device_get_channels(mdg_h handle, mdg_device_h device,
-// mdg_device_get_channels_cb get_channels_cb, void *user_data);
-
/**
* @brief Sends data to the remote device.
* @details We can send data to devices included in group.
unsigned char *data, int len,
mdg_device_send_data_finish_cb finish_cb, void *user_data);
+typedef void (*mdg_send_file_progress_cb)(const char *file_path, long send_size,
+ long total_size, int percent, void *user_data);
+typedef void (*mdg_send_file_finish_cb)(int result, mdg_device_h device, void *user_data);
+
+int mdg_device_send_file(mdg_h handle, mdg_device_h device, char *file_path,
+ mdg_send_file_progress_cb progress_cb, mdg_send_file_finish_cb finish_cb, void *user_data);
+
/**
* @}
*/
return ret;
}
+EXPORT_API int mdg_device_send_file(mdg_h handle, mdg_device_h device,
+ char *file_path, mdg_send_file_progress_cb progress_cb, mdg_send_file_finish_cb finish_cb, void *user_data)
+{
+ int ret = MDG_ERROR_NONE;
+ GError *error = NULL;
+
+ CHECK_FEATURE_SUPPORTED(MDG_FEATURE);
+
+ mdg_manager_s *_handle = handle;
+ mdg_check_null_ret_error("handle", handle, MDG_ERROR_INVALID_PARAMETER);
+ CHECK_HANDLE_IS_VALID(handle);
+
+ mdg_device_s *dev = (mdg_device_s *)device;
+ mdg_check_null_ret_error("dev", dev, MDG_ERROR_INVALID_PARAMETER);
+ mdg_check_null_ret_error("file_path", file_path, MDG_ERROR_INVALID_PARAMETER);
+
+ mdg_device_h cloned_device = NULL;
+ mdg_device_info_clone(&cloned_device, device);
+
+ _handle->send_file_cb.finish_cb = finish_cb;
+ _handle->send_file_cb.progress_cb = progress_cb;
+ _handle->send_file_cb.device = cloned_device;
+ _handle->send_file_cb.user_data = user_data;
+
+ group_call_send_file_sync(_handle->group_proxy, dev->device_id, dev->addr,
+ dev->secure_port, file_path, &ret, NULL, &error);
+ if (error) {
+ _ERR("Failed DBus call [%s]", error->message);
+ g_error_free(error);
+ ret = MDG_ERROR_IO_ERROR;
+ }
+
+ return ret;
+}
+
EXPORT_API int mdg_device_get_local_device(mdg_h handle,
mdg_device_h *device)
{
_DBG("Event occured : %d", event_type);
- if (event_type == MDG_EVENT_GROUP_FOUND) {
+ switch (event_type) {
+ case MDG_EVENT_GROUP_FOUND:
+ {
mdg_group_s *group = NULL;
group = mdg_get_group_from_variant(va);
} else {
_ERR("The callback not exists");
}
- } else if (event_type == MDG_EVENT_GROUP_FIND_FINISH) {
+ break;
+ }
+ case MDG_EVENT_GROUP_FIND_FINISH:
+ {
if (handle->group_find_finish_cb.finish_cb) {
handle->group_find_finish_cb.finish_cb(ret,
handle->group_find_finish_cb.user_data);
} else {
_ERR("The callback not exists");
}
- } else if (event_type == MDG_EVENT_DEVICE_FOUND) {
+ break;
+ }
+ case MDG_EVENT_DEVICE_FOUND:
+ {
mdg_device_s *device = NULL;
device = mdg_get_device_from_variant(va);
} else {
_ERR("The callback not exists");
}
- } else if (event_type == MDG_EVENT_DEVICE_FIND_FINISH) {
+ break;
+ }
+ case MDG_EVENT_DEVICE_FIND_FINISH:
+ {
if (handle->device_find_finish_cb.finish_cb) {
handle->device_find_finish_cb.finish_cb(ret,
handle->device_find_finish_cb.user_data);
} else {
_ERR("The callback not exists");
}
- } else if (event_type == MDG_EVENT_INVITE_DEVICE_FINISH) {
+ break;
+ }
+ case MDG_EVENT_INVITE_DEVICE_FINISH:
+ {
if (handle->device_invite_finish_cb.finish_cb) {
mdg_device_s *device = (mdg_device_s *)(handle->device_invite_finish_cb.device);
if (device != NULL) {
} else {
_ERR("The callback not exists");
}
- } else if (event_type == MDG_EVENT_EJECT_DEVICE_FINISH) {
+ break;
+ }
+ case MDG_EVENT_EJECT_DEVICE_FINISH:
+ {
if (handle->device_eject_finish_cb.finish_cb) {
handle->device_eject_finish_cb.finish_cb(ret,
handle->device_eject_finish_cb.user_data);
} else {
_ERR("The callback not exists");
}
- } else if (event_type == MDG_EVENT_SEND_DATA_FINISH) {
+ break;
+ }
+ case MDG_EVENT_SEND_DATA_FINISH:
+ {
if (handle->send_data_finish_cb.finish_cb) {
handle->send_data_finish_cb.finish_cb(ret,
handle->send_data_finish_cb.user_data);
} else {
_ERR("The callback not exists");
}
- } else if (event_type == MDG_EVENT_REQ_CHANNEL_LIST_FINISH) {
+ break;
+ }
+ case MDG_EVENT_REQ_CHANNEL_LIST_FINISH:
+ {
char *device_id;
char *channel_id;
} else {
_ERR("The callback not exists");
}
- } else if (event_type == MDGD_EVENT_RECEIVE_DATA) {
+ break;
+ }
+ case MDG_EVENT_RECEIVE_DATA:
+ {
char *device_id;
char *channel_id;
unsigned char *data;
if (channel != NULL)
channel->cb(0, device_id, channel_id, data, data_len, channel->user_data);
-
- } else {
+ break;
+ }
+ case MDG_EVENT_SEND_FILE_PROGRESS:
+ {
+ if (handle->send_file_cb.progress_cb) {
+ int percent = 0;
+ long send_size, total_size;
+ char *file_path;
+ mdg_get_progress_from_variant(va, &file_path, &send_size, &total_size, &percent);
+ handle->send_file_cb.progress_cb(file_path, send_size, total_size, percent,
+ handle->send_file_cb.user_data);
+ } else {
+ _ERR("The callback not exists");
+ }
+ break;
+ }
+ case MDG_EVENT_SEND_FILE_FINISH:
+ {
+ if (handle->send_file_cb.finish_cb) {
+ mdg_device_s *device = (mdg_device_s *)(handle->send_file_cb.device);
+ handle->send_file_cb.finish_cb(ret, device, handle->send_file_cb.user_data);
+ } else {
+ _ERR("The callback not exists");
+ }
+ break;
+ }
+ default:
_ERR("Unknown Event");
+ break;
}
_END();
<arg type="(iay)" name="data" direction="in"/>
<arg type="i" name="result" direction="out" />
</method>
+ <method name="SendFile">
+ <arg type="s" name="uuid" direction="in" />
+ <arg type="s" name="addr" direction="in"/>
+ <arg type="i" name="port" direction="in"/>
+ <arg type="s" name="file_path" direction="in"/>
+ <arg type="i" name="result" direction="out" />
+ </method>
<method name="RequestCreateGroup">
<arg type="s" name="uuid" direction="in" />
<arg type="s" name="addr" direction="in"/>
} send_data_finish_cb_t;
/**
+ * @brief Sending data to the device done callback structure
+ * @since_tizen 5.0
+ */
+typedef struct _send_file_cb_t {
+ mdg_send_file_progress_cb progress_cb; /**< User callback to be called */
+ mdg_send_file_finish_cb finish_cb; /**< User callback to be called */
+ mdg_device_h device;
+ void *user_data; /**< User data pointer */
+} send_file_cb_t;
+
+/**
* @brief Sending internal commands to the device done callback structure
* @since_tizen 5.0
*/
device_invite_finish_cb_t device_invite_finish_cb; /**< When it called after invinting a device done or timeout */
device_eject_finish_cb_t device_eject_finish_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 */
+ send_file_cb_t send_file_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 */
request_channel_list_finish_cb_t request_channel_list_finish_cb; /**< When it called after sending private commands or timeout */
} mdg_manager_s;
MDG_EVENT_REQUEST_FINISH,
MDG_EVENT_SEND_DATA_FINISH,
MDG_EVENT_REQ_CHANNEL_LIST_FINISH,
- MDGD_EVENT_RECEIVE_DATA,
+ MDG_EVENT_RECEIVE_DATA,
+ MDG_EVENT_RECEIVE_FILE = 10,
+ MDG_EVENT_SEND_FILE_PROGRESS,
+ MDG_EVENT_SEND_FILE_FINISH,
} mdg_event_type_e;
#endif /* __TIZEN_NETWORK_COMMON_MDG_PRIVATE_H__ */
g_variant_iter_free(iter);
}
+
void mdg_get_data_from_variant(GVariant *va, char **device_id, char **channel_id,
unsigned char **data, int *data_len)
{
g_variant_iter_free(iter);
}
+void mdg_get_progress_from_variant(GVariant *va, char **file_path,
+ long *send_size, long *total_size, int *percent)
+{
+ GVariantIter *iter = NULL;
+ const gchar *key;
+ GVariant *key_value = NULL;
+
+ g_variant_get(va, "a{sv}", &iter);
+ while (g_variant_iter_loop(iter, "{sv}", &key, &key_value)) {
+ if (g_strcmp0(key, "FilePath") == 0)
+ *file_path = (char *)g_variant_get_string(key_value, NULL);
+ if (g_strcmp0(key, "SendSize") == 0)
+ *send_size = g_variant_get_int64(key_value);
+ if (g_strcmp0(key, "TotalSize") == 0)
+ *total_size = g_variant_get_int64(key_value);
+ if (g_strcmp0(key, "Percent") == 0)
+ *percent = g_variant_get_int32(key_value);
+ }
+
+ g_variant_iter_free(iter);
+}
+
GVariant *mdg_create_variant_device(mdg_device_s *device)
{
GVariant *va;
void mdg_get_channel_from_variant(GVariant *va, char **device_id, char **channel_id);
void mdg_get_data_from_variant(GVariant *va, char **device_id, char **channel_id,
unsigned char **data, int *data_len);
+void mdg_get_progress_from_variant(GVariant *va, char **file_path,
+ long *send_size, long *total_size, int *percent);
#ifdef __cplusplus
}
return __send_data(devidx, chaidx);
}
-static int __send_file(int devidx, int chaidx)
+void __send_file_progress_cb(const char *file_path, long send_size,
+ long total_size, int percent, void *user_data)
+{
+ msgp("%s %d%% [%ld/%ld]", file_path, percent, send_size, total_size);
+}
+void __send_file_finish_cb(int result, mdg_device_h device, void *user_data)
+{
+ char *addr;
+
+ mdg_device_info_get_addr(device, &addr);
+
+ msgp("Send file to %s Finished [%s]", addr, mdg_error_to_string(result));
+}
+
+static int __send_file(int devidx)
{
int ret = 0;
char *deviceid = NULL;
char *address = NULL;
mdg_device_h device = NULL;
- channel_t *channel = NULL;
+
if (found_invited_device_list) {
device = g_list_nth_data(found_invited_device_list, devidx - 1);
if (NULL == device) {
}
}
- if (found_channel_list) {
- channel = g_list_nth_data(found_channel_list, chaidx - 1);
- if (NULL == channel) {
- msgr("Find local device first");
- return RET_FAILURE;
- }
- }
-
mdg_device_info_get_device_id(device, &deviceid);
mdg_device_info_get_addr(device, &address);
- msgp("Sent to [ID] %s [ADDR] %s [CHANNEL ID] %s", deviceid, address, channel->channel_id);
+ msgp("Sent to [ID] %s [ADDR] %s", deviceid, address);
if (deviceid) {
free(deviceid);
deviceid = NULL;
address = NULL;
}
- ret = mdg_device_send_data(handle, device, channel->channel_id, (unsigned char *)file_path,
- strlen(file_path), _send_data_finish_cb, NULL);
+ ret = mdg_device_send_file(handle, device, file_path,
+ __send_file_progress_cb, __send_file_finish_cb, NULL);
if (MDG_ERROR_NONE != ret)
msgr("Failed to Send Data: [ID] %s [IP] %s", deviceid, address);
static int run_send_file(MManager *mm, struct menu_data *menu)
{
int devidx = 0;
- int chaidx = 0;
int count = g_list_length(found_invited_device_list);
if (0 >= count) {
devidx = 1;
}
}
- if (strlen(channel_idx)) {
- chaidx = (unsigned short)strtol(channel_idx, NULL, 10);
- if (0 >= chaidx) {
- msgp("Invalid index. set to 1");
- chaidx = 1;
- }
- }
- return __send_file(devidx, chaidx);
+
+ return __send_file(devidx);
}
void _invited_device_finish_cb(int result, void *user_data)
static struct menu_data menu_send_file[] = {
{ "0", "Show Found Invited Device(s)", NULL, run_invited_devices_show, NULL },
- { "1", "Show Channel List", NULL, run_channels_show, NULL },
- { "2", "File Path", NULL, NULL, file_path },
- { "3", "Device Index", NULL, NULL, device_idx },
- { "4", "Channel Index", NULL, NULL, channel_idx },
- { "5", "Send", NULL, run_send_file, NULL },
+ { "1", "File Path", NULL, NULL, file_path },
+ { "2", "Device Index", NULL, NULL, device_idx },
+ { "3", "Send", NULL, run_send_file, NULL },
{ NULL, NULL, },
};