00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030 #include "logger_level_panel.h"
00031
00032 #include <ros/ros.h>
00033 #include <roscpp/GetLoggers.h>
00034 #include <roscpp/SetLoggerLevel.h>
00035
00036 #include <wx/msgdlg.h>
00037
00038 #include <algorithm>
00039
00040 namespace rxtools
00041 {
00042
00043 LoggerLevelPanel::LoggerLevelPanel(wxWindow* parent, int id, wxPoint pos, wxSize size, int style)
00044 : LoggerLevelPanelBase(parent, id, pos, size, style)
00045 {
00046 fillNodeList();
00047 }
00048
00049 LoggerLevelPanel::~LoggerLevelPanel()
00050 {
00051
00052 }
00053
00054 void LoggerLevelPanel::fillNodeList()
00055 {
00056 nodes_box_->Clear();
00057
00058 ros::V_string nodes;
00059 ros::master::getNodes(nodes);
00060
00061 std::sort(nodes.begin(), nodes.end());
00062
00063 ros::V_string::iterator it = nodes.begin();
00064 ros::V_string::iterator end = nodes.end();
00065 for (; it != end; ++it)
00066 {
00067 const std::string& node = *it;
00068
00069 std::string error;
00070 if (!ros::names::validate(node, error))
00071 {
00072 ROS_ERROR("Node [%s] has an invalid name", node.c_str());
00073 continue;
00074 }
00075
00076 if (ros::service::exists(node + "/get_loggers", false))
00077 {
00078 nodes_box_->Append(wxString::FromAscii(node.c_str()));
00079 }
00080 }
00081 }
00082
00083 void LoggerLevelPanel::refresh()
00084 {
00085 fillNodeList();
00086 }
00087
00088 void LoggerLevelPanel::onNodesRefresh( wxCommandEvent& event )
00089 {
00090 fillNodeList();
00091 }
00092
00093 void LoggerLevelPanel::onNodeSelected( wxCommandEvent& event )
00094 {
00095 loggers_box_->Clear();
00096 levels_box_->Clear();
00097 loggers_.clear();
00098
00099 std::string node = (const char*)nodes_box_->GetStringSelection().fn_str();
00100 if (node.empty())
00101 {
00102 return;
00103 }
00104
00105 roscpp::GetLoggers srv;
00106 if (ros::service::call(node + "/get_loggers", srv))
00107 {
00108 std::vector<roscpp::Logger>::iterator it = srv.response.loggers.begin();
00109 std::vector<roscpp::Logger>::iterator end = srv.response.loggers.end();
00110 for (; it != end; ++it)
00111 {
00112 roscpp::Logger& logger = *it;
00113 const std::string& name = logger.name;
00114
00115 loggers_[name] = logger.level;
00116
00117 loggers_box_->Append(wxString::FromAscii(name.c_str()));
00118 }
00119 }
00120 else
00121 {
00122 wxString msg;
00123 msg.Printf(wxT("Failed to call service [%s/get_loggers]. Did the node go away?"), wxString::FromAscii(node.c_str()).c_str());
00124 wxMessageBox(msg, wxT("Failed to lookup loggers"), wxOK|wxICON_ERROR);
00125 }
00126 }
00127
00128 void LoggerLevelPanel::onLoggerSelected( wxCommandEvent& event )
00129 {
00130 levels_box_->Clear();
00131
00132 std::string logger = (const char*)loggers_box_->GetStringSelection().fn_str();
00133 if (logger.empty())
00134 {
00135 return;
00136 }
00137
00138 M_string::iterator it = loggers_.find(logger);
00139 std::string level = it->second;
00140
00141 std::transform(level.begin(), level.end(), level.begin(), (int(*)(int))std::toupper);
00142
00143 int selection = 0;
00144 if (level == "DEBUG")
00145 {
00146 selection = 0;
00147 }
00148 else if (level == "INFO")
00149 {
00150 selection = 1;
00151 }
00152 else if (level == "WARN")
00153 {
00154 selection = 2;
00155 }
00156 else if (level == "ERROR")
00157 {
00158 selection = 3;
00159 }
00160 else if (level == "FATAL")
00161 {
00162 selection = 4;
00163 }
00164 else
00165 {
00166 ROS_ERROR("Unknown logger level [%s]", level.c_str());
00167 selection = -1;
00168 }
00169
00170 levels_box_->Append(wxT("Debug"));
00171 levels_box_->Append(wxT("Info"));
00172 levels_box_->Append(wxT("Warn"));
00173 levels_box_->Append(wxT("Error"));
00174 levels_box_->Append(wxT("Fatal"));
00175 levels_box_->SetSelection(selection);
00176 }
00177
00178 void LoggerLevelPanel::onLevelSelected( wxCommandEvent& event )
00179 {
00180 std::string level = (const char*)levels_box_->GetStringSelection().fn_str();
00181 if (level.empty())
00182 {
00183 return;
00184 }
00185
00186 std::string node = (const char*)nodes_box_->GetStringSelection().fn_str();
00187 std::string logger = (const char*)loggers_box_->GetStringSelection().fn_str();
00188
00189 roscpp::SetLoggerLevel srv;
00190 srv.request.logger = logger;
00191 srv.request.level = level;
00192 if (!ros::service::call(node + "/set_logger_level", srv))
00193 {
00194 wxString msg;
00195 msg.Printf(wxT("Failed to call service [%s/set_logger_level]. Did the node go away?"), wxString::FromAscii(node.c_str()).c_str());
00196 wxMessageBox(msg, wxT("Failed to set logger level"), wxOK|wxICON_ERROR);
00197 }
00198 else
00199 {
00200 loggers_[logger] = level;
00201 }
00202 }
00203
00204 }