[Title] added maru_register_exit_msg function
authorgiwoong.kim <giwoong.kim@samsung.com>
Tue, 8 May 2012 09:38:33 +0000 (18:38 +0900)
committergiwoong.kim <giwoong.kim@samsung.com>
Tue, 8 May 2012 09:38:33 +0000 (18:38 +0900)
[Type]
[Module] Emulator
[Priority]
[Jira#]
[Redmine#]
[Problem]
[Cause] error popoup
[Solution]
[TestCase]

hw/pc.c
tizen/src/Makefile.tizen
tizen/src/emulator.c [changed mode: 0755->0644]
tizen/src/maru_err_table.c [new file with mode: 0644]
tizen/src/maru_err_table.h [new file with mode: 0644]
tizen/src/skin/maruskin_client.c
tizen/src/skin/maruskin_client.h

diff --git a/hw/pc.c b/hw/pc.c
index 67e87bd..4cca328 100644 (file)
--- a/hw/pc.c
+++ b/hw/pc.c
@@ -47,6 +47,7 @@
 #ifdef CONFIG_MARU
 #include "../tizen/src/hw/maru_overlay.h"
 #include "../tizen/src/hw/maru_brightness.h"
+#include "../tizen/src/maru_err_table.h"
 #endif
 
 /* output Bochs bios info messages */
@@ -662,10 +663,6 @@ static long get_file_size(FILE *f)
     return size;
 }
 
-#ifdef CONFIG_MARU
-extern int start_simple_client(char* msg);
-#endif
-
 static void load_linux(void *fw_cfg,
                        const char *kernel_filename,
                       const char *initrd_filename,
@@ -692,15 +689,13 @@ static void load_linux(void *fw_cfg,
                kernel_filename, strerror(errno));
 
 #ifdef CONFIG_MARU
-    const char _msg[] = "Kernel image file could not load from following path\n";
     char* current_path = (char *)g_get_current_dir();
-
-    int len = strlen(_msg) + strlen(current_path) + strlen(kernel_filename) + 3;
+    int len = strlen(current_path) + strlen(kernel_filename) + 2;
 
     char* error_msg = g_malloc0(len * sizeof(char));
-    snprintf(error_msg, len - 1, "%s%s/%s", _msg, current_path, kernel_filename);
+    snprintf(error_msg, len, "%s/%s", current_path, kernel_filename);
 
-    start_simple_client(error_msg);
+    maru_register_exit_msg(MARU_EXIT_KERNEL_FILE_EXCEPTION, error_msg);
 
     g_free(current_path);
     g_free(error_msg);
@@ -1053,16 +1048,15 @@ void pc_memory_init(MemoryRegion *system_memory,
         fprintf(stderr, "qemu: could not load PC BIOS '%s'\n", bios_name);
 
 #ifdef CONFIG_MARU
-        const char _msg[] = "Bios image file could not load from following path\n";
         char* current_path = (char *)g_get_current_dir();
         const char* _path = qemu_get_data_dir();
 
-        int len = strlen(_msg) + strlen(current_path) + strlen(_path) + strlen(bios_name) + 4;
+        int len = strlen(current_path) + strlen(_path) + strlen(bios_name) + 3;
 
         char* error_msg = g_malloc0(len * sizeof(char));
-        snprintf(error_msg, len - 1, "%s%s/%s/%s", _msg, current_path, _path, bios_name);
+        snprintf(error_msg, len, "%s/%s/%s", current_path, _path, bios_name);
 
-        start_simple_client(error_msg);
+        maru_register_exit_msg(MARU_EXIT_BIOS_FILE_EXCEPTION, error_msg);
 
         g_free(current_path);
         g_free(error_msg);
index bd9f2b6..dd2d206 100755 (executable)
@@ -56,7 +56,7 @@ endif #($(TARGET_ARCH), i386)
 endif #CONFIG_WIN32
        
 # maru loader
-obj-y += emulator.o emul_state.o option.o
+obj-y += emulator.o emul_state.o option.o maru_err_table.o
 
 # maru display
 obj-y += maru_sdl.o sdl_rotate.o maru_finger.o
old mode 100755 (executable)
new mode 100644 (file)
index d322a4b..9c15f4f
@@ -44,6 +44,7 @@
 #include "emul_state.h"
 #include "qemu_socket.h"
 #include "build_info.h"
+#include "maru_err_table.h"
 #include <glib.h>
 #include <glib/gstdio.h>
 
@@ -339,6 +340,7 @@ int main(int argc, char* argv[])
     extract_info(qemu_argc, qemu_argv);
 
     INFO("Emulator start !!!\n");
+    atexit(maru_atexit);
     system_info();
 
     INFO("Prepare running...\n");
diff --git a/tizen/src/maru_err_table.c b/tizen/src/maru_err_table.c
new file mode 100644 (file)
index 0000000..0c0f1f3
--- /dev/null
@@ -0,0 +1,79 @@
+/*
+ * Error message
+ *
+ * Copyright (C) 2011, 2012 Samsung Electronics Co., Ltd. All rights reserved.
+ *
+ * Contact: 
+ * SeokYeon Hwang <syeon.hwang@samsung.com>
+ * GiWoong Kim <giwoong.kim@samsung.com>
+ * YeongKyoon Lee <yeongkyoon.lee@samsung.com>
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
+ *
+ * Contributors:
+ * - S-Core Co., Ltd
+ *
+ */
+
+
+#include "maru_err_table.h"
+#include <stdio.h>
+#include <string.h>
+
+
+/* This table must match the enum definition */
+static char _maru_string_table[][JAVA_MAX_COMMAND_LENGTH] = {
+    "", //MARU_EXIT_NORMAL
+    "Failed to allocate memory in qemu.", //MARU_EXIT_MEMORY_EXCEPTION
+    "Fail to load kernel file. Check if the file is corrupted or missing from the following path.\n\n", //MARU_EXIT_KERNEL_FILE_EXCEPTION
+    "Fail to load bios file. Check if the file is corrupted or missing from the following path.\n\n" //MARU_EXIT_BIOS_FILE_EXCEPTION
+    /* add here */
+};
+
+
+static int maru_exit_status = MARU_EXIT_NORMAL;
+static char maru_exit_msg[JAVA_MAX_COMMAND_LENGTH] = { 0, };
+
+void maru_register_exit_msg(int maru_exit_index, char* additional_msg)
+{
+    int len = 0;
+
+    maru_exit_status = maru_exit_index;
+
+    if (maru_exit_status != MARU_EXIT_NORMAL) {
+        len = strlen(_maru_string_table[maru_exit_status]) + strlen(additional_msg) + 1;
+        if (len >= JAVA_MAX_COMMAND_LENGTH) {
+            len = JAVA_MAX_COMMAND_LENGTH;
+        }
+
+        snprintf(maru_exit_msg, len, "%s%s", _maru_string_table[maru_exit_status], additional_msg);
+    } else {
+        len = strlen(additional_msg);
+        if (len >= JAVA_MAX_COMMAND_LENGTH) {
+            additional_msg[JAVA_MAX_COMMAND_LENGTH - 1] = '\0';
+            len = JAVA_MAX_COMMAND_LENGTH - 1;
+        }
+
+        strcpy(maru_exit_msg, additional_msg);   
+    }
+}
+
+void maru_atexit(void)
+{
+    if (maru_exit_status != MARU_EXIT_NORMAL || strlen(maru_exit_msg) != 0) {
+        start_simple_client(maru_exit_msg);
+    }
+}
+
diff --git a/tizen/src/maru_err_table.h b/tizen/src/maru_err_table.h
new file mode 100644 (file)
index 0000000..5d7fa78
--- /dev/null
@@ -0,0 +1,51 @@
+/*
+ * Error message
+ *
+ * Copyright (C) 2011, 2012 Samsung Electronics Co., Ltd. All rights reserved.
+ *
+ * Contact: 
+ * SeokYeon Hwang <syeon.hwang@samsung.com>
+ * GiWoong Kim <giwoong.kim@samsung.com>
+ * YeongKyoon Lee <yeongkyoon.lee@samsung.com>
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
+ *
+ * Contributors:
+ * - S-Core Co., Ltd
+ *
+ */
+
+
+#ifndef __EMUL_ERR_TABLE_H__
+#define __EMUL_ERR_TABLE_H__
+
+#include "skin/maruskin_client.h"
+
+
+/* TODO: define macro for fair of definition */
+
+enum { //This enum must match the table definition
+    MARU_EXIT_NORMAL = 0,
+    MARU_EXIT_MEMORY_EXCEPTION,
+    MARU_EXIT_KERNEL_FILE_EXCEPTION,
+    MARU_EXIT_BIOS_FILE_EXCEPTION
+    /* add here */
+};
+
+
+void maru_register_exit_msg(int maru_exit_status, char* additional_msg);
+void maru_atexit(void);
+
+#endif /* __EMUL_ERR_TABLE_H__ */
index f195031..2f52ac9 100644 (file)
@@ -46,7 +46,6 @@
 MULTI_DEBUG_CHANNEL(qemu, maruskin_client);
 
 
-
 #define SKIN_SERVER_READY_TIME 3 // second
 #define SKIN_SERVER_SLEEP_TIME 10 // milli second
 
@@ -59,14 +58,13 @@ MULTI_DEBUG_CHANNEL(qemu, maruskin_client);
 #define OPT_VM_PATH "vm.path"
 #define OPT_NET_BASE_PORT "net.baseport"
 
-#define MAX_COMMAND 512
 
 static int skin_argc;
 static char** skin_argv;
 
 static void* run_skin_client(void* arg)
 {
-    char cmd[MAX_COMMAND] = {0};
+    char cmd[JAVA_MAX_COMMAND_LENGTH] = { 0, };
     char argv[256] = {0};
 
     INFO("run skin client\n");
@@ -222,7 +220,7 @@ int start_skin_client(int argc, char* argv[])
 
 int start_simple_client(char* msg) {
     int ret = 0;
-    char cmd[MAX_COMMAND] = {0};
+    char cmd[JAVA_MAX_COMMAND_LENGTH] = { 0, };
 
     INFO("run simple client\n");
 
index 0b832d7..7793adf 100644 (file)
@@ -30,6 +30,8 @@
 #ifndef MARUSKIN_CLIENT_H_
 #define MARUSKIN_CLIENT_H_
 
+#define JAVA_MAX_COMMAND_LENGTH 512
+
 int start_skin_client(int argc, char* argv[]);
 int start_simple_client(char* msg);