solarpowerlog trunk
/home/tobi/workspace/solarpowerlog/src/interfaces/CTimedWork.h
Go to the documentation of this file.
00001 /* ----------------------------------------------------------------------------
00002  solarpowerlog
00003  Copyright (C) 2009  Tobias Frost
00004 
00005  This file is part of solarpowerlog.
00006 
00007  Solarpowerlog is free software; However, it is dual-licenced
00008  as described in the file "COPYING".
00009 
00010  For this file (CTimedWork.h), the license terms are:
00011 
00012  You can redistribute it and/or  modify it under the terms of the GNU Lesser
00013  General Public License (LGPL) as published by the Free Software Foundation;
00014  either version 3 of the License, or (at your option) any later version.
00015 
00016  This program is distributed in the hope that it will be useful, but
00017  WITHOUT ANY WARRANTY; without even the implied warranty of
00018  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00019  Lesser General Public License for more details.
00020 
00021  You should have received a copy of the GNU Library General Public
00022  License along with this proramm; if not, see
00023  <http://www.gnu.org/licenses/>.
00024  ----------------------------------------------------------------------------
00025  */
00026 
00033 #ifndef CTIMEDWORK_H_
00034 #define CTIMEDWORK_H_
00035 
00036 #ifdef HAVE_CONFIG_H
00037 #include "config.h"
00038 #endif
00039 
00040 #include "patterns/ICommand.h"
00041 #include "CWorkScheduler.h"
00042 #include "boost/date_time/posix_time/posix_time.hpp"
00043 
00044 #include <boost/thread.hpp>
00045 
00050 class CTimedWork
00051 {
00052 public:
00055      explicit CTimedWork( CWorkScheduler *sch );
00056 
00057      virtual ~CTimedWork();
00058 
00060      void run();
00061 
00062      void ScheduleWork( ICommand *Command, struct timespec ts );
00063 
00065      void RequestTermination( void );
00066 
00067 private:
00068      CTimedWork()
00069      {
00070      }
00071 
00072      void _main( void );
00073 
00074 #if 1
00075      struct time_compare
00076      {
00077           bool operator()( const boost::posix_time::ptime t1,
00078                const boost::posix_time::ptime t2 ) const
00079           {
00080                if (t1 > t2)
00081                     return false;
00082                return true;
00083           }
00084           ;
00085      };
00086 
00087      multimap<boost::posix_time::ptime, ICommand*, time_compare>
00088           TimedCommands;
00089 #endif
00090 
00091      ICommand *cmd;
00093      struct timespec ts;
00096      CWorkScheduler *sch;
00097 
00098      volatile bool terminate;
00099 
00100      boost::thread thread;
00101 
00102      boost::mutex mut;
00103 
00104 };
00105 
00106 #endif /* CTIMEDWORK_H_ */