blob: fc552564052038e96952330699f70ea255057696 [file] [log] [blame]
Brian Silverman26e4e522015-12-17 01:56:40 -05001/*----------------------------------------------------------------------------*/
Brian Silverman1a675112016-02-20 20:42:49 -05002/* Copyright (c) FIRST 2011-2016. All Rights Reserved. */
Brian Silverman26e4e522015-12-17 01:56:40 -05003/* Open Source Software - may be modified and shared by FRC teams. The code */
Brian Silverman1a675112016-02-20 20:42:49 -05004/* must be accompanied by the FIRST BSD license file in the root directory of */
5/* the project. */
Brian Silverman26e4e522015-12-17 01:56:40 -05006/*----------------------------------------------------------------------------*/
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
24class ButtonScheduler;
25class Subsystem;
26
27class 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