-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Geoffrey McRae
committed
Nov 4, 2012
1 parent
620c734
commit 7edbc37
Showing
6 changed files
with
189 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
/* | ||
* ARMT (Another Remote Monitoring Tool) | ||
* Copyright (C) Geoffrey McRae 2012 <geoff@spacevs.com> | ||
* | ||
* This program is free software; you can redistribute it and/or | ||
* modify it under the terms of the GNU General Public License | ||
* as published by the Free Software Foundation; either version 2 | ||
* of the License, or (at your option) any later version. | ||
* | ||
* This program is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU General Public License | ||
* along with this program; if not, write to the Free Software | ||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. | ||
* | ||
*/ | ||
|
||
#include "CScheduler.h" | ||
|
||
CScheduler::CScheduler() | ||
{ | ||
} | ||
|
||
CScheduler::~CScheduler() | ||
{ | ||
for(JobList::iterator it = m_jobs.begin(); it != m_jobs.end(); ++it) | ||
{ | ||
ISchedulerJob *job = *it; | ||
delete job; | ||
} | ||
} | ||
|
||
bool CScheduler::Run() | ||
{ | ||
std::time_t currentTime = std::time(NULL); | ||
bool ran = false; | ||
|
||
for(JobList::iterator it = m_jobs.begin(); it != m_jobs.end(); ++it) | ||
{ | ||
ISchedulerJob *job = *it; | ||
if (job->GetRunTime() > currentTime) | ||
continue; | ||
|
||
ran = true; | ||
job->Execute(); | ||
job->SetRunTime(job->GetRunTime() + job->GetDelayInterval()); | ||
} | ||
|
||
return ran; | ||
} | ||
|
||
void CScheduler::AddJob(ISchedulerJob *job) | ||
{ | ||
m_jobs.push_back(job); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
/* | ||
* ARMT (Another Remote Monitoring Tool) | ||
* Copyright (C) Geoffrey McRae 2012 <geoff@spacevs.com> | ||
* | ||
* This program is free software; you can redistribute it and/or | ||
* modify it under the terms of the GNU General Public License | ||
* as published by the Free Software Foundation; either version 2 | ||
* of the License, or (at your option) any later version. | ||
* | ||
* This program is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU General Public License | ||
* along with this program; if not, write to the Free Software | ||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. | ||
* | ||
*/ | ||
|
||
#ifndef _CSCHEDULER_H_ | ||
#define _CSCHEDULER_H_ | ||
|
||
#include <ctime> | ||
#include <vector> | ||
|
||
class ISchedulerJob | ||
{ | ||
public: | ||
ISchedulerJob() {} | ||
virtual ~ISchedulerJob() {} | ||
|
||
virtual std::time_t GetRunTime() = 0; | ||
virtual void SetRunTime(std::time_t time) = 0; | ||
virtual unsigned int GetDelayInterval() = 0; | ||
virtual void Execute() = 0; | ||
}; | ||
|
||
class CScheduler | ||
{ | ||
public: | ||
CScheduler(); | ||
~CScheduler(); | ||
|
||
/** | ||
* Run's any jobs that need running | ||
* @return True if any jobs ran | ||
*/ | ||
bool Run(); | ||
|
||
/** | ||
* Add a recurring job to execute at the specified time | ||
* @param job An instance of ISchedulerJob | ||
*/ | ||
void AddJob(ISchedulerJob *job); | ||
|
||
private: | ||
typedef std::vector<ISchedulerJob *> JobList; | ||
|
||
JobList m_jobs; | ||
}; | ||
|
||
#endif // _CSCHEDULER_H_ |