23 #include "webview_thread.h" 24 #include "webview_reqproc.h" 26 #include <webview/url_manager.h> 27 #include <webview/nav_manager.h> 41 :
Thread(
"ROSWebviewThread",
Thread::OPMODE_WAITFORWAKEUP)
56 rosnode->advertiseService(
"/webview/register",
57 &ROSWebviewThread::srv_register_cb,
this);
59 rosnode->advertiseService(
"/webview/unregister",
60 &ROSWebviewThread::srv_unregister_cb,
this);
63 rosnode->advertiseService(
"/webview/add_nav_entry",
64 &ROSWebviewThread::srv_add_nav_cb,
this);
66 rosnode->advertiseService(
"/webview/remove_nav_entry",
67 &ROSWebviewThread::srv_remove_nav_cb,
this);
74 __srv_register.shutdown();
75 __srv_unregister.shutdown();
77 __srv_add_nav.shutdown();
78 __srv_remove_nav.shutdown();
80 std::map<std::string, ROSWebviewRequestProcessor *>::iterator i;
81 for (i = __procs.begin(); i != __procs.end(); ++i) {
87 std::map<std::string, std::string>::iterator ne;
88 for (ne = __nav_entries.begin(); ne != __nav_entries.end(); ++ne) {
91 __nav_entries.clear();
102 ROSWebviewThread::srv_register_cb(fawkes_msgs::WebviewUrlRegistration::Request &req,
103 fawkes_msgs::WebviewUrlRegistration::Response &resp)
105 if (__procs.find(req.url_prefix) != __procs.end()) {
106 resp.success =
false;
107 resp.error =
"A processor has already been registered for this prefix";
111 req.service_name.c_str(), req.url_prefix.c_str());
117 __procs[req.url_prefix]);
120 resp.success =
false;
121 resp.error = std::string(
"Failed to register processor: ") + e.
what();
123 }
catch (ros::Exception &e) {
124 resp.success =
false;
125 resp.error = std::string(
"Registration failed: ") + e.what();
132 ROSWebviewThread::srv_unregister_cb(fawkes_msgs::WebviewUrlRegistration::Request &req,
133 fawkes_msgs::WebviewUrlRegistration::Response &resp)
136 req.url_prefix.c_str());
137 if (__procs.find(req.url_prefix) == __procs.end()) {
138 resp.success =
false;
139 resp.error =
"A processor has not been registered for this prefix";
141 if (__procs.find(req.url_prefix) != __procs.end()) {
143 req.url_prefix.c_str());
145 delete __procs[req.url_prefix];
146 __procs.erase(req.url_prefix);
149 req.url_prefix.c_str());
157 ROSWebviewThread::srv_add_nav_cb(fawkes_msgs::WebviewNavRegistration::Request &req,
158 fawkes_msgs::WebviewNavRegistration::Response &resp)
162 __nav_entries[req.url] = req.name;
165 resp.success =
false;
166 resp.error = e.
what();
173 ROSWebviewThread::srv_remove_nav_cb(fawkes_msgs::WebviewNavRegistration::Request &req,
174 fawkes_msgs::WebviewNavRegistration::Response &resp)
177 __nav_entries.erase(req.url);
WebNavManager * webview_nav_manager
Webview navigation manager.
ROSWebviewThread()
Constructor.
virtual void log_info(const char *component, const char *format,...)=0
Log informational message.
virtual void finalize()
Finalize the thread.
Fawkes library namespace.
virtual const char * what() const
Get primary string.
Thread class encapsulation of pthreads.
Logger * logger
This is the Logger member used to access the logger.
virtual void init()
Initialize the thread.
virtual ~ROSWebviewThread()
Destructor.
Base class for exceptions in Fawkes.
WebUrlManager * webview_url_manager
Webview request processor manager.
void unregister_baseurl(const char *url_prefix)
Remove a request processor.
const char * name() const
Get name of thread.
virtual void log_warn(const char *component, const char *format,...)=0
Log warning message.
void add_nav_entry(std::string baseurl, std::string name)
Add a navigation entry.
virtual void log_debug(const char *component, const char *format,...)=0
Log debug message.
Convert webview requests to ROS service calls.
LockPtr< ros::NodeHandle > rosnode
Central ROS node handle.
void remove_nav_entry(std::string baseurl)
Remove a navigation entry.
void register_baseurl(const char *url_prefix, WebRequestProcessor *processor)
Add a request processor.
virtual void loop()
Code to execute in the thread.