Files
allwpilib/wpilibc/wpilibC++/include/LiveWindow/LiveWindow.h
James Kuszmaul f65e697107 Revert changes preventing old user code from compiling.
I'm not 100% sure whether we want these, but they are a quick
find and replace to do.

Basically, there are two primary things that we have done
this summer that break existing user code:
-Changing GetInstance() calls to return references instead
 of pointers. This forces users to change from doing something
 like LiveWindow::GetInstance()->AddSensor() to LiveWindow::GetInstance().AddSensor().
-Making PIDGet() and related calls const, forcing users to change
 the function signatures wherever they override them.

The GetInstance() calls don't really matter to me either way,
especially since there are no real ownership issues going on there,
unlike the rest of the smart pointer-related changes.

For the const stuff, it is certainly more correct to mandate that
user PIDGet() functions be const and the such, but at the same time,
I'm not sure that there is any strong need for it, and the errors
generated are not the most helpful. While this wouldn't necessarily
be an issue for more experienced teams or completely new teams (who
don't have any old code to be reusing), it may cause issues for more
average teams who aren't familiar with the intricacies of C++ anything.

Change-Id: I6e7007982069292ea70e6d0fc8ca40203340df1b
2015-09-16 19:10:01 -04:00

100 lines
3.0 KiB
C++

#ifndef _LIVE_WINDOW_H
#define _LIVE_WINDOW_H
#include "LiveWindow/LiveWindowSendable.h"
#include "tables/ITable.h"
#include "Commands/Scheduler.h"
#include <vector>
#include <map>
#include <memory>
struct LiveWindowComponent {
std::string subsystem;
std::string name;
bool isSensor;
LiveWindowComponent() = default;
LiveWindowComponent(std::string subsystem, std::string name, bool isSensor) {
this->subsystem = subsystem;
this->name = name;
this->isSensor = isSensor;
}
};
/**
* The LiveWindow class is the public interface for putting sensors and
* actuators
* on the LiveWindow.
*
* @author Brad Miller
*/
class LiveWindow {
public:
static LiveWindow *GetInstance();
void Run();
#if !defined(_MSC_VER)
[[deprecated(
"Raw pointers are deprecated; pass the component using shared_ptr "
"instead.")]]
#else
__declspec(deprecated("**Raw pointers are deprecated; pass the component using shared_ptr instead**"))
#endif
void AddSensor(const std::string &subsystem, const std::string &name,
LiveWindowSendable *component);
void AddSensor(const std::string &subsystem, const std::string &name,
LiveWindowSendable &component);
void AddSensor(const std::string &subsystem, const std::string &name,
std::shared_ptr<LiveWindowSendable> component);
#if !defined(_MSC_VER)
[[deprecated(
"Raw pointers are deprecated; pass the component using shared_ptr "
"instead.")]]
#else
__declspec(deprecated("**Raw pointers are deprecated; pass the component using shared_ptr instead**"))
#endif
void AddActuator(const std::string &subsystem, const std::string &name,
LiveWindowSendable *component);
void AddActuator(const std::string &subsystem, const std::string &name,
LiveWindowSendable &component);
void AddActuator(const std::string &subsystem, const std::string &name,
std::shared_ptr<LiveWindowSendable> component);
#if !defined(_MSC_VER)
[[deprecated(
"Raw pointers are deprecated; pass the component using shared_ptr "
"instead.")]]
#else
__declspec(deprecated("**Raw pointers are deprecated; pass the component using shared_ptr instead**"))
#endif
void AddSensor(std::string type, int channel, LiveWindowSendable *component);
void AddActuator(std::string type, int channel,
LiveWindowSendable *component);
void AddActuator(std::string type, int module, int channel,
LiveWindowSendable *component);
bool IsEnabled() const { return m_enabled; }
void SetEnabled(bool enabled);
protected:
LiveWindow();
virtual ~LiveWindow() = default;
private:
void UpdateValues();
void Initialize();
void InitializeLiveWindowComponents();
std::vector<std::shared_ptr<LiveWindowSendable>> m_sensors;
std::map<std::shared_ptr<LiveWindowSendable>, LiveWindowComponent> m_components;
std::shared_ptr<ITable> m_liveWindowTable;
std::shared_ptr<ITable> m_statusTable;
Scheduler *m_scheduler;
bool m_enabled = false;
bool m_firstTime = true;
};
#endif