Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // copyright bipping
- #ifndef SOFTWARE_ENGINE_H
- #define SOFTWARE_ENGINE_H
- /* includes ============================================================== */
- #include <vector>
- #include <cstdint>
- #include <stdexcept>
- #include <atomic>
- #include <boost/chrono.hpp>
- #include <boost/function.hpp>
- /* types =============================================================== */
- class SoftwareEngine {
- public:
- /* internal public functions =========================================== */
- static SoftwareEngine& GetInstance();
- void Start(); // Méthode publique pour gérer le cycle d'exécution
- void AddTask(boost::function<void()> func, uint32_t intervalMicros);
- void RemoveTask(boost::function<void()> func);
- void ModifyTaskInterval(boost::function<void()> func, uint32_t newIntervalMicros);
- private:
- /* internal private functions ========================================== */
- SoftwareEngine(); // Constructeur privé pour le singleton
- struct Task {
- int id;
- boost::function<void()> func;
- uint32_t intervalMicros;
- uint64_t nextExecution;
- };
- std::vector<Task> taskList;
- void UpdateCurrentTime();
- uint64_t GetCurrentTimeMicros();
- void CheckTasks(std::vector<Task*>& tasksToExecute, Task*& nextTask);
- void ExecuteTasks(const std::vector<Task*>& tasksToExecute);
- void RemoveTaskById(int taskId);
- int GenerateUniqueTaskId();
- void ExecuteNextTask(Task* nextTask);
- uint64_t currentTime;
- std::atomic<int> nextTaskId;
- };
- #endif // SOFTWARE_ENGINE_H
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement