- save support for user-defined options added

This commit is contained in:
Volker Ruppert 2006-04-14 08:07:24 +00:00
parent bbef36f5c1
commit 86a0aada3b
3 changed files with 31 additions and 12 deletions

View File

@ -1,5 +1,5 @@
/////////////////////////////////////////////////////////////////////////
// $Id: config.cc,v 1.102 2006-04-09 13:55:53 vruppert Exp $
// $Id: config.cc,v 1.103 2006-04-14 08:07:24 vruppert Exp $
/////////////////////////////////////////////////////////////////////////
//
// Copyright (C) 2002 MandrakeSoft S.A.
@ -3464,6 +3464,7 @@ int bx_write_configuration(const char *rc, int overwrite)
fprintf(fp, "mouse: enabled=%d, type=%s\n",
SIM->get_param_bool(BXPN_MOUSE_ENABLED)->get(),
SIM->get_param_enum(BXPN_MOUSE_TYPE)->get_selected());
SIM->save_user_options(fp);
fclose(fp);
return 0;
}

View File

@ -1,5 +1,5 @@
/////////////////////////////////////////////////////////////////////////
// $Id: siminterface.cc,v 1.139 2006-04-09 13:55:54 vruppert Exp $
// $Id: siminterface.cc,v 1.140 2006-04-14 08:07:24 vruppert Exp $
/////////////////////////////////////////////////////////////////////////
//
// See siminterface.h for description of the siminterface concept.
@ -36,7 +36,8 @@ class bx_real_sim_c : public bx_simulator_interface_c {
config_interface_callback_t ci_callback;
void *ci_callback_data;
int n_user_options;
user_option_handler_t user_option_handler[BX_MAX_USER_OPTIONS];
user_option_parser_t user_option_parser[BX_MAX_USER_OPTIONS];
user_option_save_t user_option_save[BX_MAX_USER_OPTIONS];
const char *user_option_name[BX_MAX_USER_OPTIONS];
int init_done;
int enabled;
@ -136,8 +137,9 @@ public:
virtual bx_bool test_for_text_console();
// user-defined option support
virtual int find_user_option(const char *keyword);
virtual bx_bool register_user_option(const char *keyword, user_option_handler_t handler);
virtual bx_bool register_user_option(const char *keyword, user_option_parser_t parser, user_option_save_t save_func);
virtual Bit32s parse_user_option(int idx, const char *context, int num_params, char *params []);
virtual Bit32s save_user_options(FILE *fp);
#if BX_SUPPORT_SAVE_RESTORE
// save/restore support
virtual bx_bool save_state(const char *checkpoint_path);
@ -803,7 +805,8 @@ int bx_real_sim_c::find_user_option(const char *keyword)
return -1;
}
bx_bool bx_real_sim_c::register_user_option(const char *keyword, user_option_handler_t handler)
bx_bool bx_real_sim_c::register_user_option(const char *keyword, user_option_parser_t parser,
user_option_save_t save_func)
{
int idx;
@ -812,8 +815,8 @@ bx_bool bx_real_sim_c::register_user_option(const char *keyword, user_option_han
}
idx = find_user_option(keyword);
if (idx >= 0) {
if (handler == user_option_handler[idx]) {
// handler already registered
if (parser == user_option_parser[idx]) {
// parse handler already registered
return 1;
} else {
// keyword already exists
@ -821,7 +824,8 @@ bx_bool bx_real_sim_c::register_user_option(const char *keyword, user_option_han
}
} else {
user_option_name[n_user_options] = keyword;
user_option_handler[n_user_options++] = handler;
user_option_parser[n_user_options] = parser;
user_option_save[n_user_options++] = save_func;
return 1;
}
}
@ -831,7 +835,19 @@ Bit32s bx_real_sim_c::parse_user_option(int idx, const char *context, int num_pa
if ((idx < 0) || (idx >= n_user_options)) {
return -1;
}
return (*user_option_handler[idx])(context, num_params, params);
return (*user_option_parser[idx])(context, num_params, params);
}
Bit32s bx_real_sim_c::save_user_options(FILE *fp)
{
int i;
for (i = 0; i < n_user_options; i++) {
if (user_option_save[i] != NULL) {
(*user_option_save[i])(fp);
}
}
return 0;
}
#if BX_SUPPORT_SAVE_RESTORE

View File

@ -1,5 +1,5 @@
/////////////////////////////////////////////////////////////////////////
// $Id: siminterface.h,v 1.184 2006-04-09 13:55:54 vruppert Exp $
// $Id: siminterface.h,v 1.185 2006-04-14 08:07:24 vruppert Exp $
/////////////////////////////////////////////////////////////////////////
//
// Intro to siminterface by Bryce Denney:
@ -1049,7 +1049,8 @@ enum ci_return_t {
};
typedef int (*config_interface_callback_t)(void *userdata, ci_command_t command);
typedef BxEvent* (*bxevent_handler)(void *theclass, BxEvent *event);
typedef Bit32s (*user_option_handler_t)(const char *context, int num_params, char *params[]);
typedef Bit32s (*user_option_parser_t)(const char *context, int num_params, char *params[]);
typedef Bit32s (*user_option_save_t)(FILE *fp);
// bx_gui->set_display_mode() changes the mode between the configuration
// interface and the simulation. This is primarily intended for display
@ -1177,8 +1178,9 @@ public:
virtual bx_bool test_for_text_console() {return 1;}
// user-defined option support
virtual int find_user_option(const char *keyword) {return -1;}
virtual bx_bool register_user_option(const char *keyword, user_option_handler_t handler) {return 0;}
virtual bx_bool register_user_option(const char *keyword, user_option_parser_t parser, user_option_save_t save_func) {return 0;}
virtual Bit32s parse_user_option(int idx, const char *context, int num_params, char *params []) {return -1;}
virtual Bit32s save_user_options(FILE *fp) {return -1;}
#if BX_SUPPORT_SAVE_RESTORE
// save/restore support
virtual bx_bool save_state(const char *checkpoint_path) {return 0;}