version 0.3.0
[fms.git] / include / freenet / iindexrequester.h
index 8744dfd..b74e69a 100644 (file)
@@ -3,7 +3,6 @@
 \r
 #include "../idatabase.h"\r
 #include "../ilogger.h"\r
-#include "../datetime.h"\r
 #include "../option.h"\r
 #include "../stringfunctions.h"\r
 #include "ifreenetregistrable.h"\r
 #include "ifcpmessagehandler.h"\r
 #include "iperiodicprocessor.h"\r
 \r
+#include <Poco/DateTime.h>\r
+#include <Poco/Timestamp.h>\r
+#include <Poco/Timespan.h>\r
+\r
 #ifdef XMEM\r
        #include <xmem.h>\r
 #endif\r
@@ -40,9 +43,9 @@ protected:
        virtual const bool HandleGetFailed(FCPMessage &message)=0;\r
        virtual void RemoveFromRequestList(const IDTYPE id);\r
 \r
-       DateTime m_tempdate;\r
-       DateTime m_lastreceived;\r
-       DateTime m_lastpopulated;\r
+       Poco::DateTime m_tempdate;\r
+       Poco::DateTime m_lastreceived;\r
+       Poco::DateTime m_lastpopulated;\r
        std::string m_messagebase;\r
        std::map<IDTYPE,bool> m_ids;                    // map of all ids we know and whether we have requested file from them yet\r
        std::vector<IDTYPE> m_requesting;               // list of ids we are currently requesting from\r
@@ -71,21 +74,21 @@ void IIndexRequester<IDTYPE>::FCPConnected()
        // make sure variables have been initialized by the derived class\r
        if(m_maxrequests==-1)\r
        {\r
-               m_log->WriteLog(LogFile::LOGLEVEL_FATAL,"IIndexRequester<IDTYPE>::FCPConnected maxrequests not initialized correctly!");\r
+               m_log->fatal("IIndexRequester<IDTYPE>::FCPConnected maxrequests not initialized correctly!");\r
        }\r
        if(m_fcpuniquename=="")\r
        {\r
-               m_log->WriteLog(LogFile::LOGLEVEL_FATAL,"IIndexRequester<IDTYPE>::FCPConnected fcpuniquename not initialized correctly!");\r
+               m_log->fatal("IIndexRequester<IDTYPE>::FCPConnected fcpuniquename not initialized correctly!");\r
        }\r
        if(m_fcpuniquename.find("|")!=std::string::npos)\r
        {\r
-               m_log->WriteLog(LogFile::LOGLEVEL_FATAL,"IIndexRequester<IDTYPE>::FCPConnected fcpuniquename contains | character!  This is not a valid character!");\r
+               m_log->fatal("IIndexRequester<IDTYPE>::FCPConnected fcpuniquename contains | character!  This is not a valid character!");\r
        }\r
 \r
-       m_lastreceived.SetToGMTime();\r
+       m_lastreceived=Poco::Timestamp();\r
        m_requesting.clear();\r
        PopulateIDList();\r
-       m_lastpopulated.SetToGMTime();\r
+       m_lastpopulated=Poco::Timestamp();\r
 }\r
 \r
 template <class IDTYPE>\r
@@ -101,7 +104,7 @@ const bool IIndexRequester<IDTYPE>::HandleMessage(FCPMessage &message)
        if(message["Identifier"].find(m_fcpuniquename)==0)\r
        {\r
 \r
-               m_lastreceived.SetToGMTime();\r
+               m_lastreceived=Poco::Timestamp();\r
 \r
                if(message.GetName()=="DataFound")\r
                {\r
@@ -140,17 +143,16 @@ void IIndexRequester<IDTYPE>::InitializeIIndexRequester()
        m_fcpuniquename="";\r
 \r
        Option::Instance()->Get("MessageBase",m_messagebase);\r
-       m_tempdate.SetToGMTime();\r
-       m_lastreceived.SetToGMTime();\r
-       m_lastpopulated.SetToGMTime();\r
-       m_lastpopulated.Add(0,-10);\r
+       m_tempdate=Poco::Timestamp();\r
+       m_lastreceived=Poco::Timestamp();\r
+       m_lastpopulated=Poco::Timestamp();\r
+       m_lastpopulated-=Poco::Timespan(0,0,10,0,0);\r
 }\r
 \r
 template <class IDTYPE>\r
 void IIndexRequester<IDTYPE>::Process()\r
 {\r
-       DateTime now;\r
-       now.SetToGMTime();\r
+       Poco::DateTime now;\r
 \r
        // max is the smaller of the config value or the total number of ids we will request from\r
        typename std::map<IDTYPE,bool>::size_type max=m_maxrequests>m_ids.size() ? m_ids.size() : m_maxrequests;\r
@@ -172,24 +174,24 @@ void IIndexRequester<IDTYPE>::Process()
                else\r
                {\r
                        // we requested from all ids in the list, repopulate the list (only every 10 minutes)\r
-                       if(m_lastpopulated<(now-1.0/144.0))\r
+                       if(m_lastpopulated<(now-Poco::Timespan(0,0,10,0,0)))\r
                        {\r
                                PopulateIDList();\r
-                               m_lastpopulated.SetToGMTime();\r
+                               m_lastpopulated=Poco::Timestamp();\r
                        }\r
                }\r
        }\r
        // special case - if there were 0 ids on the list when we started then we will never get a chance to repopulate the list\r
        // this will recheck for ids every minute\r
-       if(m_ids.size()==0 && m_tempdate<(now-(1.0/1440.0)))\r
+       if(m_ids.size()==0 && m_tempdate<(now-Poco::Timespan(0,0,1,0,0)))\r
        {\r
                PopulateIDList();\r
                m_tempdate=now;\r
        }\r
        // if we haven't received any messages to this object in 10 minutes, clear the requests and repopulate id list\r
-       if(m_ids.size()>0 && m_lastreceived<(now-(1.0/144.0)))\r
+       if(m_ids.size()>0 && m_lastreceived<(now-Poco::Timespan(0,0,10,0,0)))\r
        {\r
-               m_log->WriteLog(LogFile::LOGLEVEL_ERROR,"IIndexRequester<IDTYPE>::Process "+m_fcpuniquename+" Object has not received any messages in 10 minutes.  Restarting requests.");\r
+               m_log->error("IIndexRequester<IDTYPE>::Process "+m_fcpuniquename+" Object has not received any messages in 10 minutes.  Restarting requests.");\r
                FCPConnected();\r
        }\r
 \r