From 90b64e1e89a33317d6008e10fe2c106a0dc34c7a Mon Sep 17 00:00:00 2001 From: Tim Moore Date: Wed, 30 Sep 2009 19:02:42 +0200 Subject: [PATCH] dialog for choosing stap script and providing arguments to stap and the script * grapher/grapher.cxx (GraphicalStapLauncher): New class. (GrapherWindow constructor): Bind actions for graphical launcher buttons (GrapherWindow::setGraphicalLauncher): new method (GrapherWindow::on_menu_script_start): new method grapher/stap-start.glade, grapher/stap-start.gladep: new files grapher/Makefile.am: install stap-start.glade --- grapher/Makefile.am | 2 +- grapher/Makefile.in | 4 +- grapher/grapher.cxx | 93 +++++++++++++- grapher/stap-start.glade | 248 ++++++++++++++++++++++++++++++++++++++ grapher/stap-start.gladep | 8 ++ 5 files changed, 348 insertions(+), 7 deletions(-) create mode 100644 grapher/stap-start.glade create mode 100644 grapher/stap-start.gladep diff --git a/grapher/Makefile.am b/grapher/Makefile.am index 9fd817ec2..7f6b56fd5 100644 --- a/grapher/Makefile.am +++ b/grapher/Makefile.am @@ -5,5 +5,5 @@ stapgraph_CPPFLAGS = -DPKGDATADIR='"${pkgdatadir}"' stapgraph_CXXFLAGS = $(gtkmm_CFLAGS) -Wall -Werror stapgraph_SOURCES = grapher.cxx StapParser.cxx Graph.cxx GraphWidget.cxx CairoWidget.cxx stapgraph_LDADD = $(gtkmm_LIBS) -dist_pkgdata_DATA = graph-dialog.glade +dist_pkgdata_DATA = graph-dialog.glade stap-start.glade endif diff --git a/grapher/Makefile.in b/grapher/Makefile.in index 564dc95f2..44dddf488 100644 --- a/grapher/Makefile.in +++ b/grapher/Makefile.in @@ -71,7 +71,7 @@ CXXLINK = $(CXXLD) $(AM_CXXFLAGS) $(CXXFLAGS) $(AM_LDFLAGS) $(LDFLAGS) \ -o $@ SOURCES = $(stapgraph_SOURCES) DIST_SOURCES = $(am__stapgraph_SOURCES_DIST) -am__dist_pkgdata_DATA_DIST = graph-dialog.glade +am__dist_pkgdata_DATA_DIST = graph-dialog.glade stap-start.glade am__vpath_adj_setup = srcdirstrip=`echo "$(srcdir)" | sed 's|.|.|g'`; am__vpath_adj = case $$p in \ $(srcdir)/*) f=`echo "$$p" | sed "s|^$$srcdirstrip/||"`;; \ @@ -219,7 +219,7 @@ top_srcdir = @top_srcdir@ @BUILD_GRAPHER_TRUE@stapgraph_CXXFLAGS = $(gtkmm_CFLAGS) -Wall -Werror @BUILD_GRAPHER_TRUE@stapgraph_SOURCES = grapher.cxx StapParser.cxx Graph.cxx GraphWidget.cxx CairoWidget.cxx @BUILD_GRAPHER_TRUE@stapgraph_LDADD = $(gtkmm_LIBS) -@BUILD_GRAPHER_TRUE@dist_pkgdata_DATA = graph-dialog.glade +@BUILD_GRAPHER_TRUE@dist_pkgdata_DATA = graph-dialog.glade stap-start.glade all: all-am .SUFFIXES: diff --git a/grapher/grapher.cxx b/grapher/grapher.cxx index 62a54aec3..429d05371 100644 --- a/grapher/grapher.cxx +++ b/grapher/grapher.cxx @@ -15,6 +15,7 @@ #include #include +#include #include #include #include @@ -38,6 +39,7 @@ class ChildDeathReader public: struct Callback { + virtual ~Callback() {} virtual void childDied(int pid) {} }; ChildDeathReader() : sigfd(-1) {} @@ -61,6 +63,23 @@ private: int sigfd; }; +class StapLauncher; + +class GraphicalStapLauncher +{ +public: + GraphicalStapLauncher(StapLauncher* launcher); + bool runDialog(); + void onLaunch(); + void onLaunchCancel(); +private: + Glib::RefPtr _launchStapDialog; + Gtk::Window* _scriptWindow; + Gtk::FileChooserButton* _chooserButton; + Gtk::Entry* _stapArgEntry; + Gtk::Entry* _scriptArgEntry; + StapLauncher* _launcher; +}; class GrapherWindow : public Gtk::Window, public ChildDeathReader::Callback { @@ -71,12 +90,19 @@ public: Gtk::ScrolledWindow scrolled; GraphWidget w; void childDied(int pid); + void setGraphicalLauncher(GraphicalStapLauncher* launcher) + { + _graphicalLauncher = launcher; + } + GraphicalStapLauncher* getGraphicalLauncher() { return _graphicalLauncher; } protected: virtual void on_menu_file_quit(); + virtual void on_menu_script_start(); void addGraph(); // menu support Glib::RefPtr m_refUIManager; Glib::RefPtr m_refActionGroup; + GraphicalStapLauncher* _graphicalLauncher; }; @@ -90,10 +116,14 @@ GrapherWindow::GrapherWindow() m_refActionGroup = Gtk::ActionGroup::create(); //File menu: m_refActionGroup->add(Gtk::Action::create("FileMenu", "File")); + m_refActionGroup->add(Gtk::Action::create("StartScript", "Start script"), + sigc::mem_fun(*this, + &GrapherWindow::on_menu_script_start)); m_refActionGroup->add(Gtk::Action::create("AddGraph", "Add graph"), sigc::mem_fun(*this, &GrapherWindow::addGraph)); m_refActionGroup->add(Gtk::Action::create("FileQuit", Gtk::Stock::QUIT), - sigc::mem_fun(*this, &GrapherWindow::on_menu_file_quit)); + sigc::mem_fun(*this, + &GrapherWindow::on_menu_file_quit)); m_refUIManager = Gtk::UIManager::create(); m_refUIManager->insert_action_group(m_refActionGroup); @@ -103,7 +133,8 @@ GrapherWindow::GrapherWindow() "" " " " " - " " + " " + " " " " " " " " @@ -126,11 +157,17 @@ GrapherWindow::GrapherWindow() show_all_children(); } + void GrapherWindow::on_menu_file_quit() { hide(); } +void GrapherWindow::on_menu_script_start() +{ + _graphicalLauncher->runDialog(); +} + void GrapherWindow::childDied(int pid) { hide(); @@ -276,7 +313,8 @@ int StapLauncher::launch() { string argString = "stap" + _stapArgs + " " + _script + " " + _scriptArgs; - execl("/bin/sh", "-c", argString.c_str(), static_cast(0)); + execl("/bin/sh", "sh", "-c", argString.c_str(), + static_cast(0)); } _exit(1); } @@ -329,7 +367,8 @@ int main(int argc, char** argv) StapParser stapParser(win, win.w); launcher.setStapParser(&stapParser); - + GraphicalStapLauncher graphicalLauncher(&launcher); + win.setGraphicalLauncher(&graphicalLauncher); if (argc > 1) { launcher.setArgv(argv + 1); @@ -353,3 +392,49 @@ void GrapherWindow::addGraph() w.addGraph(); } + +GraphicalStapLauncher::GraphicalStapLauncher(StapLauncher* launcher) + : _launcher(launcher) +{ + try + { + _launchStapDialog + = Gnome::Glade::Xml::create(PKGDATADIR "/stap-start.glade"); + _launchStapDialog->get_widget("window1", _scriptWindow); + _launchStapDialog->get_widget("scriptChooserButton", _chooserButton); + _launchStapDialog->get_widget("stapEntry", _stapArgEntry); + _launchStapDialog->get_widget("scriptEntry", _scriptArgEntry); + Gtk::Button* button = 0; + _launchStapDialog->get_widget("launchButton", button); + button->signal_clicked() + .connect(sigc::mem_fun(*this, &GraphicalStapLauncher::onLaunch), false); + _launchStapDialog->get_widget("cancelButton", button); + button->signal_clicked() + .connect(sigc::mem_fun(*this, &GraphicalStapLauncher::onLaunchCancel), + false); + } + catch (const Gnome::Glade::XmlError& ex ) + { + std::cerr << ex.what() << std::endl; + throw; + } +} + +bool GraphicalStapLauncher::runDialog() +{ + _scriptWindow->show(); + return true; +} + +void GraphicalStapLauncher::onLaunch() +{ + _launcher->setArgs(_stapArgEntry->get_text(), _chooserButton->get_filename(), + _scriptArgEntry->get_text()); + _scriptWindow->hide(); + _launcher->launch(); +} + +void GraphicalStapLauncher::onLaunchCancel() +{ + _scriptWindow->hide(); +} diff --git a/grapher/stap-start.glade b/grapher/stap-start.glade new file mode 100644 index 000000000..780c4bd00 --- /dev/null +++ b/grapher/stap-start.glade @@ -0,0 +1,248 @@ + + + + + + + start script + GTK_WINDOW_TOPLEVEL + GTK_WIN_POS_NONE + False + True + False + True + False + False + GDK_WINDOW_TYPE_HINT_DIALOG + GDK_GRAVITY_NORTH_WEST + True + False + + + + True + False + 0 + + + + True + False + 0 + + + + True + script: + False + False + GTK_JUSTIFY_LEFT + False + False + 0.5 + 0.5 + 0 + 0 + PANGO_ELLIPSIZE_NONE + -1 + False + 0 + + + 0 + False + False + + + + + + True + Select A File + GTK_FILE_CHOOSER_ACTION_OPEN + True + False + False + -1 + + + 0 + True + True + + + + + 0 + True + True + + + + + + True + False + 0 + + + + True + stap arguments: + False + False + GTK_JUSTIFY_LEFT + False + False + 0.5 + 0.5 + 0 + 0 + PANGO_ELLIPSIZE_NONE + -1 + False + 0 + + + 0 + False + False + + + + + + True + True + True + True + 0 + + True + ● + False + + + 0 + True + True + + + + + 0 + False + False + + + + + + True + False + 0 + + + + True + script arguments: + False + False + GTK_JUSTIFY_LEFT + False + False + 0.5 + 0.5 + 0 + 0 + PANGO_ELLIPSIZE_NONE + -1 + False + 0 + + + 0 + False + False + + + + + + True + True + True + True + 0 + + True + ● + False + + + 0 + True + True + + + + + 0 + False + False + + + + + + True + False + 0 + + + + + + + + True + True + gtk-cancel + True + GTK_RELIEF_NORMAL + True + + + 0 + False + False + + + + + + True + True + gtk-ok + True + GTK_RELIEF_NORMAL + True + + + 0 + False + False + + + + + 0 + False + False + + + + + + + diff --git a/grapher/stap-start.gladep b/grapher/stap-start.gladep new file mode 100644 index 000000000..315e63d14 --- /dev/null +++ b/grapher/stap-start.gladep @@ -0,0 +1,8 @@ + + + + + Grapher + grapher + FALSE + -- 2.43.5