2 * Copyright (c) 2012, 2013 Samsung Electronics Co., Ltd.
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
24 #include <system_info.h>
27 #include "mtp_internal.h"
29 #include "mtp_debug.h"
30 #include "mtp_private.h"
32 #include "mtp_gdbus_manager.h"
33 #include "mtp_gdbus_deviceinfo.h"
34 #include "mtp_gdbus_storageinfo.h"
35 #include "mtp_gdbus_objectinfo.h"
37 #define MTP_FEATURE "http://tizen.org/feature/network.mtp"
41 pthread_mutex_lock(&mutex); \
46 pthread_mutex_unlock(&mutex); \
49 static pthread_mutex_t mutex = PTHREAD_MUTEX_INITIALIZER;
51 #define CHECK_INIT() \
55 if (__is_initialized == false) { \
57 return MTP_ERROR_NOT_INITIALIZED; \
64 bool __is_initialized = false;
66 static bool __is_mtp_supported()
68 bool is_supported_mtp = false;
70 system_info_get_platform_bool(MTP_FEATURE, &is_supported_mtp);
72 return is_supported_mtp;
75 static bool __is_mtp_activated()
81 int mtp_initialize(void)
83 int ret = MTP_ERROR_NONE;
87 /* precondition check start */
91 /* precondition check end */
95 if (__is_initialized == false) {
96 ret = mtp_gdbus_manager_initialize();
98 __is_initialized = true;
109 int mtp_get_devices(int **mtp_devices, int *device_count)
111 int ret = MTP_ERROR_NONE;
115 /* precondition check start */
120 cond_expr_ret(mtp_devices == NULL, MTP_ERROR_INVALID_PARAMETER);
121 cond_expr_ret(device_count == NULL, MTP_ERROR_INVALID_PARAMETER);
123 /* precondition check end */
125 ret = mtp_gdbus_manager_get_devices(mtp_devices, device_count);
127 TC_PRT("device count %d", *device_count);
134 int mtp_get_storages(int mtp_device, int **mtp_storages, int* storage_count)
136 int ret = MTP_ERROR_NONE;
140 /* precondition check start */
145 cond_expr_ret(mtp_device == 0, MTP_ERROR_INVALID_PARAMETER);
146 cond_expr_ret(mtp_storages == NULL, MTP_ERROR_INVALID_PARAMETER);
147 cond_expr_ret(storage_count == NULL, MTP_ERROR_INVALID_PARAMETER);
149 /* precondition check end */
151 ret = mtp_gdbus_manager_get_storages(mtp_device, mtp_storages, storage_count);
153 TC_PRT("storage count %d", *storage_count);
160 int mtp_get_object_handles(int mtp_device, int mtp_storage, mtp_filetype_e file_type,
161 int parent, int **object_handles, int* object_count)
163 int ret = MTP_ERROR_NONE;
167 /* precondition check start */
172 cond_expr_ret(mtp_device == 0, MTP_ERROR_INVALID_PARAMETER);
173 cond_expr_ret(mtp_storage == 0, MTP_ERROR_INVALID_PARAMETER);
174 cond_expr_ret(object_handles == NULL, MTP_ERROR_INVALID_PARAMETER);
175 cond_expr_ret(object_count == NULL, MTP_ERROR_INVALID_PARAMETER);
177 /* precondition check end */
179 ret = mtp_gdbus_manager_get_object_handles(mtp_device,
180 mtp_storage, file_type, parent, object_handles, object_count);
187 int mtp_delete_object(int mtp_device, int object_handle)
189 int ret = MTP_ERROR_NONE;
193 /* precondition check start */
198 cond_expr_ret(mtp_device == 0, MTP_ERROR_INVALID_PARAMETER);
199 cond_expr_ret(object_handle == 0, MTP_ERROR_INVALID_PARAMETER);
201 /* precondition check end */
203 ret = mtp_gdbus_manager_delete_object(mtp_device, object_handle);
210 int mtp_get_object(int mtp_device, int object_handle, char *dest_path)
212 int ret = MTP_ERROR_NONE;
216 /* precondition check start */
221 cond_expr_ret(mtp_device == 0, MTP_ERROR_INVALID_PARAMETER);
222 cond_expr_ret(dest_path == NULL, MTP_ERROR_INVALID_PARAMETER);
224 /* precondition check end */
226 ret = mtp_gdbus_manager_get_object(mtp_device, object_handle, dest_path);
233 int mtp_get_thumbnail(int mtp_device, int object_handle, char *dest_path)
235 int ret = MTP_ERROR_NONE;
239 /* precondition check start */
244 cond_expr_ret(mtp_device == 0, MTP_ERROR_INVALID_PARAMETER);
245 cond_expr_ret(dest_path == NULL, MTP_ERROR_INVALID_PARAMETER);
247 /* precondition check end */
249 ret = mtp_gdbus_manager_get_thumbnail(mtp_device, object_handle, dest_path);
256 int mtp_add_mtp_event_cb(mtp_event_cb callback, void *user_data)
258 int ret = MTP_ERROR_NONE;
262 /* precondition check start */
266 cond_expr_ret(callback == NULL, MTP_ERROR_INVALID_PARAMETER);
268 /* precondition check end */
270 ret = mtp_gdbus_manager_add_event_cb(callback, user_data);
277 int mtp_remove_mtp_event_cb(mtp_event_cb callback)
279 int ret = MTP_ERROR_NONE;
283 /* precondition check start */
287 cond_expr_ret(callback == NULL, MTP_ERROR_INVALID_PARAMETER);
289 /* precondition check end */
291 ret = mtp_gdbus_manager_remove_event_cb(callback);
298 int mtp_deinitialize(void)
300 int ret = MTP_ERROR_NONE;
304 /* precondition check start */
308 /* precondition check end */
315 if (__is_initialized == true && ref_count == 0) {
317 ret = mtp_gdbus_manager_deinitialize();
318 __is_initialized = false;
329 int mtp_deviceinfo_get_manufacturer_name(int mtp_device, char **manufacturer_name)
331 int ret = MTP_ERROR_NONE;
335 /* precondition check start */
340 cond_expr_ret(mtp_device == 0, MTP_ERROR_INVALID_PARAMETER);
342 /* precondition check end */
344 ret = mtp_gdbus_deviceinfo_get_manufacturer_name(mtp_device, manufacturer_name);
346 TC_PRT("manufacturername %s", *manufacturer_name);
353 int mtp_deviceinfo_get_model_name(int mtp_device, char **model_name)
355 int ret = MTP_ERROR_NONE;
359 /* precondition check start */
364 cond_expr_ret(mtp_device == 0, MTP_ERROR_INVALID_PARAMETER);
366 /* precondition check end */
368 ret = mtp_gdbus_deviceinfo_get_model_name(mtp_device, model_name);
370 TC_PRT("modelname %s", *model_name);
377 int mtp_deviceinfo_get_serial_number(int mtp_device, char **serial_number)
379 int ret = MTP_ERROR_NONE;
383 /* precondition check start */
388 cond_expr_ret(mtp_device == 0, MTP_ERROR_INVALID_PARAMETER);
390 /* precondition check end */
392 ret = mtp_gdbus_deviceinfo_get_serial_number(mtp_device, serial_number);
394 TC_PRT("serial number %s", *serial_number);
401 int mtp_deviceinfo_get_device_version(int mtp_device, char **device_version)
403 int ret = MTP_ERROR_NONE;
407 /* precondition check start */
412 cond_expr_ret(mtp_device == 0, MTP_ERROR_INVALID_PARAMETER);
414 /* precondition check end */
416 ret = mtp_gdbus_deviceinfo_get_device_version(mtp_device, device_version);
418 TC_PRT("device version %s", *device_version);
425 int mtp_deviceinfo_get_bus_location(int mtp_device, int *bus_location)
427 int ret = MTP_ERROR_NONE;
431 /* precondition check start */
436 cond_expr_ret(mtp_device == 0, MTP_ERROR_INVALID_PARAMETER);
437 cond_expr_ret(bus_location == NULL, MTP_ERROR_INVALID_PARAMETER);
439 /* precondition check end */
441 ret = mtp_gdbus_deviceinfo_get_bus_location(mtp_device, bus_location);
443 TC_PRT("bus location %d", *bus_location);
450 int mtp_deviceinfo_get_device_number(int mtp_device, int *device_number)
452 int ret = MTP_ERROR_NONE;
456 /* precondition check start */
461 cond_expr_ret(mtp_device == 0, MTP_ERROR_INVALID_PARAMETER);
462 cond_expr_ret(device_number == NULL, MTP_ERROR_INVALID_PARAMETER);
464 /* precondition check end */
466 ret = mtp_gdbus_deviceinfo_get_device_number(mtp_device, device_number);
468 TC_PRT("device number %d", *device_number);
476 int mtp_storageinfo_get_description(int mtp_device, int mtp_storage, char **description)
478 int ret = MTP_ERROR_NONE;
482 /* precondition check start */
487 cond_expr_ret(mtp_device == 0, MTP_ERROR_INVALID_PARAMETER);
488 cond_expr_ret(mtp_storage == 0, MTP_ERROR_INVALID_PARAMETER);
490 /* precondition check end */
492 ret = mtp_gdbus_storageinfo_get_description(mtp_device, mtp_storage, description);
494 TC_PRT("description %s", *description);
501 int mtp_storageinfo_get_free_space(int mtp_device, int mtp_storage, unsigned long long *free_space)
503 int ret = MTP_ERROR_NONE;
507 /* precondition check start */
512 cond_expr_ret(mtp_device == 0, MTP_ERROR_INVALID_PARAMETER);
513 cond_expr_ret(mtp_storage == 0, MTP_ERROR_INVALID_PARAMETER);
515 /* precondition check end */
517 ret = mtp_gdbus_storageinfo_get_free_space(mtp_device, mtp_storage, (guint64 *)free_space);
519 TC_PRT("freespace %llu", *free_space);
526 int mtp_storageinfo_get_max_capacity(int mtp_device, int mtp_storage, unsigned long long *max_capacity)
528 int ret = MTP_ERROR_NONE;
532 /* precondition check start */
537 cond_expr_ret(mtp_device == 0, MTP_ERROR_INVALID_PARAMETER);
538 cond_expr_ret(mtp_storage == 0, MTP_ERROR_INVALID_PARAMETER);
540 /* precondition check end */
542 ret = mtp_gdbus_storageinfo_get_max_capacity(mtp_device, mtp_storage, (guint64 *)max_capacity);
544 TC_PRT("maxcapacity %llu", *max_capacity);
551 int mtp_storageinfo_get_storage_type(int mtp_device, int mtp_storage, mtp_storage_type_e *storage_type)
553 int ret = MTP_ERROR_NONE;
557 /* precondition check start */
562 cond_expr_ret(mtp_device == 0, MTP_ERROR_INVALID_PARAMETER);
563 cond_expr_ret(mtp_storage == 0, MTP_ERROR_INVALID_PARAMETER);
565 /* precondition check end */
567 ret = mtp_gdbus_storageinfo_get_storage_type(mtp_device, mtp_storage, (int *)storage_type);
569 TC_PRT("storagetype %d", *storage_type);
576 int mtp_storageinfo_get_volume_identifier(int mtp_device, int mtp_storage, char **volume_identifier)
578 int ret = MTP_ERROR_NONE;
582 /* precondition check start */
587 cond_expr_ret(mtp_device == 0, MTP_ERROR_INVALID_PARAMETER);
588 cond_expr_ret(mtp_storage == 0, MTP_ERROR_INVALID_PARAMETER);
590 /* precondition check end */
592 ret = mtp_gdbus_storageinfo_get_volume_identifier(mtp_device, mtp_storage, volume_identifier);
594 TC_PRT("volumeidentifier %s", *volume_identifier);
602 int mtp_objectinfo_get_parent_object_handle(int mtp_device, int object_handle,
603 int *parent_object_handle)
605 int ret = MTP_ERROR_NONE;
609 /* precondition check start */
614 cond_expr_ret(mtp_device == 0, MTP_ERROR_INVALID_PARAMETER);
616 /* precondition check end */
618 ret = mtp_gdbus_objectinfo_get_property(mtp_device,
619 object_handle, MTP_PROPERTY_PARENT_OBJECT_HANDLE, parent_object_handle);
621 TC_PRT("parent object id %d", *parent_object_handle);
628 int mtp_objectinfo_get_storage(int mtp_device, int object_handle,
631 int ret = MTP_ERROR_NONE;
635 /* precondition check start */
640 cond_expr_ret(mtp_device == 0, MTP_ERROR_INVALID_PARAMETER);
642 /* precondition check end */
644 ret = mtp_gdbus_objectinfo_get_property(mtp_device,
645 object_handle, MTP_PROPERTY_STORAGE, mtp_storage);
652 int mtp_objectinfo_get_association_desc(int mtp_device,
653 int object_handle, int *asso_desc)
655 int ret = MTP_ERROR_NONE;
659 /* precondition check start */
664 cond_expr_ret(mtp_device == 0, MTP_ERROR_INVALID_PARAMETER);
666 /* precondition check end */
668 ret = mtp_gdbus_objectinfo_get_property(mtp_device,
669 object_handle, MTP_PROPERTY_ASSOCIATION_DESC, asso_desc);
676 int mtp_objectinfo_get_association_type(int mtp_device,
677 int object_handle, int *asso_type)
679 int ret = MTP_ERROR_NONE;
683 /* precondition check start */
688 cond_expr_ret(mtp_device == 0, MTP_ERROR_INVALID_PARAMETER);
690 /* precondition check end */
692 ret = mtp_gdbus_objectinfo_get_property(mtp_device,
693 object_handle, MTP_PROPERTY_ASSOCIATION_TYPE, asso_type);
700 int mtp_objectinfo_get_size(int mtp_device, int object_handle, int *size)
702 int ret = MTP_ERROR_NONE;
706 /* precondition check start */
711 cond_expr_ret(mtp_device == 0, MTP_ERROR_INVALID_PARAMETER);
713 /* precondition check end */
715 ret = mtp_gdbus_objectinfo_get_property(mtp_device,
716 object_handle, MTP_PROPERTY_SIZE, size);
723 int mtp_objectinfo_get_date_created(int mtp_device,
724 int object_handle, int *data_created)
726 int ret = MTP_ERROR_NONE;
730 /* precondition check start */
735 cond_expr_ret(mtp_device == 0, MTP_ERROR_INVALID_PARAMETER);
737 /* precondition check end */
739 ret = mtp_gdbus_objectinfo_get_property(mtp_device,
740 object_handle, MTP_PROPERTY_DATE_CREATED, data_created);
747 int mtp_objectinfo_get_date_modified(int mtp_device,
748 int object_handle, int *data_modified)
750 int ret = MTP_ERROR_NONE;
754 /* precondition check start */
759 cond_expr_ret(mtp_device == 0, MTP_ERROR_INVALID_PARAMETER);
761 /* precondition check end */
763 ret = mtp_gdbus_objectinfo_get_property(mtp_device,
764 object_handle, MTP_PROPERTY_DATE_MODIFIED, data_modified);
771 int mtp_objectinfo_get_file_type(int mtp_device, int object_handle, mtp_filetype_e *file_type)
773 int ret = MTP_ERROR_NONE;
777 /* precondition check start */
782 cond_expr_ret(mtp_device == 0, MTP_ERROR_INVALID_PARAMETER);
784 /* precondition check end */
786 ret = mtp_gdbus_objectinfo_get_property(mtp_device,
787 object_handle, MTP_PROPERTY_FILE_TYPE, (int*)file_type);
794 int mtp_objectinfo_get_image_bit_depth(int mtp_device,
795 int object_handle, int *depth)
797 int ret = MTP_ERROR_NONE;
801 /* precondition check start */
806 cond_expr_ret(mtp_device == 0, MTP_ERROR_INVALID_PARAMETER);
808 /* precondition check end */
810 ret = mtp_gdbus_objectinfo_get_property(mtp_device,
811 object_handle, MTP_PROPERTY_IMAGE_BIT_DEPTH, depth);
818 int mtp_objectinfo_get_image_pix_width(int mtp_device,
819 int object_handle, int *width)
821 int ret = MTP_ERROR_NONE;
825 /* precondition check start */
830 cond_expr_ret(mtp_device == 0, MTP_ERROR_INVALID_PARAMETER);
832 /* precondition check end */
834 ret = mtp_gdbus_objectinfo_get_property(mtp_device,
835 object_handle, MTP_PROPERTY_IMAGE_PIX_WIDTH, width);
842 int mtp_objectinfo_get_image_pix_height(int mtp_device,
843 int object_handle, int *height)
845 int ret = MTP_ERROR_NONE;
849 /* precondition check start */
854 cond_expr_ret(mtp_device == 0, MTP_ERROR_INVALID_PARAMETER);
856 /* precondition check end */
858 ret = mtp_gdbus_objectinfo_get_property(mtp_device,
859 object_handle, MTP_PROPERTY_IMAGE_PIX_HEIGHT, height);
866 int mtp_objectinfo_get_thumbnail_size(int mtp_device,
867 int object_handle, int *size)
869 int ret = MTP_ERROR_NONE;
873 /* precondition check start */
878 cond_expr_ret(mtp_device == 0, MTP_ERROR_INVALID_PARAMETER);
880 /* precondition check end */
882 ret = mtp_gdbus_objectinfo_get_property(mtp_device,
883 object_handle, MTP_PROPERTY_THUMBNAIL_SIZE, size);
890 int mtp_objectinfo_get_thumbnail_file_type(int mtp_device,
891 int object_handle, mtp_filetype_e *file_type)
893 int ret = MTP_ERROR_NONE;
897 /* precondition check start */
902 cond_expr_ret(mtp_device == 0, MTP_ERROR_INVALID_PARAMETER);
904 /* precondition check end */
906 ret = mtp_gdbus_objectinfo_get_property(mtp_device,
907 object_handle, MTP_PROPERTY_THUMBNAIL_FILE_TYPE, (int*)file_type);
914 int mtp_objectinfo_get_thumbnail_pix_height(int mtp_device,
915 int object_handle, int *height)
917 int ret = MTP_ERROR_NONE;
921 /* precondition check start */
926 cond_expr_ret(mtp_device == 0, MTP_ERROR_INVALID_PARAMETER);
928 /* precondition check end */
930 ret = mtp_gdbus_objectinfo_get_property(mtp_device,
931 object_handle, MTP_PROPERTY_THUMBNAIL_HEIGHT, height);
938 int mtp_objectinfo_get_thumbnail_pix_width(int mtp_device,
939 int object_handle, int *width)
941 int ret = MTP_ERROR_NONE;
945 /* precondition check start */
950 cond_expr_ret(mtp_device == 0, MTP_ERROR_INVALID_PARAMETER);
952 /* precondition check end */
954 ret = mtp_gdbus_objectinfo_get_property(mtp_device,
955 object_handle, MTP_PROPERTY_THUMBNAIL_WIDTH, width);
962 int mtp_objectinfo_get_file_name(int mtp_device,
963 int object_handle, char **filename)
965 int ret = MTP_ERROR_NONE;
969 /* precondition check start */
974 cond_expr_ret(mtp_device == 0, MTP_ERROR_INVALID_PARAMETER);
976 /* precondition check end */
978 ret = mtp_gdbus_objectinfo_get_property_string(mtp_device,
979 object_handle, MTP_PROPERTY_FILENAME, filename);
986 int mtp_objectinfo_get_keywords(int mtp_device,
987 int object_handle, char **keywords)
989 int ret = MTP_ERROR_NONE;
993 /* precondition check start */
998 cond_expr_ret(mtp_device == 0, MTP_ERROR_INVALID_PARAMETER);
1000 /* precondition check end */
1002 ret = mtp_gdbus_objectinfo_get_property_string(mtp_device,
1003 object_handle, MTP_PROPERTY_KEYWORDS, keywords);
1010 int mtp_objectinfo_get_object_info(int mtp_device,
1011 int object_handle, mtp_object_info **object_info)
1013 int ret = MTP_ERROR_NONE;
1017 /* precondition check start */
1022 cond_expr_ret(mtp_device == 0, MTP_ERROR_INVALID_PARAMETER);
1024 /* precondition check end */
1026 ret = mtp_db_get_object_info(mtp_device, object_handle, object_info);