WPILibC++  unspecified
 All Classes Files Functions Variables Typedefs Enumerations Enumerator Pages
Scheduler.h
1 /*----------------------------------------------------------------------------*/
2 /* Copyright (c) FIRST 2011-2016. All Rights Reserved. */
3 /* Open Source Software - may be modified and shared by FRC teams. The code */
4 /* must be accompanied by the FIRST BSD license file in the root directory of */
5 /* the project. */
6 /*----------------------------------------------------------------------------*/
7 
8 #ifndef __SCHEDULER_H__
9 #define __SCHEDULER_H__
10 
11 #include "Commands/Command.h"
12 #include "ErrorBase.h"
13 #include "SmartDashboard/NamedSendable.h"
14 #include "networktables/NetworkTable.h"
15 #include "SmartDashboard/SmartDashboard.h"
16 #include <list>
17 #include <map>
18 #include <memory>
19 #include <set>
20 #include <string>
21 #include <vector>
22 #include "HAL/cpp/priority_mutex.h"
23 
24 class ButtonScheduler;
25 class Subsystem;
26 
27 class Scheduler : public ErrorBase, public NamedSendable {
28  public:
29  static Scheduler *GetInstance();
30 
31  void AddCommand(Command *command);
32  void AddButton(ButtonScheduler *button);
33  void RegisterSubsystem(Subsystem *subsystem);
34  void Run();
35  void Remove(Command *command);
36  void RemoveAll();
37  void ResetAll();
38  void SetEnabled(bool enabled);
39 
40  void UpdateTable();
41  std::string GetSmartDashboardType() const;
42  void InitTable(std::shared_ptr<ITable> subTable);
43  std::shared_ptr<ITable> GetTable() const;
44  std::string GetName() const;
45  std::string GetType() const;
46 
47  private:
48  Scheduler();
49  virtual ~Scheduler() = default;
50 
51  void ProcessCommandAddition(Command *command);
52 
53  Command::SubsystemSet m_subsystems;
54  priority_mutex m_buttonsLock;
55  typedef std::vector<ButtonScheduler *> ButtonVector;
56  ButtonVector m_buttons;
57  typedef std::vector<Command *> CommandVector;
58  priority_mutex m_additionsLock;
59  CommandVector m_additions;
60  typedef std::set<Command *> CommandSet;
61  CommandSet m_commands;
62  bool m_adding = false;
63  bool m_enabled = true;
64  std::vector<std::string> commands;
65  std::vector<double> ids;
66  std::vector<double> toCancel;
67  std::shared_ptr<ITable> m_table;
68  bool m_runningCommandsChanged = false;
69 };
70 #endif
Definition: Scheduler.h:27
void ResetAll()
Completely resets the scheduler.
Definition: Scheduler.cpp:203
void Remove(Command *command)
Removes the Command from the Scheduler.
Definition: Scheduler.cpp:176
void UpdateTable()
Update the network tables associated with the Scheduler object on the SmartDashboard.
Definition: Scheduler.cpp:216
void Run()
Runs a single iteration of the loop.
Definition: Scheduler.cpp:108
Definition: ButtonScheduler.h:14
Definition: Subsystem.h:18
Base class for most objects.
Definition: ErrorBase.h:66
static Scheduler * GetInstance()
Returns the Scheduler, creating it if one does not exist.
Definition: Scheduler.cpp:26
void InitTable(std::shared_ptr< ITable > subTable)
Initializes a table for this sendable object.
Definition: Scheduler.cpp:265
Definition: priority_mutex.h:53
std::shared_ptr< ITable > GetTable() const
Definition: Scheduler.cpp:273
The interface for sendable objects that gives the sendable a default name in the Smart Dashboard...
Definition: NamedSendable.h:19
std::string GetName() const
Definition: Scheduler.cpp:259
std::string GetSmartDashboardType() const
Definition: Scheduler.cpp:263
The Command class is at the very core of the entire command framework.
Definition: Command.h:54
void AddCommand(Command *command)
Add a command to be scheduled later.
Definition: Scheduler.cpp:40
void RegisterSubsystem(Subsystem *subsystem)
Registers a Subsystem to this Scheduler, so that the Scheduler might know if a default Command needs ...
Definition: Scheduler.cpp:164