[Fawkes Git] branch/ggierse/webview-send-msg: 7 revs updated. (0.5.0-3092-g932ec84)

Gesche Gierse gierse at kbsg.rwth-aachen.de
Thu Jan 21 18:45:02 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 updated
        to  932ec844cfc034c52a9b9188cf416102c2fe568b (commit)
       via  f321f1948f8f61bd590f34b71006ca61801328e7 (commit)
       via  e6c9312d6660dcd54358dea68f24b485ac99b8de (commit)
       via  6b164eb8d1d66f4123c4c8d3d38c08b161056229 (commit)
       via  9f1bf92bd898d609eb0dfbbd5a41470b0c2b3cbd (commit)
       via  8143f3ee838f67cac9d13c1449ec71664bb13ca4 (commit)
       via  66388950f0883a6404fd68370dea2e7326a05056 (commit)
      from  d5de3fbecb92e2506079ea0c0b804b1b8d187e69 (commit)

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

Those revisions listed above that are new to this repository have
not appeared on any other notification email; so we list those
revisions in full, below.

- *Log* ---------------------------------------------------------------
commit 66388950f0883a6404fd68370dea2e7326a05056
Author:     Gesche Gierse <gierse at kbsg.rwth-aachen.de>
AuthorDate: Thu Jan 21 12:04:38 2016 +0100
Commit:     Gesche Gierse <gierse at kbsg.rwth-aachen.de>
CommitDate: Thu Jan 21 12:04:38 2016 +0100

    webview: add extra form for integers

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

- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
commit 8143f3ee838f67cac9d13c1449ec71664bb13ca4
Author:     Gesche Gierse <gierse at kbsg.rwth-aachen.de>
AuthorDate: Thu Jan 21 12:08:42 2016 +0100
Commit:     Gesche Gierse <gierse at kbsg.rwth-aachen.de>
CommitDate: Thu Jan 21 12:08:42 2016 +0100

    webview: minimize msg forms with javascript
    
    Msg names are clickable to expand the according form.
    Minimized as default.

http://git.fawkesrobotics.org/fawkes.git/commit/8143f3e
http://trac.fawkesrobotics.org/changeset/8143f3e

- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
commit 9f1bf92bd898d609eb0dfbbd5a41470b0c2b3cbd
Author:     Gesche Gierse <gierse at kbsg.rwth-aachen.de>
AuthorDate: Thu Jan 21 16:57:09 2016 +0100
Commit:     Gesche Gierse <gierse at kbsg.rwth-aachen.de>
CommitDate: Thu Jan 21 16:57:09 2016 +0100

    webview: catch if typo in message name, improve 404 pages
    
    Show a link back to the last page if some error was caught.

http://git.fawkesrobotics.org/fawkes.git/commit/9f1bf92
http://trac.fawkesrobotics.org/changeset/9f1bf92

- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
commit 6b164eb8d1d66f4123c4c8d3d38c08b161056229
Author:     Gesche Gierse <gierse at kbsg.rwth-aachen.de>
AuthorDate: Thu Jan 21 17:48:22 2016 +0100
Commit:     Gesche Gierse <gierse at kbsg.rwth-aachen.de>
CommitDate: Thu Jan 21 17:48:22 2016 +0100

    webview: send msg: parse all types of non-array input
    
    Still to be done: Arrays.
    In general, security could be improved, the string conversions
    provided by the fawkes util use methods that may lead to
    unspecified behavior, if parsing is not possible.

http://git.fawkesrobotics.org/fawkes.git/commit/6b164eb
http://trac.fawkesrobotics.org/changeset/6b164eb

- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
commit e6c9312d6660dcd54358dea68f24b485ac99b8de
Author:     Gesche Gierse <gierse at kbsg.rwth-aachen.de>
AuthorDate: Thu Jan 21 17:50:04 2016 +0100
Commit:     Gesche Gierse <gierse at kbsg.rwth-aachen.de>
CommitDate: Thu Jan 21 17:50:04 2016 +0100

    webview: add number input which respects different int types
    
    Allows input between min and max value of the specified integer
    type using html5.

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

- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
commit f321f1948f8f61bd590f34b71006ca61801328e7
Author:     Gesche Gierse <gierse at kbsg.rwth-aachen.de>
AuthorDate: Thu Jan 21 17:59:04 2016 +0100
Commit:     Gesche Gierse <gierse at kbsg.rwth-aachen.de>
CommitDate: Thu Jan 21 17:59:04 2016 +0100

    webview: specialize input for string, double, float
    
    Use pattern to ensure that string is of specified length.
    Use pattern to ensure that double and float are floating point
    numbers.

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

- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
commit 932ec844cfc034c52a9b9188cf416102c2fe568b
Author:     Gesche Gierse <gierse at kbsg.rwth-aachen.de>
AuthorDate: Thu Jan 21 18:44:47 2016 +0100
Commit:     Gesche Gierse <gierse at kbsg.rwth-aachen.de>
CommitDate: Thu Jan 21 18:44:47 2016 +0100

    webview: make send msg feature configurable
    
    Allow to configure whether to enable the feature that
    messages can be send via webview.

http://git.fawkesrobotics.org/fawkes.git/commit/932ec84
http://trac.fawkesrobotics.org/changeset/932ec84

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


- *Summary* -----------------------------------------------------------
 cfg/conf.d/webview.yaml                      |    5 +-
 src/plugins/webview/blackboard_processor.cpp |  222 ++++++++++++++++++++++----
 src/plugins/webview/blackboard_processor.h   |    5 +-
 src/plugins/webview/webview_thread.cpp       |    7 +-
 src/plugins/webview/webview_thread.h         |    1 +
 5 files changed, 204 insertions(+), 36 deletions(-)


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

- *commit* 66388950f0883a6404fd68370dea2e7326a05056 - - - - - - - - - -
Author:  Gesche Gierse <gierse at kbsg.rwth-aachen.de>
Date:    Thu Jan 21 12:04:38 2016 +0100
Subject: webview: add extra form for integers

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

_Diff for modified files_:
diff --git a/src/plugins/webview/blackboard_processor.cpp b/src/plugins/webview/blackboard_processor.cpp
index 21ed74e..85e5232 100644
--- a/src/plugins/webview/blackboard_processor.cpp
+++ b/src/plugins/webview/blackboard_processor.cpp
@@ -37,6 +37,7 @@
 #include <string>
 #include <cstring>
 #include <cstdlib>
+#include <limits>
 
 #include <set>
 #include <sstream>
@@ -360,6 +361,13 @@ WebviewBlackBoardRequestProcessor::process_request(const fawkes::WebRequest *req
                       }
                       break;
                     }
+                  case IFT_UINT32:
+                    r->append_body("%s (%s):\n  <input type=\"number\" min=\"%u\" max=\"%u\" step=\"1\" id=\"%s-%s\" name=\"%s\" pattern=\"\\d+\"><br>\n",
+                                   mfi.get_name(), mfi.get_typename(),
+                                   std::numeric_limits<uint32_t>::min(),
+                                   std::numeric_limits<uint32_t>::max(), *msgit, mfi.get_name(),
+                                   mfi.get_name()); //TODO for other ints
+                    break;
                   default:
                     r->append_body("%s (%s): <input type=\"text\" name=\"%s\" ><br>\n",
                           mfi.get_name(), mfi.get_typename(), mfi.get_name());

- *commit* 8143f3ee838f67cac9d13c1449ec71664bb13ca4 - - - - - - - - - -
Author:  Gesche Gierse <gierse at kbsg.rwth-aachen.de>
Date:    Thu Jan 21 12:08:42 2016 +0100
Subject: webview: minimize msg forms with javascript

 src/plugins/webview/blackboard_processor.cpp |   31 +++++++++++++++++++------
 1 files changed, 23 insertions(+), 8 deletions(-)

_Diff for modified files_:
diff --git a/src/plugins/webview/blackboard_processor.cpp b/src/plugins/webview/blackboard_processor.cpp
index 85e5232..713afb6 100644
--- a/src/plugins/webview/blackboard_processor.cpp
+++ b/src/plugins/webview/blackboard_processor.cpp
@@ -121,6 +121,10 @@ WebviewBlackBoardRequestProcessor::process_request(const fawkes::WebRequest *req
       WebPageReply *r = new WebPageReply("BlackBoard");
       r->set_html_header("  <link type=\"text/css\" href=\""
 			 "/static/css/jqtheme/jquery-ui.custom.css\" rel=\"stylesheet\" />\n"
+                   "  <script type=\"text/javascript\" src=\"/static/js/"
+                   "jquery.min.js\"></script>\n"
+                   "  <script type=\"text/javascript\" src=\"/static/js/"
+                   "jquery-ui.custom.min.js\"></script>\n"
 			 "  <link type=\"text/css\" href=\""
 			 "/static/css/blackboard.css\" rel=\"stylesheet\" />\n");
 
@@ -164,6 +168,7 @@ WebviewBlackBoardRequestProcessor::process_request(const fawkes::WebRequest *req
 	*r += "<p><b>No interfaces found.</b></p>\n";
       }
 
+      std::list<const char *> all_msgs; // needed for collapsible msg forms
       if (subpath.find("/view/") == 0) {
         std::string iuid = "";
         try {
@@ -323,7 +328,7 @@ WebviewBlackBoardRequestProcessor::process_request(const fawkes::WebRequest *req
         // Show possible messages
         std::list<const char *> msg_types = iface->get_message_types();
         if (!msg_types.empty()){
-          *r +="<h3>Messages</h3>";
+          *r +="<h3>Messages</h3>\n";
 
           /*r->append_body("<table>\n"
                    " <tr>\n"
@@ -331,8 +336,10 @@ WebviewBlackBoardRequestProcessor::process_request(const fawkes::WebRequest *req
                    " </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\">",
+            all_msgs.push_front(*msgit);
+            r->append_body("<div class=\"msg-name-%s\"><h5 class=\"close\">%s</h5></div>\n", *msgit, *msgit);
+            r->append_body("<div class=\"msg-form-%s\" id=\"msg-form-%s\">\n<form action=\"%s/view/%s/send/%s\" method=\"post\">\n",
+                        *msgit, *msgit, __baseurl, iuid.c_str(), *msgit);
                         __baseurl, iuid.c_str(), *msgit);
             Message* ifmsg = iface->create_message(*msgit);
               /*r->append_body("  <td rowspan=\"%d\">%s</td>\n </tr>\n",
@@ -347,16 +354,16 @@ WebviewBlackBoardRequestProcessor::process_request(const fawkes::WebRequest *req
               } 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",
+                    r->append_body("%s (%s):\n  <input type=\"radio\" name=\"%s\" value=\"true\" checked>true\n"
+                          "  <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());
+                      r->append_body("%s:<br>\n", 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>",
+                        r->append_body("  <input type=\"radio\" name=\"%s\" value=\"%s\">%s<br>\n",
                             mfi.get_name(), *enum_it, *enum_it);
                       }
                       break;
@@ -374,7 +381,7 @@ WebviewBlackBoardRequestProcessor::process_request(const fawkes::WebRequest *req
                 }
               }
             }
-            *r += "<input type=\"submit\" value=\"Send\" /></form></p>\n";
+            *r += "  <input type=\"submit\" value=\"Send\" />\n</form>\n</div>\n";
           }
           //r->append_body("</table>\n");
         }
@@ -415,6 +422,13 @@ WebviewBlackBoardRequestProcessor::process_request(const fawkes::WebRequest *req
 	  r->append_body("<p><a href=\"%s/graph\">Full Graph</a></p>\n\n", __baseurl);
 	}
       }
+      r->append_body("<script>\n");
+      for (std::list<const char *>::iterator it = all_msgs.begin(); it != all_msgs.end(); ++it){
+        r->append_body( "  $('.msg-name-%s').click(function(){\n    $('.msg-form-%s').slideToggle('slow');\n  });\n", *it, *it);
+        //r->append_body("  $('.msg-form-%s').style.display=\"none\";", *it);
+        r->append_body("  document.getElementById(\"msg-form-%s\").style.display=\"none\";", *it);
+      }
+      r->append_body("\n</script>");
       return r;
     }
 
@@ -423,6 +437,7 @@ WebviewBlackBoardRequestProcessor::process_request(const fawkes::WebRequest *req
   }
 }
 
+
 #if defined(HAVE_GRAPHVIZ) && ((defined(__GNUC__) && (__GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 5))) || defined(__clang__))
 std::string
 WebviewBlackBoardRequestProcessor::generate_graph(std::string for_owner)

- *commit* 9f1bf92bd898d609eb0dfbbd5a41470b0c2b3cbd - - - - - - - - - -
Author:  Gesche Gierse <gierse at kbsg.rwth-aachen.de>
Date:    Thu Jan 21 16:57:09 2016 +0100
Subject: webview: catch if typo in message name, improve 404 pages

 src/plugins/webview/blackboard_processor.cpp |   12 +++++++++---
 1 files changed, 9 insertions(+), 3 deletions(-)

_Diff for modified files_:
diff --git a/src/plugins/webview/blackboard_processor.cpp b/src/plugins/webview/blackboard_processor.cpp
index 713afb6..a2f6969 100644
--- a/src/plugins/webview/blackboard_processor.cpp
+++ b/src/plugins/webview/blackboard_processor.cpp
@@ -177,10 +177,10 @@ WebviewBlackBoardRequestProcessor::process_request(const fawkes::WebRequest *req
           iuid = subpath.substr(tmp);
         } catch (Exception &e) {
           return new WebErrorPageReply(WebReply::HTTP_NOT_FOUND,
-                           "Could not parse interface id: %s", e.what());
+                           "Could not parse interface id: %s<br>\n<a href=\"%s\">Back to BlackBoard</a>", e.what(), __baseurl);
         } catch (std::exception &e) {
           return new WebErrorPageReply(WebReply::HTTP_NOT_FOUND,
-                           "Could not parse interface id: %s", e.what());
+                           "Could not parse interface id: %s<br>\n<a href=\"%s\">Back to BlackBoard</a>", e.what(), __baseurl);
         }
         std::string message_type;
         bool send = false;
@@ -209,7 +209,13 @@ WebviewBlackBoardRequestProcessor::process_request(const fawkes::WebRequest *req
 
         if(send){
           // handle send message request
-          Message* msg_to_send = iface->create_message(message_type.c_str()); //TODO catch if not possible
+          Message* msg_to_send;
+          try {
+            msg_to_send = iface->create_message(message_type.c_str());
+          } catch (Exception &e) {
+            return new WebErrorPageReply(WebReply::HTTP_NOT_FOUND,
+                           "Could not parse message name: %s<br>\n <a href=\"%s/view/%s::%s\">Back to %s::%s</a>", e.what(), __baseurl, iftype.c_str(), ifname.c_str(), iftype.c_str(), ifname.c_str());
+          }
           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");

- *commit* 6b164eb8d1d66f4123c4c8d3d38c08b161056229 - - - - - - - - - -
Author:  Gesche Gierse <gierse at kbsg.rwth-aachen.de>
Date:    Thu Jan 21 17:48:22 2016 +0100
Subject: webview: send msg: parse all types of non-array input

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

_Diff for modified files_:
diff --git a/src/plugins/webview/blackboard_processor.cpp b/src/plugins/webview/blackboard_processor.cpp
index a2f6969..822057e 100644
--- a/src/plugins/webview/blackboard_processor.cpp
+++ b/src/plugins/webview/blackboard_processor.cpp
@@ -33,6 +33,7 @@
 #include <interface/interface_info.h>
 #include <utils/time/time.h>
 #include <utils/misc/string_split.h>
+#include <utils/misc/string_conversions.h>
 
 #include <string>
 #include <cstring>
@@ -224,21 +225,84 @@ WebviewBlackBoardRequestProcessor::process_request(const fawkes::WebRequest *req
             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;
+                if (mfi.get_length() > 1 && mfi.get_type() != IFT_STRING){
+                  r->append_body("<font color=\"red\">Error: Type array is currently not supported by webview send message functionality.</font><br>\n");
+                  no_errors = false;
+                } else {
+                  switch(mfi.get_type()){
+                    case IFT_STRING: {
+                        std::string str = request->post_value(mfi.get_name());
+                        if (str.length() > mfi.get_length()) {
+                          r->append_body("<font color=\"red\">Error: The entered string is longer than %i! </font><br>\n", mfi.get_length());
+                          no_errors = false;
+                        } else {
+                          mfi.set_string(str.c_str());
+                          printf("received string, it is at most of length: %lu<br>\n", mfi.get_length());
+                        }
+                      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;
+                    case IFT_INT8: {
+                      int i = StringConversions::to_int(request->post_value(mfi.get_name()));
+                      mfi.set_int8(i);
+                      break;
+                    }
+                    case IFT_UINT8: {
+                      unsigned int i = StringConversions::to_uint(request->post_value(mfi.get_name()));
+                      mfi.set_uint8(i);
+                      break;
+                    }
+                    case IFT_INT16: {
+                      int i = StringConversions::to_int(request->post_value(mfi.get_name()));
+                      mfi.set_int16(i);
+                      break;
+                    }
+                    case IFT_UINT16: {
+                      unsigned int i = StringConversions::to_uint(request->post_value(mfi.get_name()));
+                      mfi.set_uint16(i);
+                      break;
+                    }
+                    case IFT_INT32: {
+                      int i = StringConversions::to_int(request->post_value(mfi.get_name()));
+                      mfi.set_int32(i);
+                      break;
+                    }
+                    case IFT_UINT32: {
+                      unsigned int i = StringConversions::to_uint(request->post_value(mfi.get_name()));
+                      mfi.set_uint32(i);
+                      break;
+                    }
+                    case IFT_INT64: {
+                      int i = StringConversions::to_int(request->post_value(mfi.get_name()));
+                      mfi.set_int64(i);
+                      break;
+                    }
+                    case IFT_UINT64: {
+                      unsigned int i = StringConversions::to_uint(request->post_value(mfi.get_name()));
+                      mfi.set_uint64(i);
+                      break;
+                    }
+                    case IFT_FLOAT: {
+                      float f = StringConversions::to_float(request->post_value(mfi.get_name()));
+                      mfi.set_float(f);
+                      break;
+                    }
+                    case IFT_DOUBLE: {
+                      double d = StringConversions::to_double(request->post_value(mfi.get_name()));
+                      mfi.set_float(d);
+                      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());
                 }
-                r->append_body("Received value %s for the field %s\n",request->post_value(mfi.get_name()).c_str(), mfi.get_name());
               }
             }
           }
@@ -346,7 +410,6 @@ WebviewBlackBoardRequestProcessor::process_request(const fawkes::WebRequest *req
             r->append_body("<div class=\"msg-name-%s\"><h5 class=\"close\">%s</h5></div>\n", *msgit, *msgit);
             r->append_body("<div class=\"msg-form-%s\" id=\"msg-form-%s\">\n<form action=\"%s/view/%s/send/%s\" method=\"post\">\n",
                         *msgit, *msgit, __baseurl, iuid.c_str(), *msgit);
-                        __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,

- *commit* e6c9312d6660dcd54358dea68f24b485ac99b8de - - - - - - - - - -
Author:  Gesche Gierse <gierse at kbsg.rwth-aachen.de>
Date:    Thu Jan 21 17:50:04 2016 +0100
Subject: webview: add number input which respects different int types

 src/plugins/webview/blackboard_processor.cpp |   66 +++++++++++++++++++++++--
 src/plugins/webview/blackboard_processor.h   |    1 +
 2 files changed, 61 insertions(+), 6 deletions(-)

_Diff for modified files_:
diff --git a/src/plugins/webview/blackboard_processor.cpp b/src/plugins/webview/blackboard_processor.cpp
index 822057e..b2ad47b 100644
--- a/src/plugins/webview/blackboard_processor.cpp
+++ b/src/plugins/webview/blackboard_processor.cpp
@@ -437,13 +437,56 @@ WebviewBlackBoardRequestProcessor::process_request(const fawkes::WebRequest *req
                       }
                       break;
                     }
+                  case IFT_INT8:
+                    {
+                      std::string form = get_input_form_string<int8_t>(*msgit, mfi.get_name(), mfi.get_typename());
+                      r->append_body(form.c_str());
+                      break;
+                    }
+                  case IFT_BYTE:
+                  case IFT_UINT8:
+                    {
+                      std::string form = get_input_form_string<uint8_t>(*msgit, mfi.get_name(), mfi.get_typename());
+                      r->append_body(form.c_str());
+                      break;
+                    }
+                  case IFT_INT16:
+                    {
+                      std::string form = get_input_form_string<int16_t>(*msgit, mfi.get_name(), mfi.get_typename());
+                      r->append_body(form.c_str());
+                      break;
+                    }
+                  case IFT_UINT16:
+                    {
+                      std::string form = get_input_form_string<uint16_t>(*msgit, mfi.get_name(), mfi.get_typename());
+                      r->append_body(form.c_str());
+                      break;
+                    }
+                  case IFT_INT32:
+                    {
+                      std::string form = get_input_form_string<int32_t>(*msgit, mfi.get_name(), mfi.get_typename());
+                      r->append_body(form.c_str());
+                      break;
+                    }
                   case IFT_UINT32:
-                    r->append_body("%s (%s):\n  <input type=\"number\" min=\"%u\" max=\"%u\" step=\"1\" id=\"%s-%s\" name=\"%s\" pattern=\"\\d+\"><br>\n",
-                                   mfi.get_name(), mfi.get_typename(),
-                                   std::numeric_limits<uint32_t>::min(),
-                                   std::numeric_limits<uint32_t>::max(), *msgit, mfi.get_name(),
-                                   mfi.get_name()); //TODO for other ints
-                    break;
+                    {
+                      std::string form = get_input_form_string<uint32_t>(*msgit, mfi.get_name(), mfi.get_typename());
+                      r->append_body(form.c_str());
+                      break;
+                    }
+                  case IFT_INT64:
+                    {
+                      std::string form = get_input_form_string<int64_t>(*msgit, mfi.get_name(), mfi.get_typename());
+                      r->append_body(form.c_str());
+                      break;
+                    }
+                  case IFT_UINT64:
+                    {
+                      std::string form = get_input_form_string<uint64_t>(*msgit, mfi.get_name(), mfi.get_typename());
+                      r->append_body(form.c_str());
+                      break;
+                    }
+
                   default:
                     r->append_body("%s (%s): <input type=\"text\" name=\"%s\" ><br>\n",
                           mfi.get_name(), mfi.get_typename(), mfi.get_name());
@@ -506,6 +549,17 @@ WebviewBlackBoardRequestProcessor::process_request(const fawkes::WebRequest *req
   }
 }
 
+template<typename T> std::string
+WebviewBlackBoardRequestProcessor::get_input_form_string(std::string msgit, const char * fieldname, std::string fieldtype)
+{
+  std::stringstream ss;
+  ss << fieldname << " (" << fieldtype << "):\n <input type=\"number\" min=\"" <<
+                 std::numeric_limits<T>::min() << "\" max=\"" << 
+                 std::numeric_limits<T>::max() << "\" step=\"1\" id=\"" << msgit <<
+                 "-" << fieldname << "\" name=\"" << fieldname << "\" pattern=\"\\d+\"><br>\n";
+  return ss.str();
+}
+
 
 #if defined(HAVE_GRAPHVIZ) && ((defined(__GNUC__) && (__GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 5))) || defined(__clang__))
 std::string
diff --git a/src/plugins/webview/blackboard_processor.h b/src/plugins/webview/blackboard_processor.h
index af45081..0eaa99b 100644
--- a/src/plugins/webview/blackboard_processor.h
+++ b/src/plugins/webview/blackboard_processor.h
@@ -43,6 +43,7 @@ class WebviewBlackBoardRequestProcessor : public fawkes::WebRequestProcessor
   virtual fawkes::WebReply * process_request(const fawkes::WebRequest *request);
 
  private:
+  template<typename T> std::string get_input_form_string(std::string msgit, const char* fieldname, std::string fieldtype);
 #if defined(HAVE_GRAPHVIZ) && ((defined(__GNUC__) && (__GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 5))) || defined(__clang__))
   std::string generate_graph(std::string for_owner = "");
 #endif

- *commit* f321f1948f8f61bd590f34b71006ca61801328e7 - - - - - - - - - -
Author:  Gesche Gierse <gierse at kbsg.rwth-aachen.de>
Date:    Thu Jan 21 17:59:04 2016 +0100
Subject: webview: specialize input for string, double, float

 src/plugins/webview/blackboard_processor.cpp |   17 +++++++++++++----
 1 files changed, 13 insertions(+), 4 deletions(-)

_Diff for modified files_:
diff --git a/src/plugins/webview/blackboard_processor.cpp b/src/plugins/webview/blackboard_processor.cpp
index b2ad47b..9f0edb8 100644
--- a/src/plugins/webview/blackboard_processor.cpp
+++ b/src/plugins/webview/blackboard_processor.cpp
@@ -411,17 +411,26 @@ WebviewBlackBoardRequestProcessor::process_request(const fawkes::WebRequest *req
             r->append_body("<div class=\"msg-form-%s\" id=\"msg-form-%s\">\n<form action=\"%s/view/%s/send/%s\" method=\"post\">\n",
                         *msgit, *msgit, __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",
+                if (mfi.get_type() == IFT_STRING) {
+                  r->append_body("%s (%s [%zu]): <input type=\"text\" name=\"%s\" maxlength=\"%i\"><br>\n",
+                          mfi.get_name(), mfi.get_typename(),
+                          mfi.get_length(), mfi.get_name(), mfi.get_length());
+                } else {
+                  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_DOUBLE:
+                  case IFT_FLOAT:
+                    r->append_body("%s (%s): <input type=\"text\" name=\"%s\" pattern=\"[0-9]*.[0-9]*\"><br>\n",
+                          mfi.get_name(), mfi.get_typename(),
+                          mfi.get_name());
+                    break;
                   case IFT_BOOL:
                     r->append_body("%s (%s):\n  <input type=\"radio\" name=\"%s\" value=\"true\" checked>true\n"
                           "  <input type=\"radio\" name=\"%s\" value=\"false\">false<br>\n",

- *commit* 932ec844cfc034c52a9b9188cf416102c2fe568b - - - - - - - - - -
Author:  Gesche Gierse <gierse at kbsg.rwth-aachen.de>
Date:    Thu Jan 21 18:44:47 2016 +0100
Subject: webview: make send msg feature configurable

 cfg/conf.d/webview.yaml                      |    5 ++++-
 src/plugins/webview/blackboard_processor.cpp |    7 ++++---
 src/plugins/webview/blackboard_processor.h   |    4 +++-
 src/plugins/webview/webview_thread.cpp       |    7 ++++++-
 src/plugins/webview/webview_thread.h         |    1 +
 5 files changed, 18 insertions(+), 6 deletions(-)

_Diff for modified files_:
diff --git a/cfg/conf.d/webview.yaml b/cfg/conf.d/webview.yaml
index b237ee2..419cb09 100644
--- a/cfg/conf.d/webview.yaml
+++ b/cfg/conf.d/webview.yaml
@@ -64,4 +64,7 @@ webview:
       jpeg-vflip: false
 
   # directories with static files
-  static-dirs: ["@BASEDIR@/res/webview"]
\ No newline at end of file
+  static-dirs: ["@BASEDIR@/res/webview"]
+
+  # Enable the feature that users can send messages to the BlackBoard using webview?
+  bb_enable_msgs: true
\ No newline at end of file
diff --git a/src/plugins/webview/blackboard_processor.cpp b/src/plugins/webview/blackboard_processor.cpp
index 9f0edb8..70ea4c9 100644
--- a/src/plugins/webview/blackboard_processor.cpp
+++ b/src/plugins/webview/blackboard_processor.cpp
@@ -60,13 +60,15 @@ using namespace fawkes;
 /** Constructor.
  * @param baseurl Base URL where processor is mounted
  * @param blackboard BlackBoard instance
+ * @param enable_msgs whether to allow sending msgs via webview
  */
 WebviewBlackBoardRequestProcessor::WebviewBlackBoardRequestProcessor(const char *baseurl,
-								     BlackBoard *blackboard)
+								     BlackBoard *blackboard, bool enable_msgs)
 {
   __baseurl     = strdup(baseurl);
   __baseurl_len = strlen(__baseurl);
   __blackboard  = blackboard;
+  __enable_msgs = enable_msgs;
 }
 
 
@@ -397,7 +399,7 @@ WebviewBlackBoardRequestProcessor::process_request(const fawkes::WebRequest *req
 
         // Show possible messages
         std::list<const char *> msg_types = iface->get_message_types();
-        if (!msg_types.empty()){
+        if (!msg_types.empty() && __enable_msgs){
           *r +="<h3>Messages</h3>\n";
 
           /*r->append_body("<table>\n"
@@ -504,7 +506,6 @@ WebviewBlackBoardRequestProcessor::process_request(const fawkes::WebRequest *req
             }
             *r += "  <input type=\"submit\" value=\"Send\" />\n</form>\n</div>\n";
           }
-          //r->append_body("</table>\n");
         }
 	  r->append_body("<p><a href=\"%s\">Clear detailed</a></p>\n", __baseurl);
       }
diff --git a/src/plugins/webview/blackboard_processor.h b/src/plugins/webview/blackboard_processor.h
index 0eaa99b..00bd734 100644
--- a/src/plugins/webview/blackboard_processor.h
+++ b/src/plugins/webview/blackboard_processor.h
@@ -37,7 +37,8 @@ class WebviewBlackBoardRequestProcessor : public fawkes::WebRequestProcessor
 {
  public:
   WebviewBlackBoardRequestProcessor(const char *baseurl,
-				fawkes::BlackBoard *blackboard);
+				fawkes::BlackBoard *blackboard,
+				bool enable_msgs = false);
   virtual ~WebviewBlackBoardRequestProcessor();
 
   virtual fawkes::WebReply * process_request(const fawkes::WebRequest *request);
@@ -52,6 +53,7 @@ class WebviewBlackBoardRequestProcessor : public fawkes::WebRequestProcessor
   char *__baseurl;
   size_t __baseurl_len;
   fawkes::BlackBoard *__blackboard;
+  bool __enable_msgs;
 
   std::map<std::string, fawkes::Interface *> __interfaces;
   std::map<std::string, fawkes::Interface *>::iterator __ifi;
diff --git a/src/plugins/webview/webview_thread.cpp b/src/plugins/webview/webview_thread.cpp
index 6c174e5..efeb6c7 100644
--- a/src/plugins/webview/webview_thread.cpp
+++ b/src/plugins/webview/webview_thread.cpp
@@ -153,6 +153,11 @@ WebviewThread::init()
     __cfg_access_log = config->get_string("/webview/access_log");
   } catch (Exception &e) {}
 
+  __cfg_bb_enable_msgs = false;
+  try{
+    __cfg_bb_enable_msgs = config->get_bool("/webview/bb_enable_msgs");
+  } catch (Exception &e) {}
+
 
   __cache_logger.clear();
 
@@ -211,7 +216,7 @@ WebviewThread::init()
     static_dirs_cstr[i] = static_dirs[i].c_str();
   }
   __static_processor     = new WebviewStaticRequestProcessor(STATIC_URL_PREFIX, static_dirs_cstr, logger);
-  __blackboard_processor = new WebviewBlackBoardRequestProcessor(BLACKBOARD_URL_PREFIX, blackboard);
+  __blackboard_processor = new WebviewBlackBoardRequestProcessor(BLACKBOARD_URL_PREFIX, blackboard, __cfg_bb_enable_msgs);
   __plugins_processor    = new WebviewPluginsRequestProcessor(PLUGINS_URL_PREFIX, plugin_manager);
 #ifdef HAVE_TF
   __tf_processor         = new WebviewTfRequestProcessor(TF_URL_PREFIX, tf_listener);
diff --git a/src/plugins/webview/webview_thread.h b/src/plugins/webview/webview_thread.h
index b4da1f2..4d7fa71 100644
--- a/src/plugins/webview/webview_thread.h
+++ b/src/plugins/webview/webview_thread.h
@@ -125,6 +125,7 @@ class WebviewThread
   bool         __cfg_use_basic_auth;
   std::string  __cfg_basic_auth_realm;
   std::string  __cfg_access_log;
+  bool         __cfg_bb_enable_msgs;
 
   fawkes::CacheLogger     __cache_logger;
   fawkes::NetworkService *__webview_service;




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


More information about the fawkes-commits mailing list