- wx: NetConfigDialog replaced by a new version using ParamDialog

- parameter for the ethernet module must be of type bx_param_enum_c, since we
  have a list of valid modules
This commit is contained in:
Volker Ruppert 2003-08-25 16:46:18 +00:00
parent 63e67d7bcc
commit ca60988fd9
6 changed files with 48 additions and 352 deletions

View File

@ -1,5 +1,5 @@
/////////////////////////////////////////////////////////////////////////
// $Id: bochs.h,v 1.125 2003-08-24 10:08:49 vruppert Exp $
// $Id: bochs.h,v 1.126 2003-08-25 16:46:18 vruppert Exp $
/////////////////////////////////////////////////////////////////////////
//
// Copyright (C) 2002 MandrakeSoft S.A.
@ -582,7 +582,7 @@ typedef struct {
bx_param_num_c *Oioaddr;
bx_param_num_c *Oirq;
bx_param_string_c *Omacaddr;
bx_param_string_c *Oethmod;
bx_param_enum_c *Oethmod;
bx_param_string_c *Oethdev;
bx_param_string_c *Oscript;
} bx_ne2k_options;

View File

@ -1,5 +1,5 @@
/////////////////////////////////////////////////////////////////
// $Id: wxdialog.cc,v 1.58 2003-08-25 15:21:19 vruppert Exp $
// $Id: wxdialog.cc,v 1.59 2003-08-25 16:46:18 vruppert Exp $
/////////////////////////////////////////////////////////////////
// Define BX_PLUGGABLE in files that can be compiled into plugins. For
@ -380,216 +380,6 @@ void FloppyConfigDialog::ShowHelp ()
wxMessageBox(MSG_NO_HELP, MSG_NO_HELP_CAPTION, wxOK | wxICON_ERROR );
}
//////////////////////////////////////////////////////////////////////
// NetConfigDialog implementation
//////////////////////////////////////////////////////////////////////
// Structure:
// mainSizer:
// vertSizer:
// prompt
// gridSizer 2 columns:
// "enable networking"
// enable = checkbox
// "i/o addr"
// io = wxTextCtrl
// "irq"
// irq = wxSpinCtrl
// "mac"
// mac = wxTextCtrl
// "conn"
// conn = wxChoice
// "phys"
// phys = wxTextCtrl
// "script"
// script = wxTextCtrl
// buttonSizer:
// help
// cancel
// ok
// all events go to OnEvent method
BEGIN_EVENT_TABLE(NetConfigDialog, wxDialog)
EVT_BUTTON(-1, NetConfigDialog::OnEvent)
EVT_CHECKBOX(-1, NetConfigDialog::OnEvent)
EVT_TEXT(-1, NetConfigDialog::OnEvent)
END_EVENT_TABLE()
NetConfigDialog::NetConfigDialog(
wxWindow* parent,
wxWindowID id)
: wxDialog (parent, id, "", wxDefaultPosition, wxDefaultSize,
wxDEFAULT_DIALOG_STYLE | wxRESIZE_BORDER)
{
n_conn_choices = 0;
SetTitle (NET_CONFIG_TITLE);
// top level objects
mainSizer = new wxBoxSizer (wxVERTICAL);
wxBoxSizer *vertSizer = new wxBoxSizer (wxVERTICAL);
mainSizer->Add (vertSizer, 1, wxGROW|wxALIGN_LEFT);
wxBoxSizer *buttonSizer = new wxBoxSizer (wxHORIZONTAL);
mainSizer->Add (buttonSizer, 0, wxALIGN_RIGHT);
// vertSizer contents
wxStaticText *text;
text = new wxStaticText (this, -1, NET_CONFIG_PROMPT);
vertSizer->Add (text, 0, wxLEFT|wxRIGHT|wxTOP, 20);
wxFlexGridSizer *gridSizer = new wxFlexGridSizer (2);
vertSizer->Add (gridSizer, 1, wxALL|wxGROW, 30);
// gridSizer contents
gridSizer->AddGrowableCol (1);
#define add(x) gridSizer->Add (x, 0, wxALL|wxADJUST_MINSIZE, 5)
#define add_grow(x) gridSizer->Add (x, 1, wxALL|wxGROW, 5)
#define label(x) (new wxStaticText (this, -1, x))
add (label (NET_CONFIG_EN));
add (enable = new wxCheckBox (this, ID_Enable, ""));
gridSizer->Add (30, 30);
gridSizer->Add (30, 30);
add (label (NET_CONFIG_IO));
add (io = new wxTextCtrl (this, -1, "", wxDefaultPosition, normalTextSize));
add (label (NET_CONFIG_IRQ));
add (irq = new wxSpinCtrl (this, -1));
add (label (NET_CONFIG_MAC));
add (mac = new wxTextCtrl (this, -1, "", wxDefaultPosition, normalTextSize));
add (label (NET_CONFIG_CONN));
add (conn = new wxChoice (this, -1));
add (label (NET_CONFIG_PHYS));
add (phys = new wxTextCtrl (this, -1, "", wxDefaultPosition, normalTextSize));
add (label (NET_CONFIG_SCRIPT));
add_grow (script = new wxTextCtrl (this, -1, "", wxDefaultPosition, normalTextSize));
#undef label
#undef add
irq->SetRange (0, 15);
// buttonSizer contents
wxButton *btn = new wxButton (this, wxID_HELP, BTNLABEL_HELP);
buttonSizer->Add (btn, 0, wxALL, 5);
// use wxID_CANCEL because pressing ESC produces this same code
btn = new wxButton (this, wxID_CANCEL, BTNLABEL_CANCEL);
buttonSizer->Add (btn, 0, wxALL, 5);
btn = new wxButton (this, wxID_OK, BTNLABEL_OK);
buttonSizer->Add (btn, 0, wxALL, 5);
}
void NetConfigDialog::Init()
{
EnableChanged ();
// lay it out!
SetAutoLayout(TRUE);
SetSizer(mainSizer);
mainSizer->Fit (this);
wxSize size = mainSizer->GetMinSize ();
wxLogMessage ("minsize is %d,%d", size.GetWidth(), size.GetHeight ());
int margin = 5;
SetSizeHints (size.GetWidth () + margin, size.GetHeight () + margin);
Center ();
}
void NetConfigDialog::EnableChanged ()
{
bool en = enable->GetValue ();
io->Enable (en);
irq->Enable (en);
mac->Enable (en);
conn->Enable (en);
phys->Enable (en);
script->Enable (en);
}
// allow (encourage) use of hex addresses started with "0x"
int NetConfigDialog::GetIO () {
char buf[1024];
wxString string(io->GetValue ());
string.Trim ();
strncpy (buf, string, sizeof(buf));
int n = strtol (string, NULL, 0);
if (n<0 || n>0xffff) {
wxMessageBox("I/O address out of range. Try 0 - 0xffff.", "Bad I/O address", wxOK | wxICON_ERROR );
return -1;
}
return n;
}
void NetConfigDialog::SetMac (unsigned char addr[6]) {
wxString text;
text.Printf ("%02x:%02x:%02x:%02x:%02x:%02x", addr[0], addr[1], addr[2], addr[3], addr[4], addr[5]);
mac->SetValue (text);
}
bool
NetConfigDialog::GetMac (unsigned char addr[6]) {
char buf[32];
wxString string(mac->GetValue ());
string.Trim ();
strncpy (buf, string, sizeof(buf));
// expect NN:NN:NN:NN:NN:NN format
int part[6];
if (6 != sscanf (string, "%x:%x:%x:%x:%x:%x", &part[0], &part[1], &part[2],
&part[3], &part[4], &part[5]))
{
wxMessageBox("MAC address must be in the form FF:FF:FF:FF:FF:FF.", "Bad MAC Address", wxOK | wxICON_ERROR );
return false;
}
for (int i=0; i<6; i++)
addr[i] = part[i];
return true;
}
void NetConfigDialog::AddConn (wxString niceName, char *realName) {
conn->Append (niceName);
int index = n_conn_choices++;
conn->SetClientData (index, realName);
}
void NetConfigDialog::SetConn (const char *realname) {
// search through the choices and find the one whose clientData matches
// realname.
for (int i=0; i<n_conn_choices; i++) {
char *choiceRealName = (char *)conn->GetClientData (i);
if (!strcmp (choiceRealName, realname)) {
conn->SetSelection (i);
return;
}
}
wxLogError ("no choice match for '%s'", realname);
}
void NetConfigDialog::OnEvent(wxCommandEvent& event)
{
int id = event.GetId ();
wxLogMessage ("you pressed button id=%d", id);
switch (id) {
case ID_Enable:
EnableChanged (); // enable/disable fields that depend on this
break;
case wxID_OK:
{
// check for valid mac address by calling GetMac()
unsigned char tmp[6];
if (GetMac (tmp)) {
// mac address was legal
EndModal (wxID_OK);
}
}
break;
case wxID_CANCEL:
EndModal (wxID_CANCEL);
break;
case wxID_HELP:
ShowHelp();
break;
default:
event.Skip ();
}
}
void NetConfigDialog::ShowHelp ()
{
wxMessageBox(MSG_NO_HELP, MSG_NO_HELP_CAPTION, wxOK | wxICON_ERROR );
}
//////////////////////////////////////////////////////////////////////
// LogOptionsDialog implementation

View File

@ -1,5 +1,5 @@
////////////////////////////////////////////////////////////////////
// $Id: wxdialog.h,v 1.48 2003-08-23 17:53:27 vruppert Exp $
// $Id: wxdialog.h,v 1.49 2003-08-25 16:46:18 vruppert Exp $
////////////////////////////////////////////////////////////////////
//
// wxWindows dialogs for Bochs
@ -208,76 +208,6 @@ public:
DECLARE_EVENT_TABLE()
};
////////////////////////////////////////////////////////////////////////////
// ConfigNetworkDialog allows the user to change the settings for
// the emulated NE2000 network card.
////////////////////////////////////////////////////////////////////////////
// +--- Configure Networking --------------------------------------+
// | |
// | Bochs can emulate an NE2000-compatible network card. Would |
// | you like to enable it? |
// | |
// | Enable networking? [X] |
// | |
// | NE2000 I/O address: [ 0x280 ] |
// | IRQ: [ 9 ] |
// | MAC address: [ b0:c4:00:00:00:00 ] |
// | Connection to the OS: [ Linux Packet Filter ] |
// | Physical NIC to use: [ eth0 ] |
// | Setup script: [_________________] |
// | |
// | [ Help ] [ Cancel ] [ Ok ] |
// +---------------------------------------------------------------+
// To use this dialog:
// After constructor, use AddConn() to add values to the choice box
// called "Connection to the OS". Then use SetEnable, SetIO, SetIrq, SetMac,
// SetConn, SetNic, and SetDebug to fill in the current values. Then call
// ShowModal(), which will return wxID_OK or wxID_CANCEL. Then use the Get*
// methods to retrieve the values that were chosen.
class NetConfigDialog: public wxDialog
{
private:
#define NET_CONFIG_TITLE "Configure Networking"
#define NET_CONFIG_PROMPT "Bochs can emulate an NE2000-compatible network card. Would you like to enable it?"
#define NET_CONFIG_EN "Enable networking?"
#define NET_CONFIG_IO "I/O address (hex): "
#define NET_CONFIG_IRQ "IRQ: "
#define NET_CONFIG_MAC "MAC address: "
#define NET_CONFIG_CONN "Connection to OS: "
#define NET_CONFIG_PHYS "Physical NIC to use: "
#define NET_CONFIG_SCRIPT "Setup script: "
void Init (); // called automatically by ShowModal()
void ShowHelp ();
wxBoxSizer *mainSizer, *vertSizer, *buttonSizer;
wxCheckBox *enable;
wxTextCtrl *io, *mac, *phys, *script;
wxSpinCtrl *irq;
wxChoice *conn;
int n_conn_choices;
void EnableChanged ();
public:
NetConfigDialog(wxWindow* parent, wxWindowID id);
void OnEvent (wxCommandEvent& event);
int ShowModal() { Init(); return wxDialog::ShowModal(); }
void SetEnable (bool en) { enable->SetValue (en); EnableChanged (); }
bool GetEnable () { return enable->GetValue (); }
void SetIO (int addr) { SetTextCtrl (io, "0x%03x", addr); }
int GetIO ();
void SetIrq (int addr) { irq->SetValue (addr); }
int GetIrq () { return irq->GetValue (); }
void SetMac (unsigned char addr[6]);
bool GetMac (unsigned char addr[6]);
void SetConn(const char *realname);
int GetConn () { return conn->GetSelection (); }
void *GetConnData () { return conn->GetClientData (conn->GetSelection ()); }
void AddConn (wxString niceName, char *realName);
void SetPhys (wxString s) { phys->SetValue (s); }
wxString GetPhys () { return phys->GetValue (); }
void SetScript (wxString s) { script->SetValue (s); }
wxString GetScript () { return script->GetValue (); }
DECLARE_EVENT_TABLE()
};
////////////////////////////////////////////////////////////////////////////
// ConfigMemoryDialog
////////////////////////////////////////////////////////////////////////////

View File

@ -1,5 +1,5 @@
/////////////////////////////////////////////////////////////////
// $Id: wxmain.cc,v 1.93 2003-08-23 15:28:06 vruppert Exp $
// $Id: wxmain.cc,v 1.94 2003-08-25 16:46:18 vruppert Exp $
/////////////////////////////////////////////////////////////////
//
// wxmain.cc implements the wxWindows frame, toolbar, menus, and dialogs.
@ -669,61 +669,11 @@ void MyFrame::OnEditTiming(wxCommandEvent& WXUNUSED(event))
void MyFrame::OnEditNet(wxCommandEvent& WXUNUSED(event))
{
NetConfigDialog dlg (this, -1);
bx_param_bool_c *present = (bx_param_bool_c*)SIM->get_param (BXP_NE2K_PRESENT);
bx_param_num_c *io = (bx_param_num_c*)SIM->get_param (BXP_NE2K_IOADDR);
bx_param_num_c *irq = (bx_param_num_c*)SIM->get_param (BXP_NE2K_IRQ);
bx_param_string_c *mac = (bx_param_string_c*)
SIM->get_param (BXP_NE2K_MACADDR);
bx_param_string_c *module = (bx_param_string_c*)
SIM->get_param (BXP_NE2K_ETHMOD);
bx_param_string_c *device = (bx_param_string_c*)
SIM->get_param (BXP_NE2K_ETHDEV);
bx_param_string_c *script = (bx_param_string_c*)
SIM->get_param (BXP_NE2K_SCRIPT);
dlg.SetEnable (present->get ());
dlg.SetIO (io->get ());
dlg.SetIrq (irq->get ());
dlg.SetMac ((unsigned char *) mac->getptr ());
dlg.AddConn ("Null Packet Mover", "null");
#if defined(ETH_LINUX)
dlg.AddConn ("Linux Socket Filter", "linux");
#endif
#if HAVE_ETHERTAP
dlg.AddConn ("Ethertap", "tap");
#endif
#if HAVE_TUNTAP
dlg.AddConn ("TUN/TAP", "tuntap");
#endif
#if defined(ETH_WIN32)
dlg.AddConn ("Win32 packet mover", "win32");
#endif
#if defined(ETH_FBSD)
dlg.AddConn ("Berkeley Packet Filter (FreeBSD, OpenBSD)", "fbsd");
#endif
#ifdef ETH_ARPBACK
dlg.AddConn ("ARPback packet mover", "arpback");
#endif
dlg.SetConn (module->getptr ());
dlg.SetPhys (device->getptr ());
dlg.SetScript (script->getptr ());
int n = dlg.ShowModal ();
if (n==wxID_OK) {
present->set (dlg.GetEnable ());
io->set (dlg.GetIO ());
irq->set (dlg.GetIrq ());
unsigned char tmp[6];
dlg.GetMac (tmp);
mac->set ((char *)tmp);
module->set ((char *)dlg.GetConnData ());
char buf[1024];
wxString deviceString (dlg.GetPhys ());
strncpy (buf, deviceString.c_str (), sizeof(buf));
device->set (buf);
wxString scriptString (dlg.GetScript ());
strncpy (buf, scriptString.c_str (), sizeof(buf));
script->set (buf);
}
ParamDialog dlg (this, -1);
bx_list_c *list = (bx_list_c*) SIM->get_param (BXP_NE2K);
dlg.SetTitle (list->get_name ());
dlg.AddParam (list);
dlg.ShowModal ();
}
void MyFrame::OnEditKeyboard(wxCommandEvent& WXUNUSED(event))

View File

@ -1,5 +1,5 @@
/////////////////////////////////////////////////////////////////////////
// $Id: ne2k.cc,v 1.54 2003-07-31 12:04:48 vruppert Exp $
// $Id: ne2k.cc,v 1.55 2003-08-25 16:46:18 vruppert Exp $
/////////////////////////////////////////////////////////////////////////
//
// Copyright (C) 2002 MandrakeSoft S.A.
@ -1272,7 +1272,7 @@ bx_ne2k_c::rx_frame(const void *buf, unsigned io_len)
void
bx_ne2k_c::init(void)
{
BX_DEBUG(("Init $Id: ne2k.cc,v 1.54 2003-07-31 12:04:48 vruppert Exp $"));
BX_DEBUG(("Init $Id: ne2k.cc,v 1.55 2003-08-25 16:46:18 vruppert Exp $"));
// Read in values from config file
BX_NE2K_THIS s.base_address = bx_options.ne2k.Oioaddr->get ();
@ -1322,17 +1322,17 @@ bx_ne2k_c::init(void)
BX_NE2K_THIS s.macaddr[i] = 0x57;
// Attach to the simulated ethernet dev
BX_NE2K_THIS ethdev = eth_locator_c::create(bx_options.ne2k.Oethmod->getptr (),
char *ethmod = bx_options.ne2k.Oethmod->get_choice(bx_options.ne2k.Oethmod->get());
BX_NE2K_THIS ethdev = eth_locator_c::create(ethmod,
bx_options.ne2k.Oethdev->getptr (),
(const char *) bx_options.ne2k.Omacaddr->getptr (),
rx_handler,
this);
if (BX_NE2K_THIS ethdev == NULL) {
BX_PANIC(("could not find eth module %s", bx_options.ne2k.Oethmod->getptr ()));
BX_PANIC(("could not find eth module %s", ethmod));
// if they continue, use null.
BX_INFO(("could not find eth module %s - using null instead",
bx_options.ne2k.Oethmod->getptr ()));
BX_INFO(("could not find eth module %s - using null instead", ethmod));
BX_NE2K_THIS ethdev = eth_locator_c::create("null", NULL,
(const char *) bx_options.ne2k.Omacaddr->getptr (),

View File

@ -1,5 +1,5 @@
/////////////////////////////////////////////////////////////////////////
// $Id: main.cc,v 1.240 2003-08-24 10:08:49 vruppert Exp $
// $Id: main.cc,v 1.241 2003-08-25 16:46:18 vruppert Exp $
/////////////////////////////////////////////////////////////////////////
//
// Copyright (C) 2002 MandrakeSoft S.A.
@ -1185,10 +1185,35 @@ void bx_init_options ()
"", 6);
bx_options.ne2k.Omacaddr->get_options ()->set (bx_options.ne2k.Omacaddr->RAW_BYTES);
bx_options.ne2k.Omacaddr->set_separator (':');
bx_options.ne2k.Oethmod = new bx_param_string_c (BXP_NE2K_ETHMOD,
static char *eth_module_list[] = {
"null",
#if defined(ETH_LINUX)
"linux",
#endif
#if HAVE_ETHERTAP
"tap",
#endif
#if HAVE_TUNTAP
"tuntap",
#endif
#if defined(ETH_WIN32)
"win32",
#endif
#if defined(ETH_FBSD)
"fbsd",
#endif
#ifdef ETH_ARPBACK
"arpback",
#endif
NULL
};
bx_options.ne2k.Oethmod = new bx_param_enum_c (BXP_NE2K_ETHMOD,
"Ethernet module",
"to be written",
"null", 16);
eth_module_list,
0,
0);
bx_options.ne2k.Oethmod->set_by_name ("null");
bx_options.ne2k.Oethdev = new bx_param_string_c (BXP_NE2K_ETHDEV,
"Ethernet device",
"to be written",
@ -3747,7 +3772,7 @@ parse_line_formatted(char *context, int num_params, char *params[])
if ((num_params < 4) || (num_params > 7)) {
PARSE_ERR(("%s: ne2k directive malformed.", context));
}
bx_options.ne2k.Oethmod->set ("null");
bx_options.ne2k.Oethmod->set_by_name ("null");
if (strncmp(params[1], "ioaddr=", 7)) {
PARSE_ERR(("%s: ne2k directive malformed.", context));
}
@ -3771,7 +3796,8 @@ parse_line_formatted(char *context, int num_params, char *params[])
if (strncmp(params[4], "ethmod=", 7)) {
PARSE_ERR(("%s: ne2k directive malformed.", context));
}
bx_options.ne2k.Oethmod->set (strdup(&params[4][7]));
if (!bx_options.ne2k.Oethmod->set_by_name (strdup(&params[4][7])))
PARSE_ERR(("%s: ethernet module '%s' not available", context, strdup(&params[4][7])));
if (num_params > 5) {
if (strncmp(params[5], "ethdev=", 7)) {
PARSE_ERR(("%s: ne2k directive malformed.", context));
@ -4075,7 +4101,7 @@ bx_write_ne2k_options (FILE *fp, bx_ne2k_options *opt)
(unsigned int)(0xff & ptr[3]),
(unsigned int)(0xff & ptr[4]),
(unsigned int)(0xff & ptr[5]),
opt->Oethmod->getptr (),
opt->Oethmod->get_choice(opt->Oethmod->get()),
opt->Oethdev->getptr (),
opt->Oscript->getptr ());
return 0;