Scheduler.h
1 /*
2 
3 Copyright (c) 2018, Johnathan Corkery. (jcorkery@umich.edu)
4 All rights reserved.
5 
6 This file is part of the Dynacoe project (https://github.com/jcorks/Dynacoe)
7 Dynacoe was released under the MIT License, as detailed below.
8 
9 
10 
11 Permission is hereby granted, free of charge, to any person obtaining a copy
12 of this software and associated documentation files (the "Software"), to deal
13 in the Software without restriction, including without limitation the rights
14 to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
15 copies of the Software, and to permit persons to whom the Software is furnished
16 to do so, subject to the following conditions:
17 
18 The above copyright notice and this permission notice shall
19 be included in all copies or substantial portions of the Software.
20 
21 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
22 EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
23 MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
24 IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
25 DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
26 ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
27 DEALINGS IN THE SOFTWARE.
28 
29 
30 
31 */
32 
33 #ifndef H_DC_COMPONENT_SCHEDULER_INCLUDED
34 #define H_DC_COMPONENT_SCHEDULER_INCLUDED
35 
36 #include <Dynacoe/Component.h>
37 
38 
39 
40 namespace Dynacoe {
41 struct TaskM;
42 
43 
46 
49 class Scheduler : public Dynacoe::Component {
50  public:
51  Scheduler();
52  ~Scheduler();
53  void OnStep();
54 
55 
56 
67  void StartTask(
68  const std::string & name,
69  uint32_t intervalMS,
71  uint32_t initialDelay=0,
72  void * data = nullptr
73  );
74 
75 
79  void EndTask(const std::string & name);
80 
83  uint32_t GetTaskInterval(const std::string & name);
84 
87  std::vector<std::string> GetTasks();
88 
92  void Pause();
93 
96  void Resume();
97 
98 
99  std::string GetInfo();
100  private:
101 
102  std::set<TaskM*, bool(*)(const TaskM *, const TaskM *)> * tasks;
103 };
105 
106 }
107 
108 
109 
110 
111 #endif
void Resume()
Resumes all tasks.
A Scheduler allows for automatic running of logic at certain intervals.
Definition: Scheduler.h:49
bool(*)(void *, Component *component, Entity::ID self, Entity::ID source, const std::vector< std::string > &args) EventHandler
A handler for an event.
Definition: Component.h:132
std::vector< std::string > GetTasks()
Returns a vector of the names of currently running tasks.
Definition: AssetID.h:37
void EndTask(const std::string &name)
Halts the task with the given name.
void OnStep()
Function that is called upon each Run iteration. Component Run()s are run before the entity's run fun...
void StartTask(const std::string &name, uint32_t intervalMS, Component::EventHandler task, uint32_t initialDelay=0, void *data=nullptr)
Begins a new task. A task will run once per every announced millisecond interval. The resolution is o...
std::string GetInfo()
Returns a string containing human-readable information on the state of the component.
void Pause()
Stops running tasks until Resume() is run.
uint32_t GetTaskInterval(const std::string &name)
Returns the number of milliseconds that the given task is set to.
Class that extends the functionality of an Entity, but as a removable and addable object...
Definition: Component.h:66