external: add function to get state of storages 27/67727/3
authorTaeyoung Kim <ty317.kim@samsung.com>
Thu, 28 Apr 2016 06:51:26 +0000 (15:51 +0900)
committerTaeyoung Kim <ty317.kim@samsung.com>
Fri, 29 Apr 2016 01:27:09 +0000 (10:27 +0900)
- Storage states are delivered from deviced. To get
  the information, dbus method is used.

Change-Id: Ib6c03dae93e428cadd6f484cc5b84e2e12bf1050
Signed-off-by: Taeyoung Kim <ty317.kim@samsung.com>
src/storage-external.c
src/storage-external.h
src/storage.c

index 63d564a..8fdde8c 100755 (executable)
@@ -220,3 +220,32 @@ out:
        storage_ext_release_device(&dev);
        return ret;
 }
+
+int storage_ext_get_state(int storage_id, storage_state_e *state)
+{
+       storage_ext_device *dev;
+       int ret;
+
+       if (storage_id < 0 || !state)
+               return -EINVAL;
+
+       dev = calloc(1, sizeof(storage_ext_device));
+       if (!dev) {
+               _E("calloc failed");
+               return -ENOMEM;
+       }
+
+       ret = storage_ext_get_device_info(storage_id, dev);
+       if (ret < 0) {
+               _E("Cannot get the storage with id (%d, ret:%d)", storage_id, ret);
+               goto out;
+       }
+
+       ret = storage_ext_get_dev_state(dev, STORAGE_EXT_CHANGED, state);
+       if (ret < 0)
+               _E("Failed to get state of storage id (%d, ret:%d)", storage_id, ret);
+
+out:
+       storage_ext_release_device(&dev);
+       return ret;
+}
index a002c0b..a9046af 100755 (executable)
@@ -25,5 +25,6 @@ int storage_ext_foreach_device_list(storage_device_supported_cb callback, void *
 int storage_ext_register_cb(enum storage_cb_type type, struct storage_cb_info *info);
 int storage_ext_unregister_cb(enum storage_cb_type type, struct storage_cb_info *info);
 int storage_ext_get_root(int storage_id, char *path, size_t len);
+int storage_ext_get_state(int storage_id, storage_state_e *state);
 
 #endif /* __STORAGE_EXTERNAL_H__ */
index 275b8a9..3e372a8 100644 (file)
@@ -205,9 +205,11 @@ API int storage_get_type(int storage_id, storage_type_e *type)
 API int storage_get_state(int storage_id, storage_state_e *state)
 {
        const struct storage_ops *ops;
+       storage_state_e st;
        dd_list *elem;
+       int ret;
 
-       if (!state) {
+       if (!state || storage_id < 0) {
                _E("Invalid parameger");
                return STORAGE_ERROR_INVALID_PARAMETER;
        }
@@ -221,7 +223,13 @@ API int storage_get_state(int storage_id, storage_state_e *state)
        }
 
        /* external storage */
+       ret = storage_ext_get_state(storage_id, &st);
+       if (ret < 0) {
+               _E("Failed to get state (storage id(%d), ret(%d))", storage_id, ret);
+               return STORAGE_ERROR_OPERATION_FAILED;
+       }
 
+       *state = st;
        return STORAGE_ERROR_NONE;
 }