17 #ifndef CONTROLLERMANAGER_H
18 #define CONTROLLERMANAGER_H
24 #include "ControllerFactory.h"
25 #include "VirtualController.h"
85 template <
class T = VirtualController>
87 std::unique_ptr<VirtualController>& controller = mControllers[deviceId];
88 initControllerIfNeeded(deviceId, controller, factory);
89 return dynamic_cast<T*
>(controller.get());
98 return dynamic_cast<T*
>(controller) !=
nullptr;
108 return isControllerOfType<T>(mControllers[deviceId].get());
134 return mControllerIds.find(deviceId) != mControllerIds.end();
141 return mControllerIds;
159 mutable std::map<int, std::unique_ptr<VirtualController>> mControllers;
160 mutable std::set<int> mControllerIds;
161 std::set<DeviceConnectionListener*> mDeviceConnectionListeners;
163 void notifyDeviceConnectionChanged(
int deviceId,
bool isConnected)
const;
164 void initControllerIfNeeded(
int deviceId, std::unique_ptr<VirtualController>& controller,
170 #endif // CONTROLLERMANAGER_H
virtual void onDeviceConnectionChanged(int deviceId, bool isConnected) override
Callback function invoked when the device identified by deviceId has connected or disconnected...
bool isControllerOfType(int deviceId) const
Returns whether or not the VirtualController specified by deviceId is of the template type...
Definition: ControllerManager.h:107
const std::set< int > & getConnectedControllers() const
Returns the list of all VirtualController deviceIds that are currently connected. ...
Definition: ControllerManager.h:140
Helper factory class to generate a new DeviceConnectionListerer instance for a static callback functi...
Definition: ControllerManager.h:59
Software represention and state capable of describing almost all physical controllers.
Definition: VirtualController.h:36
void unregisterDeviceConnectionListener(DeviceConnectionListener *listener)
Unregisters a listener to no longer be notified of device connection change events.
Base interface for constructing virtual controllers from a deviceId.
Definition: ControllerFactory.h:34
void reset()
Resets the state (i.e. disconnects) of all connected controllers.
std::function< void(int, bool)> DeviceConnectionCallback
Callback indicating whether the device identified by deviceId has either connected or disconnected...
Definition: ControllerManager.h:52
Interface for listening to changes in device connection statuses.
Definition: ControllerManager.h:38
bool isControllerConnected(int deviceId) const
Returns whether or not the VirtualController specified by deviceId is currently known to be connected...
Definition: ControllerManager.h:133
void registerDeviceConnectionListener(DeviceConnectionListener *listener)
Registers a new listener to be notified of device connection change events.
Maintains global list of connected controllers and notifies registered listeners of changes in these ...
Definition: ControllerManager.h:32
void onControllerDisconnect(int deviceId)
Notifies the ControllerManager that the VirtualController specified by deviceId has disconnected...
T * getController(int deviceId, const ControllerFactory *factory=nullptr) const
Returns the VirtualController corresponding to the specified deviceId.
Definition: ControllerManager.h:86
static ControllerManager * getInstance()
Returns the global singleton instance of the ControllerManager.
bool isControllerOfType(VirtualController *controller) const
Returns whether or not the specified VirtualController is of the template type.
Definition: ControllerManager.h:97
virtual void onDeviceConnectionChanged(int deviceId, bool isConnected)=0
Callback function invoked when the device identified by deviceId has connected or disconnected...