*
* @see mdg_device_send_data()
*/
-typedef void (*mdg_device_send_data_finish_cb)(int result, void *user_data);
+typedef void (*mdg_device_send_data_finish_cb)(int result, mdg_device_h device,
+ char *channel_id, int msg_id, unsigned char *data, int len, void *user_data);
/**
* @brief Gets my local device handle.
* @see mdg_device_info_get_my_uuid()
*
*/
-int mdg_device_get_local_device(mdg_h handle,
- mdg_device_h *device);
+int mdg_device_get_local_device(mdg_h handle, mdg_device_h *device);
/**
* @brief Finds candidate devices to include my groups in the network.
mdg_device_found_cb found_cb, mdg_device_find_finish_cb finish_cb,
void *user_data);
-typedef void (*mdg_channel_cb)(int result, char *device_id, char *channel_id,
- unsigned char *data, int data_length, void *user_data);
+typedef void (*mdg_receive_data_cb)(int result, char *device_id, char *channel_id,
+ int msg_id, unsigned char *data, int len, void *user_data);
/* Server Side */
int mdg_device_regist_channel(mdg_h handle, char *channel_id,
- mdg_channel_cb channel_cb, void *user_data);
+ mdg_receive_data_cb receive_data_cb, void *user_data);
+
+/* In 5 seconds */
+int mdg_device_send_response(mdg_h handle, char *device_id, char *channel_id,
+ int msg_id, unsigned char *data, int len);
int mdg_device_unregist_channel(mdg_h handle, char *channel_id);
* @see mdg_request_result_callback()
*
*/
-int mdg_device_send_data(mdg_h handle, mdg_device_h device, char *channel_id,
- unsigned char *data, int len,
- mdg_device_send_data_finish_cb finish_cb, void *user_data);
+int mdg_device_send_data(mdg_h handle,
+ mdg_device_h device, char *channel_id, unsigned char *data, int len,
+ mdg_device_send_data_finish_cb finish_cb, void *user_data, int *msg_id);
/**
* @}
#endif
/* File transfer for Client Side */
-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_progress_cb)(const char *file_path, long long send_size,
+ long 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,
/**
* Companion Manager CAPI
*/
-int __add_channel_cb(mdg_manager_s *handle, char *channel_id, mdg_channel_cb channel_cb, void *user_data)
+int __add_channel_cb(mdg_manager_s *handle, char *channel_id, mdg_receive_data_cb channel_cb, void *user_data)
{
channel_cb_s *channel_s;
}
EXPORT_API int mdg_device_regist_channel(mdg_h handle, char *channel_id,
- mdg_channel_cb channel_cb, void *user_data)
+ mdg_receive_data_cb receive_data_cb, void *user_data)
{
int ret = MDG_ERROR_NONE;
GError *error = NULL;
}
if (ret == MDG_ERROR_NONE)
- ret = __add_channel_cb(handle, channel_id, channel_cb, user_data);
+ ret = __add_channel_cb(handle, channel_id, receive_data_cb, user_data);
_END();
return ret;
}
+EXPORT_API int mdg_device_send_response(mdg_h handle, char *device_id, char *channel_id,
+ int msg_id, unsigned char *data, int len)
+{
+ int ret = MDG_ERROR_NONE;
+ unsigned char *buf = NULL;
+ GVariantBuilder *bytearray_builder = NULL;
+ int i;
+ GVariant *params = NULL;
+ 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);
+
+ buf = g_try_malloc0(len + 1);
+ if (NULL == buf) {
+ /* LCOV_EXCL_START */
+ _ERR("g_malloc0 is failed");
+ return MDG_ERROR_OUT_OF_MEMORY;
+ /* LCOV_EXCL_STOP */
+ }
+ memcpy(buf, data, len);
+
+ bytearray_builder = g_variant_builder_new(G_VARIANT_TYPE("ay"));
+ for (i = 0; i < len; i++)
+ g_variant_builder_add(bytearray_builder, "y", buf[i]);
+
+ params = g_variant_new("(iay)", len, bytearray_builder);
+ g_variant_builder_unref(bytearray_builder);
+
+ group_call_send_response_sync(_handle->group_proxy, device_id, channel_id, msg_id,
+ params, &ret, NULL, &error);
+ if (error) {
+ _ERR("Failed DBus call [%s]", error->message);
+ g_error_free(error);
+ ret = MDG_ERROR_IO_ERROR;
+ }
+
+ g_free(buf);
+ buf = NULL;
+
+ return ret;
+}
+
EXPORT_API int mdg_device_unregist_channel(mdg_h handle, char *channel_id)
{
int ret = MDG_ERROR_NONE;
EXPORT_API int mdg_device_send_data(mdg_h handle,
mdg_device_h device, char *channel_id, unsigned char *data, int len,
- mdg_device_send_data_finish_cb finish_cb, void *user_data)
+ mdg_device_send_data_finish_cb finish_cb, void *user_data, int *msg_id)
{
int ret = MDG_ERROR_NONE;
unsigned char *buf = NULL;
params = g_variant_new("(iay)", len, bytearray_builder);
g_variant_builder_unref(bytearray_builder);
+ mdg_device_h cloned_device = NULL;
+ mdg_device_info_clone(&cloned_device, device);
+
_handle->send_data_finish_cb.finish_cb = finish_cb;
_handle->send_data_finish_cb.user_data = user_data;
+ _handle->send_data_finish_cb.device = cloned_device;
group_call_send_data_sync(_handle->group_proxy, dev->device_id,
- channel_id, params, &ret, NULL, &error);
+ channel_id, params, &ret, msg_id, NULL, &error);
if (error) {
_ERR("Failed DBus call [%s]", error->message);
g_error_free(error);
}
case MDG_EVENT_SEND_DATA_FINISH:
{
+ char *device_id;
+ char *channel_id;
+ int msg_id;
+ unsigned char *data = NULL;
+ int data_len = 0;
+
+ mdg_get_data_from_variant(va, &device_id, &channel_id, &msg_id, &data, &data_len);
+ mdg_device_s *device = (mdg_device_s *)(handle->send_data_finish_cb.device);
if (handle->send_data_finish_cb.finish_cb) {
- handle->send_data_finish_cb.finish_cb(ret,
+ handle->send_data_finish_cb.finish_cb(ret, device, channel_id, msg_id, data, data_len,
handle->send_data_finish_cb.user_data);
} else {
_ERR("The callback not exists");
{
char *device_id;
char *channel_id;
+ int msg_id;
unsigned char *data;
int data_len;
- mdg_get_data_from_variant(va, &device_id, &channel_id, &data, &data_len);
+ mdg_get_data_from_variant(va, &device_id, &channel_id, &msg_id, &data, &data_len);
channel_cb_s *channel = NULL;
}
if (channel != NULL)
- channel->cb(0, device_id, channel_id, data, data_len, channel->user_data);
+ channel->cb(0, device_id, channel_id, msg_id, data, data_len, channel->user_data);
break;
}
case MDG_EVENT_SEND_FILE_PROGRESS:
{
if (handle->send_file_cb.progress_cb) {
int percent = 0;
- long send_size, total_size;
+ long 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,
<arg type="s" name="channel_id" direction="in"/>
<arg type="(iay)" name="data" direction="in"/>
<arg type="i" name="result" direction="out" />
+ <arg type="i" name="msg_id" direction="out" />
+ </method>
+ <method name="SendResponse">
+ <arg type="s" name="uuid" direction="in" />
+ <arg type="s" name="channel_id" direction="in"/>
+ <arg type="i" name="msg_id" direction="in"/>
+ <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" />
*/
typedef struct _send_data_finish_cb_t {
mdg_device_send_data_finish_cb finish_cb; /**< User callback to be called */
+ mdg_device_h device;
void *user_data; /**< User data pointer */
} send_data_finish_cb_t;
typedef struct _channel_cb_s {
char *channel_id;
- mdg_channel_cb cb;
+ mdg_receive_data_cb cb;
void *user_data;
} channel_cb_s;
MDG_EVENT_RECEIVE_FILE = 10,
MDG_EVENT_SEND_FILE_PROGRESS,
MDG_EVENT_SEND_FILE_FINISH,
+ MDG_EVENT_INVITED,
+ MDG_EVENT_EJECTED,
} mdg_event_type_e;
#endif /* __TIZEN_NETWORK_COMMON_MDG_PRIVATE_H__ */
}
void mdg_get_data_from_variant(GVariant *va, char **device_id, char **channel_id,
- unsigned char **data, int *data_len)
+ int *msg_id, unsigned char **data, int *data_len)
{
GVariantIter *iter = NULL;
const gchar *key;
*device_id = (char *)g_variant_get_string(key_value, NULL);
else if (g_strcmp0(key, "ChannelID") == 0)
*channel_id = (char *)g_variant_get_string(key_value, NULL);
+ else if (g_strcmp0(key, "MsgID") == 0)
+ *msg_id = g_variant_get_int32(key_value);
else if (g_strcmp0(key, "Data") == 0)
data_va = g_variant_get_variant(key_value);
- else if (g_strcmp0(key, "DataLength") == 0)
+ else if (g_strcmp0(key, "DataLen") == 0)
*data_len = g_variant_get_int32(key_value);
}
- int i = 0;
- *data = (unsigned char *)g_try_malloc0(*data_len + 1);
+ if (*data_len > 0) {
+ int i = 0;
+ *data = (unsigned char *)g_try_malloc0(*data_len + 1);
- g_variant_get(data_va, "a(y)", &data_iter);
- while (g_variant_iter_loop(data_iter, "(y)", &byte_data))
- (*data)[i++] = byte_data;
+ g_variant_get(data_va, "a(y)", &data_iter);
+ while (g_variant_iter_loop(data_iter, "(y)", &byte_data))
+ (*data)[i++] = byte_data;
+ }
g_variant_iter_free(iter);
}
void mdg_get_progress_from_variant(GVariant *va, char **file_path,
- long *send_size, long *total_size, int *percent)
+ long long *send_size, long long *total_size, int *percent)
{
GVariantIter *iter = NULL;
const gchar *key;
mdg_group_s *mdg_get_group_from_variant(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);
+ int *msg_id, unsigned char **data, int *data_len);
void mdg_get_receive_file_from_variant(GVariant *va, char **device_id, char **file_path);
void mdg_get_progress_from_variant(GVariant *va, char **file_path,
- long *send_size, long *total_size, int *percent);
+ long long *send_size, long long *total_size, int *percent);
#ifdef __cplusplus
}
return RET_SUCCESS;
}
-void _send_data_finish_cb(int result, void *user_data)
+void _send_data_finish2_cb(int result, mdg_device_h device, char *channel_id, int msg_id,
+ unsigned char *data, int len, void *user_data)
{
- msgb("\rFind Send Data Finished = %d", result);
+ msgb("\rmsg id = %d, data = %s, len = %d", msg_id, data, len);
+ msgb("\rSend Data once more Finished = %d", result);
+}
+
+void _send_data_finish_cb(int result, mdg_device_h device, char *channel_id, int msg_id,
+ unsigned char *data, int len, void *user_data)
+{
+ int msg_id2;
+
+ msgb("\rmsg id = %d, channel ID data = %s, len = %d", msg_id, data, len);
+ msgb("\rSend Data Finished = %d", result);
+
+ msgb("\rSend Data Once more");
+ mdg_device_send_data(handle, device, channel_id, (unsigned char *)"Welcome",
+ 7, _send_data_finish2_cb, NULL, &msg_id2);
+
+ msgp("The message ID is %d", msg_id2);
}
static int __send_data(int devidx, int chaidx)
address = NULL;
}
+ int msg_id;
ret = mdg_device_send_data(handle, device, channel->channel_id, (unsigned char *)message,
- strlen(message), _send_data_finish_cb, NULL);
+ strlen(message), _send_data_finish_cb, NULL, &msg_id);
if (MDG_ERROR_NONE != ret)
msgr("Failed to Send Data: [ID] %s [IP] %s", deviceid, address);
+ msgp("The message ID is %d", msg_id);
+
return ret;
}
return __send_data(devidx, chaidx);
}
-void __send_file_progress_cb(const char *file_path, long send_size,
- long total_size, int percent, void *user_data)
+void __send_file_progress_cb(const char *file_path, long long send_size,
+ long long total_size, int percent, void *user_data)
{
- msgp("%s %d%% [%ld/%ld]", file_path, percent, send_size, total_size);
+ msgp("%s %d%% [%lld/%lld]", file_path, percent, send_size, total_size);
}
void __send_file_finish_cb(int result, mdg_device_h device, void *user_data)
{
return RET_SUCCESS;
}
-void __channel_cb(int result, char *device_id, char *channel_id,
+void __channel_cb(int result, char *device_id, char *channel_id, int msg_id,
unsigned char *arg, int len, void *user_data)
{
- msg("[%s] channel callback is called by [%s]'s send message", channel_id, device_id);
- msg("arg : %s, len : %d", arg, len);
- msg("result is %d", result);
+ msgb("[%s] channel callback is called by [%s]'s send message", channel_id, device_id);
+ msgb("The msg_id is %d, arg : %s, len : %d", msg_id, arg, len);
+ msgb("result is %d", result);
+
+ mdg_device_send_response(handle, device_id, channel_id, msg_id, (unsigned char *)"Ya, Hi", 6);
}
static int run_regist_channel(MManager *mm, struct menu_data *menu)