]> git-server-git.apps.pok.os.sepia.ceph.com Git - ceph.git/commitdiff
cephtool gui: install and locate gui_resources
authorColin Patrick McCabe <cmccabe@alumni.cmu.edu>
Thu, 28 Oct 2010 20:19:10 +0000 (13:19 -0700)
committerColin Patrick McCabe <cmccabe@alumni.cmu.edu>
Thu, 28 Oct 2010 22:51:19 +0000 (15:51 -0700)
Make install now installs the gui resource files into
/usr/share/cephtool/gui_resources (or wherever we configure it to go
using configure). We also support grabbing the resources out of the
local source tree, for when we're running the program from there.

run_gui: catch exceptions and explain what they are, rather than letting
them go to the top level.

GuiMonitor::open_icon: const cleanup.

Signed-off-by: Colin McCabe <colinm@hq.newdream.net>
src/Makefile.am
src/tools/gui.cc
src/tools/gui.h
src/tools/gui_resources.h

index b57000df8caa5b3943f3549465286e6247b19e3d..437f54a28ad791e190e5ba083b5f320b1b3f533d 100644 (file)
@@ -32,9 +32,29 @@ ceph_LDADD = libcrush.a libcommon.a -ledit -lpthread -lm -lcrypto
 ceph_CXXFLAGS = ${AM_CFLAGS}
 
 if WITH_GTK2
+ceph_tool_guidir = ${datadir}/ceph_tool/gui_resources/
+ceph_tool_gui_DATA = \
+       tools/gui_resources/blacklist.svg \
+       tools/gui_resources/client.svg \
+       tools/gui_resources/cluster_stats_window.glade \
+       tools/gui_resources/down_osd.svg \
+       tools/gui_resources/failed_mds.svg \
+       tools/gui_resources/gui_monitor.build \
+       tools/gui_resources/gui_monitor.glade \
+       tools/gui_resources/gui_monitor_old.glade \
+       tools/gui_resources/main-window.glade \
+       tools/gui_resources/mds.svg \
+       tools/gui_resources/monitor.svg \
+       tools/gui_resources/node_stats_window.glade \
+       tools/gui_resources/osd.svg \
+       tools/gui_resources/out_osd.svg \
+       tools/gui_resources/pg.svg \
+       tools/gui_resources/stats_window.glade \
+       tools/gui_resources/stopped_mds.svg
 ceph_SOURCES += tools/gui.cc
 ceph_LDADD += $(GTKMM_LIBS)
 ceph_CXXFLAGS += $(GTKMM_CFLAGS)
+ceph_CXXFLAGS += -DCEPH_TOOL_GUIDIR="\"${ceph_tool_guidir}\""
 endif
 
 cconf_SOURCES = cconf.cc
@@ -353,8 +373,6 @@ common/debug.cc: ceph_ver.h
 common/BackTrace.cc: ceph_ver.h
 config.cc: ceph_ver.h
 
-
-
 # cleaning
 clean-local:
        -rm *.so
index 79e3758a83737aae04ff1c691042c0e82e26edc4..65def5cb8ca2f7a99a50e8d34a370721a3db00b0 100644 (file)
@@ -13,6 +13,8 @@
 #include "tools/gui.h"
 #include "tools/gui_resources.h"
 
+#include <gtkmm.h>
+#include <libgen.h>
 #include <set>
 #include <string>
 
@@ -27,6 +29,44 @@ using std::string;
 #define MY_GET_WIDGET(x) do { builder->get_widget(#x, x); } while(0);
 
 ///////////////// Functions /////////////////
+static std::string resource_path_prefix(".");
+
+static std::string resource_path(const std::string &loc)
+{
+  ostringstream oss;
+  oss << resource_path_prefix << "/" << loc;
+  return oss.str();
+}
+
+//
+// Figure out where our XML files are for the GUI.
+//
+// The first place we look is in "D/gui_resources"
+// (where D is the directory where the executable lives.)
+// If we find it there, we assume that the developer has built the application and is running it
+// from the source tree.
+//
+// If that doesn't work, we use the GUI_RESOURCE_DIR set up by automake.
+// When the user runs make install, all the XML files will get placed there.
+//
+static int calculate_resource_path_prefix(const char *argv0)
+{
+  char d_input[strlen(argv0) + 1];
+  memset(d_input, 0, sizeof(d_input));
+  char *d_name = dirname(d_input);
+
+  ostringstream oss;
+  oss << d_name << "/tools/gui_resources";
+  resource_path_prefix = oss.str();
+  if (!access(resource_path(GUI_MONITOR_BUILDER_FILE).c_str(), R_OK))
+    return 0;
+
+  resource_path_prefix = CEPH_TOOL_GUIDIR;
+  if (!access(resource_path(GUI_MONITOR_BUILDER_FILE).c_str(), R_OK))
+    return 0;
+
+  return EIO;
+}
 
 // Given an integer m and an array of length n, divides m into n categories of
 // equal or near-equal values.
@@ -149,7 +189,7 @@ GuiMonitor::~GuiMonitor()
    delete guiMonitorAboutDialog;
 }
 
-bool GuiMonitor::open_icon(Glib::RefPtr<Gdk::Pixbuf> &icon, std::string path)
+bool GuiMonitor::open_icon(Glib::RefPtr<Gdk::Pixbuf> &icon, const std::string &path)
 {
    try {
       icon = Gdk::Pixbuf::create_from_file(path);
@@ -173,25 +213,25 @@ bool GuiMonitor::init()
 
   if (!guiMonitorWindow)
     return false;
-  if (!open_icon(blacklistIcon, BLACKLIST_ICON_PATH))
+  if (!open_icon(blacklistIcon, resource_path(BLACKLIST_ICON_PATH)))
     return false;
-  if (!open_icon(clientIcon, CLIENT_ICON_PATH))
+  if (!open_icon(clientIcon, resource_path(CLIENT_ICON_PATH)))
     return false;
-  if (!open_icon(MDSIcon, MDS_ICON_PATH))
+  if (!open_icon(MDSIcon, resource_path(MDS_ICON_PATH)))
     return false;
-  //if (!open_icon(failedMDSIcon, FAILED_MDS_ICON_PATH))
+  //if (!open_icon(failedMDSIcon, resource_path(FAILED_MDS_ICON_PATH)))
   //  return false;
-  //if (!open_icon(stoppedMDSIcon, STOPPED_MDS_ICON_PATH))
+  //if (!open_icon(stoppedMDSIcon, resource_path(STOPPED_MDS_ICON_PATH)))
   //  return false;
-  if (!open_icon(monitorIcon, MONITOR_ICON_PATH))
+  if (!open_icon(monitorIcon, resource_path(MONITOR_ICON_PATH)))
     return false;
-  if (!open_icon(upOSDIcon, UP_OSD_ICON_PATH))
+  if (!open_icon(upOSDIcon, resource_path(UP_OSD_ICON_PATH)))
     return false;
-  if (!open_icon(downOSDIcon, DOWN_OSD_ICON_PATH))
+  if (!open_icon(downOSDIcon, resource_path(DOWN_OSD_ICON_PATH)))
     return false;
-  if (!open_icon(outOSDIcon, OUT_OSD_ICON_PATH))
+  if (!open_icon(outOSDIcon, resource_path(OUT_OSD_ICON_PATH)))
     return false;
-  if (!open_icon(PGIcon, PG_ICON_PATH))
+  if (!open_icon(PGIcon, resource_path(PG_ICON_PATH)))
     return false;
 
   // connect callbacks to their corresponding signals.
@@ -974,7 +1014,7 @@ void GuiMonitor::gen_icons_from_node_info(vector<NodeInfo *>& nodeInfo)
 void GuiMonitor::open_stats(enum NodeType type, bool is_cluster, int id)
 {
   Glib::RefPtr<Gtk::Builder> builder_file =
-    Gtk::Builder::create_from_file(STATS_WINDOW_BUILDER_FILE);
+    Gtk::Builder::create_from_file(resource_path(STATS_WINDOW_BUILDER_FILE));
 
   /* note that node_stats will be deleted once the stats window closes */
   StatsWindowInfo *node_stats =
@@ -1268,19 +1308,15 @@ void GuiMonitor::handle_view_node_response(int response)
 
   switch (selected_type) {
     case OSD_NODE: {
-      long id;
+      int id;
 
       try {
-       id = boost::lexical_cast<long>(id_entry);
+       id = boost::lexical_cast<int>(id_entry);
       }
       catch (const boost::bad_lexical_cast &) {
        dialog_error("Node ID must be a number.", Gtk::MESSAGE_ERROR);
        return;
       }
-      if (id < 0) {
-       dialog_error("ID must be a positive number.", Gtk::MESSAGE_ERROR);
-       return;
-      }
       if (id >= g.osdmap.get_max_osd()) {
        dialog_error("OSD does not exist.", Gtk::MESSAGE_ERROR);
        return;
@@ -1696,30 +1732,59 @@ void GuiMonitor::StatsWindowInfo::insert_stats(const std::string &key,
 int run_gui(int argc, char **argv)
 {
   int ret = EXIT_SUCCESS;
+  GuiMonitor *gui = NULL;
 
-  // Now that the monitor map is up and running, initialize the GUI and start
-  // sending observe requests.  The observe requests will update the
-  // guiMonitorWindow (the main window of the Ceph monitor).  Observe requests
-  // will continue to be sent until the application is closed or until the file
-  // system is no longer running.
-  Gtk::Main kit(&argc, &argv);
-
-  // read the Gtk::Builder file that contains the layout of the windows.
-  Glib::RefPtr<Gtk::Builder> builder =
-       Gtk::Builder::create_from_file(GUI_MONITOR_BUILDER_FILE);
+  ret = calculate_resource_path_prefix(argv[0]);
+  if (ret) {
+    cerr << "Couldn't find GUI resource files!" << std::endl;
+    goto done;
+  }
 
-  // stores pointers to all GUI elements
-  GuiMonitor *gui = new GuiMonitor(builder);
+  try {
+    // Now that the monitor map is up and running, initialize the GUI and start
+    // sending observe requests.  The observe requests will update the
+    // guiMonitorWindow (the main window of the Ceph monitor).  Observe requests
+    // will continue to be sent until the application is closed or until the file
+    // system is no longer running.
+    Gtk::Main kit(argc, argv);
+
+    // read the Gtk::Builder file that contains the layout of the windows.
+    Glib::RefPtr<Gtk::Builder> builder =
+         Gtk::Builder::create_from_file(resource_path(GUI_MONITOR_BUILDER_FILE));
+
+    // stores pointers to all GUI elements
+    gui = new GuiMonitor(builder);
+
+    if (!gui->init()) {
+       cerr << "There was a problem with initializing the GUI." << std::endl;
+       ret = EXIT_FAILURE;
+       goto done;
+    }
 
-  if (!gui->init()) {
-     cerr << "There was a problem with initializing the GUI." << std::endl;
-     ret = EXIT_FAILURE;
-     goto done;
+    // The GUI will now enter its main run loop and will
+    // not exit until the GUI closes.
+    gui->run_main_loop(kit);
+  }
+  catch(const Gtk::BuilderError& ex) {
+    std::cerr << "Gtk BuilderError: " << ex.what() << std::endl;
+    ret = EXIT_FAILURE;
+    goto done;
+  }
+  catch(const Glib::FileError& ex) {
+    std::cerr << "FileError: " << ex.what() << std::endl;
+    ret = EXIT_FAILURE;
+    goto done;
+  }
+  catch (const Glib::Exception &e) {
+    cerr << "got Glib exception: " << e.what() << std::endl;
+    ret = EXIT_FAILURE;
+    goto done;
+  }
+  catch (const std::exception &e) {
+    cerr << "got exception: " << e.what() << std::endl;
+    ret = EXIT_FAILURE;
+    goto done;
   }
-
-  // The GUI will now enter its main run loop and will
-  // not exit until the GUI closes.
-  gui->run_main_loop(kit);
 
 done:
   delete gui;
index 8982efd3dfa88087937a47726be892190f288974..a2e403880b42d51b8e008033c22ccedcfa147a8f 100644 (file)
@@ -177,7 +177,7 @@ private:
    * Private Functions
    */
   void get_widgets(Glib::RefPtr<Gtk::Builder> builder_object);
-  bool open_icon(Glib::RefPtr<Gdk::Pixbuf> &icon, std::string path);
+  bool open_icon(Glib::RefPtr<Gdk::Pixbuf> &icon, const std::string &path);
   void connect_signals();
   void link_elements();
   void update_osd_cluster_view();
index 71b4edf08177d1b4f6717a585815bd73221e99ff..1196fbdde081a8a1935c8c9d63a686d8667c70f2 100644 (file)
@@ -2,18 +2,18 @@
 #define GUI_RESOURCES_H
 
 /* TODO: Place these in a resource file or some other mechanism */
-#define GUI_MONITOR_BUILDER_FILE "gui_resources/gui_monitor.build"
-#define STATS_WINDOW_BUILDER_FILE "gui_resources/stats_window.glade"
+#define GUI_MONITOR_BUILDER_FILE      "gui_monitor.build"
+#define STATS_WINDOW_BUILDER_FILE     "stats_window.glade"
 
-#define BLACKLIST_ICON_PATH "gui_resources/blacklist.svg"
-#define CLIENT_ICON_PATH "gui_resources/client.svg"
-#define FAILED_MDS_ICON_PATH "gui_resources/failed_mds.svg"
-#define MDS_ICON_PATH "gui_resources/mds.svg"
-#define MONITOR_ICON_PATH "gui_resources/monitor.svg"
-#define UP_OSD_ICON_PATH "gui_resources/osd.svg"
-#define DOWN_OSD_ICON_PATH "gui_resources/down_osd.svg"
-#define OUT_OSD_ICON_PATH "gui_resources/out_osd.svg"
-#define PG_ICON_PATH "gui_resources/pg.svg"
-#define STOPPED_MDS_ICON_PATH "gui_resources/stopped_mds.svg"
+#define BLACKLIST_ICON_PATH          "blacklist.svg"
+#define CLIENT_ICON_PATH             "client.svg"
+#define FAILED_MDS_ICON_PATH         "failed_mds.svg"
+#define MDS_ICON_PATH                "mds.svg"
+#define MONITOR_ICON_PATH            "monitor.svg"
+#define UP_OSD_ICON_PATH             "osd.svg"
+#define DOWN_OSD_ICON_PATH           "down_osd.svg"
+#define OUT_OSD_ICON_PATH            "out_osd.svg"
+#define PG_ICON_PATH                 "pg.svg"
+#define STOPPED_MDS_ICON_PATH        "stopped_mds.svg"
 
 #endif