Advertisement
bipping

SoftwareEngine.h

Oct 7th, 2024
69
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.56 KB | Source Code | 0 0
  1. //  copyright bipping
  2. #ifndef SOFTWARE_ENGINE_H
  3. #define SOFTWARE_ENGINE_H
  4.  
  5. /* includes ============================================================== */
  6. #include <vector>
  7. #include <cstdint>
  8. #include <stdexcept>
  9. #include <atomic>
  10. #include <boost/chrono.hpp>
  11. #include <boost/function.hpp>
  12.  
  13. /* types =============================================================== */
  14. class SoftwareEngine {
  15.  public:
  16.     /* internal public functions =========================================== */
  17.     static SoftwareEngine& GetInstance();
  18.  
  19.     void Start();  // Méthode publique pour gérer le cycle d'exécution
  20.  
  21.     void AddTask(boost::function<void()> func, uint32_t intervalMicros);
  22.     void RemoveTask(boost::function<void()> func);
  23.     void ModifyTaskInterval(boost::function<void()> func, uint32_t newIntervalMicros);
  24.  
  25.  private:
  26.     /* internal private functions ========================================== */
  27.     SoftwareEngine();  // Constructeur privé pour le singleton
  28.  
  29.     struct Task {
  30.         int id;
  31.         boost::function<void()> func;
  32.         uint32_t intervalMicros;
  33.         uint64_t nextExecution;
  34.     };
  35.  
  36.     std::vector<Task> taskList;
  37.  
  38.     void UpdateCurrentTime();
  39.     uint64_t GetCurrentTimeMicros();
  40.  
  41.     void CheckTasks(std::vector<Task*>& tasksToExecute, Task*& nextTask);
  42.     void ExecuteTasks(const std::vector<Task*>& tasksToExecute);
  43.     void RemoveTaskById(int taskId);
  44.     int GenerateUniqueTaskId();
  45.     void ExecuteNextTask(Task* nextTask);
  46.  
  47.     uint64_t currentTime;
  48.     std::atomic<int> nextTaskId;
  49. };
  50.  
  51. #endif  // SOFTWARE_ENGINE_H
  52.  
Tags: Header
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement