From: Taeyoung Kim Date: Thu, 28 Apr 2016 06:51:26 +0000 (+0900) Subject: external: add function to get state of storages X-Git-Tag: accepted/tizen/ivi/20160511.080403~3 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=dd4cb30512c937ca15e6899edadb4f5d1b672d0b;p=platform%2Fcore%2Fsystem%2Flibstorage.git external: add function to get state of storages - Storage states are delivered from deviced. To get the information, dbus method is used. Change-Id: Ib6c03dae93e428cadd6f484cc5b84e2e12bf1050 Signed-off-by: Taeyoung Kim --- diff --git a/src/storage-external.c b/src/storage-external.c index 63d564a..8fdde8c 100755 --- a/src/storage-external.c +++ b/src/storage-external.c @@ -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; +} diff --git a/src/storage-external.h b/src/storage-external.h index a002c0b..a9046af 100755 --- a/src/storage-external.h +++ b/src/storage-external.h @@ -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__ */ diff --git a/src/storage.c b/src/storage.c index 275b8a9..3e372a8 100644 --- a/src/storage.c +++ b/src/storage.c @@ -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; }