SET(LIBDIR "${PREFIX}/lib")
SET(MODULEDIR "${LIBDIR}/mtp")
+IF(BUILD_GCOV)
+ ADD_DEFINITIONS(-DBUILD_GCOV)
+ENDIF(BUILD_GCOV)
+
ADD_SUBDIRECTORY(src/daemon)
ADD_SUBDIRECTORY(haltest)
+IF(BUILD_GTESTS)
+ ADD_SUBDIRECTORY(unittest)
+ENDIF(BUILD_GTESTS)
IF(DEFINED TIZEN_ENGINEER_MODE)
#ADD_SUBDIRECTORY(src/test)
BuildRequires: python-xml
Requires: security-config
+%if 0%{?gtests:1}
+BuildRequires: pkgconfig(gmock)
+%endif
+
%define upgrade_script_path /usr/share/upgrade/scripts
%description
cp %{SOURCE1} .
%build
+%if 0%{?gcov:1}
+export CFLAGS+=" -fprofile-arcs -ftest-coverage"
+export CXXFLAGS+=" -fprofile-arcs -ftest-coverage"
+export LDFLAGS+=" -lgcov "
+%endif
+
CFLAGS+=" -DTIZEN_EXT"
MAJORVER=`echo %{version} | awk 'BEGIN {FS="."}{print $1}'`
-%cmake . -DMAJORVER=${MAJORVER} -DFULLVER=%{version} %{?ARM_DEF}
+%cmake . -DMAJORVER=${MAJORVER} -DFULLVER=%{version} %{?ARM_DEF} \
+ -DBUILD_GTESTS=%{?gtests:1}%{!?gtests:0} \
+ -DBUILD_GCOV=%{?gcov:1}%{!?gcov:0}
+
make %{?jobs:-j%jobs}
%{_unitdir}/mtp-initiator.service
%{_prefix}/lib/udev/rules.d/99-mtp.rules
%config %{_sysconfdir}/dbus-1/system.d/org.tizen.mtp.conf
+%if 0%{?gtests:1}
+%{_bindir}/gtest*
+%endif
%files haltests
%manifest %{name}.manifest
SET(CMAKE_EXE_LINKER_FLAGS " -Wl,--as-needed -pie -Wl,--hash-style=both")
ADD_EXECUTABLE(${PROJECT_NAME} ${SRCS})
-TARGET_LINK_LIBRARIES(${PROJECT_NAME} ${mtp_pkgs_LDFLAGS} pthread)
+TARGET_LINK_LIBRARIES(${PROJECT_NAME} ${mtp_pkgs_LDFLAGS} pthread -lgcov)
INSTALL(TARGETS ${PROJECT_NAME} RUNTIME DESTINATION bin)
#include "mtp_daemon_event.h"
#include "mtp_daemon_db.h"
+#if (BUILD_GCOV != 0)
+extern void __gcov_flush(void);
+#endif
+
static mtp_context *_mtp_ctx = NULL;
static mtp_error_e __daemon_initalize(mtp_context *mtp_ctx)
ret = mtp_daemon_controller_init(mtp_ctx);
if (ret != MTP_ERROR_NONE) {
+ /* LCOV_EXCL_START */
MTP_LOGE("mtp_daemon_controller_init is failed: %d", ret);
return ret;
+ /* LCOV_EXCL_STOP */
}
ret = mtp_daemon_db_init(mtp_ctx);
if (ret != MTP_ERROR_NONE) {
+ /* LCOV_EXCL_START */
MTP_LOGE("mtp_daemon_db_init is failed: %d", ret);
return ret;
+ /* LCOV_EXCL_STOP */
}
ret = mtp_daemon_event_init(mtp_ctx);
if (ret != MTP_ERROR_NONE) {
+ /* LCOV_EXCL_START */
MTP_LOGE("mtp_daemon_event_init is failed: %d", ret);
return ret;
+ /* LCOV_EXCL_STOP */
}
ret = mtp_daemon_gdbus_init(mtp_ctx);
if (ret != MTP_ERROR_NONE) {
+ /* LCOV_EXCL_START */
MTP_LOGE("mtp_daemon_gdbus_init is failed: %d", ret);
return ret;
+ /* LCOV_EXCL_STOP */
}
return ret;
}
+/* LCOV_EXCL_START */
static mtp_error_e __daemon_deinitalize(mtp_context *mtp_ctx)
{
mtp_error_e ret = MTP_ERROR_NONE;
return ret;
}
+/* LCOV_EXCL_STOP */
static void __mtp_signal_handler(int signo)
{
gint ret;
+#if (BUILD_GCOV != 0)
+ __gcov_flush();
+ MTP_LOGI("Flushed gcov data");
+#endif
+
if (!_mtp_ctx)
return;
sigemptyset(&sigact.sa_mask);
sigact.sa_flags = 0;
if (sigaction(SIGTERM, &sigact, NULL) < 0)
- MTP_LOGW("sigaction is failed");
+ MTP_LOGW("sigaction is failed"); //LCOV_EXCL_LINE
/* 2. create mtp daemon context */
mtp_ctx = g_new0(mtp_context, 1);
if (!mtp_ctx) {
- MTP_LOGE("create mtp_context is failed");
+ MTP_LOGE("create mtp_context is failed"); //LCOV_EXCL_LINE
goto EXIT;
}
mtp_ctx->device_list = g_new0(mtp_device_list, 1);
if (mtp_ctx->device_list == NULL) {
- MTP_LOGE("create device_list is failed");
+ MTP_LOGE("create device_list is failed"); //LCOV_EXCL_LINE
goto EXIT;
}
/* 3. initialize daemon */
ret = __daemon_initalize(mtp_ctx);
if (ret != MTP_ERROR_NONE) {
- MTP_LOGE("daemon initalize is failed");
+ MTP_LOGE("daemon initalize is failed"); //LCOV_EXCL_LINE
goto EXIT;
}
g_main_loop_run(mtp_ctx->main_loop);
EXIT:
+ /* LCOV_EXCL_START */
ret = __daemon_deinitalize(mtp_ctx);
if (ret != MTP_ERROR_NONE)
- MTP_LOGE("daemon deinitalize is failed");
+ MTP_LOGE("daemon deinitalize is failed"); //LCOV_EXCL_LINE
+
+#if (BUILD_GCOV != 0)
+ __gcov_flush();
+#endif
MTP_LOGE("mtp initiator exit");
return 0;
+ /* LCOV_EXCL_STOP */
}
#include "mtp_daemon_controller.h"
+/* LCOV_EXCL_START */
static void _controller_queue_free(gpointer user_data)
{
mtp_queue_data* data = (mtp_queue_data*)user_data;
if (data != NULL)
g_free(data);
}
+/* LCOV_EXCL_STOP */
static gpointer _controller_thread(gpointer user_data)
{
mtp_context* mtp_ctx = (mtp_context*)user_data;
if (mtp_ctx == NULL || mtp_ctx->c_queue == NULL) {
+ /* LCOV_EXCL_START */
MTP_LOGE("create thread failed");
g_thread_exit(NULL);
return NULL;
+ /* LCOV_EXCL_STOP */
}
mtp_ctx->is_running = true;
_controller_queue_free(data);
}
- g_thread_exit(NULL);
+ g_thread_exit(NULL); //LCOV_EXCL_LINE
- return NULL;
+ return NULL; //LCOV_EXCL_LINE
}
mtp_error_e mtp_daemon_controller_push(mtp_controller_func func,
RETV_IF(mtp_ctx->c_queue == NULL, MTP_ERROR_INVALID_PARAMETER);
if (mtp_ctx->is_releasing == true) {
+ /* LCOV_EXCL_START */
MTP_LOGE("controller queue is busy now");
return MTP_ERROR_CONTROLLER;
+ /* LCOV_EXCL_STOP */
}
data = g_new0(mtp_queue_data, 1);
mtp_ctx->c_thread = g_thread_try_new(NULL, _controller_thread, mtp_ctx, &error);
if (mtp_ctx->c_thread == NULL) {
+ /* LCOV_EXCL_START */
MTP_LOGE("Can not create controller thread");
if (error != NULL) {
MTP_LOGE("The error msg: %s", error->message);
}
return MTP_ERROR_CONTROLLER;
+ /* LCOV_EXCL_STOP */
}
return ret;
#include "mtp_daemon_db.h"
+/* LCOV_EXCL_START */
mtp_error_e mtp_daemon_db_delete(int mtp_device, int mtp_storage,
int object_handle, mtp_context *mtp_ctx)
{
return ret;
}
+/* LCOV_EXCL_STOP */
static mtp_error_e __create_table(mtp_context *mtp_ctx)
{
char *error = NULL;
if (mtp_ctx->db == NULL) {
+ /* LCOV_EXCL_START */
MTP_LOGE("mtp_ctx->db is NULL");
return MTP_ERROR_DB;
+ /* LCOV_EXCL_STOP */
}
sql = sqlite3_mprintf("CREATE TABLE %s(id INTEGER PRIMARY KEY, mtp_device INTEGER, mtp_storage INTEGER, object_handle INTEGER, ObjectFormat INTEGER, ProtectionStatus INTEGER, ObjectCompressedSize INTEGER, ThumbFormat INTEGER, ThumbCompressedSize INTEGER, ThumbPixWidth INTEGER, ThumbPixHeight INTEGER, ImagePixWidth INTEGER, ImagePixHeight INTEGER, ImageBitDepth INTEGER, ParentObject INTEGER, AssociationType INTEGER, AssociationDesc INTEGER, SequenceNumber INTEGER, Filename TEXT, CaptureDate INTEGER, ModificationDate INTEGER, Keywords TEXT);",
if (sql != NULL) {
sql_ret = sqlite3_exec(mtp_ctx->db, sql, NULL, NULL, &error);
if (sql_ret != SQLITE_OK) {
+ /* LCOV_EXCL_START */
MTP_LOGE("sqlite3_exec failed, %d, %s", sql_ret, error);
ret = MTP_ERROR_DB;
sqlite3_free(error);
+ /* LCOV_EXCL_STOP */
}
sqlite3_free(sql);
} else {
- MTP_LOGE("sql is NULL");
+ MTP_LOGE("sql is NULL"); //LCOV_EXCL_LINE
ret = MTP_ERROR_DB;
}
return ret;
}
+/* LCOV_EXCL_START */
mtp_error_e mtp_daemon_db_deinit(mtp_context *mtp_ctx)
{
int ret = MTP_ERROR_NONE;
return ret;
}
+/* LCOV_EXCL_STOP */
#include "mtp_daemon_db.h"
#include "mtp_daemon_util.h"
+/* LCOV_EXCL_START */
static void __print_device_list(mtp_context *mtp_ctx)
{
int slot;
}
}
}
+/* LCOV_EXCL_STOP */
static int __search_empty_slot(mtp_context *mtp_ctx)
{
} while (check_count++ < 100);
}
+/* LCOV_EXCL_START */
int __usb_host_status_changed_cb(struct libusb_context *ctx,
struct libusb_device *dev, libusb_hotplug_event event, void *user_data)
{
return 0;
}
+/* LCOV_EXCL_STOP */
static void* __event_thread(gpointer dev, gpointer data)
{
device_id = mtp_daemon_util_get_device_id(device, mtp_ctx);
if (device_id < 0)
- return NULL;
+ return NULL; //LCOV_EXCL_LINE
device_info = mtp_ctx->device_list->device_info_list[device_id];
if (device_info == NULL)
device_info->bus_location, device_info->device_number);
while (LIBMTP_Read_Event(device, &device_event, ¶m1) == 0) {
+ /* LCOV_EXCL_START */
MTP_LOGI("%s, %03d-%03d event occurs", device_info->model_name,
device_info->bus_location, device_info->device_number);
g_free(object_info);
}
mtp_daemon_gdbus_emit_event(device_event, (int)param1, mtp_ctx);
+ /* LCOV_EXCL_STOP */
}
MTP_LOGI("%s, %03d-%03d event loop stop", device_info->model_name,
LIBMTP_Detect_Raw_Devices(&rawdevices, &numrawdevices);
if (numrawdevices == 0) {
+ /* LCOV_EXCL_START */
MTP_LOGW("MTP Host have not any mtp device");
g_free(rawdevices);
return MTP_ERROR_NO_DEVICE;
+ /* LCOV_EXCL_STOP */
}
for (device_index = 0; device_index < numrawdevices; device_index++) {
empty_slot = __search_empty_slot(mtp_ctx);
if (empty_slot < 0) {
+ /* LCOV_EXCL_START */
MTP_LOGE("Not enough space in device_list");
continue;
+ /* LCOV_EXCL_STOP */
}
snprintf(usb_node, sizeof(usb_node), "/dev/bus/usb/%03d/%03d",
device = LIBMTP_Open_Raw_Device_Uncached(&rawdevices[device_index]);
if (device == NULL) {
+ /* LCOV_EXCL_START */
MTP_LOGE("Unable to open raw device : %s", usb_node);
continue;
+ /* LCOV_EXCL_STOP */
}
device_info = g_new0(mtp_device_info, 1);
MTP_LOGI("Device version : %s", device_version);
if (!strncmp(device_version, "SM", 2) && strlen(device_version) > 25) {
+ /* LCOV_EXCL_START */
device_info->stitching_engine_version = g_strndup(&device_version[21], 4);
MTP_LOGI("stitching engine version : %s", device_info->stitching_engine_version);
+ /* LCOV_EXCL_STOP */
}
g_free(device_version);
device_version = NULL;
if (device_info->model_name == NULL)
- device_info->model_name = strdup(tmp_name);
+ device_info->model_name = strdup(tmp_name); //LCOV_EXCL_LINE
mtp_ctx->device_list->device_info_list[empty_slot] = device_info;
mtp_ctx->device_list->device_num++;
mtp_context* mtp_ctx = (mtp_context*)user_data;
if (mtp_ctx == NULL) {
+ /* LCOV_EXCL_START */
MTP_LOGE("create thread failed");
g_thread_exit(NULL);
return NULL;
+ /* LCOV_EXCL_STOP */
}
MTP_LOGE("dispatch thread created");
/* usb event setting */
ret = libusb_init(&(mtp_ctx->usb_ctx));
if (ret != LIBUSB_SUCCESS) {
+ /* LCOV_EXCL_START */
MTP_LOGE("libusb_init failed : %d", ret);
return MTP_ERROR_PLUGIN_FAIL;
+ /* LCOV_EXCL_STOP */
}
ret = libusb_hotplug_register_callback(mtp_ctx->usb_ctx,
mtp_ctx->usb_event_thread = g_thread_try_new("dispatch", __dispatch_event, mtp_ctx, NULL);
if (ret != LIBUSB_SUCCESS) {
+ /* LCOV_EXCL_START */
MTP_LOGE("libusb_hotplug_register_callback failed");
return MTP_ERROR_PLUGIN_FAIL;
+ /* LCOV_EXCL_STOP */
}
/* create thread pool */
mtp_ctx->connection, MTP_DBUS_MANAGER_PATH, &error);
if (ret == FALSE) {
+ /* LCOV_EXCL_START */
MTP_LOGE("Can not skeleton_export %s", error->message);
g_error_free(error);
+ /* LCOV_EXCL_STOP */
}
mtp_ctx->manager = manager_skeleton;
mtp_ctx->connection, MTP_DBUS_DEVICEINFO_PATH, &error);
if (ret == FALSE) {
+ /* LCOV_EXCL_START */
MTP_LOGE("Can not skeleton_export %s", error->message);
g_error_free(error);
+ /* LCOV_EXCL_STOP */
}
return ret;
mtp_ctx->connection, MTP_DBUS_STORAGEINFO_PATH, &error);
if (ret == FALSE) {
+ /* LCOV_EXCL_START */
MTP_LOGE("Can not skeleton_export %s", error->message);
g_error_free(error);
+ /* LCOV_EXCL_STOP */
}
return ret;
mtp_ctx->connection, MTP_DBUS_OBJECTINFO_PATH, &error);
if (ret == FALSE) {
+ /* LCOV_EXCL_START */
MTP_LOGE("Can not skeleton_export %s", error->message);
g_error_free(error);
+ /* LCOV_EXCL_STOP */
}
return ret;
mtp_ctx->connection = connection;
if (__manager_init(mtp_ctx) == FALSE) {
- MTP_LOGE("Can not signal connect");
+ MTP_LOGE("Can not signal connect"); //LCOV_EXCL_LINE
/* Deinitialize and quit daemon */
}
if (__deviceinfo_init(mtp_ctx) == FALSE) {
- MTP_LOGE("Can not signal connect");
+ MTP_LOGE("Can not signal connect"); //LCOV_EXCL_LINE
/* Deinitialize and quit daemon */
}
if (__storageinfo_init(mtp_ctx) == FALSE) {
- MTP_LOGE("Can not signal connect");
+ MTP_LOGE("Can not signal connect"); //LCOV_EXCL_LINE
/* Deinitialize and quit daemon */
}
if (__objectinfo_init(mtp_ctx) == FALSE) {
- MTP_LOGE("Can not signal connect");
+ MTP_LOGE("Can not signal connect"); //LCOV_EXCL_LINE
/* Deinitialize and quit daemon */
}
}
}
}
+/* LCOV_EXCL_START */
static void on_name_lost(GDBusConnection *connnection,
const gchar *name,
gpointer user_data)
{
MTP_LOGE("on_name_lost : %s", name);
}
+/* LCOV_EXCL_STOP */
mtp_error_e mtp_daemon_gdbus_init(mtp_context *mtp_ctx)
{
/* do process */
name = LIBMTP_Get_Manufacturername(device);
} else {
+ /* LCOV_EXCL_START */
name = strdup("N/A");
MTP_LOGE("No MTP device");
result = MTP_ERROR_NO_DEVICE;
+ /* LCOV_EXCL_STOP */
}
MTP_LOGI("manufacturer name: %s", name);
/* do process */
name = LIBMTP_Get_Modelname(device);
} else {
+ /* LCOV_EXCL_START */
name = strdup("N/A");
MTP_LOGE("No MTP device");
result = MTP_ERROR_NO_DEVICE;
+ /* LCOV_EXCL_STOP */
}
MTP_LOGI("model name: %s", name);
/* do process */
number = LIBMTP_Get_Serialnumber(device);
} else {
+ /* LCOV_EXCL_START */
number = strdup("N/A");
MTP_LOGE("No MTP device");
result = MTP_ERROR_NO_DEVICE;
+ /* LCOV_EXCL_STOP */
}
MTP_LOGI("serial number: %s", number);
/* do process */
version = LIBMTP_Get_Deviceversion(device);
} else {
+ /* LCOV_EXCL_START */
version = strdup("N/A");
MTP_LOGE("No MTP device");
result = MTP_ERROR_NO_DEVICE;
+ /* LCOV_EXCL_STOP */
}
MTP_LOGI("device version: %s", version);
if (device_info != NULL) {
bus_location = device_info->bus_location;
} else {
+ /* LCOV_EXCL_START */
MTP_LOGE("No MTP device");
result = MTP_ERROR_NO_DEVICE;
+ /* LCOV_EXCL_STOP */
}
MTP_LOGI("bus location: %d", bus_location);
if (device_info != NULL) {
device_number = device_info->device_number;
} else {
+ /* LCOV_EXCL_START */
MTP_LOGE("No MTP device");
result = MTP_ERROR_NO_DEVICE;
+ /* LCOV_EXCL_STOP */
}
MTP_LOGI("device number: %d", device_number);
if (device_info->stitching_engine_version != NULL)
stitching_engine_version = strdup(device_info->stitching_engine_version);
} else {
+ /* LCOV_EXCL_START */
MTP_LOGE("No MTP device");
result = MTP_ERROR_NO_DEVICE;
+ /* LCOV_EXCL_STOP */
}
MTP_LOGI("stitching_engine_version : %s", stitching_engine_version);
param = g_try_new0(mtp_param, 1);
if (param == NULL) {
+ /* LCOV_EXCL_START */
MTP_LOGE("Memory allocation failed");
result = MTP_ERROR_OUT_OF_MEMORY;
goto OUT;
+ /* LCOV_EXCL_STOP */
}
param->object = g_object_ref(deviceinfo);
if (mtp_daemon_controller_push(__deviceinfo_get_manufacturer_name_thread_func,
param, param->mtp_ctx) != MTP_ERROR_NONE) {
+ /* LCOV_EXCL_START */
/* return error if queue was blocked */
MTP_LOGE("controller is processing important message");
result = MTP_ERROR_CONTROLLER;
goto OUT;
+ /* LCOV_EXCL_STOP */
}
return TRUE;
OUT:
if (param != NULL) {
+ /* LCOV_EXCL_START */
g_object_unref(param->invocation);
g_object_unref(param->object);
g_free(param);
+ /* LCOV_EXCL_STOP */
}
mtp_gdbuslib_deviceinfo_complete_get_manufacturer_name(deviceinfo,
param = g_try_new0(mtp_param, 1);
if (param == NULL) {
+ /* LCOV_EXCL_START */
MTP_LOGE("Memory allocation failed");
result = MTP_ERROR_OUT_OF_MEMORY;
goto OUT;
+ /* LCOV_EXCL_STOP */
}
param->object = g_object_ref(deviceinfo);
if (mtp_daemon_controller_push(__deviceinfo_get_model_name_thread_func,
param, param->mtp_ctx) != MTP_ERROR_NONE) {
+ /* LCOV_EXCL_START */
/* return error if queue was blocked */
MTP_LOGE("controller is processing important message");
result = MTP_ERROR_CONTROLLER;
goto OUT;
+ /* LCOV_EXCL_STOP */
}
return TRUE;
OUT:
if (param != NULL) {
+ /* LCOV_EXCL_START */
g_object_unref(param->invocation);
g_object_unref(param->object);
g_free(param);
+ /* LCOV_EXCL_STOP */
}
mtp_gdbuslib_deviceinfo_complete_get_model_name(deviceinfo, invocation, 0, result);
param = g_try_new0(mtp_param, 1);
if (param == NULL) {
+ /* LCOV_EXCL_START */
MTP_LOGE("Memory allocation failed");
result = MTP_ERROR_OUT_OF_MEMORY;
goto OUT;
+ /* LCOV_EXCL_STOP */
}
param->object = g_object_ref(deviceinfo);
if (mtp_daemon_controller_push(__deviceinfo_get_serial_number_thread_func,
param, param->mtp_ctx) != MTP_ERROR_NONE) {
+ /* LCOV_EXCL_START */
/* return error if queue was blocked */
MTP_LOGE("controller is processing important message");
result = MTP_ERROR_CONTROLLER;
goto OUT;
+ /* LCOV_EXCL_STOP */
}
return TRUE;
OUT:
if (param != NULL) {
+ /* LCOV_EXCL_START */
g_object_unref(param->invocation);
g_object_unref(param->object);
g_free(param);
+ /* LCOV_EXCL_STOP */
}
mtp_gdbuslib_deviceinfo_complete_get_serial_number(deviceinfo, invocation, 0, result);
param = g_try_new0(mtp_param, 1);
if (param == NULL) {
+ /* LCOV_EXCL_START */
MTP_LOGE("Memory allocation failed");
result = MTP_ERROR_OUT_OF_MEMORY;
goto OUT;
+ /* LCOV_EXCL_STOP */
}
param->object = g_object_ref(deviceinfo);
if (mtp_daemon_controller_push(__deviceinfo_get_device_version_thread_func,
param, param->mtp_ctx) != MTP_ERROR_NONE) {
+ /* LCOV_EXCL_START */
/* return error if queue was blocked */
MTP_LOGE("controller is processing important message");
result = MTP_ERROR_CONTROLLER;
goto OUT;
+ /* LCOV_EXCL_STOP */
}
return TRUE;
OUT:
if (param != NULL) {
+ /* LCOV_EXCL_START */
g_object_unref(param->invocation);
g_object_unref(param->object);
g_free(param);
+ /* LCOV_EXCL_STOP */
}
mtp_gdbuslib_deviceinfo_complete_get_device_version(deviceinfo, invocation, 0, result);
param = g_try_new0(mtp_param, 1);
if (param == NULL) {
+ /* LCOV_EXCL_START */
MTP_LOGE("Memory allocation failed");
result = MTP_ERROR_OUT_OF_MEMORY;
goto OUT;
+ /* LCOV_EXCL_STOP */
}
param->object = g_object_ref(deviceinfo);
if (mtp_daemon_controller_push(__deviceinfo_get_bus_location_thread_func,
param, param->mtp_ctx) != MTP_ERROR_NONE) {
+ /* LCOV_EXCL_START */
/* return error if queue was blocked */
MTP_LOGE("controller is processing important message");
result = MTP_ERROR_CONTROLLER;
goto OUT;
+ /* LCOV_EXCL_STOP */
}
return TRUE;
OUT:
if (param != NULL) {
+ /* LCOV_EXCL_START */
g_object_unref(param->invocation);
g_object_unref(param->object);
g_free(param);
+ /* LCOV_EXCL_STOP */
}
mtp_gdbuslib_deviceinfo_complete_get_bus_location(deviceinfo, invocation, 0, result);
param = g_try_new0(mtp_param, 1);
if (param == NULL) {
+ /* LCOV_EXCL_START */
MTP_LOGE("Memory allocation failed");
result = MTP_ERROR_OUT_OF_MEMORY;
goto OUT;
+ /* LCOV_EXCL_STOP */
}
param->object = g_object_ref(deviceinfo);
if (mtp_daemon_controller_push(__deviceinfo_get_device_number_thread_func,
param, param->mtp_ctx) != MTP_ERROR_NONE) {
+ /* LCOV_EXCL_START */
/* return error if queue was blocked */
MTP_LOGE("controller is processing important message");
result = MTP_ERROR_CONTROLLER;
goto OUT;
+ /* LCOV_EXCL_STOP */
}
return TRUE;
OUT:
if (param != NULL) {
+ /* LCOV_EXCL_START */
g_object_unref(param->invocation);
g_object_unref(param->object);
g_free(param);
+ /* LCOV_EXCL_STOP */
}
mtp_gdbuslib_deviceinfo_complete_get_device_number(deviceinfo, invocation, 0, result);
param = g_try_new0(mtp_param, 1);
if (param == NULL) {
+ /* LCOV_EXCL_START */
MTP_LOGE("Memory allocation failed");
result = MTP_ERROR_OUT_OF_MEMORY;
goto OUT;
+ /* LCOV_EXCL_STOP */
}
param->object = g_object_ref(deviceinfo);
if (mtp_daemon_controller_push(__deviceinfo_get_stitching_engine_version_thread_func,
param, param->mtp_ctx) != MTP_ERROR_NONE) {
+ /* LCOV_EXCL_START */
/* return error if queue was blocked */
MTP_LOGE("controller is processing important message");
result = MTP_ERROR_CONTROLLER;
goto OUT;
+ /* LCOV_EXCL_STOP */
}
return TRUE;
OUT:
if (param != NULL) {
+ /* LCOV_EXCL_START */
g_object_unref(param->invocation);
g_object_unref(param->object);
g_free(param);
+ /* LCOV_EXCL_STOP */
}
mtp_gdbuslib_deviceinfo_complete_get_stitching_engine_version(deviceinfo, invocation, 0, result);
g_variant_builder_init(&b, G_VARIANT_TYPE("aa{sv}"));
if (device_info != NULL) {
+ /* LCOV_EXCL_START */
for (storage = device->storage; storage != NULL; storage = storage->next) {
g_variant_builder_open(&b, G_VARIANT_TYPE("a{sv}"));
count++;
}
+ /* LCOV_EXCL_STOP */
} else {
result = MTP_ERROR_NO_DEVICE;
}
+OUT:
+ /* LCOV_EXCL_START */
gv = g_variant_builder_end(&b);
MTP_LOGI("storage_num: %d", count);
g_object_unref(param->invocation);
g_object_unref(param->object);
g_free(param);
+ /* LCOV_EXCL_STOP */
}
static void __manager_get_object_handles_thread_func(gpointer user_data)
g_variant_builder_init(&b, G_VARIANT_TYPE("aa{sv}"));
if (device_id < 0 || param->mtp_ctx->device_list->device_num < device_id) {
+ /* LCOV_EXCL_START */
MTP_LOGE("device_id : out of range");
result = MTP_ERROR_NO_DEVICE;
goto END;
+ /* LCOV_EXCL_STOP */
}
device_info = (mtp_device_info *)param->mtp_ctx->device_list->device_info_list[device_id];
if (device_info == NULL) {
+ /* LCOV_EXCL_START */
MTP_LOGE("device_info is NULL");
result = MTP_ERROR_NO_DEVICE;
goto END;
+ /* LCOV_EXCL_STOP */
}
device = (LIBMTP_mtpdevice_t *)device_info->device;
if (device == NULL) {
+ /* LCOV_EXCL_START */
MTP_LOGE("device is NULL");
result = MTP_ERROR_NO_DEVICE;
goto END;
+ /* LCOV_EXCL_STOP */
}
+ /* LCOV_EXCL_START */
+
MTP_LOGI("device_id: %d, storage id: %d, format: %d, parent: %d",
param->param1, param->param2, param->param3, param->param4);
g_variant_builder_add(&b, "{sv}", "object_handle",
g_variant_new_int32(object_list[slot]));
+ MTP_LOGI("object %d", object_list[slot]);
g_variant_builder_close(&b);
g_object_unref(param->invocation);
g_object_unref(param->object);
g_free(param);
+ /* LCOV_EXCL_STOP */
}
static void __manager_get_object_thread_func(gpointer user_data)
fd = open(dest_path, O_WRONLY | O_CREAT | O_EXCL, 0644);
if (fd < 0) {
+ /* LCOV_EXCL_START */
MTP_LOGE("file open fail - fd: %d, dest_path: %s", fd, dest_path);
result = MTP_ERROR_IO_ERROR;
+ /* LCOV_EXCL_STOP */
} else {
ret = LIBMTP_Get_File_To_File_Descriptor(device, object_handle, fd, NULL, NULL);
if (ret != 0) {
+ /* LCOV_EXCL_START */
MTP_LOGE("get descriptor fail - ret: %d", ret);
result = MTP_ERROR_PLUGIN_FAIL;
+ /* LCOV_EXCL_STOP */
}
close(fd);
}
} else {
+ /* LCOV_EXCL_START */
MTP_LOGE("No MTP device");
result = MTP_ERROR_NO_DEVICE;
+ /* LCOV_EXCL_STOP */
}
mtp_gdbuslib_manager_complete_get_object(param->object,
fd = open(dest_path, O_WRONLY | O_CREAT | O_EXCL, 0644);
if (fd < 0) {
+ /* LCOV_EXCL_START */
MTP_LOGE("file open fail - fd: %d, dest_path: %s", fd, dest_path);
result = MTP_ERROR_IO_ERROR;
+ /* LCOV_EXCL_STOP */
} else {
ret = LIBMTP_GetPartialObject(device, object_handle, (uint32_t)offset, (uint32_t)max_bytes, &data, &actual_written);
if (ret == 0) {
+ /* LCOV_EXCL_START */
ret = write(fd, data, actual_written);
if (ret == 0)
result = MTP_ERROR_OUT_OF_MEMORY;
+ /* LCOV_EXCL_STOP */
} else {
MTP_LOGE("get partial object fail - ret: %d", ret);
result = MTP_ERROR_PLUGIN_FAIL;
}
if (data != NULL)
- free(data);
+ free(data); //LCOV_EXCL_LINE
close(fd);
}
} else {
+ /* LCOV_EXCL_START */
MTP_LOGE("No MTP device");
result = MTP_ERROR_NO_DEVICE;
+ /* LCOV_EXCL_STOP */
}
mtp_gdbuslib_manager_complete_get_partial_object(param->object,
fd = open(dest_path, O_WRONLY | O_CREAT | O_EXCL, 0644);
if (fd < 0) {
+ /* LCOV_EXCL_START */
MTP_LOGE("file open fail - fd: %d, dest_path: %s", fd, dest_path);
result = MTP_ERROR_IO_ERROR;
+ /* LCOV_EXCL_STOP */
} else {
ret = LIBMTP_Get_Thumbnail_From_Exif_Data(device, object_handle, &thumb_data, &thumb_size);
if (ret != 0)
if (ret == 0)
result = MTP_ERROR_OUT_OF_MEMORY;
} else {
+ /* LCOV_EXCL_START */
MTP_LOGE("get thumbnail fail - ret: %d", ret);
result = MTP_ERROR_PLUGIN_FAIL;
+ /* LCOV_EXCL_STOP */
}
if (thumb_data != NULL)
close(fd);
}
} else {
+ /* LCOV_EXCL_START */
MTP_LOGE("No MTP device");
result = MTP_ERROR_NO_DEVICE;
+ /* LCOV_EXCL_STOP */
}
mtp_gdbuslib_manager_complete_get_thumbnail(param->object,
if (ret != 0)
result = MTP_ERROR_PLUGIN_FAIL;
} else {
+ /* LCOV_EXCL_START */
MTP_LOGE("No MTP device");
result = MTP_ERROR_NO_DEVICE;
+ /* LCOV_EXCL_STOP */
}
mtp_gdbuslib_manager_complete_delete_object(param->object,
param = g_try_new0(mtp_param, 1);
if (param == NULL) {
+ /* LCOV_EXCL_START */
MTP_LOGE("Memory allocation failed");
result = MTP_ERROR_OUT_OF_MEMORY;
goto OUT;
+ /* LCOV_EXCL_STOP */
}
param->object = g_object_ref(manager);
if (mtp_daemon_controller_push(__manager_get_devices_thread_func, param, param->mtp_ctx)
!= MTP_ERROR_NONE) {
+ /* LCOV_EXCL_START */
/* return error if queue was blocked */
MTP_LOGE("controller is processing important message");
result = MTP_ERROR_CONTROLLER;
goto OUT;
+ /* LCOV_EXCL_STOP */
}
return TRUE;
OUT:
+ /* LCOV_EXCL_START */
if (param != NULL) {
g_object_unref(param->invocation);
g_object_unref(param->object);
mtp_gdbuslib_manager_complete_get_devices(manager, invocation, 0, NULL, result);
return TRUE;
+ /* LCOV_EXCL_STOP */
}
gboolean manager_get_storages(
param = g_try_new0(mtp_param, 1);
if (param == NULL) {
+ /* LCOV_EXCL_START */
MTP_LOGE("Memory allocation failed");
result = MTP_ERROR_OUT_OF_MEMORY;
goto OUT;
+ /* LCOV_EXCL_STOP */
}
param->object = g_object_ref(manager);
if (mtp_daemon_controller_push(__manager_get_storages_thread_func,
param, param->mtp_ctx) != MTP_ERROR_NONE) {
+ /* LCOV_EXCL_START */
/* return error if queue was blocked */
MTP_LOGE("controller is processing important message");
result = MTP_ERROR_CONTROLLER;
goto OUT;
+ /* LCOV_EXCL_STOP */
}
return TRUE;
OUT:
+ /* LCOV_EXCL_START */
if (param != NULL) {
g_object_unref(param->invocation);
g_object_unref(param->object);
invocation, 0, NULL, result);
return TRUE;
+ /* LCOV_EXCL_STOP */
}
gboolean manager_get_object_handles(
param = g_try_new0(mtp_param, 1);
if (param == NULL) {
+ /* LCOV_EXCL_START */
MTP_LOGE("Memory allocation failed");
result = MTP_ERROR_OUT_OF_MEMORY;
goto OUT;
+ /* LCOV_EXCL_STOP */
}
param->object = g_object_ref(manager);
if (mtp_daemon_controller_push(__manager_get_object_handles_thread_func,
param, param->mtp_ctx) != MTP_ERROR_NONE) {
+ /* LCOV_EXCL_START */
/* return error if queue was blocked */
MTP_LOGE("controller is processing important message");
result = MTP_ERROR_CONTROLLER;
goto OUT;
+ /* LCOV_EXCL_STOP */
}
return TRUE;
OUT:
+ /* LCOV_EXCL_START */
if (param != NULL) {
g_object_unref(param->invocation);
g_object_unref(param->object);
invocation, 0, NULL, result);
return TRUE;
+ /* LCOV_EXCL_STOP */
}
gboolean manager_get_object(
param = g_try_new0(mtp_param, 1);
if (param == NULL) {
+ /* LCOV_EXCL_START */
MTP_LOGE("Memory allocation failed");
result = MTP_ERROR_OUT_OF_MEMORY;
goto OUT;
+ /* LCOV_EXCL_STOP */
}
param->object = g_object_ref(manager);
if (mtp_daemon_controller_push(__manager_get_object_thread_func,
param, param->mtp_ctx) != MTP_ERROR_NONE) {
+ /* LCOV_EXCL_START */
/* return error if queue was blocked */
MTP_LOGE("controller is processing important message");
result = MTP_ERROR_CONTROLLER;
goto OUT;
+ /* LCOV_EXCL_STOP */
}
return TRUE;
OUT:
+ /* LCOV_EXCL_START */
if (param != NULL) {
g_object_unref(param->invocation);
g_object_unref(param->object);
mtp_gdbuslib_manager_complete_get_object(manager, invocation, result);
return TRUE;
+ /* LCOV_EXCL_STOP */
}
gboolean manager_get_partial_object(
param = g_try_new0(mtp_param, 1);
if (param == NULL) {
+ /* LCOV_EXCL_START */
MTP_LOGE("Memory allocation failed");
result = MTP_ERROR_OUT_OF_MEMORY;
goto OUT;
+ /* LCOV_EXCL_STOP */
}
param->object = g_object_ref(manager);
if (mtp_daemon_controller_push(__manager_get_partial_object_thread_func,
param, param->mtp_ctx) != MTP_ERROR_NONE) {
+ /* LCOV_EXCL_START */
/* return error if queue was blocked */
MTP_LOGE("controller is processing important message");
result = MTP_ERROR_CONTROLLER;
goto OUT;
+ /* LCOV_EXCL_STOP */
}
return TRUE;
OUT:
+ /* LCOV_EXCL_START */
if (param != NULL) {
g_object_unref(param->invocation);
g_object_unref(param->object);
mtp_gdbuslib_manager_complete_get_partial_object(manager, invocation, 0, result);
return TRUE;
+ /* LCOV_EXCL_STOP */
}
gboolean manager_get_thumbnail(
param = g_try_new0(mtp_param, 1);
if (param == NULL) {
+ /* LCOV_EXCL_START */
MTP_LOGE("Memory allocation failed");
result = MTP_ERROR_OUT_OF_MEMORY;
goto OUT;
+ /* LCOV_EXCL_STOP */
}
param->object = g_object_ref(manager);
if (mtp_daemon_controller_push(__manager_get_thumbnail_thread_func,
param, param->mtp_ctx) != MTP_ERROR_NONE) {
+ /* LCOV_EXCL_START */
/* return error if queue was blocked */
MTP_LOGE("controller is processing important message");
result = MTP_ERROR_CONTROLLER;
goto OUT;
+ /* LCOV_EXCL_STOP */
}
return TRUE;
OUT:
+ /* LCOV_EXCL_START */
if (param != NULL) {
g_object_unref(param->invocation);
g_object_unref(param->object);
mtp_gdbuslib_manager_complete_get_thumbnail(manager, invocation, result);
return TRUE;
+ /* LCOV_EXCL_STOP */
}
gboolean manager_delete_object(
param = g_try_new0(mtp_param, 1);
if (param == NULL) {
+ /* LCOV_EXCL_START */
MTP_LOGE("Memory allocation failed");
result = MTP_ERROR_OUT_OF_MEMORY;
goto OUT;
+ /* LCOV_EXCL_STOP */
}
param->object = g_object_ref(manager);
if (mtp_daemon_controller_push(__manager_delete_object_thread_func,
param, param->mtp_ctx) != MTP_ERROR_NONE) {
+ /* LCOV_EXCL_START */
/* return error if queue was blocked */
MTP_LOGE("controller is processing important message");
result = MTP_ERROR_CONTROLLER;
goto OUT;
+ /* LCOV_EXCL_STOP */
}
return TRUE;
OUT:
+ /* LCOV_EXCL_START */
if (param != NULL) {
g_object_unref(param->invocation);
g_object_unref(param->object);
mtp_gdbuslib_manager_complete_delete_object(manager, invocation, result);
return TRUE;
+ /* LCOV_EXCL_STOP */
}
object_info = LIBMTP_Get_Object_Info(mtp_device, object_handle);
if (object_info != NULL) {
+ /* LCOV_EXCL_START */
switch (property) {
case MTP_PROPERTY_ASSOCIATION_DESC:
property_value = object_info->AssociationDesc;
break;
}
MTP_LOGI("property value is %d", property_value);
+ /* LCOV_EXCL_STOP */
} else {
property_value = -999;
MTP_LOGE("object_info is NULL");
}
} else {
+ /* LCOV_EXCL_START */
MTP_LOGE("No MTP device");
property_value = -999;
result = MTP_ERROR_NO_DEVICE;
+ /* LCOV_EXCL_STOP */
}
mtp_gdbuslib_objectinfo_complete_get_property(param->object,
object_info = LIBMTP_Get_Object_Info(mtp_device, object_handle);
if (object_info != NULL) {
+ /* LCOV_EXCL_START */
switch (property) {
case MTP_PROPERTY_FILENAME:
property_value = object_info->Filename;
break;
}
MTP_LOGI("property_value is %s", property_value);
+ /* LCOV_EXCL_STOP */
} else {
property_value = NULL;
MTP_LOGE("object_info is NULL");
}
} else {
+ /* LCOV_EXCL_START */
MTP_LOGE("No MTP device");
property_value = NULL;
result = MTP_ERROR_NO_DEVICE;
+ /* LCOV_EXCL_STOP */
}
mtp_gdbuslib_objectinfo_complete_get_property_string(param->object,
param = g_try_new0(mtp_param, 1);
if (param == NULL) {
+ /* LCOV_EXCL_START */
MTP_LOGE("Memory allocation failed");
result = MTP_ERROR_OUT_OF_MEMORY;
goto OUT;
+ /* LCOV_EXCL_STOP */
}
param->object = g_object_ref(objectinfo);
if (mtp_daemon_controller_push(__objectinfo_get_property_thread_func,
param, param->mtp_ctx) != MTP_ERROR_NONE) {
+ /* LCOV_EXCL_START */
/* return error if queue was blocked */
MTP_LOGE("controller is processing important message");
result = MTP_ERROR_CONTROLLER;
goto OUT;
+ /* LCOV_EXCL_STOP */
}
return TRUE;
OUT:
+ /* LCOV_EXCL_START */
if (param != NULL) {
g_object_unref(param->invocation);
g_object_unref(param->object);
invocation, 0, result);
return TRUE;
+ /* LCOV_EXCL_STOP */
}
gboolean objectinfo_get_property_string(
param = g_try_new0(mtp_param, 1);
if (param == NULL) {
+ /* LCOV_EXCL_START */
MTP_LOGE("Memory allocation failed");
result = MTP_ERROR_OUT_OF_MEMORY;
goto OUT;
+ /* LCOV_EXCL_STOP */
}
param->object = g_object_ref(objectinfo);
if (mtp_daemon_controller_push(__objectinfo_get_property_string_thread_func,
param, param->mtp_ctx) != MTP_ERROR_NONE) {
+ /* LCOV_EXCL_START */
/* return error if queue was blocked */
MTP_LOGE("controller is processing important message");
result = MTP_ERROR_CONTROLLER;
goto OUT;
+ /* LCOV_EXCL_STOP */
}
return TRUE;
OUT:
+ /* LCOV_EXCL_START */
if (param != NULL) {
g_object_unref(param->invocation);
g_object_unref(param->object);
invocation, NULL, result);
return TRUE;
+ /* LCOV_EXCL_STOP */
}
mtp_storage, param->mtp_ctx);
if (storage)
- name = storage->StorageDescription;
+ name = storage->StorageDescription; //LCOV_EXCL_LINE
MTP_LOGI("device_id: %d, mtp_storage: %d, StorageDescription: %s",
device_id, mtp_storage, name);
} else {
+ /* LCOV_EXCL_START */
MTP_LOGE("No MTP device");
result = MTP_ERROR_NO_DEVICE;
+ /* LCOV_EXCL_STOP */
}
mtp_gdbuslib_storageinfo_complete_get_description(param->object,
mtp_storage, param->mtp_ctx);
if (storage)
- value = storage->FreeSpaceInBytes;
+ value = storage->FreeSpaceInBytes; //LCOV_EXCL_LINE
MTP_LOGI("device_id: %d, mtp_storage: %d, FreeSpaceInBytes: %llu",
device_id, mtp_storage, value);
} else {
+ /* LCOV_EXCL_START */
MTP_LOGE("No MTP device");
result = MTP_ERROR_NO_DEVICE;
+ /* LCOV_EXCL_STOP */
}
mtp_gdbuslib_storageinfo_complete_get_free_space(param->object,
mtp_storage, param->mtp_ctx);
if (storage)
- value = storage->MaxCapacity;
+ value = storage->MaxCapacity; //LCOV_EXCL_LINE
MTP_LOGI("device_id: %d, mtp_storage: %d, MaxCapacity: %llu",
device_id, mtp_storage, value);
} else {
+ /* LCOV_EXCL_START */
MTP_LOGE("No MTP device");
result = MTP_ERROR_NO_DEVICE;
+ /* LCOV_EXCL_STOP */
}
mtp_gdbuslib_storageinfo_complete_get_max_capacity(param->object,
mtp_storage, param->mtp_ctx);
if (storage)
- value = storage->StorageType;
+ value = storage->StorageType; //LCOV_EXCL_LINE
MTP_LOGI("device_id: %d, mtp_storage: %d, StorageType: %d",
device_id, mtp_storage, value);
} else {
+ /* LCOV_EXCL_START */
MTP_LOGE("No MTP device");
result = MTP_ERROR_NO_DEVICE;
+ /* LCOV_EXCL_STOP */
}
mtp_gdbuslib_storageinfo_complete_get_storage_type(param->object,
mtp_storage, param->mtp_ctx);
if (storage)
- name = storage->VolumeIdentifier;
+ name = storage->VolumeIdentifier; //LCOV_EXCL_LINE
MTP_LOGI("device_id: %d, mtp_storage: %d, VolumeIdentifier: %s",
device_id, mtp_storage, name);
} else {
+ /* LCOV_EXCL_START */
MTP_LOGE("No MTP device");
result = MTP_ERROR_NO_DEVICE;
+ /* LCOV_EXCL_STOP */
}
mtp_gdbuslib_storageinfo_complete_get_volume_identifier(param->object,
param = g_try_new0(mtp_param, 1);
if (param == NULL) {
+ /* LCOV_EXCL_START */
MTP_LOGE("Memory allocation failed");
result = MTP_ERROR_OUT_OF_MEMORY;
goto OUT;
+ /* LCOV_EXCL_STOP */
}
param->object = g_object_ref(storageinfo);
if (mtp_daemon_controller_push(__storageinfo_get_description_thread_func,
param, param->mtp_ctx) != MTP_ERROR_NONE) {
+ /* LCOV_EXCL_START */
/* return error if queue was blocked */
MTP_LOGE("controller is processing important message");
result = MTP_ERROR_CONTROLLER;
goto OUT;
+ /* LCOV_EXCL_STOP */
}
return TRUE;
OUT:
+ /* LCOV_EXCL_START */
if (param != NULL) {
g_object_unref(param->invocation);
g_object_unref(param->object);
mtp_gdbuslib_storageinfo_complete_get_description(storageinfo, invocation, 0, result);
return TRUE;
+ /* LCOV_EXCL_STOP */
}
gboolean storageinfo_get_freespace(
param = g_try_new0(mtp_param, 1);
if (param == NULL) {
+ /* LCOV_EXCL_START */
MTP_LOGE("Memory allocation failed");
result = MTP_ERROR_OUT_OF_MEMORY;
goto OUT;
+ /* LCOV_EXCL_STOP */
}
param->object = g_object_ref(storageinfo);
if (mtp_daemon_controller_push(__storageinfo_get_freespace_thread_func,
param, param->mtp_ctx) != MTP_ERROR_NONE) {
+ /* LCOV_EXCL_START */
/* return error if queue was blocked */
MTP_LOGE("controller is processing important message");
result = MTP_ERROR_CONTROLLER;
goto OUT;
+ /* LCOV_EXCL_STOP */
}
return TRUE;
OUT:
+ /* LCOV_EXCL_START */
if (param != NULL) {
g_object_unref(param->invocation);
g_object_unref(param->object);
mtp_gdbuslib_storageinfo_complete_get_free_space(storageinfo, invocation, 0, result);
return TRUE;
+ /* LCOV_EXCL_STOP */
}
gboolean storageinfo_get_maxcapacity(
param = g_try_new0(mtp_param, 1);
if (param == NULL) {
+ /* LCOV_EXCL_START */
MTP_LOGE("Memory allocation failed");
result = MTP_ERROR_OUT_OF_MEMORY;
goto OUT;
+ /* LCOV_EXCL_STOP */
}
param->object = g_object_ref(storageinfo);
if (mtp_daemon_controller_push(__storageinfo_get_maxcapacity_thread_func,
param, param->mtp_ctx) != MTP_ERROR_NONE) {
+ /* LCOV_EXCL_START */
/* return error if queue was blocked */
MTP_LOGE("controller is processing important message");
result = MTP_ERROR_CONTROLLER;
goto OUT;
+ /* LCOV_EXCL_STOP */
}
return TRUE;
OUT:
+ /* LCOV_EXCL_START */
if (param != NULL) {
g_object_unref(param->invocation);
g_object_unref(param->object);
mtp_gdbuslib_storageinfo_complete_get_max_capacity(storageinfo, invocation, 0, result);
return TRUE;
+ /* LCOV_EXCL_STOP */
}
gboolean storageinfo_get_storagetype(
param = g_try_new0(mtp_param, 1);
if (param == NULL) {
+ /* LCOV_EXCL_START */
MTP_LOGE("Memory allocation failed");
result = MTP_ERROR_OUT_OF_MEMORY;
goto OUT;
+ /* LCOV_EXCL_STOP */
}
param->object = g_object_ref(storageinfo);
if (mtp_daemon_controller_push(__storageinfo_get_storagetype_thread_func,
param, param->mtp_ctx) != MTP_ERROR_NONE) {
+ /* LCOV_EXCL_START */
/* return error if queue was blocked */
MTP_LOGE("controller is processing important message");
result = MTP_ERROR_CONTROLLER;
goto OUT;
+ /* LCOV_EXCL_STOP */
}
return TRUE;
OUT:
+ /* LCOV_EXCL_START */
if (param != NULL) {
g_object_unref(param->invocation);
g_object_unref(param->object);
mtp_gdbuslib_storageinfo_complete_get_storage_type(storageinfo, invocation, 0, result);
return TRUE;
+ /* LCOV_EXCL_STOP */
}
gboolean storageinfo_get_volumeidentifier(
param = g_try_new0(mtp_param, 1);
if (param == NULL) {
+ /* LCOV_EXCL_START */
MTP_LOGE("Memory allocation failed");
result = MTP_ERROR_OUT_OF_MEMORY;
goto OUT;
+ /* LCOV_EXCL_STOP */
}
param->object = g_object_ref(storageinfo);
if (mtp_daemon_controller_push(__storageinfo_get_volumeidentifier_thread_func,
param, param->mtp_ctx) != MTP_ERROR_NONE) {
+ /* LCOV_EXCL_START */
/* return error if queue was blocked */
MTP_LOGE("controller is processing important message");
result = MTP_ERROR_CONTROLLER;
goto OUT;
+ /* LCOV_EXCL_STOP */
}
return TRUE;
OUT:
+ /* LCOV_EXCL_START */
if (param != NULL) {
g_object_unref(param->invocation);
g_object_unref(param->object);
invocation, 0, result);
return TRUE;
+ /* LCOV_EXCL_STOP */
}
if (device_info != NULL && device_info->device == mtp_device) {
for (storage = device_info->device->storage; storage != NULL; storage = storage->next) {
- if (storage->id == mtp_storage)
+ if (storage->id == mtp_storage) //LCOV_EXCL_LINE
return storage;
}
}
--- /dev/null
+CMAKE_MINIMUM_REQUIRED(VERSION 2.6)
+PROJECT(gtest-mtp-initiator C CXX)
+
+SET(GTEST_TEST "gtest-mtp-initiator")
+ADD_DEFINITIONS("-DUSE_DLOG")
+
+SET(REQUIRES_LIST ${REQUIRES_LIST}
+ glib-2.0
+ gio-2.0
+ gmock
+ dlog
+ capi-system-info
+)
+
+INCLUDE(FindPkgConfig)
+PKG_CHECK_MODULES(GTEST_TEST_PKG REQUIRED ${REQUIRES_LIST})
+
+FOREACH(flag ${GTEST_TEST_PKG_CFLAGS})
+ SET(EXTRA_CFLAGS "${EXTRA_CFLAGS} ${flag}")
+ENDFOREACH(flag)
+
+SET(EXTRA_CFLAGS "${EXTRA_CFLAGS} -Wall -fPIE")
+SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${EXTRA_CFLAGS}")
+SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${EXTRA_CFLAGS}")
+SET(CMAKE_EXE_LINKER_FLAGS "-Wl,--as-needed -pie")
+
+FILE(GLOB GTEST_TEST_SRCS *.cpp)
+SET(GTEST_TEST_SRCS ${GTEST_TEST_SRCS})
+
+ADD_EXECUTABLE(${GTEST_TEST} ${GTEST_TEST_SRCS})
+TARGET_LINK_LIBRARIES(${GTEST_TEST} ${GTEST_TEST_LDFLAGS} ${GTEST_TEST_PKG_LDFLAGS} -ldl)
+
+INSTALL(TARGETS ${GTEST_TEST} RUNTIME DESTINATION bin)
--- /dev/null
+/*
+ * Copyright (c) 2018 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 __MTP_INITIATOR_CONF_H__
+#define __MTP_INITIATOR_CONF_H__
+
+#include <glib.h>
+
+#ifdef USE_DLOG
+#include <dlog.h>
+#undef LOG_TAG
+#define LOG_TAG "MTP_INITIATOR_GTEST"
+#define GLOGD(format, args...) LOGD(format, ##args)
+#else
+#define GLOGD(format, args...)
+#endif
+
+#define MTP_FEATURE "http://tizen.org/feature/network.mtp"
+
+
+typedef enum {
+ ERROR_NONE = 0,
+ ERROR_NOT_PERMITTED = -1,
+ ERROR_OUT_OF_MEMORY = -2,
+ ERROR_PERMISSION_DENIED = -3,
+ ERROR_RESOURCE_BUSY = -4,
+ ERROR_INVALID_OPERATION = -5,
+ ERROR_INVALID_PARAMETER = -6,
+ ERROR_NOT_SUPPORTED = -7,
+ ERROR_OPERATION_FAILED = -8,
+ ERROR_NOT_INITIALIZED = -9,
+ ERROR_ALREADY_INITIALIZED = -10,
+ ERROR_IN_PROGRESS = -11,
+} error_e;
+#endif /* __MTP_INITIATOR_CONF_H__ */
--- /dev/null
+/*
+ * Copyright (c) 2018 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.
+ */
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <iostream>
+#include <gmock/gmock.h>
+#include <gtest/gtest.h>
+
+#include "gdbus.h"
+
+GDbus::GDbus()
+{
+ this->m_pConnection = NULL;
+ this->m_pCancellable = NULL;
+}
+
+GDbus::~GDbus()
+{
+ GDBusConnection *conn = this->m_pConnection;
+ GCancellable *cancel = this->m_pCancellable;
+
+ if (cancel) {
+ g_cancellable_cancel(cancel);
+ g_object_unref(cancel);
+ cancel = NULL;
+ }
+
+ if (conn) {
+ g_object_unref(conn);
+ conn = NULL;
+ }
+}
+
+error_e GDbus::Create(void)
+{
+ GError *err = NULL;
+
+#if !GLIB_CHECK_VERSION(2, 36, 0)
+ g_type_init();
+#endif
+
+ this->m_pConnection = g_bus_get_sync(G_BUS_TYPE_SYSTEM, NULL, &err);
+ if (this->m_pConnection == NULL) {
+ if (err != NULL) {
+ GLOGD("Failed to connect to the D-BUS daemon [%s]", err->message);
+ g_error_free(err);
+ }
+
+ return ERROR_OPERATION_FAILED;
+ }
+
+ this->m_pCancellable = g_cancellable_new();
+
+ return ERROR_NONE;
+}
+
+error_e GDbus::Destroy(void)
+{
+ g_cancellable_cancel(this->m_pCancellable);
+ g_object_unref(this->m_pCancellable);
+ this->m_pCancellable = NULL;
+
+ g_object_unref(this->m_pConnection);
+ this->m_pConnection = NULL;
+
+ return ERROR_NONE;
+}
+
+GDBusConnection *GDbus::GetConnection(void)
+{
+ return this->m_pConnection;
+}
+
+GCancellable *GDbus::GetCancellable(void)
+{
+ return this->m_pCancellable;
+}
+
+error_e GDbus::ConvertErrorStringToEnum(const char *error)
+{
+ if (NULL != strstr(error, "NoReply"))
+ return ERROR_INVALID_OPERATION;
+ else if (NULL != strstr(error, "Failed"))
+ return ERROR_OPERATION_FAILED;
+ else if (NULL != strstr(error, "UnknownMethod"))
+ return ERROR_INVALID_OPERATION;
+ else if (NULL != strstr(error, "InvalidArguments"))
+ return ERROR_INVALID_PARAMETER;
+ else if (NULL != strstr(error, "AccessDenied"))
+ return ERROR_PERMISSION_DENIED;
+ else if (NULL != strstr(error, "PermissionDenied"))
+ return ERROR_PERMISSION_DENIED;
+ else if (NULL != strstr(error, "NotSupported"))
+ return ERROR_NOT_SUPPORTED;
+ else if (NULL != strstr(error, "InProgress"))
+ return ERROR_IN_PROGRESS;
+
+ return ERROR_OPERATION_FAILED;
+}
+
+GVariant *GDbus::InvokeMethod(const char *dest, const char *path,
+ const char *iface_name, const char *method, GVariant *params, error_e *dbus_error)
+{
+ GError *error = NULL;
+ GVariant *reply = NULL;
+ GDBusConnection *connection = NULL;
+ *dbus_error = ERROR_NONE;
+
+ connection = GetConnection();
+ if (connection == NULL) {
+ GLOGD("GDBusconnection is NULL");
+ *dbus_error = ERROR_NOT_INITIALIZED;
+ return reply;
+ }
+
+ reply = g_dbus_connection_call_sync(connection,
+ dest,
+ path,
+ iface_name,
+ method,
+ params,
+ NULL,
+ G_DBUS_CALL_FLAGS_NONE,
+ DBUS_REPLY_TIMEOUT,
+ GetCancellable(),
+ &error);
+
+ if (reply == NULL) {
+ if (error != NULL) {
+ GLOGD("g_dbus_connection_call_sync() failed "
+ "error [%d: %s]", error->code, error->message);
+ *dbus_error = ConvertErrorStringToEnum(error->message);
+ g_error_free(error);
+ } else {
+ GLOGD("g_dbus_connection_call_sync() failed");
+ *dbus_error = ERROR_OPERATION_FAILED;
+ }
+
+ return NULL;
+ }
+
+ return reply;
+}
--- /dev/null
+/*
+ * Copyright (c) 2018 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 __MTP_INIATOR_GDBUS_H__
+#define __MTP_INIATOR_GDBUS_H__
+
+#include <glib.h>
+#include <gio/gio.h>
+
+#include "common.h"
+
+#define GMAINTIMEOUT 10000
+#define DBUS_REPLY_TIMEOUT (120 * 1000)
+
+#define MTP_INITIATOR "org.tizen.mtp"
+
+#define MTP_INITIATOR_PATH "/org/tizen/mtp/manager"
+#define MTP_INITIATOR_INTERFACE "org.tizen.mtp.manager"
+
+#define MTP_DEVICE_PATH "/org/tizen/mtp/deviceinfo"
+#define MTP_DEVICE_INTERFACE "org.tizen.mtp.deviceinfo"
+
+#define MTP_STORAGE_PATH "/org/tizen/mtp/storageinfo"
+#define MTP_STORAGE_INTERFACE "org.tizen.mtp.storageinfo"
+
+#define MTP_OBJECT_PATH "/org/tizen/mtp/objectinfo"
+#define MTP_OBJECT_INTERFACE "org.tizen.mtp.objectinfo"
+
+#define GET_DEVICES "GetDevices"
+#define GET_STORAGES "GetStorages"
+#define GET_OBJECT_HANDLES "GetObjectHandles"
+#define GET_OBJECT "GetObject"
+#define GET_THUMBNAIL "GetThumbnail"
+#define DELETE_OBJECT "DeleteObject"
+#define GET_MANUFACTURER_NAME "GetManufacturerName"
+#define GET_MODEL_NAME "GetModelName"
+#define GET_SERIAL_NAME "GetSerialName"
+#define GET_DEVICE_VERSION "GetDeviceVersion"
+#define GET_STITCHING_ENGINE_VERSION "GetStitchingEngineVersion"
+#define GET_SERIAL_NUMBER "GetSerialNumber"
+#define GET_DESCRIPTION "GetDescription"
+#define GET_PROPERTY "GetProperty"
+#define GET_PROPERTY_VALUE "GetPropertyString"
+#define GET_FREE_SPACE "GetFreeSpace"
+#define GET_MAX_CAPACITY "GetMaxCapacity"
+#define GET_VOLUME_IDENTIFIER "GetVolumeIdentifier"
+#define GET_STORAGE_TYPE "GetStorageType"
+#define GET_BUS_LOCATION "GetBusLocation"
+#define GET_DEVICE_NUMBER "GetDeviceNumber"
+#define GET_PARTIAL_OBJECT "GetPartialObject"
+
+class GDbus {
+ private:
+ GDBusConnection *m_pConnection;
+ GCancellable *m_pCancellable;
+ public:
+ GDbus();
+ ~GDbus();
+ error_e Create(void);
+ error_e Destroy(void);
+ GDBusConnection *GetConnection(void);
+ GCancellable *GetCancellable(void);
+ error_e ConvertErrorStringToEnum(const char *error);
+ GVariant *InvokeMethod(const char *dest, const char *path,
+ const char *iface_name, const char *method, GVariant *params, error_e *dbus_error);
+ error_e InvokeMethodNonblock(const char *dest, const char *path,
+ const char *iface_name, const char *method, GVariant *params, int timeout,
+ GAsyncReadyCallback notify_func, void *user_data);
+ GVariant *InvokeMethod_with_fd(GUnixFDList *fd_list, const char *dest, const char *path,
+ const char *iface_name, const char *method, GVariant *params, error_e *dbus_error);
+};
+#endif /* __MTP_INIATOR_GDBUS_H__ */
--- /dev/null
+/*
+ * Copyright (c) 2018 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.
+ */
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <iostream>
+#include <gmock/gmock.h>
+#include <gtest/gtest.h>
+
+#include "mtp_initiator.h"
+
+MtpInitiator::MtpInitiator(void)
+{
+ Create();
+}
+
+MtpInitiator::~MtpInitiator(void)
+{
+ Destroy();
+}
+
+error_e MtpInitiator::GetDevices(void)
+{
+ GVariant *message = NULL;
+ error_e error = ERROR_NONE;
+ gint result;
+ GVariant *mtp_devices;
+ gint device_count;
+
+ message = InvokeMethod(MTP_INITIATOR,
+ MTP_INITIATOR_PATH,
+ MTP_INITIATOR_INTERFACE,
+ GET_DEVICES,
+ NULL,
+ &error);
+
+ if (message == NULL) {
+ GLOGD("Failed to invoke dbus method");
+ return error;
+ }
+
+ g_variant_get(message, "(i@aa{sv}i)", &device_count, &mtp_devices,
+ &result);
+
+ GLOGD("discovered devices[%d], result[%d]", device_count, result);
+
+ g_variant_unref(message);
+ g_variant_unref(mtp_devices);
+
+ return ERROR_NONE;
+}
+
+error_e MtpInitiator::GetStorages(gint mtp_device)
+{
+ GVariant *message = NULL;
+ error_e error = ERROR_NONE;
+ gint result;
+ GVariant *mtp_storages;
+ gint storage_count;
+
+ message = InvokeMethod(MTP_INITIATOR,
+ MTP_INITIATOR_PATH,
+ MTP_INITIATOR_INTERFACE,
+ GET_STORAGES,
+ g_variant_new("(i)", mtp_device),
+ &error);
+
+ if (message == NULL) {
+ GLOGD("Failed to invoke dbus method");
+ return error;
+ }
+
+ g_variant_get(message, "(i@aa{sv}i)", &storage_count,
+ &mtp_storages, &result);
+
+ GLOGD("discoverd storages[%d], result[%d]", storage_count, result);
+
+ g_variant_unref(message);
+ g_variant_unref(mtp_storages);
+
+ return ERROR_NONE;
+}
+
+error_e MtpInitiator::GetObjectHandles(gint mtp_device, gint mtp_storage,
+ gint file_type, gint parent_object_handle)
+{
+ GVariant *message = NULL;
+ error_e error = ERROR_NONE;
+ gint result;
+ GVariant *object_handles;
+ gint object_count;
+
+ message = InvokeMethod(MTP_INITIATOR,
+ MTP_INITIATOR_PATH,
+ MTP_INITIATOR_INTERFACE,
+ GET_OBJECT_HANDLES,
+ g_variant_new("(iiii)", mtp_device, mtp_storage, file_type,
+ parent_object_handle),
+ &error);
+
+ if (message == NULL) {
+ GLOGD("Failed to invoke dbus method");
+ return error;
+ }
+
+ g_variant_get(message, "(i@aa{sv}i)", &object_count,
+ &object_handles, &result);
+
+ g_variant_unref(message);
+ g_variant_unref(object_handles);
+
+ return ERROR_NONE;
+}
+
+error_e MtpInitiator::GetObject(gint mtp_device, gint object_handle, char *dest_path)
+{
+ GVariant *message = NULL;
+ error_e error = ERROR_NONE;
+ gint result;
+
+ message = InvokeMethod(MTP_INITIATOR,
+ MTP_INITIATOR_PATH,
+ MTP_INITIATOR_INTERFACE,
+ GET_OBJECT,
+ g_variant_new("(iis)", mtp_device, object_handle, dest_path),
+ &error);
+
+ if (message == NULL) {
+ GLOGD("Failed to invoke dbus method");
+ return error;
+ }
+
+ g_variant_get(message, "(i)", &result);
+
+ g_variant_unref(message);
+
+ return ERROR_NONE;
+}
+
+error_e MtpInitiator::GetPartialObject(gint mtp_device, gint object_handle, char *dest_path,
+ gint offset, gint max_bytes)
+{
+ GVariant *message = NULL;
+ error_e error = ERROR_NONE;
+ gint result;
+ gint bytes;
+
+ message = InvokeMethod(MTP_INITIATOR,
+ MTP_INITIATOR_PATH,
+ MTP_INITIATOR_INTERFACE,
+ GET_PARTIAL_OBJECT,
+ g_variant_new("(iisii)", mtp_device, object_handle, dest_path,
+ offset, max_bytes),
+ &error);
+
+ if (message == NULL) {
+ GLOGD("Failed to invoke dbus method");
+ return error;
+ }
+
+ g_variant_get(message, "(ii)", &bytes, &result);
+
+ g_variant_unref(message);
+
+ return ERROR_NONE;
+}
+
+error_e MtpInitiator::GetThumbnail(gint mtp_device, gint object_handle, char *dest_path)
+{
+ GVariant *message = NULL;
+ error_e error = ERROR_NONE;
+ gint result;
+
+ message = InvokeMethod(MTP_INITIATOR,
+ MTP_INITIATOR_PATH,
+ MTP_INITIATOR_INTERFACE,
+ GET_THUMBNAIL,
+ g_variant_new("(iis)", mtp_device, object_handle, dest_path),
+ &error);
+
+ if (message == NULL) {
+ GLOGD("Failed to invoke dbus method");
+ return error;
+ }
+
+ g_variant_get(message, "(i)", &result);
+
+ g_variant_unref(message);
+
+ return ERROR_NONE;
+}
+
+error_e MtpInitiator::DeleteObject(gint mtp_device, gint object_handle)
+{
+ GVariant *message = NULL;
+ error_e error = ERROR_NONE;
+ gint result;
+
+ message = InvokeMethod(MTP_INITIATOR,
+ MTP_INITIATOR_PATH,
+ MTP_INITIATOR_INTERFACE,
+ DELETE_OBJECT,
+ g_variant_new("(ii)", mtp_device, object_handle),
+ &error);
+
+ if (message == NULL) {
+ GLOGD("Failed to invoke dbus method");
+ return error;
+ }
+
+ g_variant_get(message, "(i)", &result);
+
+ g_variant_unref(message);
+
+ return ERROR_NONE;
+}
+
+error_e MtpInitiator::GetManufacturerName(gint mtp_device)
+{
+ GVariant *message = NULL;
+ error_e error = ERROR_NONE;
+ gint result;
+ gchar *serial = NULL;
+
+ message = InvokeMethod(MTP_INITIATOR,
+ MTP_DEVICE_PATH,
+ MTP_DEVICE_INTERFACE,
+ GET_MANUFACTURER_NAME,
+ g_variant_new("(i)", mtp_device),
+ &error);
+
+ if (message == NULL) {
+ GLOGD("Failed to invoke dbus method");
+ return error;
+ }
+
+ g_variant_get(message, "(si)", &serial, &result);
+ GLOGD("Manufacturer Serial : %s", serial);
+
+ g_variant_unref(message);
+
+ return ERROR_NONE;
+}
+
+error_e MtpInitiator::GetModelName(gint mtp_device)
+{
+ GVariant *message = NULL;
+ error_e error = ERROR_NONE;
+ gint result;
+ gchar *model_name = NULL;
+
+ message = InvokeMethod(MTP_INITIATOR,
+ MTP_DEVICE_PATH,
+ MTP_DEVICE_INTERFACE,
+ GET_MODEL_NAME,
+ g_variant_new("(i)", mtp_device),
+ &error);
+
+ if (message == NULL) {
+ GLOGD("Failed to invoke dbus method");
+ return error;
+ }
+
+ g_variant_get(message, "(si)", &model_name, &result);
+ GLOGD("Model name: %s", model_name);
+
+ g_variant_unref(message);
+
+ return ERROR_NONE;
+}
+
+error_e MtpInitiator::GetSerialName(gint mtp_device)
+{
+ GVariant *message = NULL;
+ error_e error = ERROR_NONE;
+ gint result;
+ gchar *serial_number = NULL;
+
+ message = InvokeMethod(MTP_INITIATOR,
+ MTP_DEVICE_PATH,
+ MTP_DEVICE_INTERFACE,
+ GET_SERIAL_NAME,
+ g_variant_new("(i)", mtp_device),
+ &error);
+
+ if (message == NULL) {
+ GLOGD("Failed to invoke dbus method");
+ return error;
+ }
+
+ g_variant_get(message, "(si)", &serial_number, &result);
+ GLOGD("serial number : %s", serial_number);
+
+ g_variant_unref(message);
+
+ return ERROR_NONE;
+}
+
+error_e MtpInitiator::GetDeviceVersion(gint mtp_device)
+{
+ GVariant *message = NULL;
+ error_e error = ERROR_NONE;
+ gint result;
+ gchar *device_version = NULL;
+
+ message = InvokeMethod(MTP_INITIATOR,
+ MTP_DEVICE_PATH,
+ MTP_DEVICE_INTERFACE,
+ GET_DEVICE_VERSION,
+ g_variant_new("(i)", mtp_device),
+ &error);
+
+ if (message == NULL) {
+ GLOGD("Failed to invoke dbus method");
+ return error;
+ }
+
+ g_variant_get(message, "(si)", &device_version, &result);
+ GLOGD("Device version: %s", device_version);
+
+ g_variant_unref(message);
+
+ return ERROR_NONE;
+}
+
+error_e MtpInitiator::GetBusLocation(gint mtp_device)
+{
+ GVariant *message = NULL;
+ error_e error = ERROR_NONE;
+ gint result;
+ int bus_location = 0;
+
+ message = InvokeMethod(MTP_INITIATOR,
+ MTP_DEVICE_PATH,
+ MTP_DEVICE_INTERFACE,
+ GET_BUS_LOCATION,
+ g_variant_new("(i)", mtp_device),
+ &error);
+
+ if (message == NULL) {
+ GLOGD("Failed to invoke dbus method");
+ return error;
+ }
+
+ g_variant_get(message, "(ii)", &bus_location, &result);
+ GLOGD("Bus location: %d", bus_location);
+
+ g_variant_unref(message);
+
+ return ERROR_NONE;
+}
+
+error_e MtpInitiator::GetDeviceNumber(gint mtp_device)
+{
+ GVariant *message = NULL;
+ error_e error = ERROR_NONE;
+ gint result;
+ int device_num = 0;
+
+ message = InvokeMethod(MTP_INITIATOR,
+ MTP_DEVICE_PATH,
+ MTP_DEVICE_INTERFACE,
+ GET_DEVICE_NUMBER,
+ g_variant_new("(i)", mtp_device),
+ &error);
+
+ if (message == NULL) {
+ GLOGD("Failed to invoke dbus method");
+ return error;
+ }
+
+ g_variant_get(message, "(ii)", &device_num, &result);
+ GLOGD("Device number: %d", device_num);
+
+ g_variant_unref(message);
+
+ return ERROR_NONE;
+}
+
+error_e MtpInitiator::GetStitchingEngineVersion(gint mtp_device)
+{
+ GVariant *message = NULL;
+ error_e error = ERROR_NONE;
+ gint result;
+ gchar *engine_number = NULL;
+
+ message = InvokeMethod(MTP_INITIATOR,
+ MTP_DEVICE_PATH,
+ MTP_DEVICE_INTERFACE,
+ GET_STITCHING_ENGINE_VERSION,
+ g_variant_new("(i)", mtp_device),
+ &error);
+
+ if (message == NULL) {
+ GLOGD("Failed to invoke dbus method");
+ return error;
+ }
+
+ g_variant_get(message, "(si)", &engine_number, &result);
+ GLOGD("Stitching Engine Version: %s", engine_number);
+
+ g_variant_unref(message);
+
+ return ERROR_NONE;
+}
+
+error_e MtpInitiator::GetSerialNumber(gint mtp_device)
+{
+ GVariant *message = NULL;
+ error_e error = ERROR_NONE;
+ gint result;
+ gchar *serial = NULL;
+
+ message = InvokeMethod(MTP_INITIATOR,
+ MTP_DEVICE_PATH,
+ MTP_DEVICE_INTERFACE,
+ GET_SERIAL_NUMBER,
+ g_variant_new("(i)", mtp_device),
+ &error);
+
+ if (message == NULL) {
+ GLOGD("Failed to invoke dbus method");
+ return error;
+ }
+
+ g_variant_get(message, "(si)", &serial, &result);
+ GLOGD("Serial Number: %s", serial);
+
+ g_variant_unref(message);
+
+ return ERROR_NONE;
+}
+
+error_e MtpInitiator::GetDescription(gint mtp_device, gint storage)
+{
+ GVariant *message = NULL;
+ error_e error = ERROR_NONE;
+ gint result;
+ gchar *description = NULL;
+
+ message = InvokeMethod(MTP_INITIATOR,
+ MTP_STORAGE_PATH,
+ MTP_STORAGE_INTERFACE,
+ GET_DESCRIPTION,
+ g_variant_new("(ii)", mtp_device, storage),
+ &error);
+
+ if (message == NULL) {
+ GLOGD("Failed to invoke dbus method");
+ return error;
+ }
+
+ g_variant_get(message, "(si)", &description, &result);
+ GLOGD("Description: %s", description);
+
+ g_variant_unref(message);
+
+ return ERROR_NONE;
+}
+
+error_e MtpInitiator::GetFreeSpace(gint mtp_device, gint storage)
+{
+ GVariant *message = NULL;
+ error_e error = ERROR_NONE;
+ gint result;
+ guint64 free_space;
+
+ message = InvokeMethod(MTP_INITIATOR,
+ MTP_STORAGE_PATH,
+ MTP_STORAGE_INTERFACE,
+ GET_FREE_SPACE,
+ g_variant_new("(ii)", mtp_device, storage),
+ &error);
+
+ if (message == NULL) {
+ GLOGD("Failed to invoke dbus method");
+ return error;
+ }
+
+ g_variant_get(message, "(ti)", &free_space, &result);
+ GLOGD("free space: %" G_GUINT64_FORMAT, free_space);
+
+ g_variant_unref(message);
+
+ return ERROR_NONE;
+}
+
+error_e MtpInitiator::GetMaxCapacity(gint mtp_device, gint storage)
+{
+ GVariant *message = NULL;
+ error_e error = ERROR_NONE;
+ gint result;
+ guint64 max_capacity;
+
+ message = InvokeMethod(MTP_INITIATOR,
+ MTP_STORAGE_PATH,
+ MTP_STORAGE_INTERFACE,
+ GET_MAX_CAPACITY,
+ g_variant_new("(ii)", mtp_device, storage),
+ &error);
+
+ if (message == NULL) {
+ GLOGD("Failed to invoke dbus method");
+ return error;
+ }
+
+ g_variant_get(message, "(ti)", &max_capacity, &result);
+ GLOGD("max capacity: %" G_GUINT64_FORMAT, max_capacity);
+
+ g_variant_unref(message);
+
+ return ERROR_NONE;
+}
+
+error_e MtpInitiator::GetStorageType(gint mtp_device, gint storage)
+{
+ GVariant *message = NULL;
+ error_e error = ERROR_NONE;
+ gint result;
+ gint storage_type;
+
+ message = InvokeMethod(MTP_INITIATOR,
+ MTP_STORAGE_PATH,
+ MTP_STORAGE_INTERFACE,
+ GET_STORAGE_TYPE,
+ g_variant_new("(ii)", mtp_device, storage),
+ &error);
+
+ if (message == NULL) {
+ GLOGD("Failed to invoke dbus method");
+ return error;
+ }
+
+ g_variant_get(message, "(ii)", &storage_type, &result);
+ GLOGD("storage type: %d", storage_type);
+
+ g_variant_unref(message);
+
+ return ERROR_NONE;
+}
+
+error_e MtpInitiator::GetVolumeIdentifier(gint mtp_device, gint storage)
+{
+ GVariant *message = NULL;
+ error_e error = ERROR_NONE;
+ gint result;
+ gchar *volume_identifier = NULL;
+
+ message = InvokeMethod(MTP_INITIATOR,
+ MTP_STORAGE_PATH,
+ MTP_STORAGE_INTERFACE,
+ GET_VOLUME_IDENTIFIER,
+ g_variant_new("(ii)", mtp_device, storage),
+ &error);
+
+ if (message == NULL) {
+ GLOGD("Failed to invoke dbus method");
+ return error;
+ }
+
+ g_variant_get(message, "(si)", &volume_identifier, &result);
+ GLOGD("storage type: %s", volume_identifier);
+
+ g_variant_unref(message);
+
+ return ERROR_NONE;
+}
+
+error_e MtpInitiator::GetProperty(gint mtp_device, gint object_handle, gint property)
+{
+ GVariant *message = NULL;
+ error_e error = ERROR_NONE;
+ gint result;
+ gint property_value;
+
+ message = InvokeMethod(MTP_INITIATOR,
+ MTP_OBJECT_PATH,
+ MTP_OBJECT_INTERFACE,
+ GET_PROPERTY,
+ g_variant_new("(iii)", mtp_device, object_handle, property),
+ &error);
+
+ if (message == NULL) {
+ GLOGD("Failed to invoke dbus method");
+ return error;
+ }
+
+ g_variant_get(message, "(ii)", &property_value, &result);
+ GLOGD("storage type: %d", property_value);
+
+ g_variant_unref(message);
+
+ return ERROR_NONE;
+}
+
+error_e MtpInitiator::GetPropertyString(gint mtp_device, gint object_handle, gint property)
+{
+ GVariant *message = NULL;
+ error_e error = ERROR_NONE;
+ gint result;
+ gchar *property_string = NULL;
+
+ message = InvokeMethod(MTP_INITIATOR,
+ MTP_OBJECT_PATH,
+ MTP_OBJECT_INTERFACE,
+ GET_PROPERTY_VALUE,
+ g_variant_new("(iii)", mtp_device, object_handle, property),
+ &error);
+
+ if (message == NULL) {
+ GLOGD("Failed to invoke dbus method");
+ return error;
+ }
+
+ g_variant_get(message, "(si)", &property_string, &result);
+ GLOGD("storage type: %s", property_string);
+
+ g_variant_unref(message);
+
+ return ERROR_NONE;
+}
--- /dev/null
+/*
+ * Copyright (c) 2018 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 __MTP_INITIATOR_H__
+#define __MTP_INITIATOR_H__
+
+#include <glib.h>
+#include <gio/gio.h>
+
+#include "gdbus.h"
+
+class MtpInitiator:public GDbus {
+ private:
+ public:
+ MtpInitiator(void);
+ ~MtpInitiator(void);
+ error_e GetDevices(void);
+ error_e GetStorages(gint mtp_device);
+ error_e GetObjectHandles(gint mtp_device, gint mtp_storage,
+ gint file_type, gint parent_object_handle);
+ error_e GetObject(gint mtp_device, gint object_handle, char *dest_path);
+ error_e GetPartialObject(gint mtp_device, gint object_handle, char *dest_path,
+ gint offset, gint max_bytes);
+ error_e DeleteObject(gint mtp_device, gint object_handle);
+ error_e GetThumbnail(gint mtp_device, gint object_handle, char *dest_path);
+ error_e GetManufacturerName(gint mtp_device);
+ error_e GetStitchingEngineVersion(gint mtp_device);
+ error_e GetDeviceNumber(gint mtp_device);
+ error_e GetBusLocation(gint mtp_device);
+ error_e GetDeviceVersion(gint mtp_device);
+ error_e GetSerialName(gint mtp_device);
+ error_e GetModelName(gint mtp_device);
+ error_e GetDescription(gint mtp_device, gint storage);
+ error_e GetFreeSpace(gint mtp_device, gint storage);
+ error_e GetMaxCapacity(gint mtp_device, gint storage);
+ error_e GetStorageType(gint mtp_device, gint storage);
+ error_e GetVolumeIdentifier(gint mtp_device, gint storage);
+ error_e GetPropertyString(gint mtp_device, gint object_handle, gint property);
+ error_e GetProperty(gint mtp_device, gint object_handle, gint property);
+ error_e GetSerialNumber(gint mtp_device);
+
+};
+
+#endif /* __MTP_INITIATOR_H__ */
--- /dev/null
+/*
+ * 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.
+ */
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <iostream>
+#include <gmock/gmock.h>
+#include <gtest/gtest.h>
+#include <unistd.h>
+#include <glib.h>
+#include <system_info.h>
+
+#include "mtp_initiator.h"
+
+using ::testing::InitGoogleTest;
+using ::testing::Test;
+using ::testing::TestCase;
+
+char *feature_name = (char *)"http://tizen.org/feature/network.mtp";
+
+int CheckFeature()
+{
+ bool mtp_supported = FALSE;
+ if (!system_info_get_platform_bool(feature_name, &mtp_supported)) {
+ if (FALSE == mtp_supported) {
+ GLOGD("mtp feature is disabled"); // LCOV_EXCL_LINE
+ return ERROR_NOT_SUPPORTED;
+ }
+ return ERROR_NONE;
+ } else {
+ GLOGD("Error - Feature getting from System Info"); // LCOV_EXCL_LINE
+ return ERROR_INVALID_PARAMETER;
+ }
+}
+
+TEST(MtpManager_t, GetDevices_p)
+{
+ int ret = 0;
+ MtpInitiator M;
+
+ ret = M.GetDevices();
+ EXPECT_EQ(ERROR_NONE, ret);
+}
+
+TEST(MtpManager_t, GetStorages_p)
+{
+ int ret = 0;
+ MtpInitiator M;
+
+ ret = M.GetStorages(1);
+ EXPECT_EQ(ERROR_NONE, ret);
+}
+
+TEST(MtpManager_t, GetObjectHandles_p)
+{
+ int ret = 0;
+ MtpInitiator M;
+
+ ret = M.GetObjectHandles(1, 1, 0, 1);
+ EXPECT_EQ(ERROR_NONE, ret);
+}
+
+TEST(MtpManager_t, GetObject_p)
+{
+ int ret = 0;
+ MtpInitiator M;
+
+ ret = M.GetObject(1, 1, "/tmp/gtest_file");
+ EXPECT_EQ(ERROR_NONE, ret);
+}
+
+TEST(MtpManager_t, GetPartialObject_p)
+{
+ int ret = 0;
+ MtpInitiator M;
+
+ ret = M.GetPartialObject(1, 1, "/tmp/gtest_file", 0, 1);
+ EXPECT_EQ(ERROR_NONE, ret);
+}
+
+TEST(MtpManager_t, GetThumbnail_p)
+{
+ int ret = 0;
+ MtpInitiator M;
+
+ ret = M.GetThumbnail(1, 1, "/tmp/gtest_thumb");
+ EXPECT_EQ(ERROR_NONE, ret);
+}
+
+TEST(MtpManager_t, DeleteObject_p)
+{
+ int ret = 0;
+ MtpInitiator M;
+
+ ret = M.DeleteObject(1, 1);
+ EXPECT_EQ(ERROR_NONE, ret);
+}
+
+TEST(MtpDeviceInfo_t, GetManufacturerName_p)
+{
+ int ret = 0;
+ MtpInitiator M;
+
+ ret = M.GetManufacturerName(1);
+ EXPECT_EQ(ERROR_NONE, ret);
+}
+
+TEST(MtpDeviceInfo_t, GetModelName_p)
+{
+ int ret = 0;
+ MtpInitiator M;
+
+ ret = M.GetModelName(1);
+ EXPECT_EQ(ERROR_NONE, ret);
+}
+
+TEST(MtpDeviceInfo_t, GetDeviceVersion_p)
+{
+ int ret = 0;
+ MtpInitiator M;
+
+ ret = M.GetDeviceVersion(1);
+ EXPECT_EQ(ERROR_NONE, ret);
+}
+TEST(MtpDeviceInfo_t, GetBusLocation_p)
+{
+ int ret = 0;
+ MtpInitiator M;
+
+ ret = M.GetBusLocation(1);
+ EXPECT_EQ(ERROR_NONE, ret);
+}
+TEST(MtpDeviceInfo_t, GetDeviceNumber_p)
+{
+ int ret = 0;
+ MtpInitiator M;
+
+ ret = M.GetDeviceNumber(1);
+ EXPECT_EQ(ERROR_NONE, ret);
+}
+TEST(MtpDeviceInfo_t, GetStitchingEngineVersion_p)
+{
+ int ret = 0;
+ MtpInitiator M;
+
+ ret = M.GetStitchingEngineVersion(1);
+ EXPECT_EQ(ERROR_NONE, ret);
+}
+
+TEST(MtpDeviceInfo_t, GetSerialNumber_p)
+{
+ int ret = 0;
+ MtpInitiator M;
+
+ ret = M.GetSerialNumber(1);
+ EXPECT_EQ(ERROR_NONE, ret);
+}
+
+TEST(MtpStorageInfo_t, GetDescription_p)
+{
+ int ret = 0;
+ MtpInitiator M;
+
+ ret = M.GetDescription(1, 1);
+ EXPECT_EQ(ERROR_NONE, ret);
+}
+
+TEST(MtpStorageInfo_t, GetFreeSpace_p)
+{
+ int ret = 0;
+ MtpInitiator M;
+
+ ret = M.GetFreeSpace(1, 1);
+ EXPECT_EQ(ERROR_NONE, ret);
+}
+
+TEST(MtpStorageInfo_t, GetMaxCapacity_p)
+{
+ int ret = 0;
+ MtpInitiator M;
+
+ ret = M.GetMaxCapacity(1, 1);
+ EXPECT_EQ(ERROR_NONE, ret);
+}
+
+TEST(MtpStorageInfo_t, GetStorageType_p)
+{
+ int ret = 0;
+ MtpInitiator M;
+
+ ret = M.GetStorageType(1, 1);
+ EXPECT_EQ(ERROR_NONE, ret);
+}
+
+TEST(MtpStorageInfo_t, GetVolumeIdentifier_p)
+{
+ int ret = 0;
+ MtpInitiator M;
+
+ ret = M.GetVolumeIdentifier(1, 1);
+ EXPECT_EQ(ERROR_NONE, ret);
+}
+
+TEST(MtpObjectInfo_t, GetProperty_p)
+{
+ int ret = 0;
+ MtpInitiator M;
+
+ ret = M.GetProperty(1, 1, 1);
+ EXPECT_EQ(ERROR_NONE, ret);
+}
+
+TEST(MtpObjectInfo_t, GetPropertyString_p)
+{
+ int ret = 0;
+ MtpInitiator M;
+
+ ret = M.GetPropertyString(1, 1, 1);
+ EXPECT_EQ(ERROR_NONE, ret);
+}
+
+int main(int argc, char **argv)
+{
+ int ret = 0;
+ ret = CheckFeature();
+
+ if (ERROR_NONE != ret)
+ return ret;
+
+ InitGoogleTest(&argc, argv);
+ return RUN_ALL_TESTS();
+}