[Fawkes Git] branch/ggierse/webview-send-msg: created (0.5.0-3085-gd5de3fb)

Gesche Gierse gierse at kbsg.rwth-aachen.de
Thu Jan 14 17:55:11 CET 2016


Changes have been pushed for the project "Fawkes Robotics Software Framework".

Gitweb: http://git.fawkesrobotics.org/fawkes.git
Trac:   http://trac.fawkesrobotics.org

The branch, ggierse/webview-send-msg has been created
        at  d5de3fbecb92e2506079ea0c0b804b1b8d187e69 (commit)

http://git.fawkesrobotics.org/fawkes.git/ggierse/webview-send-msg

- *Log* ---------------------------------------------------------------
commit 38b17ab77d2476fe4519a4890648a3d8f5b1e358
Author:     Gesche Gierse <gierse at kbsg.rwth-aachen.de>
AuthorDate: Thu Jan 14 15:25:52 2016 +0100
Commit:     Gesche Gierse <gierse at kbsg.rwth-aachen.de>
CommitDate: Thu Jan 14 15:25:52 2016 +0100

    webview: fail gracefully, if url ends with a "/view/"
    
    Do not segfault but show a 404 instead.

http://git.fawkesrobotics.org/fawkes.git/commit/38b17ab
http://trac.fawkesrobotics.org/changeset/38b17ab

- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
commit b3e6b450d5b42b50f32a63363ab8610a21d9f889
Author:     Gesche Gierse <gierse at kbsg.rwth-aachen.de>
AuthorDate: Thu Jan 14 15:34:49 2016 +0100
Commit:     Gesche Gierse <gierse at kbsg.rwth-aachen.de>
CommitDate: Thu Jan 14 15:34:49 2016 +0100

    webview: show all sendable msgs and input forms for them
    
    Currently only optimizing for type bool

http://git.fawkesrobotics.org/fawkes.git/commit/b3e6b45
http://trac.fawkesrobotics.org/changeset/b3e6b45

- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
commit 813ae8e33c741296ab100e2b336ccb7a6b35d03a
Author:     Gesche Gierse <gierse at kbsg.rwth-aachen.de>
AuthorDate: Thu Jan 14 15:45:58 2016 +0100
Commit:     Gesche Gierse <gierse at kbsg.rwth-aachen.de>
CommitDate: Thu Jan 14 15:45:58 2016 +0100

    libinterface: add method to return enum value names
    
    The field iterator can now return all possible enum values as a list
    of c strings.

http://git.fawkesrobotics.org/fawkes.git/commit/813ae8e
http://trac.fawkesrobotics.org/changeset/813ae8e

- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
commit aa507ca04eb9c477b477cb9a7a2206c6917e5386
Author:     Gesche Gierse <gierse at kbsg.rwth-aachen.de>
AuthorDate: Thu Jan 14 15:47:15 2016 +0100
Commit:     Gesche Gierse <gierse at kbsg.rwth-aachen.de>
CommitDate: Thu Jan 14 15:47:15 2016 +0100

    webview: show radio input form for enums
    
    Dynamically get all possible values and generate according radio forms.

http://git.fawkesrobotics.org/fawkes.git/commit/aa507ca
http://trac.fawkesrobotics.org/changeset/aa507ca

- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
commit d5de3fbecb92e2506079ea0c0b804b1b8d187e69
Author:     Gesche Gierse <gierse at kbsg.rwth-aachen.de>
AuthorDate: Thu Jan 14 15:51:50 2016 +0100
Commit:     Gesche Gierse <gierse at kbsg.rwth-aachen.de>
CommitDate: Thu Jan 14 15:51:50 2016 +0100

    webview: generate if msg based on form post
    
    Does not yet support all datatypes. Additionally, error handling
    on bad/malicious input has to be added.

http://git.fawkesrobotics.org/fawkes.git/commit/d5de3fb
http://trac.fawkesrobotics.org/changeset/d5de3fb

- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -


- *Summary* -----------------------------------------------------------
 src/libs/interface/field_iterator.cpp        |   12 +++
 src/libs/interface/field_iterator.h          |    2 +
 src/plugins/webview/blackboard_processor.cpp |   98 +++++++++++++++++++++++++-
 3 files changed, 111 insertions(+), 1 deletions(-)


- *Diffs* -------------------------------------------------------------

- *commit* 38b17ab77d2476fe4519a4890648a3d8f5b1e358 - - - - - - - - - -
Author:  Gesche Gierse <gierse at kbsg.rwth-aachen.de>
Date:    Thu Jan 14 15:25:52 2016 +0100
Subject: webview: fail gracefully, if url ends with a "/view/"

 src/plugins/webview/blackboard_processor.cpp |   15 ++++++++++++++-
 1 files changed, 14 insertions(+), 1 deletions(-)

_Diff for modified files_:
diff --git a/src/plugins/webview/blackboard_processor.cpp b/src/plugins/webview/blackboard_processor.cpp
index 0617e05..97a70ff 100644
--- a/src/plugins/webview/blackboard_processor.cpp
+++ b/src/plugins/webview/blackboard_processor.cpp
@@ -25,6 +25,8 @@
 #include <webview/file_reply.h>
 #include <webview/error_reply.h>
 
+#include <core/exceptions/software.h>
+
 #include <blackboard/blackboard.h>
 #include <interface/interface.h>
 #include <interface/field_iterator.h>
@@ -162,7 +164,18 @@ WebviewBlackBoardRequestProcessor::process_request(const fawkes::WebRequest *req
       }
 
       if (subpath.find("/view/") == 0) {
-	std::string iuid = subpath.substr(subpath.find_first_not_of("/", std::string("/view/").length()));
+        std::string iuid = "";
+        try {
+          std::size_t tmp = subpath.find_first_not_of("/", std::string("/view/").length());
+          if (tmp == std::string::npos) { throw IllegalArgumentException("String ended after \"/view/\"."); }
+          iuid = subpath.substr(tmp);
+        } catch (Exception &e) {
+          return new WebErrorPageReply(WebReply::HTTP_NOT_FOUND,
+                           "Could not parse interface id: %s", e.what());
+        } catch (std::exception &e) {
+          return new WebErrorPageReply(WebReply::HTTP_NOT_FOUND,
+                           "Could not parse interface id: %s", e.what());
+        }
 	std::string iftype = iuid.substr(0, iuid.find("::"));
 	std::string ifname = iuid.substr(iuid.find("::") + 2);
 

- *commit* b3e6b450d5b42b50f32a63363ab8610a21d9f889 - - - - - - - - - -
Author:  Gesche Gierse <gierse at kbsg.rwth-aachen.de>
Date:    Thu Jan 14 15:34:49 2016 +0100
Subject: webview: show all sendable msgs and input forms for them

 src/plugins/webview/blackboard_processor.cpp |   44 +++++++++++++++++++++++++-
 1 files changed, 43 insertions(+), 1 deletions(-)

_Diff for modified files_:
diff --git a/src/plugins/webview/blackboard_processor.cpp b/src/plugins/webview/blackboard_processor.cpp
index 97a70ff..430141e 100644
--- a/src/plugins/webview/blackboard_processor.cpp
+++ b/src/plugins/webview/blackboard_processor.cpp
@@ -274,8 +274,50 @@ WebviewBlackBoardRequestProcessor::process_request(const fawkes::WebRequest *req
 	    *r += " </tr>\n";
 	  }
 	  r->append_body("</table>\n");
+
+        // Show possible messages
+        std::list<const char *> msg_types = iface->get_message_types();
+        if (!msg_types.empty()){
+          *r +="<h3>Messages</h3>";
+
+          /*r->append_body("<table>\n"
+                   " <tr>\n"
+                   "  <th>Name</th><th>Field Name</th><th>Type</th><th>Value</th>\n"
+                   " </tr>\n");
+        */
+          for (std::list<const char *>::iterator msgit = msg_types.begin(); msgit != msg_types.end(); ++msgit) {
+            r->append_body("<b>%s</b>", *msgit);
+            r->append_body("<p><form action=\"%s/view/%s/send/%s\" method=\"post\">",
+                        __baseurl, iuid.c_str(), *msgit);
+            Message* ifmsg = iface->create_message(*msgit);
+              /*r->append_body("  <td rowspan=\"%d\">%s</td>\n </tr>\n",
+                             ifmsg->num_fields()+1,
+                            *msgit);*/
+            for (InterfaceFieldIterator mfi = ifmsg->fields(); mfi != ifmsg->fields_end(); ++mfi) {
+              //*r += " <tr>\n";
+              if ( mfi.get_length() > 1 ) {
+                r->append_body("%s (%s [%zu]): <input type=\"text\" name=\"%s\" ><br>\n",
+                          mfi.get_name(), mfi.get_typename(),
+                          mfi.get_length(), mfi.get_name());
+              } else {
+                switch (mfi.get_type()) {
+                  case IFT_BOOL:
+                    r->append_body("%s (%s): <input type=\"radio\" name=\"%s\" value=\"true\" checked>true"
+                          "<input type=\"radio\" name=\"%s\" value=\"false\">false<br>\n",
+                          mfi.get_name(), mfi.get_typename(), mfi.get_name(), mfi.get_name());
+                    break;
+                  default:
+                    r->append_body("%s (%s): <input type=\"text\" name=\"%s\" ><br>\n",
+                          mfi.get_name(), mfi.get_typename(), mfi.get_name());
+                }
+              }
+            }
+            *r += "<input type=\"submit\" value=\"Send\" /></form></p>\n";
+          }
+          //r->append_body("</table>\n");
+        }
 	  r->append_body("<p><a href=\"%s\">Clear detailed</a></p>\n", __baseurl);
-	}
+      }
       } else if (subpath.find("/graph") == 0) {
 	std::string graph_baseurl("/graph/");
 	std::string graph_node =

- *commit* 813ae8e33c741296ab100e2b336ccb7a6b35d03a - - - - - - - - - -
Author:  Gesche Gierse <gierse at kbsg.rwth-aachen.de>
Date:    Thu Jan 14 15:45:58 2016 +0100
Subject: libinterface: add method to return enum value names

 src/libs/interface/field_iterator.cpp |   12 ++++++++++++
 src/libs/interface/field_iterator.h   |    2 ++
 2 files changed, 14 insertions(+), 0 deletions(-)

_Diff for modified files_:
diff --git a/src/libs/interface/field_iterator.cpp b/src/libs/interface/field_iterator.cpp
index 07d44b6..58aa388 100644
--- a/src/libs/interface/field_iterator.cpp
+++ b/src/libs/interface/field_iterator.cpp
@@ -254,6 +254,18 @@ InterfaceFieldIterator::is_enum() const
   }
 }
 
+/** Return the list of all enum value names.
+ * @return a list of the possible enum values.
+ */
+std::list<const char*>
+InterfaceFieldIterator::get_enum_valuenames() const
+{
+  std::list<const char*> enums;
+  for (interface_enum_map_t::const_iterator enum_it = __infol->enum_map->begin(); enum_it != __infol->enum_map->end(); ++enum_it) { // TODO
+    enums.push_back(enum_it->second.c_str());
+  }
+  return enums;
+}
 
 /** Get name of current field.
  * @return field name
diff --git a/src/libs/interface/field_iterator.h b/src/libs/interface/field_iterator.h
index 3a89352..939c529 100644
--- a/src/libs/interface/field_iterator.h
+++ b/src/libs/interface/field_iterator.h
@@ -28,6 +28,7 @@
 #include <interface/types.h>
 
 #define __STD_LIMIT_MACROS
+#include <list>
 #include <stdint.h>
 
 namespace fawkes {
@@ -55,6 +56,7 @@ class InterfaceFieldIterator
   interface_fieldtype_t  get_type() const;
   const char *           get_typename() const;
   bool                   is_enum() const;
+  std::list<const char*> get_enum_valuenames() const;
   const char *           get_name() const;
   const void *           get_value() const;
   const char *           get_value_string(const char *array_sep = ", ");

- *commit* aa507ca04eb9c477b477cb9a7a2206c6917e5386 - - - - - - - - - -
Author:  Gesche Gierse <gierse at kbsg.rwth-aachen.de>
Date:    Thu Jan 14 15:47:15 2016 +0100
Subject: webview: show radio input form for enums

 src/plugins/webview/blackboard_processor.cpp |   10 ++++++++++
 1 files changed, 10 insertions(+), 0 deletions(-)

_Diff for modified files_:
diff --git a/src/plugins/webview/blackboard_processor.cpp b/src/plugins/webview/blackboard_processor.cpp
index 430141e..a5577f5 100644
--- a/src/plugins/webview/blackboard_processor.cpp
+++ b/src/plugins/webview/blackboard_processor.cpp
@@ -306,6 +306,16 @@ WebviewBlackBoardRequestProcessor::process_request(const fawkes::WebRequest *req
                           "<input type=\"radio\" name=\"%s\" value=\"false\">false<br>\n",
                           mfi.get_name(), mfi.get_typename(), mfi.get_name(), mfi.get_name());
                     break;
+                  case IFT_ENUM:
+                    {
+                      std::list<const char*> enum_values = mfi.get_enum_valuenames();
+                      r->append_body("%s:<br>", mfi.get_name());
+                      for (std::list<const char*>::iterator enum_it = enum_values.begin(); enum_it != enum_values.end(); ++enum_it) { // TODO improve formatting
+                        r->append_body("<input type=\"radio\" name=\"%s\" value=\"%s\">%s<br>",
+                            mfi.get_name(), *enum_it, *enum_it);
+                      }
+                      break;
+                    }
                   default:
                     r->append_body("%s (%s): <input type=\"text\" name=\"%s\" ><br>\n",
                           mfi.get_name(), mfi.get_typename(), mfi.get_name());

- *commit* d5de3fbecb92e2506079ea0c0b804b1b8d187e69 - - - - - - - - - -
Author:  Gesche Gierse <gierse at kbsg.rwth-aachen.de>
Date:    Thu Jan 14 15:51:50 2016 +0100
Subject: webview: generate if msg based on form post

 src/plugins/webview/blackboard_processor.cpp |   44 ++++++++++++++++++++++++++
 1 files changed, 44 insertions(+), 0 deletions(-)

_Diff for modified files_:
diff --git a/src/plugins/webview/blackboard_processor.cpp b/src/plugins/webview/blackboard_processor.cpp
index a5577f5..21ed74e 100644
--- a/src/plugins/webview/blackboard_processor.cpp
+++ b/src/plugins/webview/blackboard_processor.cpp
@@ -176,6 +176,15 @@ WebviewBlackBoardRequestProcessor::process_request(const fawkes::WebRequest *req
           return new WebErrorPageReply(WebReply::HTTP_NOT_FOUND,
                            "Could not parse interface id: %s", e.what());
         }
+        std::string message_type;
+        bool send = false;
+        if (iuid.find("/send/") != std::string::npos) {
+          std::string::size_type slash_pos1 = iuid.find("/");
+          std::string::size_type slash_pos2 = iuid.find("/", slash_pos1+1);
+          message_type = iuid.substr(slash_pos2+1,iuid.length());
+          iuid = iuid.substr(0,slash_pos1);
+          send = true;
+      }
 	std::string iftype = iuid.substr(0, iuid.find("::"));
 	std::string ifname = iuid.substr(iuid.find("::") + 2);
 
@@ -192,6 +201,41 @@ WebviewBlackBoardRequestProcessor::process_request(const fawkes::WebRequest *req
 	  Interface *iface = __interfaces[iuid];
 	  iface->read();
 
+        if(send){
+          // handle send message request
+          Message* msg_to_send = iface->create_message(message_type.c_str()); //TODO catch if not possible
+          bool no_errors = true;
+          if (!iface->has_writer()){
+            r->append_body("<font color=\"red\">Error: Cannot send message because the interface has no writer!</font>\n");
+            no_errors = false;
+          }else{
+            for (InterfaceFieldIterator mfi = msg_to_send->fields(); mfi != msg_to_send->fields_end(); ++mfi) {
+              if(!request->post_value(mfi.get_name()).empty()){
+
+                switch(mfi.get_type()){
+                  case IFT_STRING: // TODO check length of input
+                      mfi.set_string(request->post_value(mfi.get_name()).c_str());
+                    break;
+                  case IFT_ENUM:
+                    mfi.set_enum_string(request->post_value(mfi.get_name()).c_str());
+                    break;
+                  case IFT_BOOL:
+                    mfi.set_bool( (strcmp("true",request->post_value(mfi.get_name()).c_str()) != 0) ? true : false);
+                    break;
+                  default:
+                    r->append_body("<font color=\"red\">Error: Type %s is currently not supported by webview send message functionality.</font>\n", mfi.get_typename());
+                    no_errors = false;
+                }
+                r->append_body("Received value %s for the field %s\n",request->post_value(mfi.get_name()).c_str(), mfi.get_name());
+              }
+            }
+          }
+          if (no_errors){
+            unsigned int msg_id = iface->msgq_enqueue(msg_to_send);
+             r->append_body("Sent Message of type %s with id %d\n",message_type.c_str(), msg_id);
+          }
+        }
+
 	  /*
 	   *r += "<script type=\"text/javascript\">\n"
 	   "  $(function(){\n"




-- 
Fawkes Robotics Framework                 http://www.fawkesrobotics.org


More information about the fawkes-commits mailing list