[dss-commits] digitalSTROM Server branch, master, updated. d255b03f00610bd17ef0b04635781c8a5051a062

git version control dss-commits at forum.digitalstrom.org
Fri Jan 8 16:28:33 CET 2010


This is an automated email from the git hooks/post-receive script. It was
generated because a ref change was pushed to the repository containing
the project "digitalSTROM Server".

The branch, master has been updated
       via  d255b03f00610bd17ef0b04635781c8a5051a062 (commit)
      from  d230e2248871dec73385c4d4ebd2ec8032ec602e (commit)

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 d255b03f00610bd17ef0b04635781c8a5051a062
Author: Patrick Stählin <pstaehlin at futurelab.ch>
Date:   Fri Jan 8 16:27:21 2010 +0100

    Removed some dependencies on dss::DSS

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

Changes:
diff --git a/core/web/handler/apartmentrequesthandler.cpp b/core/web/handler/apartmentrequesthandler.cpp
index a44046e..166b434 100644
--- a/core/web/handler/apartmentrequesthandler.cpp
+++ b/core/web/handler/apartmentrequesthandler.cpp
@@ -23,7 +23,6 @@
 #include "apartmentrequesthandler.h"
 
 #include "core/foreach.h"
-#include "core/dss.h"
 #include "core/ds485const.h"
 
 #include "core/web/json.h"
@@ -42,11 +41,15 @@ namespace dss {
 
   //=========================================== ApartmentRequestHandler
 
+  ApartmentRequestHandler::ApartmentRequestHandler(Apartment& _apartment)
+  : m_Apartment(_apartment)
+  { }
+
   boost::shared_ptr<JSONObject> ApartmentRequestHandler::jsonHandleRequest(const RestfulRequest& _request, Session* _session) {
     std::string errorMessage;
     if(_request.getMethod() == "getConsumption") {
       int accumulatedConsumption = 0;
-      foreach(DSMeter* pDSMeter, getDSS().getApartment().getDSMeters()) {
+      foreach(DSMeter* pDSMeter, m_Apartment.getDSMeters()) {
         accumulatedConsumption += pDSMeter->getPowerConsumption();
       }
       boost::shared_ptr<JSONObject> resultObj(new JSONObject());
@@ -58,7 +61,7 @@ namespace dss {
       std::string groupIDString = _request.getParameter("groupID");
       if(!groupName.empty()) {
         try {
-          Group& grp = getDSS().getApartment().getGroup(groupName);
+          Group& grp = m_Apartment.getGroup(groupName);
           interface = &grp;
         } catch(std::runtime_error& e) {
           return failure("Could not find group with name '" + groupName + "'");
@@ -67,7 +70,7 @@ namespace dss {
         try {
           int groupID = strToIntDef(groupIDString, -1);
           if(groupID != -1) {
-            Group& grp = getDSS().getApartment().getGroup(groupID);
+            Group& grp = m_Apartment.getGroup(groupID);
             interface = &grp;
           } else {
             return failure("Could not parse group id '" + groupIDString + "'");
@@ -77,17 +80,17 @@ namespace dss {
         }
       }
       if(interface != NULL) {
-        interface = &getDSS().getApartment().getGroup(GroupIDBroadcast);
+        interface = &m_Apartment.getGroup(GroupIDBroadcast);
         return success();
       }
       return failure("No interface");
     } else {
       if(_request.getMethod() == "getStructure") {
-        return success(toJSON(getDSS().getApartment()));
+        return success(toJSON(m_Apartment));
       } else if(_request.getMethod() == "getDevices") {
         Set devices;
         if(_request.getParameter("unassigned").empty()) {
-          devices = getDSS().getApartment().getDevices();
+          devices = m_Apartment.getDevices();
         } else {
           devices = getUnassignedDevices();
         }
@@ -104,7 +107,7 @@ namespace dss {
         boost::shared_ptr<JSONArrayBase> circuits(new JSONArrayBase());
 
         resultObj->addElement("circuits", circuits);
-        std::vector<DSMeter*>& dsMeters = getDSS().getApartment().getDSMeters();
+        std::vector<DSMeter*>& dsMeters = m_Apartment.getDSMeters();
         foreach(DSMeter* dsMeter, dsMeters) {
           boost::shared_ptr<JSONObject> circuit(new JSONObject());
           circuits->addElement("", circuit);
@@ -120,13 +123,13 @@ namespace dss {
         return success(resultObj);
       } else if(_request.getMethod() == "getName") {
         boost::shared_ptr<JSONObject> resultObj(new JSONObject());
-        resultObj->addProperty("name", getDSS().getApartment().getName());
+        resultObj->addProperty("name", m_Apartment.getName());
         return success(resultObj);
       } else if(_request.getMethod() == "setName") {
-        getDSS().getApartment().setName(_request.getParameter("newName"));
+        m_Apartment.setName(_request.getParameter("newName"));
         return success();
       } else if(_request.getMethod() == "rescan") {
-        std::vector<DSMeter*> mods = getDSS().getApartment().getDSMeters();
+        std::vector<DSMeter*> mods = m_Apartment.getDSMeters();
         foreach(DSMeter* pDSMeter, mods) {
           pDSMeter->setIsValid(false);
         }
diff --git a/core/web/handler/apartmentrequesthandler.h b/core/web/handler/apartmentrequesthandler.h
index b434ae6..4f70575 100644
--- a/core/web/handler/apartmentrequesthandler.h
+++ b/core/web/handler/apartmentrequesthandler.h
@@ -28,12 +28,15 @@
 namespace dss {
 
   class Set;
+  class Apartment;
 
   class ApartmentRequestHandler : public DeviceInterfaceRequestHandler {
   public:
+    ApartmentRequestHandler(Apartment& _apartment);
     virtual boost::shared_ptr<JSONObject> jsonHandleRequest(const RestfulRequest& _request, Session* _session);
   private:
     Set getUnassignedDevices();
+    Apartment& m_Apartment;
   }; // ApartmentRequestHandler
 
 } // namespace dss
diff --git a/core/web/handler/circuitrequesthandler.cpp b/core/web/handler/circuitrequesthandler.cpp
index 5532e0c..a5af14b 100644
--- a/core/web/handler/circuitrequesthandler.cpp
+++ b/core/web/handler/circuitrequesthandler.cpp
@@ -22,8 +22,6 @@
 
 #include "circuitrequesthandler.h"
 
-#include "core/dss.h"
-
 #include "core/model/modulator.h"
 #include "core/model/apartment.h"
 
@@ -34,6 +32,10 @@ namespace dss {
 
   //=========================================== CircuitRequestHandler
 
+  CircuitRequestHandler::CircuitRequestHandler(Apartment& _apartment)
+  : m_Apartment(_apartment)
+  { }
+
   boost::shared_ptr<JSONObject> CircuitRequestHandler::jsonHandleRequest(const RestfulRequest& _request, Session* _session) {
     std::string idString = _request.getParameter("id");
     if(idString.empty()) {
@@ -44,7 +46,7 @@ namespace dss {
       return failure("could not parse dsid");
     }
     try {
-      DSMeter& dsMeter = getDSS().getApartment().getDSMeterByDSID(dsid);
+      DSMeter& dsMeter = m_Apartment.getDSMeterByDSID(dsid);
       if(_request.getMethod() == "getName") {
         boost::shared_ptr<JSONObject> resultObj(new JSONObject());
         resultObj->addProperty("name", dsMeter.getName());
diff --git a/core/web/handler/circuitrequesthandler.h b/core/web/handler/circuitrequesthandler.h
index 64e94e6..beffde7 100644
--- a/core/web/handler/circuitrequesthandler.h
+++ b/core/web/handler/circuitrequesthandler.h
@@ -27,9 +27,14 @@
 
 namespace dss {
 
+  class Apartment;
+
   class CircuitRequestHandler : public WebServerRequestHandlerJSON {
   public:
+    CircuitRequestHandler(Apartment& _apartment);
     virtual boost::shared_ptr<JSONObject> jsonHandleRequest(const RestfulRequest& _request, Session* _session);
+  private:
+    Apartment& m_Apartment;
   }; // CircuitRequestHandler
 
 } // namespace dss
diff --git a/core/web/handler/debugrequesthandler.cpp b/core/web/handler/debugrequesthandler.cpp
index fb2c2be..06fd68b 100644
--- a/core/web/handler/debugrequesthandler.cpp
+++ b/core/web/handler/debugrequesthandler.cpp
@@ -42,6 +42,10 @@ namespace dss {
 
   //=========================================== DebugRequestHandler
 
+  DebugRequestHandler::DebugRequestHandler(DSS& _dss)
+  : m_DSS(_dss)
+  { }
+
   boost::shared_ptr<JSONObject> DebugRequestHandler::jsonHandleRequest(const RestfulRequest& _request, Session* _session) {
     std::ostringstream logSStream;
     if(_request.getMethod() == "sendFrame") {
@@ -96,7 +100,7 @@ namespace dss {
         dsid_t deviceDSID = dsid_t::fromString(deviceDSIDString);
         if(!(deviceDSID == NullDSID)) {
           try {
-            Device& device = getDSS().getApartment().getDeviceByDSID(deviceDSID);
+            Device& device = m_DSS.getApartment().getDeviceByDSID(deviceDSID);
             pDevice = &device;
           } catch(std::runtime_error& e) {
             return failure("Could not find device with dsid '" + deviceDSIDString + "'");
@@ -143,14 +147,16 @@ namespace dss {
       }
       try {
         dsid_t deviceDSID = dsid_t::fromString(deviceDSIDString);
-        Device& device = getDSS().getApartment().getDeviceByDSID(deviceDSID);
+        Device& device = m_DSS.getApartment().getDeviceByDSID(deviceDSID);
+        // TODO: move this code somewhere else (might also relax the requirement
+        //       having DSS as constructor parameter)
         DS485CommandFrame* frame = new DS485CommandFrame();
         frame->getHeader().setBroadcast(true);
         frame->getHeader().setDestination(device.getDSMeterID());
         frame->setCommand(CommandRequest);
         frame->getPayload().add<uint8_t>(FunctionDeviceGetTransmissionQuality);
         frame->getPayload().add<uint16_t>(device.getShortAddress());
-        DS485Interface* intf = &DSS::getInstance()->getDS485Interface();
+        DS485Interface* intf = &m_DSS.getDS485Interface();
         DS485Proxy* proxy = dynamic_cast<DS485Proxy*>(intf);
         if(proxy != NULL) {
           boost::shared_ptr<FrameBucketCollector> bucket = proxy->sendFrameAndInstallBucket(*frame, FunctionDeviceGetTransmissionQuality);
diff --git a/core/web/handler/debugrequesthandler.h b/core/web/handler/debugrequesthandler.h
index 4707386..211aacc 100644
--- a/core/web/handler/debugrequesthandler.h
+++ b/core/web/handler/debugrequesthandler.h
@@ -27,9 +27,14 @@
 
 namespace dss {
 
+  class DSS;
+
   class DebugRequestHandler : public WebServerRequestHandlerJSON {
   public:
+    DebugRequestHandler(DSS& _dss);
     virtual boost::shared_ptr<JSONObject> jsonHandleRequest(const RestfulRequest& _request, Session* _session);
+  private:
+    DSS& m_DSS;
   }; // DebugRequestHandler
 
 } // namespace dss
diff --git a/core/web/handler/devicerequesthandler.cpp b/core/web/handler/devicerequesthandler.cpp
index 44e0022..3736a81 100644
--- a/core/web/handler/devicerequesthandler.cpp
+++ b/core/web/handler/devicerequesthandler.cpp
@@ -22,8 +22,6 @@
 
 #include "devicerequesthandler.h"
 
-#include "core/dss.h"
-
 #include "core/model/apartment.h"
 #include "core/model/device.h"
 
@@ -34,6 +32,10 @@ namespace dss {
 
   //=========================================== DeviceRequestHandler
 
+  DeviceRequestHandler::DeviceRequestHandler(Apartment& _apartment)
+  : m_Apartment(_apartment)
+  { }
+
   boost::shared_ptr<JSONObject> DeviceRequestHandler::jsonHandleRequest(const RestfulRequest& _request, Session* _session) {
     bool ok = true;
     std::string errorMessage;
@@ -44,7 +46,7 @@ namespace dss {
       dsid_t deviceDSID = dsid_t::fromString(deviceDSIDString);
       if(!(deviceDSID == NullDSID)) {
         try {
-          Device& device = getDSS().getApartment().getDeviceByDSID(deviceDSID);
+          Device& device = m_Apartment.getDeviceByDSID(deviceDSID);
           pDevice = &device;
         } catch(std::runtime_error& e) {
           ok = false;
@@ -56,7 +58,7 @@ namespace dss {
       }
     } else if(!deviceName.empty()) {
       try {
-        Device& device = getDSS().getApartment().getDeviceByName(deviceName);
+        Device& device = m_Apartment.getDeviceByName(deviceName);
         pDevice = &device;
       } catch(std::runtime_error&  e) {
         ok = false;
diff --git a/core/web/handler/devicerequesthandler.h b/core/web/handler/devicerequesthandler.h
index 051263c..1ac77b3 100644
--- a/core/web/handler/devicerequesthandler.h
+++ b/core/web/handler/devicerequesthandler.h
@@ -29,7 +29,10 @@ namespace dss {
 
   class DeviceRequestHandler : public DeviceInterfaceRequestHandler {
   public:
+    DeviceRequestHandler(Apartment& _apartment);
     virtual boost::shared_ptr<JSONObject> jsonHandleRequest(const RestfulRequest& _request, Session* _session);
+  private:
+    Apartment& m_Apartment;
   }; // DeviceRequestHandler
 
 }
diff --git a/core/web/handler/eventrequesthandler.cpp b/core/web/handler/eventrequesthandler.cpp
index bad6460..dc47b25 100644
--- a/core/web/handler/eventrequesthandler.cpp
+++ b/core/web/handler/eventrequesthandler.cpp
@@ -23,14 +23,18 @@
 #include "eventrequesthandler.h"
 
 #include "core/web/json.h"
+
 #include "core/event.h"
 #include "core/base.h"
-#include "core/dss.h"
 
 namespace dss {
 
   //=========================================== EventRequestHandler
 
+  EventRequestHandler::EventRequestHandler(EventQueue& _queue)
+  : m_Queue(_queue)
+  { }
+
   boost::shared_ptr<JSONObject> EventRequestHandler::jsonHandleRequest(const RestfulRequest& _request, Session* _session) {
     if(_request.getMethod() == "raise") {
       std::string name = _request.getParameter("name");
@@ -58,7 +62,7 @@ namespace dss {
         }
       }
 
-      getDSS().getEventQueue().pushEvent(evt);
+      m_Queue.pushEvent(evt);
       return success();
     }
     throw std::runtime_error("Unhandled function");
diff --git a/core/web/handler/eventrequesthandler.h b/core/web/handler/eventrequesthandler.h
index 0cc4c50..9c4f0bc 100644
--- a/core/web/handler/eventrequesthandler.h
+++ b/core/web/handler/eventrequesthandler.h
@@ -27,9 +27,14 @@
 
 namespace dss {
 
+  class EventQueue;
+
   class EventRequestHandler : public WebServerRequestHandlerJSON {
   public:
+    EventRequestHandler(EventQueue& _queue);
     virtual boost::shared_ptr<JSONObject> jsonHandleRequest(const RestfulRequest& _request, Session* _session);
+  private:
+    EventQueue& m_Queue;
   }; // StructureRequestHandler
 
 } // namespace dss
diff --git a/core/web/webrequests.h b/core/web/webrequests.h
index 3257ee4..02488d0 100644
--- a/core/web/webrequests.h
+++ b/core/web/webrequests.h
@@ -38,6 +38,7 @@ namespace dss {
   
   class WebServerRequestHandler : public RestfulRequestHandler {
   protected:
+
     DSS& getDSS() {
       return *DSS::getInstance();
     }
diff --git a/core/web/webserver.cpp b/core/web/webserver.cpp
index 2e2c24f..c3db3f4 100644
--- a/core/web/webserver.cpp
+++ b/core/web/webserver.cpp
@@ -185,17 +185,17 @@ namespace dss {
   const char* kHandlerMetering = "metering";
 
   void WebServer::instantiateHandlers() {
-    m_Handlers[kHandlerApartment] = new ApartmentRequestHandler();
+    m_Handlers[kHandlerApartment] = new ApartmentRequestHandler(getDSS().getApartment());
     m_Handlers[kHandlerZone] = new ZoneRequestHandler();
-    m_Handlers[kHandlerDevice] = new DeviceRequestHandler();
-    m_Handlers[kHandlerCircuit] = new CircuitRequestHandler();
+    m_Handlers[kHandlerDevice] = new DeviceRequestHandler(getDSS().getApartment());
+    m_Handlers[kHandlerCircuit] = new CircuitRequestHandler(getDSS().getApartment());
     m_Handlers[kHandlerSet] = new SetRequestHandler();
     m_Handlers[kHandlerProperty] = new PropertyRequestHandler();
-    m_Handlers[kHandlerEvent] = new EventRequestHandler();
+    m_Handlers[kHandlerEvent] = new EventRequestHandler(getDSS().getEventQueue());
     m_Handlers[kHandlerSystem] = new SystemRequestHandler();
     m_Handlers[kHandlerStructure] = new StructureRequestHandler();
     m_Handlers[kHandlerSim] = new SimRequestHandler();
-    m_Handlers[kHandlerDebug] = new DebugRequestHandler();
+    m_Handlers[kHandlerDebug] = new DebugRequestHandler(getDSS());
     m_Handlers[kHandlerMetering] = new MeteringRequestHandler();
   } // instantiateHandlers
   


hooks/post-receive
-- 
digitalSTROM Server


More information about the dss-commits mailing list