Add new internal api 62/182062/2
authorpr.jung <pr.jung@samsung.com>
Wed, 20 Jun 2018 05:56:52 +0000 (14:56 +0900)
committerpr.jung <pr.jung@samsung.com>
Fri, 22 Jun 2018 06:46:25 +0000 (15:46 +0900)
- storage_get_storage_level
- Get the current storage level

Change-Id: I9be56c1c98a38cc210582aee1072b0b9d340badd
Signed-off-by: pr.jung <pr.jung@samsung.com>
include/storage-internal.h
src/storage-external-dbus.c
src/storage-external-dbus.h
src/storage-inhouse.c

index 391a721..1b14798 100644 (file)
@@ -30,6 +30,7 @@ extern "C" {
  */
 
 #include <tizen.h>
+#include <tzplatform_config.h>
 #include "storage.h"
 
 #define STORAGE_ERROR_NO_DEVICE TIZEN_ERROR_NO_SUCH_DEVICE
@@ -55,6 +56,7 @@ int storage_get_primary_sdcard(int *storage_id, char **path);
 
 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);
+int storage_get_storage_level(enum tzplatform_variable id, char **level);
 
 /**
  * @}
index 8b66ca3..d335ca7 100755 (executable)
 
 #define CHECK_STR(a) (a ? a : "")
 
-#define STORAGE_EXT_GET_LIST       "GetDeviceList"
-#define STORAGE_EXT_GET_STATVFS    "GetStatvfs"
+#define STORAGE_EXT_GET_LIST               "GetDeviceList"
+#define STORAGE_EXT_GET_STATVFS            "GetStatvfs"
+#define STORAGE_EXT_GET_STORAGE_LEVEL      "GetStorageLevel"
 
-#define STORAGE_EXT_DEVICE_CHANGED "DeviceChanged"
-#define STORAGE_EXT_DEVICE_ADDED   "DeviceAdded"
-#define STORAGE_EXT_DEVICE_REMOVED "DeviceRemoved"
-#define STORAGE_EXT_DEVICE_BLOCKED "DeviceBlocked"
+#define STORAGE_EXT_DEVICE_CHANGED         "DeviceChanged"
+#define STORAGE_EXT_DEVICE_ADDED           "DeviceAdded"
+#define STORAGE_EXT_DEVICE_REMOVED         "DeviceRemoved"
+#define STORAGE_EXT_DEVICE_BLOCKED         "DeviceBlocked"
 
 #define DBUS_REPLY_TIMEOUT (-1)
 
@@ -286,6 +287,29 @@ int storage_ext_get_statvfs_size64(char *path, struct statvfs *buf)
        return 0;
 }
 
+int storage_ext_get_storage_level(enum tzplatform_variable id, char **level)
+{
+       GVariant *result;
+       char *tmp;
+
+       result = dbus_method_call_sync(STORAGE_EXT_BUS_NAME,
+                       STORAGE_EXT_PATH_STORAGE,
+                       STORAGE_EXT_IFACE_STORAGE,
+                       STORAGE_EXT_GET_STORAGE_LEVEL,
+                       g_variant_new("(i)", id));
+       if (!result) {
+               _E("Failed to get %d level", id);
+               return -EIO;
+       }
+
+       g_variant_get(result, "(s)", &tmp);
+       *level = strdup(tmp);
+       if (*level == NULL)
+               return -ENOMEM;
+
+       return 0;
+}
+
 //LCOV_EXCL_START Not called Callback
 static void storage_ext_device_changed(GVariant *params, enum storage_ext_state state, gpointer user_data)
 {
index 195d72e..24800f8 100644 (file)
@@ -23,6 +23,7 @@
 #include <stdbool.h>
 #include <glib.h>
 #include <gio/gio.h>
+#include <tzplatform_config.h>
 #include "list.h"
 
 #define STORAGE_EXT_BUS_NAME              "org.tizen.system.storage"
@@ -106,6 +107,7 @@ int storage_ext_register_device_change(storage_ext_changed_cb func, void *data);
 void storage_ext_unregister_device_change(storage_ext_changed_cb func);
 
 int storage_ext_get_device_info(int storage_id, storage_ext_device *info);
+int storage_ext_get_storage_level(enum tzplatform_variable id, char **level);
 
 /* storage-internal.c */
 GVariant *dbus_method_call_sync(const gchar *dest, const gchar *path,
index 34ec31d..a522ee9 100755 (executable)
@@ -19,7 +19,6 @@
 #include <stdlib.h>
 #include <string.h>
 #include <errno.h>
-#include <tzplatform_config.h>
 
 #include "common.h"
 #include "list.h"
@@ -181,3 +180,76 @@ 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_NO_DEVICE;
+       }
+
+       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;
+       }
+       if (*type == STORAGE_TYPE_INTERNAL)
+               return STORAGE_ERROR_NONE;
+
+       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_NO_DEVICE;
+               goto out;
+       }
+
+       if (ext_dev->type == STORAGE_EXT_SCSI)
+               *dev = STORAGE_DEV_EXT_USB_MASS_STORAGE;
+       else if (ext_dev->type == STORAGE_EXT_MMC)
+               *dev = STORAGE_DEV_EXT_SDCARD;
+       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;
+}
+
+API int storage_get_storage_level(enum tzplatform_variable id, char **level)
+{
+       int ret;
+
+       if (!level)
+               return STORAGE_ERROR_INVALID_PARAMETER;
+
+       if (id != TZ_SYS_USER || id != TZ_SYS_TMP || id != TZ_SYS_OPT)
+               return STORAGE_ERROR_INVALID_PARAMETER;
+
+       ret = storage_ext_get_storage_level(id, level);
+       if (ret == -ENOMEM)
+               return STORAGE_ERROR_OUT_OF_MEMORY; //LCOV_EXCL_LINE System Error
+       else if (ret < 0)
+               return STORAGE_ERROR_OPERATION_FAILED;
+
+       return STORAGE_ERROR_NONE;
+}