summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorYoshihisa Uchida <uchida@rockbox.org>2010-06-29 11:05:36 +0000
committerYoshihisa Uchida <uchida@rockbox.org>2010-06-29 11:05:36 +0000
commit07d03729ff537eca8429cea27c1f2d15f04ec54f (patch)
tree2f72e7d67f3da45710c2dd302f16654b80aa1016
parent7195f3a30cc73e1540a590c519c9a2ecec137952 (diff)
downloadrockbox-07d03729ff537eca8429cea27c1f2d15f04ec54f.zip
rockbox-07d03729ff537eca8429cea27c1f2d15f04ec54f.tar.gz
rockbox-07d03729ff537eca8429cea27c1f2d15f04ec54f.tar.bz2
rockbox-07d03729ff537eca8429cea27c1f2d15f04ec54f.tar.xz
text_viewer: callback functions are changed to the function that returns int value.
And the text viewer quits when the problem occurs by callback functions. git-svn-id: svn://svn.rockbox.org/rockbox/trunk@27172 a1c6a512-1295-4272-9138-f99709370657
-rw-r--r--apps/plugins/text_viewer/text_viewer.c2
-rw-r--r--apps/plugins/text_viewer/tv_action.c3
-rw-r--r--apps/plugins/text_viewer/tv_bookmark.c13
-rw-r--r--apps/plugins/text_viewer/tv_display.c13
-rw-r--r--apps/plugins/text_viewer/tv_menu.c3
-rw-r--r--apps/plugins/text_viewer/tv_menu.h1
-rw-r--r--apps/plugins/text_viewer/tv_pager.c3
-rw-r--r--apps/plugins/text_viewer/tv_preferences.c15
-rw-r--r--apps/plugins/text_viewer/tv_preferences.h14
-rw-r--r--apps/plugins/text_viewer/tv_reader.c5
-rw-r--r--apps/plugins/text_viewer/tv_settings.c4
-rw-r--r--apps/plugins/text_viewer/tv_settings.h2
-rw-r--r--apps/plugins/text_viewer/tv_window.c3
13 files changed, 56 insertions, 25 deletions
diff --git a/apps/plugins/text_viewer/text_viewer.c b/apps/plugins/text_viewer/text_viewer.c
index 4817710..db370f5 100644
--- a/apps/plugins/text_viewer/text_viewer.c
+++ b/apps/plugins/text_viewer/text_viewer.c
@@ -73,6 +73,8 @@ enum plugin_status plugin_start(const void* file)
done = true;
if (res == TV_MENU_RESULT_ATTACHED_USB)
return PLUGIN_USB_CONNECTED;
+ else if (res == TV_MENU_RESULT_ERROR)
+ return PLUGIN_ERROR;
}
}
break;
diff --git a/apps/plugins/text_viewer/tv_action.c b/apps/plugins/text_viewer/tv_action.c
index 2549709..5226d90 100644
--- a/apps/plugins/text_viewer/tv_action.c
+++ b/apps/plugins/text_viewer/tv_action.c
@@ -42,7 +42,8 @@ bool tv_init(const unsigned char *file)
return false;
/* load the preferences and bookmark */
- tv_load_settings(file);
+ if (!tv_load_settings(file))
+ return false;
/* select to read the page */
tv_select_bookmark();
diff --git a/apps/plugins/text_viewer/tv_bookmark.c b/apps/plugins/text_viewer/tv_bookmark.c
index d569ed8..7e38d76 100644
--- a/apps/plugins/text_viewer/tv_bookmark.c
+++ b/apps/plugins/text_viewer/tv_bookmark.c
@@ -98,15 +98,16 @@ static int tv_find_bookmark(const struct tv_screen_pos *pos)
return -1;
}
-static void tv_change_preferences(const struct tv_preferences *oldp)
+static int tv_change_preferences(const struct tv_preferences *oldp)
{
int i;
- if (oldp == NULL)
- return;
-
- for (i = 0; i < bookmark_count; i++)
- tv_convert_fpos(bookmarks[i].pos.file_pos, &bookmarks[i].pos);
+ if (oldp)
+ {
+ for (i = 0; i < bookmark_count; i++)
+ tv_convert_fpos(bookmarks[i].pos.file_pos, &bookmarks[i].pos);
+ }
+ return TV_CALLBACK_OK;
}
void tv_init_bookmark(void)
diff --git a/apps/plugins/text_viewer/tv_display.c b/apps/plugins/text_viewer/tv_display.c
index 59b4bdf..c59765e 100644
--- a/apps/plugins/text_viewer/tv_display.c
+++ b/apps/plugins/text_viewer/tv_display.c
@@ -349,7 +349,7 @@ static bool tv_set_font(const unsigned char *font)
}
#endif
-static void tv_change_preferences(const struct tv_preferences *oldp)
+static int tv_change_preferences(const struct tv_preferences *oldp)
{
#ifdef HAVE_LCD_BITMAP
static bool font_changing = false;
@@ -363,10 +363,18 @@ static void tv_change_preferences(const struct tv_preferences *oldp)
{
if (!tv_set_font(preferences->font_name))
{
+ /*
+ * tv_set_font(rb->global_settings->font_file) doesn't fail usually.
+ * if it fails, a fatal problem occurs in Rockbox.
+ */
+ if (!rb->strcmp(preferences->font_name, rb->global_settings->font_file))
+ return TV_CALLBACK_ERROR;
+
font_changing = true;
tv_copy_preferences(&new_prefs);
rb->strlcpy(new_prefs.font_name, font_str, MAX_PATH);
- tv_set_preferences(&new_prefs);
+
+ return (tv_set_preferences(&new_prefs))? TV_CALLBACK_STOP : TV_CALLBACK_ERROR;
}
col_width = 2 * rb->font_get_width(preferences->font, ' ');
font_changing = false;
@@ -375,6 +383,7 @@ static void tv_change_preferences(const struct tv_preferences *oldp)
(void)oldp;
#endif
tv_change_viewport();
+ return TV_CALLBACK_OK;
}
bool tv_init_display(unsigned char **buf, size_t *size)
diff --git a/apps/plugins/text_viewer/tv_menu.c b/apps/plugins/text_viewer/tv_menu.c
index 2e3a26d..7e706eb 100644
--- a/apps/plugins/text_viewer/tv_menu.c
+++ b/apps/plugins/text_viewer/tv_menu.c
@@ -366,7 +366,8 @@ unsigned tv_display_menu(void)
case 1: /* change settings */
tv_copy_preferences(&new_prefs);
result = tv_options_menu();
- tv_set_preferences(&new_prefs);
+ if (!tv_set_preferences(&new_prefs))
+ result = TV_MENU_RESULT_ERROR;
break;
case 2: /* playback control */
playback_control(NULL);
diff --git a/apps/plugins/text_viewer/tv_menu.h b/apps/plugins/text_viewer/tv_menu.h
index 0db5051..42da8b0 100644
--- a/apps/plugins/text_viewer/tv_menu.h
+++ b/apps/plugins/text_viewer/tv_menu.h
@@ -28,6 +28,7 @@ enum {
TV_MENU_RESULT_EXIT_MENU,
TV_MENU_RESULT_EXIT_PLUGIN,
TV_MENU_RESULT_ATTACHED_USB,
+ TV_MENU_RESULT_ERROR,
};
/*
diff --git a/apps/plugins/text_viewer/tv_pager.c b/apps/plugins/text_viewer/tv_pager.c
index e7016c7..a91d9d9 100644
--- a/apps/plugins/text_viewer/tv_pager.c
+++ b/apps/plugins/text_viewer/tv_pager.c
@@ -73,7 +73,7 @@ static off_t tv_get_fpos(int page)
return 0;
}
-static void tv_change_preferences(const struct tv_preferences *oldp)
+static int tv_change_preferences(const struct tv_preferences *oldp)
{
(void)oldp;
@@ -83,6 +83,7 @@ static void tv_change_preferences(const struct tv_preferences *oldp)
max_page = TV_MAX_PAGE - 1;
tv_set_fpos(cur_pos.page, 0);
tv_seek(0, SEEK_SET);
+ return TV_CALLBACK_OK;
}
bool tv_init_pager(unsigned char **buf, size_t *size)
diff --git a/apps/plugins/text_viewer/tv_preferences.c b/apps/plugins/text_viewer/tv_preferences.c
index 924cedb..7d4fd3c 100644
--- a/apps/plugins/text_viewer/tv_preferences.c
+++ b/apps/plugins/text_viewer/tv_preferences.c
@@ -31,11 +31,12 @@ const struct tv_preferences * const preferences = &prefs;
static int listner_count = 0;
#define TV_MAX_LISTNERS 5
-static void (*listners[TV_MAX_LISTNERS])(const struct tv_preferences *oldp);
+static int (*listners[TV_MAX_LISTNERS])(const struct tv_preferences *oldp);
-static void tv_notify_change_preferences(const struct tv_preferences *oldp)
+static bool tv_notify_change_preferences(const struct tv_preferences *oldp)
{
int i;
+ int res = TV_CALLBACK_OK;
/*
* the following items do not check.
@@ -65,11 +66,13 @@ static void tv_notify_change_preferences(const struct tv_preferences *oldp)
{
/* callback functions are called as FILO */
for (i = listner_count - 1; i >= 0; i--)
- listners[i](oldp);
+ if ((res = listners[i](oldp)) != TV_CALLBACK_OK)
+ break;
}
+ return (res != TV_CALLBACK_ERROR);
}
-void tv_set_preferences(const struct tv_preferences *new_prefs)
+bool tv_set_preferences(const struct tv_preferences *new_prefs)
{
static struct tv_preferences old_prefs;
struct tv_preferences *oldp = NULL;
@@ -80,7 +83,7 @@ void tv_set_preferences(const struct tv_preferences *new_prefs)
is_initialized = true;
rb->memcpy(&prefs, new_prefs, sizeof(struct tv_preferences));
- tv_notify_change_preferences(oldp);
+ return tv_notify_change_preferences(oldp);
}
void tv_copy_preferences(struct tv_preferences *copy_prefs)
@@ -118,7 +121,7 @@ void tv_set_default_preferences(struct tv_preferences *p)
p->file_name[0] = '\0';
}
-void tv_add_preferences_change_listner(void (*listner)(const struct tv_preferences *oldp))
+void tv_add_preferences_change_listner(int (*listner)(const struct tv_preferences *oldp))
{
if (listner_count < TV_MAX_LISTNERS)
listners[listner_count++] = listner;
diff --git a/apps/plugins/text_viewer/tv_preferences.h b/apps/plugins/text_viewer/tv_preferences.h
index d1ba7f2..42d6fb4 100644
--- a/apps/plugins/text_viewer/tv_preferences.h
+++ b/apps/plugins/text_viewer/tv_preferences.h
@@ -23,6 +23,12 @@
#ifndef PLUGIN_TEXT_VIEWER_PREFERENCES_H
#define PLUGIN_TEXT_VIEWER_PREFERENCES_H
+enum {
+ TV_CALLBACK_OK,
+ TV_CALLBACK_STOP,
+ TV_CALLBACK_ERROR,
+};
+
/* scrollbar_mode */
enum {
SB_OFF = 0,
@@ -129,8 +135,12 @@ extern const struct tv_preferences * const preferences;
*
* [In] new_prefs
* new preferences
+ *
+ * return
+ * true success
+ * false error
*/
-void tv_set_preferences(const struct tv_preferences *new_prefs);
+bool tv_set_preferences(const struct tv_preferences *new_prefs);
/*
* copy the preferences
@@ -154,6 +164,6 @@ void tv_set_default_preferences(struct tv_preferences *p);
* [In] listner
* the function to be executed when the current preferences is changed
*/
-void tv_add_preferences_change_listner(void (*listner)(const struct tv_preferences *oldp));
+void tv_add_preferences_change_listner(int (*listner)(const struct tv_preferences *oldp));
#endif
diff --git a/apps/plugins/text_viewer/tv_reader.c b/apps/plugins/text_viewer/tv_reader.c
index 8403c30..b94dc17 100644
--- a/apps/plugins/text_viewer/tv_reader.c
+++ b/apps/plugins/text_viewer/tv_reader.c
@@ -132,7 +132,7 @@ void tv_seek(off_t offset, int whence)
}
}
-static void tv_change_preferences(const struct tv_preferences *oldp)
+static int tv_change_preferences(const struct tv_preferences *oldp)
{
unsigned char bom[BOM_SIZE];
int cur_start_file_pos = start_file_pos;
@@ -151,7 +151,7 @@ static void tv_change_preferences(const struct tv_preferences *oldp)
fd = rb->open(preferences->file_name, O_RDONLY);
if (fd < 0)
- return;
+ return TV_CALLBACK_ERROR;
}
/*
@@ -168,6 +168,7 @@ static void tv_change_preferences(const struct tv_preferences *oldp)
file_size = rb->filesize(fd) - start_file_pos;
tv_seek(cur_file_pos + cur_start_file_pos - start_file_pos, SEEK_SET);
+ return TV_CALLBACK_OK;
}
bool tv_init_reader(unsigned char **buf, size_t *size)
diff --git a/apps/plugins/text_viewer/tv_settings.c b/apps/plugins/text_viewer/tv_settings.c
index 56c0bbe..0b1fe20 100644
--- a/apps/plugins/text_viewer/tv_settings.c
+++ b/apps/plugins/text_viewer/tv_settings.c
@@ -417,7 +417,7 @@ bool tv_save_global_settings(const struct tv_preferences *prefs)
* ----------------------------------------------------------------------------
*/
-void tv_load_settings(const unsigned char *file_name)
+bool tv_load_settings(const unsigned char *file_name)
{
unsigned char buf[MAX_PATH+2];
unsigned int fcount;
@@ -470,7 +470,7 @@ void tv_load_settings(const unsigned char *file_name)
tv_set_default_preferences(&prefs);
}
rb->strlcpy(prefs.file_name, file_name, MAX_PATH);
- tv_set_preferences(&prefs);
+ return tv_set_preferences(&prefs);
}
static bool tv_copy_settings(int sfd, int dfd, int size)
diff --git a/apps/plugins/text_viewer/tv_settings.h b/apps/plugins/text_viewer/tv_settings.h
index c2218e7..65b31ec 100644
--- a/apps/plugins/text_viewer/tv_settings.h
+++ b/apps/plugins/text_viewer/tv_settings.h
@@ -59,7 +59,7 @@ bool tv_save_global_settings(const struct tv_preferences *prefs);
* true success
* false failure
*/
-void tv_load_settings(const unsigned char *file_name);
+bool tv_load_settings(const unsigned char *file_name);
/*
* save the settings at each file
diff --git a/apps/plugins/text_viewer/tv_window.c b/apps/plugins/text_viewer/tv_window.c
index 9e35b49..05214fa 100644
--- a/apps/plugins/text_viewer/tv_window.c
+++ b/apps/plugins/text_viewer/tv_window.c
@@ -102,7 +102,7 @@ bool tv_traverse_lines(void)
return res;
}
-static void tv_change_preferences(const struct tv_preferences *oldp)
+static int tv_change_preferences(const struct tv_preferences *oldp)
{
bool need_vertical_scrollbar = false;
@@ -131,6 +131,7 @@ static void tv_change_preferences(const struct tv_preferences *oldp)
cur_column = 0;
tv_set_read_conditions(preferences->windows, window_width);
+ return TV_CALLBACK_OK;
}
bool tv_init_window(unsigned char **buf, size_t *size)