Now you can download a copy of these docs so you can use them offline! Download now
Subsystem.cpp
00001 /*----------------------------------------------------------------------------*/ 00002 /* Copyright (c) FIRST 2011. All Rights Reserved. */ 00003 /* Open Source Software - may be modified and shared by FRC teams. The code */ 00004 /* must be accompanied by the FIRST BSD license file in $(WIND_BASE)/WPILib. */ 00005 /*----------------------------------------------------------------------------*/ 00006 00007 #include "Commands/Subsystem.h" 00008 00009 #include "Commands/Command.h" 00010 #include "Commands/Scheduler.h" 00011 #include "NetworkTables/NetworkTable.h" 00012 #include "WPIErrors.h" 00013 00018 Subsystem::Subsystem(const char *name) : 00019 m_table(NULL), 00020 m_currentCommand(NULL), 00021 m_defaultCommand(NULL), 00022 m_initializedDefaultCommand(false) 00023 { 00024 m_name = name; 00025 Scheduler::GetInstance()->RegisterSubsystem(this); 00026 } 00035 void Subsystem::InitDefaultCommand() { 00036 00037 } 00038 00048 void Subsystem::SetDefaultCommand(Command *command) 00049 { 00050 if (command == NULL) 00051 { 00052 m_defaultCommand = NULL; 00053 } 00054 else 00055 { 00056 bool found = false; 00057 Command::SubsystemSet requirements = command->GetRequirements(); 00058 Command::SubsystemSet::iterator iter = requirements.begin(); 00059 for (; iter != requirements.end(); iter++) 00060 { 00061 if (*iter == this) 00062 { 00063 found = true; 00064 break; 00065 } 00066 } 00067 00068 if (!found) 00069 { 00070 wpi_setWPIErrorWithContext(CommandIllegalUse, "A default command must require the subsystem"); 00071 return; 00072 } 00073 00074 m_defaultCommand = command; 00075 } 00076 if (m_table != NULL) 00077 { 00078 if (m_defaultCommand != 0) 00079 { 00080 m_table->PutBoolean("hasDefault", true); 00081 m_table->PutSubTable("default", m_defaultCommand->GetTable()); 00082 } 00083 else 00084 { 00085 m_table->PutBoolean("hasDefault", false); 00086 } 00087 } 00088 } 00089 00094 Command *Subsystem::GetDefaultCommand() 00095 { 00096 if (!m_initializedDefaultCommand) { 00097 m_initializedDefaultCommand = true; 00098 InitDefaultCommand(); 00099 } 00100 return m_defaultCommand; 00101 } 00102 00107 void Subsystem::SetCurrentCommand(Command *command) 00108 { 00109 m_currentCommand = command; 00110 } 00111 00116 Command *Subsystem::GetCurrentCommand() 00117 { 00118 return m_currentCommand; 00119 } 00120 00126 void Subsystem::ConfirmCommand() 00127 { 00128 if (m_table != NULL) 00129 { 00130 if (m_currentCommand != NULL) 00131 { 00132 m_table->PutBoolean("hasCommand", true); 00133 m_table->PutSubTable("command", m_currentCommand->GetTable()); 00134 } 00135 else 00136 { 00137 m_table->PutBoolean("hasCommand", false); 00138 } 00139 } 00140 } 00141 00142 std::string Subsystem::GetName() 00143 { 00144 return "Subsystem"; 00145 } 00146 00147 std::string Subsystem::GetType() 00148 { 00149 return "Subsystem"; 00150 } 00151 00152 NetworkTable *Subsystem::GetTable() 00153 { 00154 if (m_table == NULL) 00155 { 00156 m_table = new NetworkTable(); 00157 m_table->PutInt("count", 0); 00158 } 00159 return m_table; 00160 }
Generated on Thu Jan 12 2012 22:35:24 for WPILibC++ by
1.7.1