blob: eb749aa2b456c0f703f1563897b58465db5cc34f [file] [log] [blame]
Brian Silvermanf7f267a2017-02-04 16:16:08 -08001/*----------------------------------------------------------------------------*/
2/* Copyright (c) FIRST 2011-2017. 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#pragma once
9
10#include <list>
11#include <map>
12#include <memory>
13#include <set>
14#include <string>
15#include <vector>
16
17#include "Commands/Command.h"
18#include "ErrorBase.h"
19#include "HAL/cpp/priority_mutex.h"
20#include "SmartDashboard/NamedSendable.h"
21#include "SmartDashboard/SmartDashboard.h"
22#include "networktables/NetworkTable.h"
23
24namespace frc {
25
26class ButtonScheduler;
27class Subsystem;
28
29class Scheduler : public ErrorBase, public NamedSendable {
30 public:
31 static Scheduler* GetInstance();
32
33 void AddCommand(Command* command);
34 void AddButton(ButtonScheduler* button);
35 void RegisterSubsystem(Subsystem* subsystem);
36 void Run();
37 void Remove(Command* command);
38 void RemoveAll();
39 void ResetAll();
40 void SetEnabled(bool enabled);
41
42 void UpdateTable();
43 std::string GetSmartDashboardType() const;
44 void InitTable(std::shared_ptr<ITable> subTable);
45 std::shared_ptr<ITable> GetTable() const;
46 std::string GetName() const;
47 std::string GetType() const;
48
49 private:
50 Scheduler();
51 virtual ~Scheduler() = default;
52
53 void ProcessCommandAddition(Command* command);
54
55 Command::SubsystemSet m_subsystems;
56 priority_mutex m_buttonsLock;
57 typedef std::vector<ButtonScheduler*> ButtonVector;
58 ButtonVector m_buttons;
59 typedef std::vector<Command*> CommandVector;
60 priority_mutex m_additionsLock;
61 CommandVector m_additions;
62 typedef std::set<Command*> CommandSet;
63 CommandSet m_commands;
64 bool m_adding = false;
65 bool m_enabled = true;
66 std::vector<std::string> commands;
67 std::vector<double> ids;
68 std::vector<double> toCancel;
69 std::shared_ptr<ITable> m_table;
70 bool m_runningCommandsChanged = false;
71};
72
73} // namespace frc