Permalink
Cannot retrieve contributors at this time
Name already in use
A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?
garlic/src/cron.hpp
Go to fileThis commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
40 lines (34 sloc)
986 Bytes
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 Source Code Form is subject to the terms | |
* of the Mozilla Public License, v. 2.0. If a | |
* copy of the MPL was not distributed with this | |
* file, You can obtain one at http://mozilla.org/MPL/2.0/. | |
*/ | |
#pragma once | |
#include <functional> | |
#include <string> | |
#include <vector> | |
#include <thread> | |
namespace Garlic{ | |
class CronJob; | |
class Cron{ | |
std::vector<std::shared_ptr<CronJob>> job_queue; | |
std::thread job_thread; | |
bool working; | |
public: | |
/// Cant satisfy the cron expression request. For example non existant date. | |
class unsatisfiable : public std::exception{}; | |
/// Trying to set an invalid rule. | |
class invalid_rule : public std::exception{}; | |
Cron(); | |
~Cron(); | |
/// Adds a function to call acording to that timespec | |
void add(const std::string ×pec, const std::function<void()> &f); | |
/// Starts the cron daemon, creates a new thread. | |
void start(); | |
/// Stops the cron daemon | |
void stop(); | |
/// Works until stop | |
void work(); | |
}; | |
}; |