- Fix plugin.hh visibility attributes

- Improve option parsing
- Strange SIGSEGV still happening (a different one, though)


git-svn-id: svn://svn.gna.org/svn/sgpemv2/trunk@736 3ecf2c5c-341e-0410-92b4-d18e462d057c
This commit is contained in:
tchernobog 2006-07-06 09:49:35 +00:00
parent 3125f3d3cf
commit 8b1da4e1c7
8 changed files with 92 additions and 185 deletions

View File

@ -102,9 +102,20 @@
<property name="position">1</property> <property name="position">1</property>
</packing> </packing>
</child> </child>
<child>
<widget class="GtkHPaned" id="HorizontalPaned">
<property name="visible">True</property>
<child> <child>
<placeholder/> <placeholder/>
</child> </child>
<child>
<placeholder/>
</child>
</widget>
<packing>
<property name="position">2</property>
</packing>
</child>
<child> <child>
<widget class="GtkStatusbar" id="statusbar1"> <widget class="GtkStatusbar" id="statusbar1">
<property name="visible">True</property> <property name="visible">True</property>

View File

@ -43,13 +43,16 @@ extern "C"
* Sets up the plugin's initial state and * Sets up the plugin's initial state and
* performs needed actions before its usage can start. * performs needed actions before its usage can start.
*/ */
void sgpem__Plugin__on_init(); SG_DLLEXPORT void sgpem__Plugin__on_init();
void sgpem__Plugin__on_exit(); SG_DLLEXPORT void sgpem__Plugin__on_exit();
const char* sgpem__Plugin__describe(); SG_DLLEXPORT const char* sgpem__Plugin__describe();
const char* sgpem__Plugin__get_name(); SG_DLLEXPORT const char* sgpem__Plugin__get_name();
const char* sgpem__Plugin__get_author(); SG_DLLEXPORT const char* sgpem__Plugin__get_author();
float sgpem__Plugin__get_version(); SG_DLLEXPORT float sgpem__Plugin__get_version();
// To know why SG_DLLEXPORT must go *before* the return
// value, see http://gcc.gnu.org/ml/gcc-help/2005-04/msg00340.html
#ifdef __cplusplus #ifdef __cplusplus
} }

View File

@ -24,11 +24,9 @@
#include "main.hh" #include "main.hh"
#include "parse_opts.hh" #include "parse_opts.hh"
#include "start_gui.hh"
#include "backend/plugin_manager.hh"
#include <glibmm/module.h> #include <glibmm/module.h>
#include <glibmm/thread.h>
#include <glibmm/ustring.h> #include <glibmm/ustring.h>
#include <algorithm> #include <algorithm>
@ -41,7 +39,6 @@
int int
main(int argc, char* argv[]) main(int argc, char* argv[])
{ {
using namespace sgpem;
using namespace std; using namespace std;
using Glib::ustring; using Glib::ustring;
@ -55,18 +52,7 @@ main(int argc, char* argv[])
// Parses options and prepares vector with // Parses options and prepares vector with
// filenames of documents to be opened // filenames of documents to be opened
vector<string> filenames; parse_options(argc, argv);
{
int a_count = argc;
char** a_ptr = argv;
parse_options(a_count, a_ptr);
filenames.insert(filenames.begin(), a_ptr, a_ptr + a_count);
}
// Initializes plugin system
PluginManager::get_instance();
start_gui(argc, argv);
return 0; return 0;
} }

View File

@ -22,92 +22,78 @@
#include "gettext.h" #include "gettext.h"
#include "backend/global_preferences.hh" #include "backend/global_preferences.hh"
#include "backend/plugin_manager.hh"
#include "parse_opts.hh" #include "parse_opts.hh"
#include "start_gui.hh"
//#ifdef _GNU_SOURCE
//#include <getopt.h>
//#endif
#include <glibmm/optioncontext.h> #include <glibmm/optioncontext.h>
#include <gtkmm/main.h>
//#include <cstdio>
#include <cstdlib> #include <cstdlib>
//#include <unistd.h>
#include <iostream> #include <iostream>
using namespace sgpem; using namespace sgpem;
// Static declarations:
static void display_help();
void void
parse_options(int& argc, char**& argv) parse_options(int argc, char** argv)
{ {
// FIXME this code causes a segfault some time after the method is returned (!!!),
// ddd says the problem originates from libglib. Any clue?
using Glib::OptionEntry; using Glib::OptionEntry;
using Glib::OptionContext; using Glib::OptionContext;
using Glib::OptionGroup; using Glib::OptionGroup;
print_license(); print_license();
// Here we try to sort out the order of creation of the Option* objects, but it's useless...
OptionContext context("SGPEMv2, a graphical simulator for process "
"scheduling in a multitasking computer");
OptionGroup group("options", "options");
// Prepare the option entries // Prepare the option entries
OptionEntry no_gui; OptionEntry no_gui;
OptionEntry policies_dir; OptionEntry policies_dir;
OptionEntry modules_dir; OptionEntry modules_dir;
OptionEntry filename;
no_gui.set_short_name('N'); no_gui.set_short_name('N');
policies_dir.set_short_name('P'); policies_dir.set_short_name('P');
modules_dir.set_short_name('M'); modules_dir.set_short_name('M');
#ifdef _GNU_SOURCE
no_gui.set_long_name("no-gui"); no_gui.set_long_name("no-gui");
policies_dir.set_long_name("policies-dir"); policies_dir.set_long_name("policies-dir");
modules_dir.set_long_name("modules_dir"); modules_dir.set_long_name("modules_dir");
#endif filename.set_long_name(G_OPTION_REMAINING);
no_gui.set_description("starts the program in command line mode"); no_gui.set_description(_("starts the program in command line mode"));
policies_dir.set_description("adds this directory to the default modules search path"); policies_dir.set_description(_("adds this directory to the default modules search path"));
modules_dir.set_description("adds this directory to default plugin search path"); modules_dir.set_description(_("adds this directory to default plugin search path"));
filename.set_description(_("a list of savefiles; only the first will be opened"));
// Places where araguments will be saved // Places where araguments will be saved
bool no_gui_enabled = false; bool no_gui_enabled = false;
OptionGroup::vecustrings policies_dir_val; OptionGroup::vecustrings policies_dir_val;
OptionGroup::vecustrings modules_dir_val; OptionGroup::vecustrings modules_dir_val;
OptionGroup::vecstrings fnames;
no_gui.set_flags(OptionEntry::FLAG_NO_ARG);
filename.set_flags(OptionEntry::FLAG_FILENAME | OptionEntry::FLAG_OPTIONAL_ARG);
// Create the only group // Create the only group
OptionGroup group("options", "options");
//OptionGroup group("options", "options");
group.add_entry(no_gui, no_gui_enabled); group.add_entry(no_gui, no_gui_enabled);
group.add_entry(policies_dir, policies_dir_val); group.add_entry(policies_dir, policies_dir_val);
group.add_entry(modules_dir, modules_dir_val); group.add_entry(modules_dir, modules_dir_val);
group.add_entry_filename(filename, fnames);
// Create context // Create context
OptionContext context(_("SGPEMv2, a graphical simulator for process "
//OptionContext context("SGPEMv2, a graphical simulator for process " "scheduling in a multitasking computer"));
// "scheduling in a multitasking computer");
context.set_main_group(group); context.set_main_group(group);
context.set_help_enabled(true); context.set_help_enabled(true);
context.set_ignore_unknown_options(true); context.set_ignore_unknown_options(false);
// Parse options
try try
{ {
context.parse(argc, argv); // Parse options, initialising the Gtk::Main at the same time
Gtk::Main(argc, argv, context);
GlobalPreferences& prefs = GlobalPreferences::get_instance(); GlobalPreferences& prefs = GlobalPreferences::get_instance();
@ -119,116 +105,31 @@ parse_options(int& argc, char**& argv)
it != modules_dir_val.end(); ++it) it != modules_dir_val.end(); ++it)
prefs.add_modules_dir(*it); prefs.add_modules_dir(*it);
// Now that GlobalPreferences has been initialized properly,
// initialize plugins, too
PluginManager::get_instance();
if(no_gui_enabled) if(no_gui_enabled)
{ {
// We don't return to main, instead we // We don't return to main, instead we
// initialize the command line version // initialize the command line version
// of sgpemv2 (?) // of sgpemv2 (?)
throw Glib::OptionError(Glib::OptionError::FAILED, _("The `No-GUI' option isn't active yet."));
// FIXME : to be written! // FIXME : to be written!
} else {
if(fnames.begin() != fnames.end())
start_gui(*fnames.begin());
else
start_gui("");
} }
} } // ~ try
catch(Glib::OptionError e) catch(Glib::OptionError e)
{ {
std::cout << "Bad invocation: " << e.what() << std::endl; std::cout << _("Bad invocation: ") << e.what() << std::endl;
std::cout << _("Use the `-?' or `--help' option to see the help") << std::endl;
//char *force_help_vec[] = { "sgpem", "--help" };
//char **force_help = &force_help_vec[0];
//int count = 2;
//assert(context.parse(count, force_help));
} }
// and now ??? I need MORE documentation for this stuff!!!
// shame on me! it was so easy...
}
//void
//parse_options(int& argc, char**& argv)
//{
// using sgpem::GlobalPreferences;
//
// print_license();
//
// static const char* short_options = "NhP:M:";
//
//#ifdef _GNU_SOURCE
// // Initialize the array for GNU long options
// static struct option long_options[] =
// {
// {"no-gui", no_argument, NULL, 'N' },
// {"help", no_argument, NULL, 'h' },
// {"policies-dir", required_argument, NULL, 'P'},
// {"modules-dir", required_argument, NULL, 'M'}
// };
// int option_index = 0;
//#endif
//
// int opt;
// do
// {
//#ifdef _GNU_SOURCE
// opt = getopt_long(argc, argv, short_options,
// long_options, &option_index);
//#else
// opt = getopt(argc, argv, short_options);
//#endif
//
// switch(opt)
// {
// case - 1:
// // We have finished normally
// break;
// case 'N' :
// // We don't return to main, instead we
// // initialize the command line version
// // of sgpemv2 (?)
//
// // FIXME : to be written!
// break;
// case 'P':
// GlobalPreferences::get_instance().add_policies_dir(optarg);
// break;
// case 'M':
// GlobalPreferences::get_instance().add_modules_dir(optarg);
// break;
// case ':':
// printf(_("[EE] Wrong number of parameters. Please see \n"
// "%s --help\n"), argv[0]);
// exit(-1);
// case 'h' :
// default :
// display_help();
// }
// }
// while( opt != -1 );
//
// // Set these two to start from additional filenames on the cmdline:
// argc -= optind;
// argv += optind;
//}
void
display_help()
{
printf( _("SGPEMv2 is an educational software acting as a process scheduling simulator\n"
"\n\nUsage : sgpemv2 [options] filename"
"\n\nOptions:\n"
"\t-h, --help this help you're reading\n"
"\t-N, --no-gui starts the program in command line mode\n"
"\t-P dir, --policies-dir=dir\n"
"\t add this directory to the default modules\n"
"\t search path\n"
"\t-M dir, --modules-dir=dir\n"
"\t add this directory to default plugin\n"
"\t search path\n"
"\nFilename:\n"
"\t a valid SGPEMv2 XML file\n"
"\t to be opened.\n"
"\nLong options are available only on GNU systems.\n\n" ) );
exit(0);
} }

View File

@ -35,7 +35,7 @@
* \param argc The number of elements of the argv array * \param argc The number of elements of the argv array
* \param argv The array of command line parameter strings * \param argv The array of command line parameter strings
*/ */
void parse_options(int& argc, char**& argv); void parse_options(int argc, char** argv);
/** \brief Prints license notice text to stderr */ /** \brief Prints license notice text to stderr */
void print_license(); void print_license();

View File

@ -31,14 +31,16 @@
#include <gtkmm/window.h> #include <gtkmm/window.h>
#include <cassert> #include <cassert>
#include <iostream>
void void
start_gui(int argc, char** argv) start_gui(const std::string& filename)
{ {
using namespace Gnome; using namespace Gnome;
using namespace Gtk; using namespace Gtk;
Main gtk_main(argc, argv); // Debug line (erase me when done):
std::cout << _("Filename to open: ") << filename << std::endl;
Glib::RefPtr<Glade::Xml> refXml = Glib::RefPtr<Glade::Xml> refXml =
Glade::Xml::create(GLADEDIR "/main-window.glade"); Glade::Xml::create(GLADEDIR "/main-window.glade");
@ -61,6 +63,8 @@ start_gui(int argc, char** argv)
refXml->get_widget("AboutDialog", about_dialog); refXml->get_widget("AboutDialog", about_dialog);
help_about->signal_activate().connect(sigc::mem_fun(*about_dialog, &Window::show)); help_about->signal_activate().connect(sigc::mem_fun(*about_dialog, &Window::show));
// Here open filename if != ""
main_window->show_all_children(); main_window->show_all_children();
Main::run(*main_window); Main::run(*main_window);

View File

@ -23,10 +23,12 @@
#include "config.h" #include "config.h"
#include <string>
/** \brief This function initialize and starts the whole GUI /** \brief This function initialize and starts the whole GUI
*/ */
void SG_DLLEXPORT start_gui(int argc, char** argv); void SG_DLLEXPORT start_gui(const std::string& filename);
#endif #endif

View File

@ -49,7 +49,7 @@ namespace sgpem
static Glib::StaticMutex SG_DLLLOCAL _mutex; static Glib::StaticMutex SG_DLLLOCAL _mutex;
private: private:
static Instantiated_class* _instance; static SG_DLLLOCAL Instantiated_class* _instance;
} }
; //~ class Singleton ; //~ class Singleton