int bus_location;
int device_number;
char *model_name;
+ GMainLoop *event_loop;
};
struct _mtp_device_list {
mtp_error_e mtp_daemon_db_init(mtp_context *mtp_ctx);
mtp_error_e mtp_daemon_db_deinit(mtp_context *mtp_ctx);
-bool mtp_daemon_db_is_exist(int mtp_device, int object_handle, mtp_context *mtp_ctx);
+bool mtp_daemon_db_is_exist(int mtp_device, int mtp_storage, int object_handle, mtp_context *mtp_ctx);
mtp_error_e mtp_daemon_db_insert(int mtp_device, int mtp_storage,
int object_handle, MTPObjectInfo *object_info, mtp_context *mtp_ctx);
mtp_error_e mtp_daemon_db_delete(int mtp_device, int mtp_storage,
gchar *dest_path,
gpointer user_data);
+gboolean manager_get_partial_object(
+ mtpgdbuslibManager *manager,
+ GDBusMethodInvocation *invocation,
+ gint mtp_device,
+ gint object_handle,
+ gchar *dest_path,
+ gint offset,
+ gint max_bytes,
+ gpointer user_data);
+
gboolean manager_get_thumbnail(
mtpgdbuslibManager *manager,
GDBusMethodInvocation *invocation,
}
/* db exist check function */
-bool mtp_daemon_db_is_exist(int mtp_device, int object_handle, mtp_context *mtp_ctx)
+bool mtp_daemon_db_is_exist(int mtp_device, int mtp_storage, int object_handle, mtp_context *mtp_ctx)
{
int sql_ret;
int count = 0;
return false;
}
- sql = sqlite3_mprintf("SELECT count(*) FROM %s WHERE mtp_device=%d and object_handle=%d;",
- MTP_DB_TABLE, mtp_device, object_handle);
+ sql = sqlite3_mprintf("SELECT count(*) FROM %s WHERE mtp_device=%d and mtp_storage=%d and object_handle=%d;",
+ MTP_DB_TABLE, mtp_device, mtp_storage, object_handle);
if (sql != NULL) {
sql_ret = sqlite3_prepare_v2(mtp_ctx->db, sql, strlen(sql), &stmt, NULL);
LIBMTP_raw_device_t *raw_devices;
LIBMTP_mtpdevice_t *device;
mtp_device_info *device_info;
+ int device_count = mtp_ctx->device_list->device_num;
MTP_LOGI("host_status: %d, bus_no: %d, dev_path: %s", host_status, bus_no, dev_path);
if (host_status == USB_HOST_ADDED) {
LIBMTP_Detect_Raw_Devices(&raw_devices, &num_of_devices);
- for (slot = 0; slot < num_of_devices; slot++) {
+ for (slot = 1; slot <= num_of_devices; slot++) {
if (bus_no == raw_devices[slot].bus_location) {
int empty_slot = 0;
char usb_node[256] = {0,};
g_free(raw_devices);
__print_device_list(mtp_ctx);
} else if (host_status == USB_HOST_REMOVED) {
- MTP_LOGI("disconnected bus_no: %d", bus_no);
+ MTP_LOGI("disconnected bus_no: %d, dev_no: %d", bus_no);
+
+ for (slot = 1; slot <= device_count; slot++) {
+ device_info = mtp_ctx->device_list->device_info_list[slot];
+ /*
+ if (device_info &&
+ bus_no == device_info->bus_location && device_info->event_loop != NULL) {
+ */
+ /* It is temp implemntation ! */
+ if (!strcmp(device_info->model_name, "SM-C200")) {
+ MTP_LOGI("Event loop exists. Quit loop.");
+ g_main_loop_quit(device_info->event_loop);
+ g_main_loop_unref(device_info->event_loop);
+ device_info->event_loop = NULL;
+ }
+ }
}
}
LIBMTP_event_t device_event;
uint32_t param1;
int device_id = -1;
+ mtp_device_info *device_info;
MTP_LOGI("Event loop is started");
- mtp_daemon_gdbus_emit_event(MTP_INITIATOR_EVENT_DEVICE_ADDED,
- mtp_daemon_util_get_device_id(device, mtp_ctx), mtp_ctx);
-
- while (LIBMTP_Read_Event(device, &device_event, ¶m1) == 0) {
- MTP_LOGI("device %d device_event is occured %d", device, device_event);
-
- device_id = mtp_daemon_util_get_device_id(device, mtp_ctx);
-
- if (device_event == LIBMTP_EVENT_STORE_ADDED) {
- LIBMTP_Get_Storage(device, LIBMTP_STORAGE_SORTBY_NOTSORTED);
- } else if (device_event == LIBMTP_EVENT_STORE_REMOVED) {
- if (device_id >= 0)
- mtp_daemon_db_delete(device_id, param1, 0, mtp_ctx);
- LIBMTP_Get_Storage(device, LIBMTP_STORAGE_SORTBY_NOTSORTED);
- } else if (device_event == LIBMTP_EVENT_OBJECT_REMOVED) {
- if (device_id >= 0)
- mtp_daemon_db_delete(device_id, 0, param1, mtp_ctx);
- } else if (device_event == LIBMTP_EVENT_OBJECT_ADDED) {
- MTPObjectInfo *object_info;
- object_info = LIBMTP_Get_Object_Info(device, param1);
-
- /* scan db and if exist, then update db */
- if (object_info != NULL && device_id >= 0) {
- if (mtp_daemon_db_is_exist(device_id, param1, mtp_ctx) == true) {
- MTP_LOGI("DB Update");
- mtp_daemon_db_update(device_id, param1, object_info, mtp_ctx);
- } else {
- MTP_LOGI("DB Insert");
- mtp_daemon_db_insert(device_id, object_info->StorageID, param1, object_info, mtp_ctx);
+ device_id = mtp_daemon_util_get_device_id(device, mtp_ctx);
+ device_info = mtp_ctx->device_list->device_info_list[device_id];
+
+ mtp_daemon_gdbus_emit_event(MTP_INITIATOR_EVENT_DEVICE_ADDED, device_id, mtp_ctx);
+
+ if(!strcmp(device_info->model_name, "SM-C200")) {
+ device_info->event_loop = g_main_loop_new(NULL, FALSE);
+ g_main_loop_run(device_info->event_loop);
+ } else {
+ while (LIBMTP_Read_Event(device, &device_event, ¶m1) == 0) {
+ MTP_LOGI("device %d device_event is occured %d", device, device_event);
+
+ if (device_event == LIBMTP_EVENT_STORE_ADDED) {
+ LIBMTP_Get_Storage(device, LIBMTP_STORAGE_SORTBY_NOTSORTED);
+ } else if (device_event == LIBMTP_EVENT_STORE_REMOVED) {
+ if (device_id >= 0)
+ mtp_daemon_db_delete(device_id, param1, 0, mtp_ctx);
+ LIBMTP_Get_Storage(device, LIBMTP_STORAGE_SORTBY_NOTSORTED);
+ } else if (device_event == LIBMTP_EVENT_OBJECT_REMOVED) {
+ if (device_id >= 0)
+ mtp_daemon_db_delete(device_id, 0, param1, mtp_ctx);
+ } else if (device_event == LIBMTP_EVENT_OBJECT_ADDED) {
+ MTPObjectInfo *object_info;
+ object_info = LIBMTP_Get_Object_Info(device, param1);
+
+ /* scan db and if exist, then update db */
+ if (object_info != NULL && device_id >= 0) {
+ if (mtp_daemon_db_is_exist(device_id, object_info->StorageID, param1, mtp_ctx) == true) {
+ MTP_LOGI("DB Update");
+ mtp_daemon_db_update(device_id, param1, object_info, mtp_ctx);
+ } else {
+ MTP_LOGI("DB Insert");
+ mtp_daemon_db_insert(device_id, object_info->StorageID, param1, object_info, mtp_ctx);
+ }
}
}
+ mtp_daemon_gdbus_emit_event(device_event, (int)param1, mtp_ctx);
}
-
- mtp_daemon_gdbus_emit_event(device_event, (int)param1, mtp_ctx);
}
- MTP_LOGI("device is closing down!! device: %p", device);
+ MTP_LOGI("device is closing down!! device_id : %d", device_id);
- mtp_daemon_gdbus_emit_event(MTP_INITIATOR_EVENT_DEVICE_REMOVED,
- mtp_daemon_util_get_device_id(device, mtp_ctx), mtp_ctx);
+ mtp_daemon_gdbus_emit_event(MTP_INITIATOR_EVENT_DEVICE_REMOVED, device_id, mtp_ctx);
/* remove the device into device list */
- device_id = mtp_daemon_util_get_device_id(device, mtp_ctx);
if (device_id >= 0) {
- mtp_device_info *device_info;
-
MTP_LOGI("remove device from the list!!");
- device_info = mtp_ctx->device_list->device_info_list[device_id];
mtp_ctx->device_list->device_num--;
LIBMTP_Release_Device(device_info->device);
device_info = (mtp_device_info *)mtp_ctx->device_list->device_info_list[slot];
if (device_info != NULL) {
- MTP_LOGI("%d. bus %d, dev %d, %p", slot, device_info->bus_location, device_info->device_number, device_info->device);
+ MTP_LOGI("%d. bus %d, dev %d, %p", slot, device_info->bus_location,
+ device_info->device_number, device_info->device);
g_thread_pool_push(mtp_ctx->device_list->threads,
(gpointer) device_info->device, NULL);
G_CALLBACK(manager_get_object),
mtp_ctx);
+ g_signal_connect(
+ manager_skeleton,
+ "handle-get-partial-object",
+ G_CALLBACK(manager_get_partial_object),
+ mtp_ctx);
+
g_signal_connect(
manager_skeleton,
"handle-get-thumbnail",
MTP_LOGI("device_id: %d, storage id: %d, format: %d, parent: %d, device: %p",
param->param1, param->param2, param->param3, param->param4, device);
+ /* loop over storages */
+ g_variant_builder_init(&b, G_VARIANT_TYPE("aa{sv}"));
+
+ if (parent_object_handle > 0) {
+ MTPObjectInfo *object_info = NULL;
+ object_info = LIBMTP_Get_Object_Info(device, parent_object_handle);
+ if (object_info->StorageID != mtp_storage) {
+ MTP_LOGE("Not Equal between real object storage id and parameter");
+ goto END;
+ }
+ }
+
if (device_info != NULL) {
ret = LIBMTP_Get_Object_Handles(device, (uint32_t)mtp_storage,
(uint32_t)format, (uint32_t)parent_object_handle,
MTP_LOGE("LIBMTP_Get_Object_Handles is failed : %d", ret);
}
- /*MTP_LOGI("Total Object number: %d", temp);*/
-
- /* loop over storages */
- g_variant_builder_init(&b, G_VARIANT_TYPE("aa{sv}"));
-
if (device_info != NULL) {
mtp_daemon_db_begin(param->mtp_ctx);
if (object_info != NULL)
mtp_daemon_db_insert(device_id, storage_id, object_list[slot], object_info, param->mtp_ctx);*/
- if (mtp_daemon_db_is_exist(device_id, object_list[slot], param->mtp_ctx) == false) {
+ if (mtp_daemon_db_is_exist(device_id, mtp_storage, object_list[slot], param->mtp_ctx) == false) {
MTP_LOGI("Objectinfo is Not stored. device_id: %d, object_list[%d]: %d",
device_id, slot, object_list[slot]);
object_info = LIBMTP_Get_Object_Info(device, (uint32_t)object_list[slot]);
/*MTP_LOGI("object id: %d, format : %d, filename : %s", object_list[slot],
object_info->ObjectFormat, object_info->Filename);*/
- if ((format == LIBMTP_FILETYPE_ALL &&
- (object_info->ObjectFormat == LIBMTP_FILETYPE_FOLDER ||
- LIBMTP_FILETYPE_IS_IMAGE(object_info->ObjectFormat))) ||
+ if (format == LIBMTP_FILETYPE_ALL ||
(format == LIBMTP_FILETYPE_ALL_IMAGE &&
LIBMTP_FILETYPE_IS_IMAGE(object_info->ObjectFormat)) ||
(format == object_info->ObjectFormat)) {
+ MTP_LOGI("The object handle (id : %d, format : %d) will be pass to caller",
+ object_list[slot],object_info->ObjectFormat);
+
g_variant_builder_open(&b, G_VARIANT_TYPE("a{sv}"));
g_variant_builder_add(&b, "{sv}", "object_handle",
result = MTP_ERROR_NO_DEVICE;
}
+END:
gv = g_variant_builder_end(&b);
/*MTP_LOGI("Real object_num: %d", target_object_num);*/
g_free(param);
}
+static void __manager_get_partial_object_thread_func(gpointer user_data)
+{
+ /* variable definition */
+ mtp_param *param = (mtp_param *)user_data;
+ mtp_error_e result = MTP_ERROR_NONE;
+ int ret;
+ int fd;
+
+ LIBMTP_mtpdevice_t *device;
+ mtp_device_info *device_info;
+ int device_id;
+ int object_handle;
+ int offset;
+ int max_bytes;
+ char *dest_path;
+ unsigned int actual_written;
+ unsigned char *data;
+
+ /* check precondition */
+ g_assert(param != NULL);
+ g_assert(param->object != NULL);
+ g_assert(param->invocation != NULL);
+ g_assert(param->mtp_ctx != NULL);
+
+ /*MTP_LOGI("%s", __func__);*/
+
+ /* parameter unpacking */
+ device_id = param->param1;
+ object_handle = param->param2;
+ offset = param->param3;
+ max_bytes = param->param4;
+ dest_path = param->char_param1;
+
+ device_info = (mtp_device_info *)param->mtp_ctx->device_list->device_info_list[device_id];
+
+ if (device_info != NULL) {
+ device = (LIBMTP_mtpdevice_t *)device_info->device;
+ MTP_LOGI("device_id: %d, device: %p, oh : %d, dest_path: %s", device_id, device, object_handle, dest_path);
+
+ /* file remove */
+ unlink(dest_path);
+
+ /* file open */
+ fd = open(dest_path, O_WRONLY | O_CREAT | O_EXCL, 0644);
+
+ if (fd < 0) {
+ MTP_LOGE("file open fail - fd: %d, dest_path: %s", fd, dest_path);
+ result = MTP_ERROR_IO_ERROR;
+ } else {
+ MTP_LOGI("offset : %d, max_bytes : %d", offset, max_bytes);
+ ret = LIBMTP_GetPartialObject(device, object_handle, (uint32_t)offset, (uint32_t)max_bytes, &data, &actual_written);
+ MTP_LOGI("actual_written : %d", actual_written);
+
+ if (ret == 0) {
+ ret = write(fd, data, actual_written);
+ if (ret == 0)
+ result = MTP_ERROR_OUT_OF_MEMORY;
+ } else {
+ MTP_LOGE("get partial object fail - ret: %d", ret);
+ result = MTP_ERROR_PLUGIN_FAIL;
+ }
+
+ close(fd);
+ }
+ } else {
+ MTP_LOGE("!!! no MTP device");
+ result = MTP_ERROR_NO_DEVICE;
+ }
+
+ mtp_gdbuslib_manager_complete_get_partial_object(param->object,
+ param->invocation, actual_written, result);
+
+ /* deinitializing */
+ g_free(dest_path);
+
+ g_object_unref(param->invocation);
+ g_object_unref(param->object);
+ g_free(param);
+}
+
static void __manager_get_thumbnail_thread_func(gpointer user_data)
{
/* variable definition */
return TRUE;
}
+gboolean manager_get_partial_object(
+ mtpgdbuslibManager *manager,
+ GDBusMethodInvocation *invocation,
+ gint mtp_device,
+ gint object_handle,
+ gchar *dest_path,
+ gint offset,
+ gint max_bytes,
+ gpointer user_data)
+{
+ mtp_param *param = NULL;
+ gint result = MTP_ERROR_NONE;
+
+ /*MTP_LOGI(">>> REQUEST from [%s]",
+ g_dbus_method_invocation_get_sender(invocation));*/
+
+ param = g_try_new0(mtp_param, 1);
+ if (param == NULL) {
+ MTP_LOGE("Memory allocation failed");
+ result = MTP_ERROR_OUT_OF_MEMORY;
+ goto OUT;
+ }
+
+ param->object = g_object_ref(manager);
+ param->invocation = g_object_ref(invocation);
+ param->mtp_ctx = (mtp_context *)user_data;
+ param->param1 = mtp_device;
+ param->param2 = object_handle;
+ param->param3 = offset;
+ param->param4 = max_bytes;
+ param->char_param1 = g_strdup(dest_path);
+
+ if (mtp_daemon_controller_push(__manager_get_partial_object_thread_func,
+ param, param->mtp_ctx) != MTP_ERROR_NONE) {
+ /* return error if queue was blocked */
+ MTP_LOGE("controller is processing important message..");
+ result = MTP_ERROR_CONTROLLER;
+
+ goto OUT;
+ }
+
+ return TRUE;
+
+OUT:
+ if (param != NULL) {
+ g_object_unref(param->invocation);
+ g_object_unref(param->object);
+
+ g_free(param);
+ }
+
+ mtp_gdbuslib_manager_complete_get_partial_object(manager, invocation, 0, result);
+
+ return TRUE;
+}
+
gboolean manager_get_thumbnail(
mtpgdbuslibManager *manager,
GDBusMethodInvocation *invocation,
{
mtp_param *param = (mtp_param *)user_data;
mtp_error_e result = MTP_ERROR_NONE;
- LIBMTP_mtpdevice_t *mtp_device = NULL;
mtp_device_info *device_info = NULL;
int device_id;
int object_handle;
device_info = (mtp_device_info *)param->mtp_ctx->device_list->device_info_list[device_id];
if (device_info != NULL) {
- mtp_device = (LIBMTP_mtpdevice_t *)device_info->device;
- /*MTP_LOGI("device_id: %d, device: %p", device_id, device_handle);*/
-
MTP_LOGI("Get property start - property %d", property);
- if (mtp_daemon_db_is_exist(device_id, object_handle, param->mtp_ctx) == false) {
- object_info = LIBMTP_Get_Object_Info(mtp_device, object_handle);
-
- if (object_info != NULL)
- mtp_daemon_db_insert(device_id, object_info->StorageID, object_handle, object_info, param->mtp_ctx);
- } else {
- object_info = mtp_daemon_db_get_object_info(device_id, object_handle, param->mtp_ctx);
- }
+ object_info = mtp_daemon_db_get_object_info(device_id, object_handle, param->mtp_ctx);
if (object_info != NULL) {
switch (property) {
{
mtp_param *param = (mtp_param *)user_data;
mtp_error_e result = MTP_ERROR_NONE;
- LIBMTP_mtpdevice_t *mtp_device = NULL;
mtp_device_info *device_info = NULL;
int device_id;
int object_handle;
device_info = (mtp_device_info *)param->mtp_ctx->device_list->device_info_list[device_id];
if (device_info != NULL) {
- mtp_device = (LIBMTP_mtpdevice_t *)device_info->device;
- /*MTP_LOGI("device_id: %d, device: %p", device_id, device_handle);*/
-
MTP_LOGI("Get property start - property %d", property);
- if (mtp_daemon_db_is_exist(device_id, object_handle, param->mtp_ctx) == false) {
- object_info = LIBMTP_Get_Object_Info(mtp_device, object_handle);
-
- if (object_info != NULL)
- mtp_daemon_db_insert(device_id, object_info->StorageID, object_handle, object_info, param->mtp_ctx);
- } else {
- object_info = mtp_daemon_db_get_object_info(device_id, object_handle, param->mtp_ctx);
- }
+ object_info = mtp_daemon_db_get_object_info(device_id, object_handle, param->mtp_ctx);
if (object_info != NULL) {
switch (property) {
<arg type="i" name="result" direction="out" />
</method>
+ <method name="GetPartialObject">
+ <arg type="i" name="mtp_device" direction="in" />
+ <arg type="i" name="object_handle" direction="in" />
+ <arg type="s" name="dest_path" direction="in" />
+ <arg type="i" name="offset" direction="in" />
+ <arg type="i" name="max_bytes" direction="in" />
+ <arg type="i" name="actual_written" direction="out" />
+ <arg type="i" name="result" direction="out" />
+ </method>
+
<method name="GetThumbnail">
<arg type="i" name="mtp_device" direction="in" />
<arg type="i" name="object_handle" direction="in" />