[dss-commits] r8887 - in dss/trunk: . core data

dss-commits at forum.digitalstrom.org dss-commits at forum.digitalstrom.org
Thu Nov 5 16:09:15 CET 2009


Author: jwinkelmann
Date: 2009-11-05 16:09:15 +0100 (Thu, 05 Nov 2009)
New Revision: 8887

Modified:
   dss/trunk/core/dss.cpp
   dss/trunk/core/dss.h
   dss/trunk/data/config.xml
   dss/trunk/main.cpp
Log:
move config loading from DSS::run() to DSS::initialize(); make the later return a bool to signal success (refs #133)


Modified: dss/trunk/core/dss.cpp
===================================================================
--- dss/trunk/core/dss.cpp	2009-11-05 14:04:57 UTC (rev 8886)
+++ dss/trunk/core/dss.cpp	2009-11-05 15:09:15 UTC (rev 8887)
@@ -120,7 +120,7 @@
     }
   } // setDataDirectory
 
-  void DSS::initialize(const vector<string>& _properties) {
+  bool DSS::initialize(const vector<string>& _properties) {
     m_State = ssCreatingSubsystems;
 
     m_pDS485Interface = boost::shared_ptr<DS485Proxy>(new DS485Proxy(this));
@@ -181,6 +181,34 @@
         m_pPropertySystem->setStringValue(name, value, true);
       }
     }
+
+    // -- setup logging
+    if(!loadConfig()) {
+      Logger::getInstance()->log("Could not parse config file", lsFatal);
+      return false;
+    }
+
+    // see whether we have a log file set in config.xml, and set the
+    // log target accordingly
+    PropertyNodePtr pNode = getPropertySystem().getProperty("/config/logfile");
+    if (pNode) {
+      std::string logFileName = pNode->getStringValue();
+      Logger::getInstance()->log("Logging to file: " + logFileName, lsInfo);
+
+      boost::shared_ptr<dss::LogTarget>
+        logTarget(new dss::FileLogTarget(logFileName));
+      if (!dss::Logger::getInstance()->setLogTarget(logTarget)) {
+        Logger::getInstance()->log("Failed to open logfile '" + 
+                                   logFileName + "'", lsFatal);
+        return false;
+      }
+    } else {
+      Logger::getInstance()->log("No logfile configured, logging to stdout", 
+                                 lsInfo);
+    }
+
+
+    return true;
   }
 
 #ifdef WITH_TESTS
@@ -231,31 +259,7 @@
 
   void DSS::run() {
     Logger::getInstance()->log("DSS starting up....", lsInfo);
-    if(!loadConfig()) {
-      Logger::getInstance()->log("Could not parse config file", lsFatal);
-      return;
-    }
-    
-    // see whether we have a log file set in config.xml, and set the
-    // log target accordingly
-    PropertyNodePtr pNode = getPropertySystem().getProperty("/config/logfile");
-    if (pNode) {
-      std::string logFileName = pNode->getStringValue();      
-      Logger::getInstance()->log("Logging to file: " + logFileName, lsInfo);
-      
-      boost::shared_ptr<dss::LogTarget> 
-        logTarget(new dss::FileLogTarget(logFileName));
-      if (!dss::Logger::getInstance()->setLogTarget(logTarget)) {
-        Logger::getInstance()->log("Failed to open logfile '" + logFileName + 
-                                   "'; exiting", lsFatal);
-        return;
-      }
-    } else {
-      Logger::getInstance()->log("No logfile configured, logging to stdout", 
-                                 lsInfo);
-    }
-    
-    dss::Logger::getInstance()->log(versionString(), lsInfo);
+    Logger::getInstance()->log(versionString(), lsInfo);
 
     SystemInfo info;
     info.collect();

Modified: dss/trunk/core/dss.h
===================================================================
--- dss/trunk/core/dss.h	2009-11-05 14:04:57 UTC (rev 8886)
+++ dss/trunk/core/dss.h	2009-11-05 15:09:15 UTC (rev 8887)
@@ -93,7 +93,7 @@
     int getUptime() const;
   public:
     ~DSS();
-    void initialize(const std::vector<std::string>& _properties);
+    bool initialize(const std::vector<std::string>& _properties);
     void run();
 
     static DSS* getInstance();

Modified: dss/trunk/data/config.xml
===================================================================
--- dss/trunk/data/config.xml	2009-11-05 14:04:57 UTC (rev 8886)
+++ dss/trunk/data/config.xml	2009-11-05 15:09:15 UTC (rev 8887)
@@ -14,6 +14,13 @@
         </property>
       </property>
     </property>
+
+<!--
+    <property name="logfile" type="string">
+	<value>/var/log/dss/dss.log</value>
+    </property>
+-->
+
  <!--
     <property name="sensornest/interface" type="string">
       <value>wlan0</value>

Modified: dss/trunk/main.cpp
===================================================================
--- dss/trunk/main.cpp	2009-11-05 14:04:57 UTC (rev 8886)
+++ dss/trunk/main.cpp	2009-11-05 15:09:15 UTC (rev 8887)
@@ -173,17 +173,20 @@
   } else {
     if(!quitAfterTests) {
       // start DSS
-      dss::DSS::getInstance()->initialize(properties);
+      if (dss::DSS::getInstance()->initialize(properties)) {
 #ifndef __APPLE__
-      if(daemonize) {
-        int result = daemon(1,0);
-        if(result != 0) {
-          perror("daemon()");
-          return 0;
+        if(daemonize) {
+          int result = daemon(1,0);
+          if(result != 0) {
+            perror("daemon()");
+            return 0;
+          }
         }
+#endif
+        dss::DSS::getInstance()->run();
+      } else {
+        dss::Logger::getInstance()->log("Failed to initialize dss. Exiting", lsFatal);
       }
-#endif
-      dss::DSS::getInstance()->run();
     }
     if(dss::DSS::hasInstance()) {
       dss::DSS::shutdown();



More information about the dss-commits mailing list