Add inhouse api to get storage type and the kind of external device 96/96196/1 accepted/tizen/3.0/common/20161114.143351 accepted/tizen/3.0/ivi/20161111.002811 accepted/tizen/3.0/mobile/20161111.002721 accepted/tizen/3.0/tv/20161111.002737 accepted/tizen/3.0/wearable/20161111.002753 submit/tizen_3.0/20161109.062156 submit/tizen_3.0_common/20161114.081136
authorpr.jung <pr.jung@samsung.com>
Tue, 8 Nov 2016 06:08:26 +0000 (15:08 +0900)
committerpr.jung <pr.jung@samsung.com>
Tue, 8 Nov 2016 06:08:26 +0000 (15:08 +0900)
Change-Id: Iac21489f726cda37c148522d34163e97f04066a3
Signed-off-by: pr.jung <pr.jung@samsung.com>
include/storage-internal.h
src/storage-external-dbus.c
src/storage-inhouse.c

index 391a721..14e81cb 100644 (file)
@@ -53,6 +53,26 @@ extern "C" {
  */
 int storage_get_primary_sdcard(int *storage_id, char **path);
 
+/**
+ * @brief Get the type and the kind of external device for given storage id.
+ *
+ * @since_tizen 3.0
+ *
+ * @param[in] storage_id The storage id
+ * @param[out] storage type (internal, external).
+ * @param[out] the kind of storage device for external type (sdcard, usb).
+ *
+ * @return @c 0 on success,
+ *         otherwise a negative error value
+ *
+ * @retval #STORAGE_ERROR_NONE               Successful
+ * @retval #STORAGE_ERROR_INVALID_PARAMETER  Invalid parameter
+ * @retval #STORAGE_ERROR_OUT_OF_MEMORY      Out of memory
+ * @retval #STORAGE_ERROR_NOT_SUPPORTED      Storage not supported
+ * @retval #STORAGE_ERROR_NO_DEVICE          No such device
+ */
+int storage_get_type_dev(int storage_id, storage_type_e *type, storage_dev_e *dev);
+
 int storage_get_compat_internal_path(const char* origin, int len, char* compat);
 int storage_get_origin_internal_path(const char* compat, int len, char* origin);
 
index 92c4dc1..f389391 100755 (executable)
@@ -402,13 +402,16 @@ int storage_ext_get_device_info(int storage_id, storage_ext_device *info)
                return -ENODEV;
        }
 
-       g_variant_get(result, "(issssssisibii)",
-                       &info->type, &info->devnode, &info->syspath,
-                       &info->fs_usage, &info->fs_type,
-                       &info->fs_version, &info->fs_uuid,
-                       &info->readonly, &info->mount_point,
-                       &info->state, &info->primary,
-                       &info->flags, &info->storage_id);
+       if (g_variant_check_format_string(result, "(issssssisibii)", true)) {
+               g_variant_get(result, "(issssssisibii)",
+                               &info->type, &info->devnode, &info->syspath,
+                               &info->fs_usage, &info->fs_type,
+                               &info->fs_version, &info->fs_uuid,
+                               &info->readonly, &info->mount_point,
+                               &info->state, &info->primary,
+                               &info->flags, &info->storage_id);
+       } else
+               return -ENODEV;
 
        g_variant_unref(result);
 
index a8031bb..72eddac 100755 (executable)
@@ -168,3 +168,53 @@ API int storage_get_primary_sdcard(int *storage_id, char **path)
 
        return STORAGE_ERROR_NONE;
 }
+
+API int storage_get_type_dev(int storage_id, storage_type_e *type, storage_dev_e *dev)
+{
+       storage_ext_device *ext_dev;
+       int ret;
+
+       if (storage_id < 0) {
+               _E("Invalid parameger");
+               return STORAGE_ERROR_NOT_SUPPORTED;
+       }
+
+       if (!type) {
+               _E("Invalid parameger");
+               return STORAGE_ERROR_INVALID_PARAMETER;
+       }
+
+       if (!dev) {
+               _E("Invalid parameger");
+               return STORAGE_ERROR_INVALID_PARAMETER;
+       }
+
+       ret = storage_get_type(storage_id, type);
+       if (ret != STORAGE_ERROR_NONE) {
+               _E("Failed to get storage type: %d", ret);
+               return ret;
+       }
+
+       ext_dev = calloc(1, sizeof(storage_ext_device));
+       if (!ext_dev) {
+//LCOV_EXCL_START System Error
+               _E("calloc failed");
+               return STORAGE_ERROR_OUT_OF_MEMORY;
+//LCOV_EXCL_STOP
+       }
+
+       ret = storage_ext_get_device_info(storage_id, ext_dev);
+       if (ret < 0) {
+               _E("Cannot get the storage with id (%d, ret:%d)", storage_id, ret); //LCOV_EXCL_LINE
+               ret = STORAGE_ERROR_NOT_SUPPORTED;
+               goto out;
+       }
+
+       *dev = ext_dev->type;
+       ret = STORAGE_ERROR_NONE;
+       _I("type: %d(internal:0, external:1) dev: %d(sdcard: 1001, usb: 1002)", *type, *dev);
+
+out:
+       storage_ext_release_device(&ext_dev);
+       return ret;
+}