[dss-commits] r8828 - in dss/trunk: core data/webroot data/webroot/js tools

dss-commits at forum.digitalstrom.org dss-commits at forum.digitalstrom.org
Tue Oct 6 16:06:12 CEST 2009


Author: jwinkelmann
Date: 2009-10-06 16:06:12 +0200 (Tue, 06 Oct 2009)
New Revision: 8828

Modified:
   dss/trunk/core/webserver.cpp
   dss/trunk/core/webserver.h
   dss/trunk/data/webroot/index.html
   dss/trunk/data/webroot/js/model.js
   dss/trunk/tools/ds3
Log:
add 'system' json class with an initial 'version' method

In addition, add a new container to index.html displaying the version

Modified: dss/trunk/core/webserver.cpp
===================================================================
--- dss/trunk/core/webserver.cpp	2009-10-06 14:05:09 UTC (rev 8827)
+++ dss/trunk/core/webserver.cpp	2009-10-06 14:06:12 UTC (rev 8828)
@@ -352,6 +352,11 @@
        .withParameter("location", "string", false)
        .withDocumentation("Raises an event", "The context describes the source of the event. The location, if provided, defines where any action that is taken "
            "by any subscription should happen.");
+    
+    RestfulClass& clsSystem = api.addClass("system");
+    clsSystem.addMethod("version")
+      .withDocumentation("Returns the dss version", 
+                         "This method returns the version string of the dss");
 
     RestfulClass& clsSet = api.addClass("set")
         .withInstanceParameter("self", "string", false);
@@ -1330,6 +1335,17 @@
     return result;
   } // handleEventCall
 
+  string WebServer::handleSystemCall(const std::string& _method, HashMapConstStringString& _parameter, struct mg_connection* _connection, bool& _handled, Session* _session) {
+    _handled = true;
+    string result;
+    if(endsWith(_method, "/version")) {
+      return ResultToJSON(true, DSS::getInstance()->versionString());
+    } else {
+      _handled = false;
+    }
+    return result;
+  } // handleEventCall
+
   string WebServer::handleStructureCall(const std::string& _method,
                                         HashMapConstStringString& _parameter,
                                         struct mg_connection* _connection,
@@ -1765,6 +1781,8 @@
       result = self.handlePropertyCall(method, paramMap, _connection, handled, session);
     } else if(beginsWith(method, "event/")) {
       result = self.handleEventCall(method, paramMap, _connection, handled, session);
+    } else if(beginsWith(method, "system/")) {
+      result = self.handleSystemCall(method, paramMap, _connection, handled, session);
     } else if(beginsWith(method, "structure/")) {
       result = self.handleStructureCall(method, paramMap, _connection, handled, session);
     } else if(beginsWith(method, "sim/")) {

Modified: dss/trunk/core/webserver.h
===================================================================
--- dss/trunk/core/webserver.h	2009-10-06 14:05:09 UTC (rev 8827)
+++ dss/trunk/core/webserver.h	2009-10-06 14:06:12 UTC (rev 8828)
@@ -62,6 +62,7 @@
     std::string handleSetCall(const std::string& _method, HashMapConstStringString& _parameter, struct mg_connection* _connection, bool& _handled, Session* _session);
     std::string handlePropertyCall(const std::string& _method, HashMapConstStringString& _parameter, struct mg_connection* _connection, bool& _handled, Session* _session);
     std::string handleEventCall(const std::string& _method, HashMapConstStringString& _parameter, struct mg_connection* _connection, bool& _handled, Session* _session);
+    std::string handleSystemCall(const std::string& _method, HashMapConstStringString& _parameter, struct mg_connection* _connection, bool& _handled, Session* _session);
     std::string handleCircuitCall(const std::string& _method, HashMapConstStringString& _parameter, struct mg_connection* _connection, bool& _handled, Session* _session);
     std::string handleStructureCall(const std::string& _method, HashMapConstStringString& _parameter, struct mg_connection* _connection, bool& _handled, Session* _session);
     std::string handleSimCall(const std::string& _method, HashMapConstStringString& _parameter, struct mg_connection* _connection, bool& _handled, Session* _session);

Modified: dss/trunk/data/webroot/index.html
===================================================================
--- dss/trunk/data/webroot/index.html	2009-10-06 14:05:09 UTC (rev 8827)
+++ dss/trunk/data/webroot/index.html	2009-10-06 14:06:12 UTC (rev 8828)
@@ -68,10 +68,19 @@
       $('numDevs').innerHTML = devTotal;
     }
   }
+}
 
+function SystemRenderer(into) {
+  var self = this;
+  self.system = new System();
+
+  this.render = function() {
+	$(into).innerHTML = self.system.version();
+  }
 }
 
 var apt = null;
+var sysinfo = null;
 
 
 	function turnOn(devid) {
@@ -125,6 +134,9 @@
     function doOnload() {
       apt = new ApartmentRenderer("bla");
       apt.render();
+
+      sysinfo = new SystemRenderer("sysinfo");
+      sysinfo.render();
     }
 </script>
   </head>
@@ -137,5 +149,6 @@
 	<div class="container">
         <div id="bla">(loading...)</div>
 	</div>
+      <div class="container" id="sysinfo">dss</div>
   </body>
 </html>

Modified: dss/trunk/data/webroot/js/model.js
===================================================================
--- dss/trunk/data/webroot/js/model.js	2009-10-06 14:05:09 UTC (rev 8827)
+++ dss/trunk/data/webroot/js/model.js	2009-10-06 14:06:12 UTC (rev 8828)
@@ -59,6 +59,17 @@
   }
 }); // Group
 
+var System = Class.create({
+  sendSyncRequest: function(_functionName, _parameter) {
+      return DSS.sendSyncRequest("system/" + _functionName, _parameter);
+    },
+
+    version: function() {
+      var respObj = this.sendSyncRequest("version", {});
+      return respObj.message;
+    }
+}); // System
+
 var Apartment = Class.create({
 	initialize: function() {
 		this.zones = [];

Modified: dss/trunk/tools/ds3
===================================================================
--- dss/trunk/tools/ds3	2009-10-06 14:05:09 UTC (rev 8827)
+++ dss/trunk/tools/ds3	2009-10-06 14:06:12 UTC (rev 8828)
@@ -28,7 +28,7 @@
 	exit 1
     else
 	if [ -n "$PRINT_RESULT" ]; then
-	    echo $result|sed -e 's|.*result\":\s*{\s*||g' -e 's|}\s*}$||g'
+	    echo $result|sed -e 's|.*,\s*||' -e 's|\s*}$||'
 	fi
     fi
     return 0
@@ -108,10 +108,16 @@
         call_dss "$target" "$target_command" "newName=$1"
 	;;
 
+    ###
+    ## system
+    #
+    "system_version")
+        PRINT_RESULT="yes" call_dss "$target" "$target_command"
+	;;
     *)
         usage
 	exit 1
 	;;
 esac
 
-exit 0
\ No newline at end of file
+exit 0



More information about the dss-commits mailing list