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

git version control dss-commits at forum.digitalstrom.org
Thu Dec 17 10:26:26 CET 2009


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  1aa3478d34a584f6768bfe36b8e34eeb2b4b7468 (commit)
       via  f1d0e66c8217c94517cb975b2e8551d3dfb25f9f (commit)
      from  ed24e1513f2fc5ff0c26f0ab3c407ff543915659 (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 1aa3478d34a584f6768bfe36b8e34eeb2b4b7468
Author: Patrick Stählin <pstaehlin at futurelab.ch>
Date:   Thu Dec 17 10:25:50 2009 +0100

    Email event-plugin by Roman
    
    Closes #250

commit f1d0e66c8217c94517cb975b2e8551d3dfb25f9f
Author: Patrick Stählin <pstaehlin at futurelab.ch>
Date:   Thu Dec 17 10:07:20 2009 +0100

    Improved testcoverage of datetools

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

Changes:
diff --git a/core/datetools.cpp b/core/datetools.cpp
index e29ef5b..ea3a054 100644
--- a/core/datetools.cpp
+++ b/core/datetools.cpp
@@ -99,10 +99,6 @@ namespace dss {
     return m_DateTime.tm_mday;
   } // getDay
 
-  int DateTime::getWeek() const {
-    return -1;
-  } // getWeek
-
   int DateTime::getMonth() const {
     return m_DateTime.tm_mon;
   } // getMonth
diff --git a/core/datetools.h b/core/datetools.h
index 2dfc414..ecdc9f2 100644
--- a/core/datetools.h
+++ b/core/datetools.h
@@ -77,8 +77,6 @@ namespace dss {
 
     /** Returns the day of month */
     int getDay() const;
-    /** Returns the week */
-    int getWeek() const;
     /** Returns the month */
     int getMonth() const;
     /** Returns the year */
diff --git a/core/dss.cpp b/core/dss.cpp
index d3a59fb..0765203 100644
--- a/core/dss.cpp
+++ b/core/dss.cpp
@@ -274,6 +274,8 @@ const char* WebrootDirectory = "data/webroot";
     m_pEventInterpreter->addPlugin(plugin);
     plugin = new EventInterpreterInternalRelay(m_pEventInterpreter.get());
     m_pEventInterpreter->addPlugin(plugin);
+    plugin = new EventInterpreterPluginEmail(m_pEventInterpreter.get());
+    m_pEventInterpreter->addPlugin(plugin);
 
     m_pEventRunner->setEventQueue(m_pEventQueue.get());
     m_pEventInterpreter->setEventRunner(m_pEventRunner.get());
diff --git a/core/eventinterpreterplugins.cpp b/core/eventinterpreterplugins.cpp
index 53801d5..c6d1773 100644
--- a/core/eventinterpreterplugins.cpp
+++ b/core/eventinterpreterplugins.cpp
@@ -21,6 +21,10 @@
 
 #include "eventinterpreterplugins.h"
 
+#include <Poco/Net/MailMessage.h>
+#include <Poco/Net/SMTPClientSession.h>
+#include <Poco/Net/MailRecipient.h>
+
 #include "base.h"
 #include "logger.h"
 #include "DS485Interface.h"
@@ -352,4 +356,94 @@ namespace dss {
     m_IDTargetMap[_subscriptionID] = NULL;
   } // removeSubscription
 
+  //================================================== EventInterpreterPluginEmail
+
+  EventInterpreterPluginEmail::EventInterpreterPluginEmail(EventInterpreter* _pInterpreter)
+  : EventInterpreterPlugin("send_email", _pInterpreter)
+  { } // ctor
+
+  void EventInterpreterPluginEmail::handleEvent(Event& _event, const EventSubscription& _subscription) {
+    std::string emailServer;
+    std::string login;
+    std::string password;
+    std::string sender;
+    std::string receiver;
+    std::string body;
+    std::string subject;
+    if(_event.hasPropertySet("email_server")) {
+      emailServer=_event.getPropertyByName("email_server");
+    } else if(_subscription.getOptions().hasParameter("email_server")) {
+      emailServer=_subscription.getOptions().getParameter("email_server");
+    } else {
+      return;
+    }
+
+    if(_event.hasPropertySet("login")) {
+      login=_event.getPropertyByName("login");
+    } else if(_subscription.getOptions().hasParameter("login")) {
+      login=_subscription.getOptions().getParameter("login");
+    } else {
+      return;
+    }
+
+    if(_event.hasPropertySet("password")) {
+      password=_event.getPropertyByName("password");
+    } else if(_subscription.getOptions().hasParameter("password")) {
+      password=_subscription.getOptions().getParameter("password");
+    } else {
+      return;
+    }
+
+    if(_event.hasPropertySet("sender")) {
+      sender=_event.getPropertyByName("sender");
+    } else if(_subscription.getOptions().hasParameter("sender")) {
+      sender=_subscription.getOptions().getParameter("sender");
+    } else {
+      return;
+    }
+
+    if(_event.hasPropertySet("receiver")) {
+      receiver=_event.getPropertyByName("receiver");
+    } else if(_subscription.getOptions().hasParameter("receiver")) {
+      receiver=_subscription.getOptions().getParameter("receiver");
+    } else {
+      return;
+    }
+
+    if (_event.hasPropertySet("body")) {
+      body=_event.getPropertyByName("body");
+    } else if(_subscription.getOptions().hasParameter("body")) {
+      body=_subscription.getOptions().getParameter("body");
+    } else {
+      return;
+    }
+
+    if(_event.hasPropertySet("subject")) {
+      subject=_event.getPropertyByName("subject");
+    } else if(_subscription.getOptions().hasParameter("subject")) {
+      subject=_subscription.getOptions().getParameter("subject");
+    } else {
+      return;
+    }
+
+    try {
+      Logger::getInstance()->log("EventInterpreterPluginEmail::handleEvent: Sending Email", lsInfo);
+      Poco::Net::MailMessage message;
+      message.setSender(sender);
+      message.addRecipient(Poco::Net::MailRecipient(Poco::Net::MailRecipient::PRIMARY_RECIPIENT, receiver));
+      message.setSubject(subject);
+      message.setContent(body);
+      Logger::getInstance()->log("EventInterpreterPluginEmail::handleEvent: host "+ emailServer, lsInfo);
+      Poco::Net::SMTPClientSession session(emailServer);
+      session.login(Poco::Net::SMTPClientSession::AUTH_LOGIN, login, password);
+      session.sendMessage(message);
+      session.close();
+    }
+    catch (Poco::Exception& exc)
+    {
+      Logger::getInstance()->log("exc.displayText()=" + exc.displayText(), lsFatal);
+    }
+  } // handleEvent
+
+
 } // namespace dss
diff --git a/core/eventinterpreterplugins.h b/core/eventinterpreterplugins.h
index 381d39c..99c9088 100644
--- a/core/eventinterpreterplugins.h
+++ b/core/eventinterpreterplugins.h
@@ -101,6 +101,14 @@ namespace dss {
     HASH_NAMESPACE::hash_map<const std::string, EventRelayTarget*> m_IDTargetMap;
   }; // EventInterpreterInternalRelay
 
+  class EventInterpreterPluginEmail : public EventInterpreterPlugin {
+   private:
+   public:
+       EventInterpreterPluginEmail(EventInterpreter* _pInterpreter);
+
+     virtual void handleEvent(Event& _event, const EventSubscription& _subscription);
+   }; // EventInterpreterPluginEmail
+
 } // namespace dss
 
 #endif /* EVENTINTERPRETERPLUGINS_H_ */
diff --git a/tests/datetoolstests.cpp b/tests/datetoolstests.cpp
index 8ad4788..d669e0f 100644
--- a/tests/datetoolstests.cpp
+++ b/tests/datetoolstests.cpp
@@ -54,6 +54,74 @@ BOOST_AUTO_TEST_CASE(testSimpleDates) {
   BOOST_CHECK_EQUAL(dt3.getYear(), 2007);
 } // testSimpleDates
 
+BOOST_AUTO_TEST_CASE(testAddingMonth) {
+  DateTime dt;
+  DateTime dt2 = dt.addMonth(1);
+
+  assert(dt2.after(dt));
+  assert(!dt2.before(dt));
+  assert(dt.before(dt2));
+  assert(!dt.after(dt2));
+
+  BOOST_CHECK(dt2.after(dt));
+  BOOST_CHECK(!dt2.before(dt));
+  BOOST_CHECK(dt.before(dt2));
+  BOOST_CHECK(!dt.after(dt2));
+} // testAddingMonth
+
+BOOST_AUTO_TEST_CASE(testISODate) {
+  DateTime dt = DateTime::fromISO("20080506T080102Z");
+  BOOST_CHECK_EQUAL(2008, dt.getYear());
+  BOOST_CHECK_EQUAL(4, dt.getMonth()); // zero based
+  BOOST_CHECK_EQUAL(6, dt.getDay());
+  BOOST_CHECK_EQUAL(8, dt.getHour());
+  BOOST_CHECK_EQUAL(1, dt.getMinute());
+  BOOST_CHECK_EQUAL(2, dt.getSecond());
+} // testISODate
+
+BOOST_AUTO_TEST_CASE(testTooshortISODate) {
+  BOOST_CHECK_THROW(DateTime::fromISO("20080506T080102"), std::invalid_argument);
+} // testISODate
+
+BOOST_AUTO_TEST_CASE(testMonthOutOfRange) {
+  BOOST_CHECK_THROW(DateTime::fromISO("20083006T080102Z"), std::invalid_argument);
+} // testMonthOutOfRange
+
+BOOST_AUTO_TEST_CASE(testMissingTISODate) {
+  BOOST_CHECK_THROW(DateTime::fromISO("20080506X080102Z"), std::invalid_argument);
+} // testMissingTISODate
+
+BOOST_AUTO_TEST_CASE(testHourOutOfRangeISODate) {
+  BOOST_CHECK_THROW(DateTime::fromISO("20080506T250102Z"), std::invalid_argument);
+} // testHourOutOfRangeISODate
+
+BOOST_AUTO_TEST_CASE(testMinuteOutOfRangeISODate) {
+  BOOST_CHECK_THROW(DateTime::fromISO("20080506T086202Z"), std::invalid_argument);
+} // testMinuteOutOfRangeISODate
+
+BOOST_AUTO_TEST_CASE(testSecondsOutOfRangeISODate) {
+  BOOST_CHECK_THROW(DateTime::fromISO("20080506T080162Z"), std::invalid_argument);
+} // testSecondOutOfRangeISODate
+
+BOOST_AUTO_TEST_CASE(testGetDayOfYear) {
+  BOOST_CHECK_EQUAL(1, DateTime::fromISO("20090102T100000Z").getDayOfYear()); // zero based
+} // testGetDayOfYear
+
+BOOST_AUTO_TEST_CASE(testSetters) {
+  DateTime dt;
+  dt.setDay(1);
+  dt.setMonth(2);
+  dt.setYear(2009);
+  dt.setHour(3);
+  dt.setMinute(4);
+  dt.setSecond(5);
+  dt.validate();
+  DateTime other;
+  other.setDate(1, 2, 2009);
+  other.setTime(3,4,5);
+  BOOST_CHECK_EQUAL(dt, other);
+} // testSetters
+
 BOOST_AUTO_TEST_CASE(testAddingComparing) {
   DateTime dt;
   DateTime dt2 = dt.addHour(1);


hooks/post-receive
-- 
digitalSTROM Server


More information about the dss-commits mailing list