00001 /************************************************************************************************** 00002 Software License Agreement (BSD License) 00003 00004 Copyright (c) 2011-2013, LAR toolkit developers - University of Aveiro - http://lars.mec.ua.pt 00005 All rights reserved. 00006 00007 Redistribution and use in source and binary forms, with or without modification, are permitted 00008 provided that the following conditions are met: 00009 00010 *Redistributions of source code must retain the above copyright notice, this list of 00011 conditions and the following disclaimer. 00012 *Redistributions in binary form must reproduce the above copyright notice, this list of 00013 conditions and the following disclaimer in the documentation and/or other materials provided 00014 with the distribution. 00015 *Neither the name of the University of Aveiro nor the names of its contributors may be used to 00016 endorse or promote products derived from this software without specific prior written permission. 00017 00018 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR 00019 IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND 00020 FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR 00021 CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 00022 DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 00023 DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER 00024 IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT 00025 OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 00026 ***************************************************************************************************/ 00032 #include <ros/ros.h> 00033 00034 #include "manager_gui.h" 00035 #include <gtkmm/application.h> 00036 00037 #include <signal.h> 00038 #include <ros/xmlrpc_manager.h> 00039 00040 using namespace std; 00041 00042 // Signal-safe flag for whether shutdown is requested 00043 sig_atomic_t volatile request_shutdown = 0; 00044 00045 void sigHandler(int s) 00046 { 00047 request_shutdown=1; 00048 } 00049 00050 //Replacement "shutdown" XMLRPC callback 00051 void shutdownCallback(XmlRpc::XmlRpcValue& params, XmlRpc::XmlRpcValue& result) 00052 { 00053 int num_params = 0; 00054 if (params.getType() == XmlRpc::XmlRpcValue::TypeArray) 00055 num_params = params.size(); 00056 if (num_params > 1) 00057 { 00058 std::string reason = params[1]; 00059 ROS_WARN("Shutdown request received. Reason: [%s]", reason.c_str()); 00060 request_shutdown=1; // Set flag 00061 } 00062 00063 result = ros::xmlrpc::responseInt(1, "", 0); 00064 } 00065 00066 int main(int argc,char**argv) 00067 { 00068 ros::init(argc,argv,"manager_gui",ros::init_options::NoSigintHandler); 00069 signal(SIGINT,sigHandler); 00070 00071 // Override XMLRPC shutdown 00072 ros::XMLRPCManager::instance()->unbind("shutdown"); 00073 ros::XMLRPCManager::instance()->bind("shutdown", shutdownCallback); 00074 00075 Glib::RefPtr<Gtk::Application> app = Gtk::Application::create(argc, argv, "org.gtkmm.example"); 00076 00077 ManagerGui gui(&request_shutdown); 00078 00079 return app->run(gui); 00080 }