Fix some more warnings, install headers

This commit is contained in:
Matteo Settenvini 2018-09-25 10:17:29 +02:00
parent 616aef27a8
commit c1ac6f279b
12 changed files with 377 additions and 288 deletions

72
.clang-format Normal file
View File

@ -0,0 +1,72 @@
---
AccessModifierOffset: 0
AlignAfterOpenBracket: Align
AlignConsecutiveAssignments: true
AlignConsecutiveDeclarations: false
AlignEscapedNewlinesLeft: false
AlignOperands: true
AlignTrailingComments: false
AllowAllParametersOfDeclarationOnNextLine: false
AllowShortBlocksOnASingleLine : false
AllowShortCaseLabelsOnASingleLine: false
AllowShortFunctionsOnASingleLine: false
AllowShortIfStatementsOnASingleLine: false
AllowShortLoopsOnASingleLine: false
AlwaysBreakAfterReturnType: TopLevelDefinitions
AlwaysBreakBeforeMultilineStrings: true
AlwaysBreakTemplateDeclarations: true
BinPackArguments: false
BinPackParameters: true
BreakAfterJavaFieldAnnotations: true
BreakBeforeBraces: Allman
BreakBeforeBinaryOperators: None
BreakBeforeTernaryOperators: false
BreakConstructorInitializersBeforeComma: false
BreakStringLiterals: true
ColumnLimit: 120
CommentPragmas: "<pre>.*?</pre>"
ConstructorInitializerAllOnOneLineOrOnePerLine: true
ConstructorInitializerIndentWidth: 4
ContinuationIndentWidth: 4
Cpp11BracedListStyle: true
PointerAlignment: Right
ForEachMacros: [ 'BOOST_FOREACH' ]
IncludeCategories:
- Regex: '^<(gtest|gmock)'
Priority: 8
- Regex: '^(<boost/)'
Priority: 7
- Regex: '^<'
Priority: 9
- Regex: '^<sgpemv2/'
Priority: 2
- Regex: '^"'
Priority: 1
IncludeIsMainRegex: "(_test)?$"
IndentCaseLabels: false
IndentWidth: 4
IndentWrappedFunctionNames: false
JavaScriptQuotes: Double
KeepEmptyLinesAtTheStartOfBlocks: false
MaxEmptyLinesToKeep: 2
NamespaceIndentation: None
PenaltyBreakBeforeFirstCallParameter: 8
PenaltyBreakFirstLessLess: 8
PenaltyBreakString: 8
PenaltyExcessCharacter: 1
PenaltyReturnTypeOnItsOwnLine: 16
PointerAlignment: Right
ReflowComments: false
SortIncludes: true
SpaceAfterCStyleCast: true
SpaceBeforeAssignmentOperators: true
SpaceBeforeParens: Always
SpaceInEmptyParentheses: false
SpacesBeforeTrailingComments: 1
SpacesInAngles: false
SpacesInCStyleCastParentheses: false
SpacesInParentheses: false
SpacesInSquareBrackets: false
Standard: Cpp17
UseTab: Never

View File

@ -163,6 +163,7 @@ set(localedir ${CMAKE_INSTALL_FULL_LOCALEDIR})
set(uidir ${CMAKE_INSTALL_FULL_DATADIR}/${PROJECT_NAME}/ui) set(uidir ${CMAKE_INSTALL_FULL_DATADIR}/${PROJECT_NAME}/ui)
set(policiesdir ${CMAKE_INSTALL_FULL_DATADIR}/${PROJECT_NAME}/policies) set(policiesdir ${CMAKE_INSTALL_FULL_DATADIR}/${PROJECT_NAME}/policies)
set(plugindir ${CMAKE_INSTALL_FULL_LIBDIR}/${PROJECT_NAME}/plugins) set(plugindir ${CMAKE_INSTALL_FULL_LIBDIR}/${PROJECT_NAME}/plugins)
set(examplesdir ${CMAKE_INSTALL_FULL_DATADIR}/${PROJECT_NAME}/examples)
configure_file(src/backend/sgpemv2/config.h.in configure_file(src/backend/sgpemv2/config.h.in
src/backend/sgpemv2/config.h src/backend/sgpemv2/config.h
@ -176,7 +177,6 @@ set_target_properties(sgpemv2-backend PROPERTIES
target_include_directories(sgpemv2-backend target_include_directories(sgpemv2-backend
PUBLIC $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/src/backend> PUBLIC $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/src/backend>
$<BUILD_INTERFACE:${CMAKE_CURRENT_BINARY_DIR}/src/backend> $<BUILD_INTERFACE:${CMAKE_CURRENT_BINARY_DIR}/src/backend>
$<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}>
PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/src/backend PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/src/backend
${Intl_INCLUDE_DIRS}) ${Intl_INCLUDE_DIRS})
target_link_libraries(sgpemv2-backend target_link_libraries(sgpemv2-backend
@ -609,6 +609,16 @@ target_sources(sgpemv2
# ------------------------------------------- # -------------------------------------------
install(TARGETS sgpemv2 sgpemv2-backend
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
INCLUDES DESTINATION ${CMAKE_INSTALL_INCLUDEDIR})
install(DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/src/backend/sgpemv2
${CMAKE_CURRENT_BINARY_DIR}/src/backend/sgpemv2
DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}
PATTERN "*.in" EXCLUDE)
install(FILES data/logo.png install(FILES data/logo.png
ui/add-process-dialog.ui ui/add-process-dialog.ui
ui/add-request-dialog.ui ui/add-request-dialog.ui

View File

@ -4,4 +4,5 @@
#define UIDIR "@uidir@" #define UIDIR "@uidir@"
#define POLDIR "@policiesdir@" #define POLDIR "@policiesdir@"
#define PLUGDIR "@plugindir@" #define PLUGDIR "@plugindir@"
#define EXAMPLESDIR "@examplesdir@"

View File

@ -35,8 +35,8 @@ using namespace sgpem;
CairoWidget::CairoWidget() CairoWidget::CairoWidget()
: Glib::ObjectBase("sgpem_CairoWidget"), : Glib::ObjectBase("sgpem_CairoWidget"),
Gtk::Widget(), Gtk::Widget(),
_draw_w(1), _draw_h(1), _draw_w(1), _draw_h(1),
_client_w(0), _client_h(0), _client_w(0), _client_h(0),
_pixbuf_w(0), _pixbuf_h(0), _pixbuf_w(0), _pixbuf_h(0),
_need_redraw(true), _scaling_mode(scaling_none), _need_redraw(true), _scaling_mode(scaling_none),
_buf(NULL) _buf(NULL)
@ -93,9 +93,9 @@ CairoWidget::on_realize()
attributes.wclass = GDK_INPUT_OUTPUT; attributes.wclass = GDK_INPUT_OUTPUT;
attributes.event_mask = get_events() | GDK_EXPOSURE_MASK; attributes.event_mask = get_events() | GDK_EXPOSURE_MASK;
attributes.window_type = GDK_WINDOW_CHILD; attributes.window_type = GDK_WINDOW_CHILD;
_client_w = alloc.get_width(); _client_w = alloc.get_width();
_client_h = alloc.get_height(); _client_h = alloc.get_height();
static const gint attributes_mask = Gdk::WA_X | Gdk::WA_Y; static const gint attributes_mask = Gdk::WA_X | Gdk::WA_Y;
@ -124,7 +124,7 @@ CairoWidget::on_size_allocate(const Gtk::Allocation& allocation)
set_allocation(allocation); set_allocation(allocation);
if (!_ref_gdk_window) return; if (!_ref_gdk_window) return;
_ref_gdk_window->move_resize(allocation.get_x(), allocation.get_y(), _ref_gdk_window->move_resize(allocation.get_x(), allocation.get_y(),
allocation.get_width(), allocation.get_height()); allocation.get_width(), allocation.get_height());
@ -163,8 +163,8 @@ CairoWidget::on_draw (const Cairo::RefPtr<Cairo::Context>& ctx)
if (!_ref_gdk_window) return true; if (!_ref_gdk_window) return true;
// save actual size // save actual size
size_t actual_w = get_width(); auto actual_w = get_width();
size_t actual_h = get_height(); auto actual_h = get_height();
// the widget must be redrawn if // the widget must be redrawn if
// - there's an explicit request(_need_redraw) // - there's an explicit request(_need_redraw)
@ -183,17 +183,17 @@ CairoWidget::on_draw (const Cairo::RefPtr<Cairo::Context>& ctx)
// allocate only if growing, keep if shrinking. // allocate only if growing, keep if shrinking.
// Taking a bigger pixmap saves operations when // Taking a bigger pixmap saves operations when
// many window resizing occours (i.e. mouse resizing). // many window resizing occours (i.e. mouse resizing).
if(_client_w>_pixbuf_w || _client_h>_pixbuf_h) if(_client_w > _pixbuf_w || _client_h > _pixbuf_h)
{ {
// previdence in the code: // previdence in the code:
// allocate more than actually needed // allocate more than actually needed
_pixbuf_w = (size_t) (_client_w*1.2); _pixbuf_w = static_cast<int>(_client_w * 1.2);
_pixbuf_h = (size_t) (_client_h*1.2); _pixbuf_h = static_cast<int>(_client_h * 1.2);
// allocate the pixmap // allocate the pixmap
_buf = Gdk::Pixbuf::create (_ref_gdk_window, 0, 0, _pixbuf_w, _pixbuf_h); _buf = Gdk::Pixbuf::create (_ref_gdk_window, 0, 0, _pixbuf_w, _pixbuf_h);
} }
// Draw the widget background as the first thing. // Draw the widget background as the first thing.
// I've seen this is how it's done in the very Gtk+ toolkit // I've seen this is how it's done in the very Gtk+ toolkit
// for the GtkProgressBar widget. // for the GtkProgressBar widget.
@ -252,22 +252,22 @@ CairoWidget::calc_scale_factors()
switch(_scaling_mode) switch(_scaling_mode)
{ {
case scaling_none: // not necessary! case scaling_none: // not necessary!
// doesn't scale // doesn't scale
_scale_x = _scale_y = 1.0; _scale_x = _scale_y = 1.0;
break; break;
case scaling_to_w: case scaling_to_w:
// scale to fit in width // scale to fit in width
// x and y take the same x value // x and y take the same x value
_scale_y = _scale_x; _scale_y = _scale_x;
break; break;
case scaling_to_h: case scaling_to_h:
// scale to fit in height // scale to fit in height
// x and y take the same y value // x and y take the same y value
_scale_x = _scale_y; _scale_x = _scale_y;
break; break;
case scaling_min: case scaling_min:
// scale to fit always in window // scale to fit always in window
// x and y take the same minimum value // x and y take the same minimum value
@ -276,7 +276,7 @@ CairoWidget::calc_scale_factors()
else else
_scale_x = _scale_y; _scale_x = _scale_y;
break; break;
case scaling_max: case scaling_max:
// scale to fit never in window // scale to fit never in window
// x and y take the same mxiimum value // x and y take the same mxiimum value
@ -285,7 +285,7 @@ CairoWidget::calc_scale_factors()
else else
_scale_x = _scale_y; _scale_x = _scale_y;
break; break;
case scaling_all: case scaling_all:
// scale to fit stretching in window // scale to fit stretching in window
// x and y mantain the differnt calculated values // x and y mantain the differnt calculated values

View File

@ -40,12 +40,12 @@ namespace sgpem
* - implement draw_widget() to draw in the widget client area \see draw_widget() * - implement draw_widget() to draw in the widget client area \see draw_widget()
* - should * - should
* - define calc_drawing_size() to provide correct size calculation * - define calc_drawing_size() to provide correct size calculation
* - call resize_redraw() to calc size and redraw * - call resize_redraw() to calc size and redraw
* - can * - can
* - define calc_widget_size() to get predefined widget dimensions * - define calc_widget_size() to get predefined widget dimensions
* - set the desired scaling mode \see set_scaling_mode() * - set the desired scaling mode \see set_scaling_mode()
* - call redraw() to only redraw the widget * - call redraw() to only redraw the widget
* *
*/ */
class CairoWidget : public Gtk::Widget class CairoWidget : public Gtk::Widget
{ {
@ -82,7 +82,7 @@ namespace sgpem
* NOTE: This scaling mode stretch the drawing and not respect the * NOTE: This scaling mode stretch the drawing and not respect the
* ratio between width and height. * ratio between width and height.
* *
*/ */
enum scaling_mode enum scaling_mode
{ {
scaling_none = 0, // without any scaling scaling_none = 0, // without any scaling
@ -97,7 +97,7 @@ namespace sgpem
* \brief Unique constructor, initialize data members. * \brief Unique constructor, initialize data members.
*/ */
CairoWidget(); CairoWidget();
/** /**
* \brief Widget's destructor. * \brief Widget's destructor.
*/ */
@ -114,7 +114,7 @@ namespace sgpem
* \return Previous scaling mode. * \return Previous scaling mode.
*/ */
scaling_mode set_scaling_mode(scaling_mode scaling_mode); scaling_mode set_scaling_mode(scaling_mode scaling_mode);
/** /**
* \brief Retrieve current scaling mode. * \brief Retrieve current scaling mode.
* *
@ -151,8 +151,8 @@ namespace sgpem
* See gtkmm documentation for more informations. * See gtkmm documentation for more informations.
*/ */
virtual void on_realize(); virtual void on_realize();
virtual void on_unrealize(); // doesn't need to be documented. virtual void on_unrealize(); // doesn't need to be documented.
/** /**
* \brief Implements standard widget's on_size_allocate() mehtod. * \brief Implements standard widget's on_size_allocate() mehtod.
* *
@ -161,7 +161,7 @@ namespace sgpem
* See gtkmm documentation for more informations. * See gtkmm documentation for more informations.
*/ */
virtual void on_size_allocate(const Gtk::Allocation& allocation); virtual void on_size_allocate(const Gtk::Allocation& allocation);
/** /**
* \brief Implements standard widget's on_size_request() mehtod. * \brief Implements standard widget's on_size_request() mehtod.
* *
@ -170,7 +170,7 @@ namespace sgpem
* See gtkmm documentation for more informations. * See gtkmm documentation for more informations.
*/ */
virtual void on_size_request(Gtk::Requisition* request); virtual void on_size_request(Gtk::Requisition* request);
/** /**
* \brief Implements standard widget's on_expose_event() mehtod. * \brief Implements standard widget's on_expose_event() mehtod.
* *
@ -206,7 +206,7 @@ namespace sgpem
* The user can implement this method to give default dimensions. * The user can implement this method to give default dimensions.
* It isn't necessary because scaling (and resizing) take care of calc_drawing_size() results. * It isn't necessary because scaling (and resizing) take care of calc_drawing_size() results.
*/ */
virtual void calc_widget_size(size_t& width, size_t& height); virtual void calc_widget_size(int& width, int& height);
/** /**
* \brief Calculate scaling factors to apply during widget's redrawing. * \brief Calculate scaling factors to apply during widget's redrawing.
@ -230,22 +230,22 @@ namespace sgpem
/** /**
* \brief Client area width of widget. * \brief Client area width of widget.
*/ */
size_t _client_w; int _client_w;
/** /**
* \brief Client area height of widget. * \brief Client area height of widget.
*/ */
size_t _client_h; int _client_h;
/** /**
* \brief Client area width of pixmap. * \brief Client area width of pixmap.
*/ */
size_t _pixbuf_w; int _pixbuf_w;
/** /**
* \brief Client area width of pixmap. * \brief Client area width of pixmap.
*/ */
size_t _pixbuf_h; int _pixbuf_h;
/** /**
* \brief Cairo x scale factor. * \brief Cairo x scale factor.

View File

@ -21,6 +21,7 @@
#ifndef GRAPHICAL_PREFERENCES_EDITOR_HH #ifndef GRAPHICAL_PREFERENCES_EDITOR_HH
#define GRAPHICAL_PREFERENCES_EDITOR_HH 1 #define GRAPHICAL_PREFERENCES_EDITOR_HH 1
#include "sgpemv2/config.h"
#include "sgpemv2/global_preferences.hh" #include "sgpemv2/global_preferences.hh"
#include <gtkmm/builder.h> #include <gtkmm/builder.h>
@ -34,61 +35,61 @@
namespace sgpem namespace sgpem
{ {
class PreferencesEditor class PreferencesEditor
{ {
public: public:
explicit PreferencesEditor(const std::string& uifile = UIDIR "/configure-dialog.ui"); explicit PreferencesEditor(const std::string& uifile = UIDIR "/configure-dialog.ui");
void void
on_close(); on_close();
void void
on_add_plugins_dir(); on_add_plugins_dir();
void void
on_remove_plugins_dir(); on_remove_plugins_dir();
void void
on_add_policies_dir(); on_add_policies_dir();
void void
on_remove_policies_dir(); on_remove_policies_dir();
void void
on_set_speed(); on_set_speed();
~PreferencesEditor(); ~PreferencesEditor();
private: private:
void void
update_policies(); update_policies();
void void
update_plugins(); update_plugins();
Glib::RefPtr<Gtk::Builder> _refXml; Glib::RefPtr<Gtk::Builder> _refXml;
Gtk::Dialog* preferences_dialog; Gtk::Dialog* preferences_dialog;
Gtk::TreeView* plugins_dirs_treeview; Gtk::TreeView* plugins_dirs_treeview;
Glib::RefPtr<Gtk::ListStore> plugins_dirs_model; Glib::RefPtr<Gtk::ListStore> plugins_dirs_model;
Gtk::TreeView* plugins_treeview; Gtk::TreeView* plugins_treeview;
Glib::RefPtr<Gtk::ListStore> plugins_model; Glib::RefPtr<Gtk::ListStore> plugins_model;
Gtk::TreeView* policies_dirs_treeview; Gtk::TreeView* policies_dirs_treeview;
Glib::RefPtr<Gtk::ListStore> policies_dirs_model; Glib::RefPtr<Gtk::ListStore> policies_dirs_model;
Gtk::TreeView* policies_treeview; Gtk::TreeView* policies_treeview;
Glib::RefPtr<Gtk::ListStore> policies_model; Glib::RefPtr<Gtk::ListStore> policies_model;
Gtk::SpinButton* speed_spin; Gtk::SpinButton* speed_spin;
}; };
} // ~ namespace } // ~ namespace

View File

@ -76,7 +76,7 @@ using namespace sgpem;
void void
GuiBuilder::on_edit_preferences_activate() GuiBuilder::on_edit_preferences_activate()
{ {
PreferencesEditor(); // Will run the dialog inside the constructor. PreferencesEditor(); // Will run the dialog inside the constructor.
} }
void void
@ -140,11 +140,11 @@ void
GuiBuilder::on_file_new_activate() GuiBuilder::on_file_new_activate()
{ {
Simulation& sim = Simulation::get_instance(); Simulation& sim = Simulation::get_instance();
History& history = sim.get_history(); History& history = sim.get_history();
ask_save(); ask_save();
sim.stop(); sim.stop();
history.clear(); history.clear();
set_filename(); set_filename();
} }
@ -156,7 +156,7 @@ GuiBuilder::on_file_open_activate()
if (!_filename.empty()) // Please test the following line extensively: if (!_filename.empty()) // Please test the following line extensively:
open_file (Glib::path_get_dirname(_filename)); open_file (Glib::path_get_dirname(_filename));
else else
open_file (); open_file ();
} }
@ -189,7 +189,7 @@ GuiBuilder::open_file(const std::string& basedir)
Gtk::FileChooserDialog dialog(_("Please choose a file"), Gtk::FILE_CHOOSER_ACTION_OPEN); Gtk::FileChooserDialog dialog(_("Please choose a file"), Gtk::FILE_CHOOSER_ACTION_OPEN);
dialog.set_transient_for(get_initial_window()); dialog.set_transient_for(get_initial_window());
dialog.set_current_folder (basedir); dialog.set_current_folder (basedir);
//Add response buttons the the dialog: //Add response buttons the the dialog:
dialog.add_button(Gtk::Stock::CANCEL, Gtk::RESPONSE_CANCEL); dialog.add_button(Gtk::Stock::CANCEL, Gtk::RESPONSE_CANCEL);
dialog.add_button(Gtk::Stock::OPEN, Gtk::RESPONSE_OK); dialog.add_button(Gtk::Stock::OPEN, Gtk::RESPONSE_OK);
@ -221,7 +221,7 @@ GuiBuilder::open_file(const std::string& basedir)
} // end - if(result==Gtk::RESPONSE_OK) } // end - if(result==Gtk::RESPONSE_OK)
} }
catch (std::out_of_range e) catch (std::out_of_range& e)
{ {
Gtk::MessageDialog error(get_initial_window(), Gtk::MessageDialog error(get_initial_window(),
_("<b>No serializer available.</b>\nThere's no " _("<b>No serializer available.</b>\nThere's no "
@ -230,10 +230,10 @@ GuiBuilder::open_file(const std::string& basedir)
error.run(); error.run();
msg = _("ERROR: No registered serializer available"); msg = _("ERROR: No registered serializer available");
} }
catch (SerializerError e) catch (SerializerError& e)
{ {
Gtk::MessageDialog error(get_initial_window(), e.what(), true, Gtk::MESSAGE_ERROR, Gtk::BUTTONS_OK, true); Gtk::MessageDialog error(get_initial_window(), e.what(), true, Gtk::MESSAGE_ERROR, Gtk::BUTTONS_OK, true);
error.run(); error.run();
msg = _("ERROR: ") + Glib::ustring(e.what()); msg = _("ERROR: ") + Glib::ustring(e.what());
set_filename(); set_filename();
} }
@ -243,7 +243,7 @@ GuiBuilder::open_file(const std::string& basedir)
_refXml->get_widget("MainStatusBar", sbar); _refXml->get_widget("MainStatusBar", sbar);
sbar->push(msg); sbar->push(msg);
} }
} }
void void
@ -262,17 +262,17 @@ GuiBuilder::on_file_save_activate()
{ {
std::vector<Serializer*> serializers = std::vector<Serializer*> serializers =
SerializersGatekeeper::get_instance().get_registered(); SerializersGatekeeper::get_instance().get_registered();
// FIXME using the first serializer available, this // FIXME using the first serializer available, this
// will need to be changed when multiple serializers will // will need to be changed when multiple serializers will
// be made available // be made available
Serializer& serializer = *serializers.at(0); Serializer& serializer = *serializers.at(0);
History& history = Simulation::get_instance().get_history(); History& history = Simulation::get_instance().get_history();
serializer.save_snapshot(_filename, history); serializer.save_snapshot(_filename, history);
msg = _("File: ") + _filename + _(" saved."); msg = _("File: ") + _filename + _(" saved.");
} }
catch (std::out_of_range e) catch (std::out_of_range& e)
{ {
Gtk::MessageDialog error(get_initial_window(), Gtk::MessageDialog error(get_initial_window(),
_("<b>No serializer available.</b>\nThere's no registered serializer. Please check the loaded plugins."), _("<b>No serializer available.</b>\nThere's no registered serializer. Please check the loaded plugins."),
@ -280,13 +280,13 @@ GuiBuilder::on_file_save_activate()
error.run(); error.run();
msg = _("ERROR: No registered serializer available"); msg = _("ERROR: No registered serializer available");
} }
catch (SerializerError e) catch (SerializerError& e)
{ {
Gtk::MessageDialog error(get_initial_window(), e.what(), true, Gtk::MESSAGE_ERROR, Gtk::BUTTONS_OK, true); Gtk::MessageDialog error(get_initial_window(), e.what(), true, Gtk::MESSAGE_ERROR, Gtk::BUTTONS_OK, true);
error.run(); error.run();
msg = _("ERROR: ") + Glib::ustring(e.what()); msg = _("ERROR: ") + Glib::ustring(e.what());
} }
if(!msg.empty()) if(!msg.empty())
{ {
Gtk::Statusbar* sbar; Gtk::Statusbar* sbar;
@ -324,12 +324,12 @@ GuiBuilder::on_file_saveas_activate()
filter_sgpem.set_name(serializer.get_filename_description()); filter_sgpem.set_name(serializer.get_filename_description());
filter_sgpem.add_pattern(Glib::ustring("*.") + serializer.get_filename_extension()); filter_sgpem.add_pattern(Glib::ustring("*.") + serializer.get_filename_extension());
dialog.add_filter(filter_sgpem); dialog.add_filter(filter_sgpem);
Gtk::FileFilter filter_any; Gtk::FileFilter filter_any;
filter_any.set_name(_("Any files")); filter_any.set_name(_("Any files"));
filter_any.add_pattern("*"); filter_any.add_pattern("*");
dialog.add_filter(filter_any); dialog.add_filter(filter_any);
//Show the dialog and wait for a user response: //Show the dialog and wait for a user response:
int result = dialog.run(); int result = dialog.run();
if(result==Gtk::RESPONSE_OK) if(result==Gtk::RESPONSE_OK)
@ -349,7 +349,7 @@ GuiBuilder::on_file_saveas_activate()
} // end - if(result==Gtk::RESPONSE_OK) } // end - if(result==Gtk::RESPONSE_OK)
} }
catch (std::out_of_range e) catch (std::out_of_range& e)
{ {
Gtk::MessageDialog error(get_initial_window(), Gtk::MessageDialog error(get_initial_window(),
_("<b>No serializer available.</b>\nThere's no registered serializer. Please check the loaded plugins."), _("<b>No serializer available.</b>\nThere's no registered serializer. Please check the loaded plugins."),
@ -357,14 +357,14 @@ GuiBuilder::on_file_saveas_activate()
error.run(); error.run();
msg = _("ERROR: No registered serializer available"); msg = _("ERROR: No registered serializer available");
} }
catch (SerializerError e) catch (SerializerError& e)
{ {
Gtk::MessageDialog error(get_initial_window(), e.what(), true, Gtk::MESSAGE_ERROR, Gtk::BUTTONS_OK, true); Gtk::MessageDialog error(get_initial_window(), e.what(), true, Gtk::MESSAGE_ERROR, Gtk::BUTTONS_OK, true);
error.run(); error.run();
msg = _("ERROR: ") + Glib::ustring(e.what()); msg = _("ERROR: ") + Glib::ustring(e.what());
set_filename(); set_filename();
} }
if(!msg.empty()) if(!msg.empty())
{ {
Gtk::Statusbar* sbar; Gtk::Statusbar* sbar;
@ -389,9 +389,9 @@ GuiBuilder::on_configure_cpu_policy()
true, MESSAGE_WARNING, BUTTONS_OK, true); true, MESSAGE_WARNING, BUTTONS_OK, true);
warn.run(); warn.run();
} }
PolicyParameters& params = policy->get_parameters(); PolicyParameters& params = policy->get_parameters();
ConfigurePolicyDialog config_dialog(_("Configuring CPU Policy ") + policy->get_name(), ConfigurePolicyDialog config_dialog(_("Configuring CPU Policy ") + policy->get_name(),
get_initial_window(), policy->get_description(), params); get_initial_window(), policy->get_description(), params);
if(config_dialog.run() == RESPONSE_OK) if(config_dialog.run() == RESPONSE_OK)
@ -420,14 +420,14 @@ GuiBuilder::on_configure_resource_policy()
} }
PolicyParameters& params = policy->get_parameters(); PolicyParameters& params = policy->get_parameters();
ConfigurePolicyDialog config_dialog(_("Configuring CPU Policy ") + policy->get_name(), ConfigurePolicyDialog config_dialog(_("Configuring CPU Policy ") + policy->get_name(),
get_initial_window(), policy->get_description(), params); get_initial_window(), policy->get_description(), params);
if(config_dialog.run() == RESPONSE_OK) if(config_dialog.run() == RESPONSE_OK)
{ {
sim.stop(); sim.stop();
sim.get_history().reset(); sim.get_history().reset();
} }
} }
@ -437,7 +437,7 @@ GuiBuilder::populate_with_cpu_policies(Gtk::Menu& menu)
using namespace Gtk; using namespace Gtk;
// NOTE: Please note that this code relies on the fact that a given // NOTE: Please note that this code relies on the fact that a given
// policy never "disappears" at runtime. A *GatekeeperObserver should // policy never "disappears" at runtime. A *GatekeeperObserver should
// be needed to avoid dangling pointers if this behaviour changes. // be needed to avoid dangling pointers if this behaviour changes.
typedef std::vector<CPUPolicyManager*> Managers; typedef std::vector<CPUPolicyManager*> Managers;
@ -490,8 +490,8 @@ GuiBuilder::on_selected_cpu_policy(CPUPolicy* pol)
Glib::ustring(_("<b>Impossible to select this CPU Policy.</b>\n")) + e.what(), Glib::ustring(_("<b>Impossible to select this CPU Policy.</b>\n")) + e.what(),
true, MESSAGE_ERROR, BUTTONS_OK, true); true, MESSAGE_ERROR, BUTTONS_OK, true);
error.run(); error.run();
} }
// If we got here, no policy is selected. // If we got here, no policy is selected.
sbar->push(_("No CPU policy selected. Please select one.")); sbar->push(_("No CPU policy selected. Please select one."));
} }
@ -503,7 +503,7 @@ GuiBuilder::populate_with_resource_policies(Gtk::Menu& menu)
using namespace Gtk; using namespace Gtk;
// NOTE: Please note that this code relies on the fact that a given // NOTE: Please note that this code relies on the fact that a given
// policy never "disappears" at runtime. A *GatekeeperObserver should // policy never "disappears" at runtime. A *GatekeeperObserver should
// be needed to avoid dangling pointers if this behaviour changes. // be needed to avoid dangling pointers if this behaviour changes.
typedef std::vector<ResourcePolicyManager*> Managers; typedef std::vector<ResourcePolicyManager*> Managers;
@ -552,14 +552,14 @@ GuiBuilder::on_toggle_simulation_mode()
{ {
using namespace Gtk; using namespace Gtk;
using Glib::RefPtr; using Glib::RefPtr;
RefPtr<UIManager> uimanager = RefPtr<UIManager>::cast_dynamic (_refXml->get_object("UIManager")); RefPtr<UIManager> uimanager = RefPtr<UIManager>::cast_dynamic (_refXml->get_object("UIManager"));
CheckMenuItem* continuous_mode = nullptr; CheckMenuItem* continuous_mode = nullptr;
continuous_mode = dynamic_cast<CheckMenuItem*>(uimanager->get_widget continuous_mode = dynamic_cast<CheckMenuItem*>(uimanager->get_widget
("/MenuBar/Action.Simulation/Action.Simulation.ContinuousMode")); ("/MenuBar/Action.Simulation/Action.Simulation.ContinuousMode"));
g_assert (continuous_mode != nullptr); g_assert (continuous_mode != nullptr);
if(continuous_mode->get_active() == true) if(continuous_mode->get_active() == true)
Simulation::get_instance().set_mode(Simulation::mode_continuous); Simulation::get_instance().set_mode(Simulation::mode_continuous);
else else
@ -567,12 +567,12 @@ GuiBuilder::on_toggle_simulation_mode()
} }
void void
GuiBuilder::ask_save() GuiBuilder::ask_save()
{ {
History& history = Simulation::get_instance().get_history(); History& history = Simulation::get_instance().get_history();
const Environment& env = history.get_environment_at(0); const Environment& env = history.get_environment_at(0);
if(!(_filename.empty() && env.get_processes().empty() && env.get_resources().empty())) if(!(_filename.empty() && env.get_processes().empty() && env.get_resources().empty()))
{ {
Gtk::MessageDialog want_to_save(get_initial_window(), Gtk::MessageDialog want_to_save(get_initial_window(),
@ -637,7 +637,7 @@ GuiBuilder::GuiBuilder(const std::string& uifile)
file_quit->signal_activate().connect(sigc::mem_fun(*this, &GuiBuilder::ask_save)); file_quit->signal_activate().connect(sigc::mem_fun(*this, &GuiBuilder::ask_save));
file_quit->signal_activate().connect(sigc::ptr_fun(&Main::quit)); file_quit->signal_activate().connect(sigc::ptr_fun(&Main::quit));
// preferences dialog // preferences dialog
RefPtr<Action>::cast_dynamic (_refXml->get_object("Action.Edit.Preferences")) RefPtr<Action>::cast_dynamic (_refXml->get_object("Action.Edit.Preferences"))
->signal_activate().connect(sigc::mem_fun(*this, &GuiBuilder::on_edit_preferences_activate)); ->signal_activate().connect(sigc::mem_fun(*this, &GuiBuilder::on_edit_preferences_activate));
@ -678,7 +678,7 @@ GuiBuilder::GuiBuilder(const std::string& uifile)
cpu_policies_tb_menu->signal_clicked().connect(sigc::mem_fun(*this, &GuiBuilder::on_configure_cpu_policy)); cpu_policies_tb_menu->signal_clicked().connect(sigc::mem_fun(*this, &GuiBuilder::on_configure_cpu_policy));
cpu_policies_tb_menu->set_menu(*manage(new Menu())); cpu_policies_tb_menu->set_menu(*manage(new Menu()));
populate_with_cpu_policies(*cpu_policies_tb_menu->get_menu()); populate_with_cpu_policies(*cpu_policies_tb_menu->get_menu());
// Configure Resource Policy // Configure Resource Policy
MenuToolButton* res_policies_tb_menu; MenuToolButton* res_policies_tb_menu;
_refXml->get_widget("ToolBar.ResourceScheduling", res_policies_tb_menu); _refXml->get_widget("ToolBar.ResourceScheduling", res_policies_tb_menu);
@ -711,7 +711,7 @@ GuiBuilder::GuiBuilder(const std::string& uifile)
resources_widget->show(); resources_widget->show();
// Main simulation widget // Main simulation widget
ScrolledWindow* simulation_window = nullptr; ScrolledWindow* simulation_window = nullptr;
_refXml->get_widget("SimulationScrolledWindow", simulation_window); _refXml->get_widget("SimulationScrolledWindow", simulation_window);
//SimulationWidget& simulation_widget = *manage(new SimulationWidget(Simulation::get_instance())); //SimulationWidget& simulation_widget = *manage(new SimulationWidget(Simulation::get_instance()));
@ -719,11 +719,11 @@ GuiBuilder::GuiBuilder(const std::string& uifile)
simulation_window->add(*_simulation_widget); simulation_window->add(*_simulation_widget);
_simulation_widget->set_show_threads(_show_threads); _simulation_widget->set_show_threads(_show_threads);
_simulation_widget->show(); _simulation_widget->show();
// ReadyQueue custom label widget // ReadyQueue custom label widget
ReadyQueueWidget& rq_widget = *manage(new ReadyQueueWidget(Simulation::get_instance().get_history())); ReadyQueueWidget& rq_widget = *manage(new ReadyQueueWidget(Simulation::get_instance().get_history()));
HBox* bottomhbox; HBox* bottomhbox;
_refXml->get_widget("BottomHBox", bottomhbox); _refXml->get_widget("BottomHBox", bottomhbox);
bottomhbox->pack_start(rq_widget); bottomhbox->pack_start(rq_widget);
rq_widget.show(); rq_widget.show();
@ -733,12 +733,12 @@ GuiBuilder::GuiBuilder(const std::string& uifile)
Button* simulation_jump_to = nullptr; Button* simulation_jump_to = nullptr;
_refXml->get_widget("BottomHBox.JumpToButton", simulation_jump_to); _refXml->get_widget("BottomHBox.JumpToButton", simulation_jump_to);
simulation_jump_to->signal_clicked().connect(sigc::mem_fun(*this, &GuiBuilder::on_simulation_jump_to_clicked)); simulation_jump_to->signal_clicked().connect(sigc::mem_fun(*this, &GuiBuilder::on_simulation_jump_to_clicked));
// HoltGraph container window
// HoltGraph container window
_holt_container.set_transient_for(main_window); _holt_container.set_transient_for(main_window);
_holt_container.get_holt_widget().set_show_threads(_show_threads); _holt_container.get_holt_widget().set_show_threads(_show_threads);
_statistics_container.get_main_window()->set_transient_for(main_window); _statistics_container.get_main_window()->set_transient_for(main_window);
} }
@ -747,7 +747,7 @@ GuiBuilder::~GuiBuilder()
{} {}
// TODO: return a RefPtr instead of a reference, because // TODO: return a RefPtr instead of a reference, because
// GtkBuilder (unalike Glade) requires explicit deallocation of // GtkBuilder (unalike Glade) requires explicit deallocation of
// the toplevel window widgets upon release. // the toplevel window widgets upon release.
Gtk::Window& Gtk::Window&

View File

@ -26,6 +26,7 @@
#include "statistics_container_window.hh" #include "statistics_container_window.hh"
#include "simulation_widget.hh" #include "simulation_widget.hh"
#include "sgpemv2/config.h"
#include "sgpemv2/cpu_policy.hh" #include "sgpemv2/cpu_policy.hh"
#include "sgpemv2/resource_policy.hh" #include "sgpemv2/resource_policy.hh"
@ -50,21 +51,21 @@ namespace sgpem
~GuiBuilder(); ~GuiBuilder();
Gtk::Window& get_initial_window() const; Gtk::Window& get_initial_window() const;
void on_file_new_activate(); void on_file_new_activate();
void on_file_open_activate(); void on_file_open_activate();
void on_file_open_example_activate(); void on_file_open_example_activate();
void on_file_save_activate(); void on_file_save_activate();
void on_file_saveas_activate(); void on_file_saveas_activate();
void on_edit_preferences_activate(); void on_edit_preferences_activate();
void on_simulation_jump_to_clicked(); void on_simulation_jump_to_clicked();
void on_view_show_threads_activate(); void on_view_show_threads_activate();
void on_view_show_holt_graph_activate(); void on_view_show_holt_graph_activate();
void on_view_show_statistics_activate(); void on_view_show_statistics_activate();
void on_configure_cpu_policy(); void on_configure_cpu_policy();
void on_configure_resource_policy(); void on_configure_resource_policy();
void on_selected_cpu_policy(CPUPolicy* pol); void on_selected_cpu_policy(CPUPolicy* pol);

View File

@ -101,15 +101,15 @@ parse_options(int argc, char** argv)
// Parse options, initialising the Gtk at the same time // Parse options, initialising the Gtk at the same time
gboolean gui_initializable = gtk_init_check(&argc, &argv); gboolean gui_initializable = gtk_init_check(&argc, &argv);
context.parse(argc, argv); context.parse(argc, argv);
GlobalPreferences& prefs = GlobalPreferences::get_instance(); GlobalPreferences& prefs = GlobalPreferences::get_instance();
try try
{ {
prefs.load_configrc(); prefs.load_configrc();
} }
catch (std::exception e) catch (std::exception& e)
{ {
std::cout << std::endl std::cout << std::endl
<< _("Error while loading preferences") << std::endl; << _("Error while loading preferences") << std::endl;
} }
@ -139,9 +139,9 @@ parse_options(int argc, char** argv)
TextSimulation sim; TextSimulation sim;
std::string str; std::string str;
std::cout << std::endl std::cout << std::endl
<< _(" [II] To see a list of commands available,\n" << _(" [II] To see a list of commands available,\n"
" [II] please type \"help\" and hit the ENTER key.") " [II] please type \"help\" and hit the ENTER key.")
<< std::endl; << std::endl;
std::cout << std::endl << "% "; std::cout << std::endl << "% ";
@ -163,10 +163,10 @@ parse_options(int argc, char** argv)
} }
} // ~ try } // ~ try
catch (Glib::OptionError e) catch (Glib::OptionError& e)
{ {
std::cout << Glib::ustring::compose (_("Bad invocation: %1\nUse the `-?' " std::cout << Glib::ustring::compose (_("Bad invocation: %1\nUse the `-?' "
"or `--help' option to see the help."), "or `--help' option to see the help."),
e.what()) << std::endl; e.what()) << std::endl;
} }
} }

View File

@ -20,6 +20,8 @@
#include "resources_widget.hh" #include "resources_widget.hh"
#include "sgpemv2/config.h"
#include <sgpemv2/templates/sequences.tcc> #include <sgpemv2/templates/sequences.tcc>
#include <sgpemv2/history.hh> #include <sgpemv2/history.hh>
@ -52,14 +54,14 @@ ResourcesWidget::CellRendererTextMarkup::_property_renderable()
} }
ResourcesWidget::ResourcesWidget(BaseObjectType* cobject, const RefPtr<Builder>&) : ResourcesWidget::ResourcesWidget(BaseObjectType* cobject, const RefPtr<Builder>&) :
TreeView(cobject), TreeView(cobject),
_add_resource_dialog_ui(Builder::create_from_file(UIDIR "/add-resource-dialog.ui")) _add_resource_dialog_ui(Builder::create_from_file(UIDIR "/add-resource-dialog.ui"))
{ {
_columns.add(_key_column); _columns.add(_key_column);
_columns.add(_main_column); _columns.add(_main_column);
_columns.add(_handles_column); _columns.add(_handles_column);
_model = ListStore::create(_columns); _model = ListStore::create(_columns);
set_model(_model); set_model(_model);
int idx = append_column(_("resources"), _cell_renderer) - 1; int idx = append_column(_("resources"), _cell_renderer) - 1;
@ -68,7 +70,7 @@ ResourcesWidget::ResourcesWidget(BaseObjectType* cobject, const RefPtr<Builder>&
/** DIALOGS **/ /** DIALOGS **/
_add_resource_dialog_ui->get_widget("AddResourceDialog", _add_resource_dialog); _add_resource_dialog_ui->get_widget("AddResourceDialog", _add_resource_dialog);
set_headers_visible(false); set_headers_visible(false);
Simulation::get_instance().get_history().attach(*this); Simulation::get_instance().get_history().attach(*this);
@ -107,42 +109,42 @@ ResourcesWidget::get_selected_resource()
return nullptr; return nullptr;
} }
bool bool
ResourcesWidget::on_button_press_event(GdkEventButton* event) ResourcesWidget::on_button_press_event(GdkEventButton* event)
{ {
TreeView::on_button_press_event(event); TreeView::on_button_press_event(event);
if((Simulation::get_instance().get_state() == Simulation::state_stopped) && if((Simulation::get_instance().get_state() == Simulation::state_stopped) &&
(event->type == GDK_BUTTON_PRESS) && (event->button == 3) ) (event->type == GDK_BUTTON_PRESS) && (event->button == 3) )
{ {
RefPtr<ActionGroup> action_group = Gtk::ActionGroup::create(); RefPtr<ActionGroup> action_group = Gtk::ActionGroup::create();
action_group->add( Gtk::Action::create("AddResource", "Add Resource"), action_group->add( Gtk::Action::create("AddResource", "Add Resource"),
sigc::mem_fun(*this, &ResourcesWidget::_on_add_resource) ); sigc::mem_fun(*this, &ResourcesWidget::_on_add_resource) );
action_group->add( Gtk::Action::create("EditResource", "Edit Resource"), action_group->add( Gtk::Action::create("EditResource", "Edit Resource"),
sigc::mem_fun(*this, &ResourcesWidget::_on_edit_resource) ); sigc::mem_fun(*this, &ResourcesWidget::_on_edit_resource) );
action_group->add( Gtk::Action::create("RemoveResource", "Remove Resource"), action_group->add( Gtk::Action::create("RemoveResource", "Remove Resource"),
sigc::mem_fun(*this, &ResourcesWidget::_on_remove_resource) ); sigc::mem_fun(*this, &ResourcesWidget::_on_remove_resource) );
RefPtr<UIManager> UIManager = Gtk::UIManager::create(); RefPtr<UIManager> UIManager = Gtk::UIManager::create();
UIManager->insert_action_group(action_group); UIManager->insert_action_group(action_group);
Glib::ustring ui_info = Glib::ustring ui_info =
"<ui>" "<ui>"
" <popup name='PopupMenu'>" " <popup name='PopupMenu'>"
" <menuitem action='AddResource'/>"; " <menuitem action='AddResource'/>";
if(get_selected_resource() != nullptr) if(get_selected_resource() != nullptr)
ui_info += ui_info +=
" <separator/>" " <separator/>"
" <menuitem action='EditResource'/>" " <menuitem action='EditResource'/>"
" <separator/>" " <separator/>"
" <menuitem action='RemoveResource'/>"; " <menuitem action='RemoveResource'/>";
ui_info += ui_info +=
" </popup>" " </popup>"
"</ui>"; "</ui>";
UIManager->add_ui_from_string(ui_info); UIManager->add_ui_from_string(ui_info);
Gtk::Menu* menu = dynamic_cast<Gtk::Menu*>(UIManager->get_widget("/PopupMenu")); Gtk::Menu* menu = dynamic_cast<Gtk::Menu*>(UIManager->get_widget("/PopupMenu"));
@ -161,7 +163,7 @@ ResourcesWidget::update(const History& history)
const Environment::Resources& resources = history.get_last_environment().get_resources(); const Environment::Resources& resources = history.get_last_environment().get_resources();
_model->clear(); _model->clear();
for(Iseq<ResourceIt> it = iseq(resources); it; ++it) for(Iseq<ResourceIt> it = iseq(resources); it; ++it)
{ {
Resource& r = *(it->second); Resource& r = *(it->second);
@ -193,7 +195,7 @@ ResourcesWidget::add_edit_resource(bool adding)
SpinButton* places_spin; SpinButton* places_spin;
Resource* resource = nullptr; Resource* resource = nullptr;
_add_resource_dialog_ui->get_widget("Name.Entry", name_entry); _add_resource_dialog_ui->get_widget("Name.Entry", name_entry);
_add_resource_dialog_ui->get_widget("Places.Spin", places_spin); _add_resource_dialog_ui->get_widget("Places.Spin", places_spin);
@ -205,19 +207,19 @@ ResourcesWidget::add_edit_resource(bool adding)
else else
{ {
resource = get_selected_resource(); resource = get_selected_resource();
name_entry->set_text(resource->get_name()); name_entry->set_text(resource->get_name());
places_spin->set_value(static_cast<double>(resource->get_places())); places_spin->set_value(static_cast<double>(resource->get_places()));
} }
if(_add_resource_dialog->run() == RESPONSE_OK) if(_add_resource_dialog->run() == RESPONSE_OK)
{ {
if(adding) if(adding)
{ {
Simulation::get_instance().get_history().add_resource(name_entry->get_text(), Simulation::get_instance().get_history().add_resource(name_entry->get_text(),
false, false,
places_spin->get_value_as_int()); places_spin->get_value_as_int());
} }
else else
{ {
@ -227,19 +229,19 @@ ResourcesWidget::add_edit_resource(bool adding)
places_spin->get_value_as_int()); places_spin->get_value_as_int());
} }
} }
_add_resource_dialog->hide(); _add_resource_dialog->hide();
} }
void void
ResourcesWidget::_on_remove_resource() ResourcesWidget::_on_remove_resource()
{ {
unsigned int selection; unsigned int selection;
if(get_selected_key(selection)) if(get_selected_key(selection))
Simulation::get_instance().get_history().remove(selection); Simulation::get_instance().get_history().remove(selection);
/** Delete empty requests, they are useless with the current GUI **/ /** Delete empty requests, they are useless with the current GUI **/
typedef Environment::Processes::const_iterator ProcessIt; typedef Environment::Processes::const_iterator ProcessIt;
using std::vector; using std::vector;
@ -247,7 +249,7 @@ ResourcesWidget::_on_remove_resource()
const Environment::Processes& processes = env.get_processes(); const Environment::Processes& processes = env.get_processes();
std::stack<Request*> to_delete; std::stack<Request*> to_delete;
for(ProcessIt pit = processes.begin(); pit != processes.end(); ++pit) for(ProcessIt pit = processes.begin(); pit != processes.end(); ++pit)
{ {
vector<Thread*> threads = (*pit)->get_threads(); vector<Thread*> threads = (*pit)->get_threads();
@ -258,8 +260,8 @@ ResourcesWidget::_on_remove_resource()
for(vector<Request*>::iterator rit = requests.begin(); rit != requests.end(); ++rit) for(vector<Request*>::iterator rit = requests.begin(); rit != requests.end(); ++rit)
{ {
if((*rit)->get_subrequests().empty()) if((*rit)->get_subrequests().empty())
to_delete.push(*rit); to_delete.push(*rit);
} }
} }
} }
@ -271,8 +273,8 @@ ResourcesWidget::_on_remove_resource()
} }
} }
void void
ResourcesWidget::_on_cell_name_data(Gtk::CellRenderer* cr, ResourcesWidget::_on_cell_name_data(Gtk::CellRenderer* cr,
const Gtk::TreeModel::iterator& it) const Gtk::TreeModel::iterator& it)
{ {
CellRendererTextMarkup& crtm = static_cast<CellRendererTextMarkup&>(*cr); CellRendererTextMarkup& crtm = static_cast<CellRendererTextMarkup&>(*cr);
@ -283,28 +285,28 @@ ResourcesWidget::_on_cell_name_data(Gtk::CellRenderer* cr,
const void* r_handle = (*it)[_handles_column]; const void* r_handle = (*it)[_handles_column];
Resource& resource = *reinterpret_cast<Resource*>(const_cast<void*>(r_handle)); Resource& resource = *reinterpret_cast<Resource*>(const_cast<void*>(r_handle));
std::ostringstream oss; std::ostringstream oss;
const Environment::SubRequestQueue& queue = env.get_request_queue(key); const Environment::SubRequestQueue& queue = env.get_request_queue(key);
oss << "<span size=\"8500\"><b>" << Markup::escape_text(resource.get_name()) oss << "<span size=\"8500\"><b>" << Markup::escape_text(resource.get_name())
<< "</b>"; << "</b>";
oss << " (" << queue.size() << "/" << resource.get_places() << ")\n"; oss << " (" << queue.size() << "/" << resource.get_places() << ")\n";
for(Iseq<Environment::SubRequestQueue::const_iterator> it = iseq(queue); it; ++it) for(Iseq<Environment::SubRequestQueue::const_iterator> it = iseq(queue); it; ++it)
{ {
SubRequest& sr = *(*it); SubRequest& sr = *(*it);
oss << "<b><span foreground=\"" oss << "<b><span foreground=\""
<< GlobalPreferences::get_instance().get_request_color(sr.get_state()) << GlobalPreferences::get_instance().get_request_color(sr.get_state())
<< "\"> " << sr.get_request().get_thread().get_name() << "\"> " << sr.get_request().get_thread().get_name()
<< "</span></b>" << " (" << "</span></b>" << " ("
<< (sr.get_length() - sr.get_remaining_time()) << (sr.get_length() - sr.get_remaining_time())
<< "/" << sr.get_length() << ")"; << "/" << sr.get_length() << ")";
} }
oss << "</span>"; oss << "</span>";
crtm.property_markup() = oss.str(); crtm.property_markup() = oss.str();

View File

@ -20,6 +20,7 @@
#include "gettext.h" #include "gettext.h"
#include "sgpemv2/config.h"
#include "schedulables_tree_widget.hh" #include "schedulables_tree_widget.hh"
#include <sgpemv2/history.hh> #include <sgpemv2/history.hh>
#include <sgpemv2/simulation.hh> #include <sgpemv2/simulation.hh>
@ -52,15 +53,15 @@ SchedulablesTreeWidget::CellRendererTextMarkup::_property_renderable()
return Glib::PropertyProxy_Base(this, "markup"); return Glib::PropertyProxy_Base(this, "markup");
} }
SchedulablesTreeWidget::SchedulablesTreeWidget() SchedulablesTreeWidget::SchedulablesTreeWidget()
{ {
_columns.add(_main_column); _columns.add(_main_column);
_columns.add(_types_column); _columns.add(_types_column);
_columns.add(_handles_column); _columns.add(_handles_column);
_model = TreeStore::create(_columns); _model = TreeStore::create(_columns);
set_model(_model); set_model(_model);
int idx = append_column(_("Arrival"), _cell_renderer) - 1; int idx = append_column(_("Arrival"), _cell_renderer) - 1;
Gtk::TreeViewColumn* tvc = get_column(idx); Gtk::TreeViewColumn* tvc = get_column(idx);
tvc->set_cell_data_func(_cell_renderer, sigc::mem_fun(*this, &SchedulablesTreeWidget::_on_arrival_column_data)); tvc->set_cell_data_func(_cell_renderer, sigc::mem_fun(*this, &SchedulablesTreeWidget::_on_arrival_column_data));
@ -68,11 +69,11 @@ SchedulablesTreeWidget::SchedulablesTreeWidget()
idx = append_column(_("Entity"), _cell_renderer) - 1; idx = append_column(_("Entity"), _cell_renderer) - 1;
tvc = get_column(idx); tvc = get_column(idx);
tvc->set_cell_data_func(_cell_renderer, sigc::mem_fun(*this, &SchedulablesTreeWidget::_on_entity_column_data)); tvc->set_cell_data_func(_cell_renderer, sigc::mem_fun(*this, &SchedulablesTreeWidget::_on_entity_column_data));
idx = append_column(_("State"), _cell_renderer) - 1; idx = append_column(_("State"), _cell_renderer) - 1;
tvc = get_column(idx); tvc = get_column(idx);
tvc->set_cell_data_func(_cell_renderer, sigc::mem_fun(*this, &SchedulablesTreeWidget::_on_state_column_data)); tvc->set_cell_data_func(_cell_renderer, sigc::mem_fun(*this, &SchedulablesTreeWidget::_on_state_column_data));
set_headers_visible(true); set_headers_visible(true);
Simulation::get_instance().get_history().attach(*this); Simulation::get_instance().get_history().attach(*this);
@ -84,7 +85,7 @@ SchedulablesTreeWidget::~SchedulablesTreeWidget()
} }
template <typename T> template <typename T>
bool bool
SchedulablesTreeWidget::check_type(SchedulablesTreeWidget::HandleType type) SchedulablesTreeWidget::check_type(SchedulablesTreeWidget::HandleType type)
{ {
return false; return false;
@ -93,28 +94,28 @@ SchedulablesTreeWidget::check_type(SchedulablesTreeWidget::HandleType type)
namespace sgpem namespace sgpem
{ {
template <> template <>
bool bool
SchedulablesTreeWidget::check_type<Process>(HandleType type) SchedulablesTreeWidget::check_type<Process>(HandleType type)
{ {
return type == htype_process; return type == htype_process;
} }
template <> template <>
bool bool
SchedulablesTreeWidget::check_type<Thread>(HandleType type) SchedulablesTreeWidget::check_type<Thread>(HandleType type)
{ {
return type == htype_thread; return type == htype_thread;
} }
template <> template <>
bool bool
SchedulablesTreeWidget::check_type<Request>(HandleType type) SchedulablesTreeWidget::check_type<Request>(HandleType type)
{ {
return type == htype_request; return type == htype_request;
} }
// template <> // template <>
// bool // bool
// SchedulablesTreeWidget::check_type<SubRequest>(HandleType type) // SchedulablesTreeWidget::check_type<SubRequest>(HandleType type)
// { // {
// return type == htype_subrequest; // return type == htype_subrequest;
@ -126,7 +127,7 @@ T*
SchedulablesTreeWidget::get_selected() SchedulablesTreeWidget::get_selected()
{ {
TreeModel::iterator sel = get_selection()->get_selected(); TreeModel::iterator sel = get_selection()->get_selected();
return get_row_handle_as<T>(sel); return get_row_handle_as<T>(sel);
} }
@ -136,7 +137,7 @@ SchedulablesTreeWidget::get_row_handle_as(const Gtk::TreeModel::iterator& row)
{ {
if(!row) if(!row)
return nullptr; return nullptr;
const void* p_handle = (*row)[_handles_column]; const void* p_handle = (*row)[_handles_column];
HandleType type = (*row)[_types_column]; HandleType type = (*row)[_types_column];
@ -164,42 +165,42 @@ SchedulablesTreeWidget::get_row_type(const TreeModel::iterator& row)
} }
bool bool
SchedulablesTreeWidget::on_button_press_event(GdkEventButton* event) SchedulablesTreeWidget::on_button_press_event(GdkEventButton* event)
{ {
TreeView::on_button_press_event(event); TreeView::on_button_press_event(event);
if((Simulation::get_instance().get_state() == Simulation::state_stopped) && if((Simulation::get_instance().get_state() == Simulation::state_stopped) &&
(event->type == GDK_BUTTON_PRESS) && (event->button == 3) ) (event->type == GDK_BUTTON_PRESS) && (event->button == 3) )
{ {
RefPtr<ActionGroup> action_group = Gtk::ActionGroup::create(); RefPtr<ActionGroup> action_group = Gtk::ActionGroup::create();
action_group->add( Gtk::Action::create("AddProcess", _("Add Process")), action_group->add( Gtk::Action::create("AddProcess", _("Add Process")),
sigc::mem_fun(*this, &SchedulablesTreeWidget::_on_add_process) ); sigc::mem_fun(*this, &SchedulablesTreeWidget::_on_add_process) );
action_group->add( Gtk::Action::create("AddThread", _("Add Thread")), action_group->add( Gtk::Action::create("AddThread", _("Add Thread")),
sigc::mem_fun(*this, &SchedulablesTreeWidget::_on_add_thread) ); sigc::mem_fun(*this, &SchedulablesTreeWidget::_on_add_thread) );
action_group->add( Gtk::Action::create("AddRequest", _("Add Request")), action_group->add( Gtk::Action::create("AddRequest", _("Add Request")),
sigc::mem_fun(*this, &SchedulablesTreeWidget::_on_add_request) ); sigc::mem_fun(*this, &SchedulablesTreeWidget::_on_add_request) );
action_group->add( Gtk::Action::create("EditProcess", _("Edit Process")), action_group->add( Gtk::Action::create("EditProcess", _("Edit Process")),
sigc::mem_fun(*this, &SchedulablesTreeWidget::_on_edit_process) ); sigc::mem_fun(*this, &SchedulablesTreeWidget::_on_edit_process) );
action_group->add( Gtk::Action::create("EditThread", _("Edit Thread")), action_group->add( Gtk::Action::create("EditThread", _("Edit Thread")),
sigc::mem_fun(*this, &SchedulablesTreeWidget::_on_edit_thread) ); sigc::mem_fun(*this, &SchedulablesTreeWidget::_on_edit_thread) );
action_group->add( Gtk::Action::create("EditRequest", _("Edit Request")), action_group->add( Gtk::Action::create("EditRequest", _("Edit Request")),
sigc::mem_fun(*this, &SchedulablesTreeWidget::_on_edit_request) ); sigc::mem_fun(*this, &SchedulablesTreeWidget::_on_edit_request) );
action_group->add( Gtk::Action::create("RemoveProcess", _("Remove Process")), action_group->add( Gtk::Action::create("RemoveProcess", _("Remove Process")),
sigc::mem_fun(*this, &SchedulablesTreeWidget::_on_remove_process) ); sigc::mem_fun(*this, &SchedulablesTreeWidget::_on_remove_process) );
action_group->add( Gtk::Action::create("RemoveThread", _("Remove Thread")), action_group->add( Gtk::Action::create("RemoveThread", _("Remove Thread")),
sigc::mem_fun(*this, &SchedulablesTreeWidget::_on_remove_thread) ); sigc::mem_fun(*this, &SchedulablesTreeWidget::_on_remove_thread) );
action_group->add( Gtk::Action::create("RemoveRequest", _("Remove Request")), action_group->add( Gtk::Action::create("RemoveRequest", _("Remove Request")),
sigc::mem_fun(*this, &SchedulablesTreeWidget::_on_remove_request) ); sigc::mem_fun(*this, &SchedulablesTreeWidget::_on_remove_request) );
// action_group->add( Gtk::Action::create("RemoveSubrequest", _("Remove Subrequest")), // action_group->add( Gtk::Action::create("RemoveSubrequest", _("Remove Subrequest")),
// sigc::mem_fun(*this, &SchedulablesTreeWidget::_on_remove_subrequest) ); // sigc::mem_fun(*this, &SchedulablesTreeWidget::_on_remove_subrequest) );
@ -208,15 +209,15 @@ SchedulablesTreeWidget::on_button_press_event(GdkEventButton* event)
UIManager->insert_action_group(action_group); UIManager->insert_action_group(action_group);
const HandleType selection_type = get_selection_type(); const HandleType selection_type = get_selection_type();
Glib::ustring adds; Glib::ustring adds;
Glib::ustring edits; Glib::ustring edits;
Glib::ustring removes; Glib::ustring removes;
Glib::ustring separator; Glib::ustring separator;
if(selection_type != htype_undefined) if(selection_type != htype_undefined)
separator = "<separator/>"; separator = "<separator/>";
switch(selection_type) switch(selection_type)
{ {
case htype_process: case htype_process:
@ -240,16 +241,16 @@ SchedulablesTreeWidget::on_button_press_event(GdkEventButton* event)
} }
adds += "<menuitem action='AddProcess'/>"; adds += "<menuitem action='AddProcess'/>";
Glib::ustring ui_info = Glib::ustring ui_info =
"<ui>" "<ui>"
" <popup name='PopupMenu'>"; " <popup name='PopupMenu'>";
ui_info += adds + separator + edits + ((edits.size() == 0) ? ustring() : separator) + removes; ui_info += adds + separator + edits + ((edits.size() == 0) ? ustring() : separator) + removes;
ui_info += ui_info +=
" </popup>" " </popup>"
"</ui>"; "</ui>";
UIManager->add_ui_from_string(ui_info); UIManager->add_ui_from_string(ui_info);
Gtk::Menu* menu = dynamic_cast<Gtk::Menu*>(UIManager->get_widget("/PopupMenu")); Gtk::Menu* menu = dynamic_cast<Gtk::Menu*>(UIManager->get_widget("/PopupMenu"));
@ -272,10 +273,10 @@ void
SchedulablesTreeWidget::update(const History&) SchedulablesTreeWidget::update(const History&)
{ {
using std::vector; using std::vector;
typedef Environment::Processes::const_iterator ProcessIt; typedef Environment::Processes::const_iterator ProcessIt;
const Environment::Processes& processes = const Environment::Processes& processes =
Simulation::get_instance().get_history().get_last_environment().get_processes(); Simulation::get_instance().get_history().get_last_environment().get_processes();
@ -283,20 +284,20 @@ SchedulablesTreeWidget::update(const History&)
map_expanded_rows(sigc::mem_fun(*this, &SchedulablesTreeWidget::_update_expanded_vector)); map_expanded_rows(sigc::mem_fun(*this, &SchedulablesTreeWidget::_update_expanded_vector));
_model->clear(); _model->clear();
for(Iseq<ProcessIt> pit = iseq(processes); pit; ++pit) for(Iseq<ProcessIt> pit = iseq(processes); pit; ++pit)
{ {
Process& p = *(*pit); Process& p = *(*pit);
TreeModel::Row prow = *(_model->append()); TreeModel::Row prow = *(_model->append());
// prow[_main_column] = p.get_name(); // prow[_main_column] = p.get_name();
prow[_types_column] = htype_process; prow[_types_column] = htype_process;
prow[_handles_column] = &p; prow[_handles_column] = &p;
vector<Thread*> threads = p.get_threads(); vector<Thread*> threads = p.get_threads();
for(Iseq<vector<Thread*>::iterator> tit = iseq(threads); tit; ++tit) for(Iseq<vector<Thread*>::iterator> tit = iseq(threads); tit; ++tit)
{ {
Thread& t = *(*tit); Thread& t = *(*tit);
@ -312,16 +313,16 @@ SchedulablesTreeWidget::update(const History&)
for(unsigned int ri = 0; ri < requests.size(); ++ri) for(unsigned int ri = 0; ri < requests.size(); ++ri)
{ {
Request& r = *requests[ri]; Request& r = *requests[ri];
TreeModel::Row rrow = *(_model->append(trow.children())); TreeModel::Row rrow = *(_model->append(trow.children()));
// std::ostringstream oss; // std::ostringstream oss;
// oss << _("request ") << ri + 1; // oss << _("request ") << ri + 1;
// rrow[_main_column] = oss.str(); // rrow[_main_column] = oss.str();
rrow[_types_column] = htype_request; rrow[_types_column] = htype_request;
rrow[_handles_column] = &r; rrow[_handles_column] = &r;
} }
} }
} }
@ -333,7 +334,7 @@ SchedulablesTreeWidget::update(const History&)
// We can clear it now, since until next update we won't need it. // We can clear it now, since until next update we won't need it.
_expanded_rows.clear(); _expanded_rows.clear();
} }
void void
@ -351,14 +352,14 @@ SchedulablesTreeWidget::_on_edit_process()
void void
SchedulablesTreeWidget::add_edit_process(bool adding) SchedulablesTreeWidget::add_edit_process(bool adding)
{ {
/** This is ugly, I know, we should be using derived widgets, but I also believe we /** This is ugly, I know, we should be using derived widgets, but I also believe we
* have little time, and I'm not going to waste too much of it on the frontend */ * have little time, and I'm not going to waste too much of it on the frontend */
RefPtr<Builder> ui(Builder::create_from_file(UIDIR "/add-process-dialog.ui")); RefPtr<Builder> ui(Builder::create_from_file(UIDIR "/add-process-dialog.ui"));
Dialog* add_process_dialog; Dialog* add_process_dialog;
ui->get_widget("AddProcessDialog", add_process_dialog); ui->get_widget("AddProcessDialog", add_process_dialog);
Entry* name_entry; Entry* name_entry;
SpinButton* arrival_time_spin; SpinButton* arrival_time_spin;
SpinButton* duration_spin; SpinButton* duration_spin;
@ -368,9 +369,9 @@ SchedulablesTreeWidget::add_edit_process(bool adding)
ui->get_widget("ArrivalTime.Spin", arrival_time_spin); ui->get_widget("ArrivalTime.Spin", arrival_time_spin);
ui->get_widget("Duration.Spin", duration_spin); ui->get_widget("Duration.Spin", duration_spin);
ui->get_widget("BasePriority.Spin", base_priority_spin); ui->get_widget("BasePriority.Spin", base_priority_spin);
Process* selection = nullptr; Process* selection = nullptr;
if(!adding) if(!adding)
{ {
selection = get_selected<Process>(); selection = get_selected<Process>();
@ -381,16 +382,16 @@ SchedulablesTreeWidget::add_edit_process(bool adding)
duration_spin->set_sensitive(false); duration_spin->set_sensitive(false);
base_priority_spin->set_value(static_cast<double>(selection->get_base_priority())); base_priority_spin->set_value(static_cast<double>(selection->get_base_priority()));
} }
if(add_process_dialog->run() == RESPONSE_OK) if(add_process_dialog->run() == RESPONSE_OK)
{ {
if(adding) if(adding)
{ {
History& h = Simulation::get_instance().get_history(); History& h = Simulation::get_instance().get_history();
History::LockNotify lock(h); History::LockNotify lock(h);
Process& np = h.add_process(name_entry->get_text(), Process& np = h.add_process(name_entry->get_text(),
arrival_time_spin->get_value_as_int(), arrival_time_spin->get_value_as_int(),
base_priority_spin->get_value_as_int()); base_priority_spin->get_value_as_int());
h.add_thread(_("Main"), np, duration_spin->get_value_as_int(), h.add_thread(_("Main"), np, duration_spin->get_value_as_int(),
@ -400,20 +401,20 @@ SchedulablesTreeWidget::add_edit_process(bool adding)
{ {
History& h = Simulation::get_instance().get_history(); History& h = Simulation::get_instance().get_history();
History::LockNotify lock(h); History::LockNotify lock(h);
h.edit_process(*selection, h.edit_process(*selection,
name_entry->get_text(), name_entry->get_text(),
arrival_time_spin->get_value_as_int(), arrival_time_spin->get_value_as_int(),
base_priority_spin->get_value_as_int()); base_priority_spin->get_value_as_int());
} }
} }
add_process_dialog->hide(); add_process_dialog->hide();
} }
void void
SchedulablesTreeWidget::_on_add_thread() SchedulablesTreeWidget::_on_add_thread()
{ {
add_edit_thread(true); add_edit_thread(true);
} }
@ -426,14 +427,14 @@ SchedulablesTreeWidget::_on_edit_thread()
void void
SchedulablesTreeWidget::add_edit_thread(bool adding) SchedulablesTreeWidget::add_edit_thread(bool adding)
{ {
/** This is ugly, I know, we should be using derived widgets, but I also believe we /** This is ugly, I know, we should be using derived widgets, but I also believe we
* have little time, and I'm not going to waste too much of it on the frontend */ * have little time, and I'm not going to waste too much of it on the frontend */
RefPtr<Builder> ui(Builder::create_from_file(UIDIR "/add-thread-dialog.ui")); RefPtr<Builder> ui(Builder::create_from_file(UIDIR "/add-thread-dialog.ui"));
Dialog* add_thread_dialog; Dialog* add_thread_dialog;
ui->get_widget("AddThreadDialog", add_thread_dialog); ui->get_widget("AddThreadDialog", add_thread_dialog);
Entry* name_entry; Entry* name_entry;
SpinButton* cpu_time_spin; SpinButton* cpu_time_spin;
SpinButton* arrival_time_spin; SpinButton* arrival_time_spin;
@ -445,18 +446,18 @@ SchedulablesTreeWidget::add_edit_thread(bool adding)
ui->get_widget("BasePriority.Spin", base_priority_spin); ui->get_widget("BasePriority.Spin", base_priority_spin);
Thread* t = nullptr; Thread* t = nullptr;
if(!adding) if(!adding)
{ {
t = get_selected<Thread>(); t = get_selected<Thread>();
name_entry->set_text(t->get_name()); name_entry->set_text(t->get_name());
cpu_time_spin->set_value(static_cast<double>(t->get_total_cpu_time())); cpu_time_spin->set_value(static_cast<double>(t->get_total_cpu_time()));
arrival_time_spin->set_value(static_cast<double>(t->get_arrival_time())); arrival_time_spin->set_value(static_cast<double>(t->get_arrival_time()));
base_priority_spin->set_value(static_cast<double>(t->get_base_priority())); base_priority_spin->set_value(static_cast<double>(t->get_base_priority()));
} }
if(add_thread_dialog->run() == RESPONSE_OK) if(add_thread_dialog->run() == RESPONSE_OK)
{ {
@ -464,63 +465,63 @@ SchedulablesTreeWidget::add_edit_thread(bool adding)
{ {
Process* p = get_selected<Process>(); Process* p = get_selected<Process>();
assert(p != nullptr); assert(p != nullptr);
Simulation::get_instance().get_history().add_thread(name_entry->get_text(), Simulation::get_instance().get_history().add_thread(name_entry->get_text(),
*p, *p,
cpu_time_spin->get_value_as_int(), cpu_time_spin->get_value_as_int(),
arrival_time_spin->get_value_as_int(), arrival_time_spin->get_value_as_int(),
base_priority_spin->get_value_as_int()); base_priority_spin->get_value_as_int());
} }
else else
{ {
Simulation::get_instance().get_history().edit_thread(*t, Simulation::get_instance().get_history().edit_thread(*t,
name_entry->get_text(), name_entry->get_text(),
cpu_time_spin->get_value_as_int(), cpu_time_spin->get_value_as_int(),
arrival_time_spin->get_value_as_int(), arrival_time_spin->get_value_as_int(),
base_priority_spin->get_value_as_int()); base_priority_spin->get_value_as_int());
} }
} }
add_thread_dialog->hide(); add_thread_dialog->hide();
} }
void void
SchedulablesTreeWidget::_on_add_request() SchedulablesTreeWidget::_on_add_request()
{ {
RefPtr<Builder> ui(Builder::create_from_file(UIDIR "/add-request-dialog.ui")); RefPtr<Builder> ui(Builder::create_from_file(UIDIR "/add-request-dialog.ui"));
AddRequestDialog* add_request_dialog; AddRequestDialog* add_request_dialog;
// NOTE This is *not* reflective programming! AddRequestDialog is the name of // NOTE This is *not* reflective programming! AddRequestDialog is the name of
// the base widget in the xml ui file. // the base widget in the xml ui file.
ui->get_widget_derived("AddRequestDialog", add_request_dialog); ui->get_widget_derived("AddRequestDialog", add_request_dialog);
Thread* t = get_selected<Thread>(); Thread* t = get_selected<Thread>();
assert(t != nullptr); assert(t != nullptr);
add_request_dialog->run_add(*t); add_request_dialog->run_add(*t);
} }
void void
SchedulablesTreeWidget::_on_edit_request() SchedulablesTreeWidget::_on_edit_request()
{ {
using std::vector; using std::vector;
RefPtr<Builder> ui(Builder::create_from_file(UIDIR "/add-request-dialog.ui")); RefPtr<Builder> ui(Builder::create_from_file(UIDIR "/add-request-dialog.ui"));
AddRequestDialog* add_request_dialog; AddRequestDialog* add_request_dialog;
// NOTE This is *not* reflective programming! AddRequestDialog is the name of // NOTE This is *not* reflective programming! AddRequestDialog is the name of
// the base widget in the xml ui file. // the base widget in the xml ui file.
ui->get_widget_derived("AddRequestDialog", add_request_dialog); ui->get_widget_derived("AddRequestDialog", add_request_dialog);
Request* r = get_selected<Request>(); Request* r = get_selected<Request>();
assert(r != nullptr); assert(r != nullptr);
// FIXME: write more polite code for doing this, and probably using the same logic // FIXME: write more polite code for doing this, and probably using the same logic
// for all other editing operations may be useful for making the app more robust // for all other editing operations may be useful for making the app more robust
const Environment::Processes& processes = const Environment::Processes& processes =
Simulation::get_instance().get_history().get_environment_at(0).get_processes(); Simulation::get_instance().get_history().get_environment_at(0).get_processes();
for(Iseq<Environment::Processes::const_iterator> pit = iseq(processes); pit; ++pit) for(Iseq<Environment::Processes::const_iterator> pit = iseq(processes); pit; ++pit)
@ -532,12 +533,12 @@ SchedulablesTreeWidget::_on_edit_request()
vector<Request*> requests = (*tit)->get_requests(); vector<Request*> requests = (*tit)->get_requests();
for(Iseq<vector<Request*>::iterator> rit = iseq(requests); rit; ++rit) for(Iseq<vector<Request*>::iterator> rit = iseq(requests); rit; ++rit)
{ {
if(*(*rit) == *r) if(*(*rit) == *r)
r = *rit; r = *rit;
} }
} }
} }
add_request_dialog->run_edit(*r); add_request_dialog->run_edit(*r);
} }
@ -568,8 +569,8 @@ SchedulablesTreeWidget::_on_remove_request()
Simulation::get_instance().get_history().remove(*r); Simulation::get_instance().get_history().remove(*r);
} }
void void
SchedulablesTreeWidget::_on_arrival_column_data(Gtk::CellRenderer* cr, SchedulablesTreeWidget::_on_arrival_column_data(Gtk::CellRenderer* cr,
const Gtk::TreeModel::iterator& it) const Gtk::TreeModel::iterator& it)
{ {
CellRendererTextMarkup& crtm = static_cast<CellRendererTextMarkup&>(*cr); CellRendererTextMarkup& crtm = static_cast<CellRendererTextMarkup&>(*cr);
@ -583,11 +584,11 @@ SchedulablesTreeWidget::_on_arrival_column_data(Gtk::CellRenderer* cr,
case htype_process: case htype_process:
oss << get_row_handle_as<Process>(it)->get_arrival_time(); oss << get_row_handle_as<Process>(it)->get_arrival_time();
break; break;
case htype_thread: case htype_thread:
oss << get_row_handle_as<Thread>(it)->get_arrival_time(); oss << get_row_handle_as<Thread>(it)->get_arrival_time();
break; break;
case htype_request: case htype_request:
oss << get_row_handle_as<Request>(it)->get_instant(); oss << get_row_handle_as<Request>(it)->get_instant();
break; break;
@ -601,8 +602,8 @@ SchedulablesTreeWidget::_on_arrival_column_data(Gtk::CellRenderer* cr,
crtm.property_markup() = oss.str(); crtm.property_markup() = oss.str();
} }
void void
SchedulablesTreeWidget::_on_entity_column_data(Gtk::CellRenderer* cr, SchedulablesTreeWidget::_on_entity_column_data(Gtk::CellRenderer* cr,
const Gtk::TreeModel::iterator& it) const Gtk::TreeModel::iterator& it)
{ {
CellRendererTextMarkup& crtm = static_cast<CellRendererTextMarkup&>(*cr); CellRendererTextMarkup& crtm = static_cast<CellRendererTextMarkup&>(*cr);
@ -614,11 +615,11 @@ SchedulablesTreeWidget::_on_entity_column_data(Gtk::CellRenderer* cr,
case htype_process: case htype_process:
marked_up = markup_schedulable(*get_row_handle_as<Process>(it)); marked_up = markup_schedulable(*get_row_handle_as<Process>(it));
break; break;
case htype_thread: case htype_thread:
marked_up = markup_schedulable(*get_row_handle_as<Thread>(it)); marked_up = markup_schedulable(*get_row_handle_as<Thread>(it));
break; break;
case htype_request: case htype_request:
marked_up = markup_request(*get_row_handle_as<Request>(it)); marked_up = markup_request(*get_row_handle_as<Request>(it));
break; break;
@ -626,7 +627,7 @@ SchedulablesTreeWidget::_on_entity_column_data(Gtk::CellRenderer* cr,
default: default:
marked_up = _("<big><b>ERROR<b></big>"); marked_up = _("<big><b>ERROR<b></big>");
} }
crtm.property_markup() = marked_up; crtm.property_markup() = marked_up;
} }
@ -634,15 +635,15 @@ ustring
SchedulablesTreeWidget::markup_schedulable(const Schedulable& s) SchedulablesTreeWidget::markup_schedulable(const Schedulable& s)
{ {
using std::endl; using std::endl;
std::ostringstream oss; std::ostringstream oss;
// TODO : add note for the translator to use HTML-escaped text // TODO : add note for the translator to use HTML-escaped text
// See the gettext manual. // See the gettext manual.
oss << "<span size=\"8500\"><span foreground=\"" oss << "<span size=\"8500\"><span foreground=\""
<< GlobalPreferences::get_instance().get_schedulable_color(s.get_state()) << GlobalPreferences::get_instance().get_schedulable_color(s.get_state())
<< "\"><b>" << Markup::escape_text(s.get_name()) << "</b></span>" << "\"><b>" << Markup::escape_text(s.get_name()) << "</b></span>"
<< Glib::ustring::compose(_(" (%1/%2), current_priority: %3"), << Glib::ustring::compose(_(" (%1/%2), current_priority: %3"),
s.get_elapsed_time(), s.get_total_cpu_time(), s.get_current_priority()) s.get_elapsed_time(), s.get_total_cpu_time(), s.get_current_priority())
<< "</span>"; << "</span>";
@ -656,8 +657,8 @@ SchedulablesTreeWidget::markup_request(Request& r)
std::ostringstream oss; std::ostringstream oss;
oss << "<span size=\"8500\"><span foreground=\"" oss << "<span size=\"8500\"><span foreground=\""
<< GlobalPreferences::get_instance().get_request_color(r.get_state()) << GlobalPreferences::get_instance().get_request_color(r.get_state())
<< "\"><b>" << _("request:") << "</b></span>"; << "\"><b>" << _("request:") << "</b></span>";
const Environment& env = Simulation::get_instance().get_history().get_last_environment(); const Environment& env = Simulation::get_instance().get_history().get_last_environment();
@ -668,44 +669,44 @@ SchedulablesTreeWidget::markup_request(Request& r)
{ {
SubRequest& sr = *(*it); SubRequest& sr = *(*it);
Resource& res = *(resources.find(sr.get_resource_key())->second); Resource& res = *(resources.find(sr.get_resource_key())->second);
oss << " -&gt; <span foreground=\"" oss << " -&gt; <span foreground=\""
<< GlobalPreferences::get_instance().get_request_color(sr.get_state()) << GlobalPreferences::get_instance().get_request_color(sr.get_state())
<< "\"><b>" << res.get_name() << "</b></span> (" << "\"><b>" << res.get_name() << "</b></span> ("
<< (sr.get_length() - sr.get_remaining_time()) << (sr.get_length() - sr.get_remaining_time())
<< "/" << sr.get_length() << ")"; << "/" << sr.get_length() << ")";
} }
oss << "</span>"; oss << "</span>";
return oss.str(); return oss.str();
} }
void void
SchedulablesTreeWidget::_on_state_column_data(Gtk::CellRenderer* cr, SchedulablesTreeWidget::_on_state_column_data(Gtk::CellRenderer* cr,
const Gtk::TreeModel::iterator& it) const Gtk::TreeModel::iterator& it)
{ {
CellRendererTextMarkup& crtm = static_cast<CellRendererTextMarkup&>(*cr); CellRendererTextMarkup& crtm = static_cast<CellRendererTextMarkup&>(*cr);
ustring marked_up = "<span size=\"8500\">"; ustring marked_up = "<span size=\"8500\">";
switch(get_row_type(it)) switch(get_row_type(it))
{ {
case htype_process: case htype_process:
marked_up += state_text(get_row_handle_as<Process>(it)->get_state()); marked_up += state_text(get_row_handle_as<Process>(it)->get_state());
break; break;
case htype_thread: case htype_thread:
marked_up += state_text(get_row_handle_as<Thread>(it)->get_state()); marked_up += state_text(get_row_handle_as<Thread>(it)->get_state());
break; break;
case htype_request: case htype_request:
marked_up += state_text(get_row_handle_as<Request>(it)->get_state()); marked_up += state_text(get_row_handle_as<Request>(it)->get_state());
break; break;
default: default:
marked_up += "<b>NO STATE</b>"; marked_up += "<b>NO STATE</b>";
} }
crtm.property_markup() = marked_up + "</span>"; crtm.property_markup() = marked_up + "</span>";
} }
@ -713,7 +714,7 @@ ustring
SchedulablesTreeWidget::state_text(Schedulable::state state) SchedulablesTreeWidget::state_text(Schedulable::state state)
{ {
ustring text; ustring text;
switch (state) switch (state)
{ {
case Schedulable::state_running: case Schedulable::state_running:
@ -742,7 +743,7 @@ ustring
SchedulablesTreeWidget::state_text(Request::state state) SchedulablesTreeWidget::state_text(Request::state state)
{ {
ustring text; ustring text;
switch (state) switch (state)
{ {
case Request::state_allocated: case Request::state_allocated:

View File

@ -26,6 +26,7 @@
#include "gettext.h" #include "gettext.h"
#include "sgpemv2/config.h"
#include "sgpemv2/simulation.hh" #include "sgpemv2/simulation.hh"
#include <gtkmm/window.h> #include <gtkmm/window.h>
@ -36,7 +37,7 @@
#include <cassert> #include <cassert>
#include <iostream> #include <iostream>
namespace sgpem namespace sgpem
{ {
/** /**
* \brief Window which displays schedulable-specific and simulation statistics * \brief Window which displays schedulable-specific and simulation statistics