23 #include "webview_thread.h"
24 #include "webview_reqproc.h"
26 #include <webview/url_manager.h>
27 #include <webview/nav_manager.h>
31 using namespace fawkes;
41 :
Thread(
"ROSWebviewThread",
Thread::OPMODE_WAITFORWAKEUP)
56 rosnode->advertiseService(
"/webview/register",
57 &ROSWebviewThread::srv_register_cb,
60 rosnode->advertiseService(
"/webview/unregister",
61 &ROSWebviewThread::srv_unregister_cb,
65 rosnode->advertiseService(
"/webview/add_nav_entry",
66 &ROSWebviewThread::srv_add_nav_cb,
69 rosnode->advertiseService(
"/webview/remove_nav_entry",
70 &ROSWebviewThread::srv_remove_nav_cb,
78 __srv_register.shutdown();
79 __srv_unregister.shutdown();
81 __srv_add_nav.shutdown();
82 __srv_remove_nav.shutdown();
84 std::map<std::string, ROSWebviewRequestProcessor *>::iterator i;
85 for (i = __procs.begin(); i != __procs.end(); ++i) {
91 std::map<std::string, std::string>::iterator ne;
92 for (ne = __nav_entries.begin(); ne != __nav_entries.end(); ++ne) {
95 __nav_entries.clear();
106 ROSWebviewThread::srv_register_cb(webview_msgs::UrlRegistration::Request &req,
107 webview_msgs::UrlRegistration::Response &resp)
109 if (__procs.find(req.url_prefix) != __procs.end()) {
110 resp.success =
false;
111 resp.error =
"A processor has already been registered for this prefix";
115 req.service_name.c_str(), req.url_prefix.c_str());
121 __procs[req.url_prefix]);
124 resp.success =
false;
125 resp.error = std::string(
"Failed to register processor: ") + e.
what();
127 }
catch (ros::Exception &e) {
128 resp.success =
false;
129 resp.error = std::string(
"Registration failed: ") + e.what();
136 ROSWebviewThread::srv_unregister_cb(webview_msgs::UrlRegistration::Request &req,
137 webview_msgs::UrlRegistration::Response &resp)
140 req.url_prefix.c_str());
141 if (__procs.find(req.url_prefix) == __procs.end()) {
142 resp.success =
false;
143 resp.error =
"A processor has not been registered for this prefix";
145 if (__procs.find(req.url_prefix) != __procs.end()) {
147 req.url_prefix.c_str());
149 delete __procs[req.url_prefix];
150 __procs.erase(req.url_prefix);
153 req.url_prefix.c_str());
161 ROSWebviewThread::srv_add_nav_cb(webview_msgs::NavRegistration::Request &req,
162 webview_msgs::NavRegistration::Response &resp)
166 __nav_entries[req.url] = req.name;
169 resp.success =
false;
170 resp.error = e.
what();
177 ROSWebviewThread::srv_remove_nav_cb(webview_msgs::NavRegistration::Request &req,
178 webview_msgs::NavRegistration::Response &resp)
181 __nav_entries.erase(req.url);