modules/information/mmc: Vconf removed. 48/59048/13
authorRadoslaw Czerski <r.czerski@samsung.com>
Wed, 10 Feb 2016 10:56:39 +0000 (11:56 +0100)
committerLukasz Stanislawski <l.stanislaws@samsung.com>
Thu, 11 Feb 2016 08:54:21 +0000 (00:54 -0800)
Storage apis used instead of vconf.
File renamed to ext_storage.c.

Change-Id: Ib6acb35861e683b0899e6d2b6a615efb6ec5e7db
Signed-off-by: Radoslaw Czerski <r.czerski@samsung.com>
src/modules/information/ext_storage.c [new file with mode: 0644]
src/modules/information/mmc.c [deleted file]
src/modules/modules.c

diff --git a/src/modules/information/ext_storage.c b/src/modules/information/ext_storage.c
new file mode 100644 (file)
index 0000000..a57050f
--- /dev/null
@@ -0,0 +1,204 @@
+/*
+ *  Indicator
+ *
+ * Copyright (c) 2000 - 2015 Samsung Electronics Co., Ltd. All rights reserved.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <storage.h>
+#include "common.h"
+#include "indicator.h"
+#include "main.h"
+#include "modules.h"
+#include "icon.h"
+#include "log.h"
+
+#define ICON_PRIORITY  INDICATOR_PRIORITY_SYSTEM_3
+#define MODULE_NAME            "mmc"
+#define TIMER_INTERVAL 0.3
+
+static int register_ext_storage_module(void *data);
+static int unregister_ext_storage_module(void);
+static int wake_up_cb(void *data);
+
+icon_s ext_storage = {
+       .name = MODULE_NAME,
+       .priority = ICON_PRIORITY,
+       .always_top = EINA_FALSE,
+       .exist_in_view = EINA_FALSE,
+       .img_obj = {0,},
+       .obj_exist = EINA_FALSE,
+       .area = INDICATOR_ICON_AREA_SYSTEM,
+       .init = register_ext_storage_module,
+       .fini = unregister_ext_storage_module,
+       .wake_up = wake_up_cb
+};
+
+typedef enum {
+       EXT_STORAGE_STATE_REMOVED = 0x01,
+       EXT_STORAGE_STATE_MOUNTED = 0x02,
+       EXT_STORAGE_STATE_MOUNTED_READ_ONLY = 0x04,
+       EXT_STORAGE_STATE_UNMOUNTABLE = 0x08,
+} ext_storage_state_e;
+
+int state = 0x00;
+
+static const char *icon_path[] = {
+       "Storage/B03_storage_t_flash.png",
+       NULL
+};
+static int updated_while_lcd_off = 0;
+static int bShown = 0;
+
+
+static void set_app_state(void* data)
+{
+       ext_storage.ad = data;
+}
+
+static void show_image_icon(void)
+{
+       if(bShown == 1)
+               return;
+
+       ext_storage.img_obj.data = icon_path[0];
+       icon_show(&ext_storage);
+
+       bShown = 1;
+}
+
+static void hide_image_icon(void)
+{
+       icon_hide(&ext_storage);
+
+       bShown = 0;
+}
+
+static void _ext_storage_cb (int storage_id, storage_state_e state, void *data)
+{
+       int *status = (int *)data;
+
+       _D("indicator_mmc_change_cb");
+       if(icon_get_update_flag() == 0) {
+               updated_while_lcd_off = 1;
+               return;
+       }
+       updated_while_lcd_off = 0;
+
+       switch (state) {
+               case STORAGE_STATE_MOUNTED_READ_ONLY:
+               case STORAGE_STATE_MOUNTED:
+                       *status = *status | EXT_STORAGE_STATE_MOUNTED;
+                       if (*status & EXT_STORAGE_STATE_REMOVED)
+                               *status = *status - EXT_STORAGE_STATE_REMOVED; // remove bit LSB
+                       break;
+
+               case STORAGE_STATE_UNMOUNTABLE:
+               case STORAGE_STATE_REMOVED:
+                       *status = *status | EXT_STORAGE_STATE_REMOVED;
+                       if (*status & EXT_STORAGE_STATE_MOUNTED)
+                               *status = *status - EXT_STORAGE_STATE_MOUNTED; // remove bit second LSB
+                       break;
+
+               default:
+                       _D("Storage with ID:%d, Invalid state:%d", storage_id, state);
+                       break;
+       }
+}
+
+static void change_indicator_state(int storage_state)
+ {
+       _D("Storage indicator icon set");
+
+       if ((storage_state & EXT_STORAGE_STATE_MOUNTED) || (storage_state & EXT_STORAGE_STATE_MOUNTED_READ_ONLY))
+               show_image_icon();
+
+       else
+               hide_image_icon();
+ }
+
+static bool _wake_up_storage_register_cb(int storage_id, storage_type_e type, storage_state_e state, const char *path, void *user_data)
+{
+       if (type == STORAGE_TYPE_EXTERNAL)
+               _ext_storage_cb(storage_id, state, user_data);
+
+       return true;
+}
+
+static int wake_up_cb(void *data)
+{
+       if(updated_while_lcd_off == 0)
+               return OK;
+
+       int ret = storage_foreach_device_supported(_wake_up_storage_register_cb, (void *)&state);
+       retvm_if(ret != STORAGE_ERROR_NONE, FAIL, "storage_foreach_device_supported failed[%s]", get_error_message(ret));
+
+       change_indicator_state(state);
+
+       return OK;
+}
+
+static bool _storage_register_cb(int storage_id, storage_type_e type, storage_state_e state, const char *path, void *user_data)
+{
+       if (type == STORAGE_TYPE_EXTERNAL) {
+               _ext_storage_cb(storage_id, state, user_data);
+               int ret = storage_set_state_changed_cb(storage_id, _ext_storage_cb, user_data);
+               retvm_if(ret != STORAGE_ERROR_NONE, false, "storage_foreach_device_supported failed[%s]", get_error_message(ret));
+       }
+
+       return true;
+}
+
+static int register_ext_storage_module(void *data)
+{
+       int ret;
+       retif(data == NULL, FAIL, "Invalid parameter!");
+
+       set_app_state(data);
+
+       state = EXT_STORAGE_STATE_REMOVED;
+
+       ret = storage_foreach_device_supported (_storage_register_cb, (void *)state);
+
+       retvm_if(ret != STORAGE_ERROR_NONE, FAIL, "storage_foreach_device_supported failed[%s]", get_error_message(ret));
+
+       change_indicator_state(state);
+
+       return OK;
+}
+
+static bool _storage_unregister_cb(int storage_id, storage_type_e type, storage_state_e state, const char *path, void *user_data)
+{
+       int ret;
+       if (type == STORAGE_TYPE_EXTERNAL) {
+               ret = storage_unset_state_changed_cb(storage_id, _ext_storage_cb);
+               if(ret != STORAGE_ERROR_NONE)
+                       _D("storage_unset_state_changed_cb failed[%s]", get_error_message(ret));
+       }
+       return true;
+}
+
+static int unregister_ext_storage_module(void)
+{
+       int ret;
+
+       ret = storage_foreach_device_supported (_storage_unregister_cb, NULL);
+       retvm_if(ret != STORAGE_ERROR_NONE, FAIL, "storage_foreach_device_supported failed[%s]", get_error_message(ret));
+
+       return OK;
+}
diff --git a/src/modules/information/mmc.c b/src/modules/information/mmc.c
deleted file mode 100644 (file)
index 3ae6172..0000000
+++ /dev/null
@@ -1,212 +0,0 @@
-/*
- *  Indicator
- *
- * Copyright (c) 2000 - 2015 Samsung Electronics Co., Ltd. All rights reserved.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- *
- */
-
-
-
-#include <stdio.h>
-#include <stdlib.h>
-#include <vconf.h>
-#include "common.h"
-#include "indicator.h"
-#include "main.h"
-#include "modules.h"
-#include "icon.h"
-
-#define ICON_PRIORITY  INDICATOR_PRIORITY_SYSTEM_3
-#define MODULE_NAME            "mmc"
-#define TIMER_INTERVAL 0.3
-
-static int register_mmc_module(void *data);
-static int unregister_mmc_module(void);
-static int wake_up_cb(void *data);
-
-icon_s mmc = {
-       .name = MODULE_NAME,
-       .priority = ICON_PRIORITY,
-       .always_top = EINA_FALSE,
-       .exist_in_view = EINA_FALSE,
-       .img_obj = {0,},
-       .obj_exist = EINA_FALSE,
-       .area = INDICATOR_ICON_AREA_SYSTEM,
-       .init = register_mmc_module,
-       .fini = unregister_mmc_module,
-       .wake_up = wake_up_cb
-};
-
-static const char *icon_path[] = {
-       "Storage/B03_storage_t_flash.png",
-       NULL
-};
-static int updated_while_lcd_off = 0;
-static int bShown = 0;
-
-
-
-static void set_app_state(void* data)
-{
-       mmc.ad = data;
-}
-
-
-
-static void show_image_icon(void)
-{
-       if(bShown == 1)
-       {
-               return;
-       }
-
-       mmc.img_obj.data = icon_path[0];
-       icon_show(&mmc);
-
-       bShown = 1;
-}
-
-
-
-static void hide_image_icon(void)
-{
-       icon_hide(&mmc);
-
-       bShown = 0;
-}
-
-
-
-static void indicator_mmc_change_cb(keynode_t *node, void *data)
-{
-       int status = 0, mmc_status = 0;
-       int ret;
-
-       retif(data == NULL, , "Invalid parameter!");
-       DBG("indicator_mmc_change_cb");
-       if(icon_get_update_flag()==0)
-       {
-               updated_while_lcd_off = 1;
-               return;
-       }
-       updated_while_lcd_off = 0;
-
-       ret = vconf_get_int(VCONFKEY_FILEMANAGER_MMC_STATUS, &status);
-       if (ret != OK) {
-               return;
-       }
-
-       switch (status) {
-       case VCONFKEY_FILEMANAGER_MMC_LOADING:
-               DBG("MMC loading");
-               ret = vconf_get_int(VCONFKEY_SYSMAN_MMC_STATUS, &mmc_status);
-               if (ret != OK) {
-                       return;
-               }
-               if(mmc_status == VCONFKEY_SYSMAN_MMC_MOUNTED)
-               {
-                       DBG("Mounting");
-                       show_image_icon();
-               }
-               else
-               {
-                       DBG("Unmounting");
-               }
-               break;
-       default:
-               hide_image_icon();
-               break;
-       }
-}
-
-
-
-static void indicator_mmc_pm_state_change_cb(keynode_t *node, void *data)
-{
-       int status = 0;
-       retif(data == NULL, , "Invalid parameter!");
-
-       if (vconf_get_int(VCONFKEY_PM_STATE, &status) < 0)
-       {
-               ERR("Error getting VCONFKEY_PM_STATE value");
-               return;
-       }
-
-       if(status == VCONFKEY_PM_STATE_LCDOFF)
-       {
-               int sos_status = 0;
-               if (vconf_get_int(VCONFKEY_FILEMANAGER_MMC_STATUS, &sos_status) < 0)
-               {
-                       ERR("Error getting VCONFKEY_FILEMANAGER_MMC_STATUS value");
-                       return;
-               }
-
-               switch (sos_status) {
-               case VCONFKEY_FILEMANAGER_MMC_LOADING:
-                       break;
-               default:
-                       break;
-               }
-       }
-}
-
-
-
-static int wake_up_cb(void *data)
-{
-       if(updated_while_lcd_off==0 )
-       {
-               return OK;
-       }
-
-       indicator_mmc_change_cb(NULL, data);
-       return OK;
-}
-
-
-
-static int register_mmc_module(void *data)
-{
-       int ret;
-
-       retif(data == NULL, FAIL, "Invalid parameter!");
-
-       set_app_state(data);
-
-       ret = vconf_notify_key_changed(VCONFKEY_FILEMANAGER_MMC_STATUS,
-                                       indicator_mmc_change_cb, data);
-
-       ret = ret | vconf_notify_key_changed(VCONFKEY_PM_STATE,
-                                               indicator_mmc_pm_state_change_cb, data);
-
-       indicator_mmc_change_cb(NULL, data);
-
-       return ret;
-}
-
-
-
-static int unregister_mmc_module(void)
-{
-       int ret;
-
-       ret = vconf_ignore_key_changed(VCONFKEY_FILEMANAGER_MMC_STATUS,
-                                       indicator_mmc_change_cb);
-
-       ret = ret | vconf_ignore_key_changed(VCONFKEY_PM_STATE,
-                                               indicator_mmc_pm_state_change_cb);
-
-       return ret;
-}
index 75e9229..f3f41e8 100644 (file)
@@ -41,7 +41,7 @@ extern icon_s call;
 extern icon_s call_divert;
 
 /* Information */
-extern icon_s mmc;
+extern icon_s ext_storage;
 extern icon_s noti;
 
 /* alarm */
@@ -101,7 +101,7 @@ static icon_s *modules[INDICATOR_MODULE_NUMBERS] = {
        /* Information */
        /* &message, */
        /* &voice_mail, */
-       &mmc,
+       &ext_storage,
        &noti,
        &useralarm,
        &fm_radio,