VoltAir
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Groups Pages
Classes | Public Types | Public Member Functions | Static Public Member Functions | List of all members
ControllerManager Class Reference

Maintains global list of connected controllers and notifies registered listeners of changes in these statuses. More...

Classes

class  DeviceConnectionListener
 Interface for listening to changes in device connection statuses. More...
 
class  StaticDeviceConnectionListener
 Helper factory class to generate a new DeviceConnectionListerer instance for a static callback function. More...
 

Public Types

typedef std::function< void(int,
bool)> 
DeviceConnectionCallback
 Callback indicating whether the device identified by deviceId has either connected or disconnected. More...
 

Public Member Functions

template<class T = VirtualController>
T * getController (int deviceId, const ControllerFactory *factory=nullptr) const
 Returns the VirtualController corresponding to the specified deviceId. More...
 
template<class T >
bool isControllerOfType (VirtualController *controller) const
 Returns whether or not the specified VirtualController is of the template type. More...
 
template<class T >
bool isControllerOfType (int deviceId) const
 Returns whether or not the VirtualController specified by deviceId is of the template type. More...
 
void reset ()
 Resets the state (i.e. disconnects) of all connected controllers. More...
 
void registerDeviceConnectionListener (DeviceConnectionListener *listener)
 Registers a new listener to be notified of device connection change events. More...
 
void unregisterDeviceConnectionListener (DeviceConnectionListener *listener)
 Unregisters a listener to no longer be notified of device connection change events. More...
 
bool isControllerConnected (int deviceId) const
 Returns whether or not the VirtualController specified by deviceId is currently known to be connected. More...
 
const std::set< int > & getConnectedControllers () const
 Returns the list of all VirtualController deviceIds that are currently connected. More...
 
void onControllerDisconnect (int deviceId)
 Notifies the ControllerManager that the VirtualController specified by deviceId has disconnected. More...
 

Static Public Member Functions

static ControllerManagergetInstance ()
 Returns the global singleton instance of the ControllerManager. More...
 

Detailed Description

Maintains global list of connected controllers and notifies registered listeners of changes in these statuses.

Member Typedef Documentation

typedef std::function<void(int, bool)> ControllerManager::DeviceConnectionCallback

Callback indicating whether the device identified by deviceId has either connected or disconnected.

Member Function Documentation

const std::set<int>& ControllerManager::getConnectedControllers ( ) const
inline

Returns the list of all VirtualController deviceIds that are currently connected.

template<class T = VirtualController>
T* ControllerManager::getController ( int  deviceId,
const ControllerFactory factory = nullptr 
) const
inline

Returns the VirtualController corresponding to the specified deviceId.

This method will construct the VirtualController if it does not exist and a ControllerFactory is provided (i.e. lazily initialize connection status).

Parameters
deviceIdId of the device to retrieve a VirtualController for
factoryControllerFactory to construct a non-existent VirtualController from
static ControllerManager* ControllerManager::getInstance ( )
static

Returns the global singleton instance of the ControllerManager.

bool ControllerManager::isControllerConnected ( int  deviceId) const
inline

Returns whether or not the VirtualController specified by deviceId is currently known to be connected.

Note
This does not directly correspond to the physical connection of the device.
Parameters
deviceIdId of the VirtualController to check for connection
template<class T >
bool ControllerManager::isControllerOfType ( VirtualController controller) const
inline

Returns whether or not the specified VirtualController is of the template type.

Parameters
controllerVirtualController whose type to check
template<class T >
bool ControllerManager::isControllerOfType ( int  deviceId) const
inline

Returns whether or not the VirtualController specified by deviceId is of the template type.

Parameters
deviceIdId of the VirtualController whose type to check
void ControllerManager::onControllerDisconnect ( int  deviceId)

Notifies the ControllerManager that the VirtualController specified by deviceId has disconnected.

Note
There is no analagous onControllerConnect(int) method since ControllerManager does lazy initialization of device connection status.
Parameters
deviceIdId of VirtualController which has become disconnected
void ControllerManager::registerDeviceConnectionListener ( DeviceConnectionListener listener)

Registers a new listener to be notified of device connection change events.

Parameters
listenerListener to be notified of all changes in device connection status
void ControllerManager::reset ( )

Resets the state (i.e. disconnects) of all connected controllers.

void ControllerManager::unregisterDeviceConnectionListener ( DeviceConnectionListener listener)

Unregisters a listener to no longer be notified of device connection change events.

Parameters
listenerListener to no longer be notified of changes in device connection status