solarpowerlog trunk
/home/tobi/workspace/solarpowerlog/src/interfaces/CWorkScheduler.h
Go to the documentation of this file.
00001 
00002 /* ----------------------------------------------------------------------------
00003    solarpowerlog
00004    Copyright (C) 2009  Tobias Frost
00005 
00006    This file is part of solarpowerlog.
00007 
00008    Solarpowerlog is free software; However, it is dual-licenced
00009    as described in the file "COPYING".
00010 
00011    For this file (CWorkScheduler.h), the license terms are:
00012 
00013    You can redistribute it and/or  modify it under the terms of the GNU Lesser
00014    General Public License (LGPL) as published by the Free Software Foundation;
00015    either version 3 of the License, or (at your option) any later version.
00016 
00017    This program is distributed in the hope that it will be useful, but
00018    WITHOUT ANY WARRANTY; without even the implied warranty of
00019    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00020    Lesser General Public License for more details.
00021 
00022    You should have received a copy of the GNU Library General Public
00023    License along with this proramm; if not, see
00024    <http://www.gnu.org/licenses/>.
00025    ----------------------------------------------------------------------------
00026 */
00033 #ifndef CWORKSCHEDULER_H_
00034 #define CWORKSCHEDULER_H_
00035 
00036 #ifdef HAVE_CONFIG_H
00037 #include "config.h"
00038 #include "porting.h"
00039 #endif
00040 
00041 #include <time.h>
00042 #include <list>
00043 
00044 #include <semaphore.h>
00045 #include <map>
00046 
00047 #include <boost/thread/mutex.hpp>
00048 
00049 class ICommand;
00050 class ICommandTarget;
00051 class CTimedWork;
00052 
00053 using namespace std;
00054 
00055 
00071 class CWorkScheduler {
00072 
00073      friend class CTimedWork;
00074 
00075 public:
00076      CWorkScheduler();
00077      virtual ~CWorkScheduler();
00078 
00079      void ScheduleWork(ICommand *Command);
00080 
00082      void ScheduleWork(ICommand *Commmand, struct timespec ts);
00083 
00092      bool DoWork(bool block=false);
00093 
00094 private:
00095 
00096      CTimedWork *timedwork;
00097 
00098      list<ICommand*> CommandsDue;
00099 
00100 #if 0
00101      struct timepec_compare
00102      {
00103            bool operator()(const struct timespec t1, const struct timespec t2) const
00104             {
00105                 if(t1.tv_sec < t2.tv_sec) return true;
00106                 if(t1.tv_sec > t2.tv_sec) return false;
00107                 if(t1.tv_nsec < t2.tv_nsec) return true;
00108                 return false;
00109             };
00110      };
00111 
00112      multimap<struct timespec, ICommand*, timepec_compare> TimedCommands;
00113 #endif
00114 
00117      ICommand *getnextcmd(void);
00118 
00119 private:
00120      sem_t semaphore;
00121 
00122 protected:
00123      boost::mutex mut;
00124 
00125 };
00126 
00127 #endif /* CWORKSCHEDULER_H_ */