VoltAir
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Groups Pages
InputRouter.h
1 /*
2  * Copyright (C) 2014 Google Inc.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
17 #ifndef INPUTROUTER_H
18 #define INPUTROUTER_H
19 
20 #include <map>
21 #include <memory>
22 #include <vector>
23 #include "ControllerEvent.h"
24 #include "ControllerFactory.h"
25 
40 class InputRouter {
41 public:
42  virtual ~InputRouter() { }
43 
50  void onControllerDisconnect(int deviceId);
59  virtual bool routeControllerEvent(ControllerEvent* event);
60 
61 protected:
65  InputRouter();
66 
72  bool conflictsWithExistingFactories(const ControllerFactory& factory) const;
76  bool hasFactoryRoutes() const { return !mControllerFactories.empty(); }
86  void clearFactories();
87 
88 private:
95  int getNextFakeDeviceId();
96 
97  // Maps a scheme to a fake deviceId for single-instance devices
98  std::map<ControllerFactory*, int> mFakeSingletonDeviceIds;
99  // Maps real deviceId to a map of scheme to fake deviceId
100  // E.g. each connected gamepad would be split according to the different schemes, generating
101  // # gamepads * # schemes different fake deviceIds
102  std::map<int, std::map<ControllerFactory*, int>> mFakeMultiDeviceIds;
103  // Factories by which to route
104  std::vector<std::unique_ptr<ControllerFactory>> mControllerFactories;
105 
106  // The next available fake device id to be assigned
107  static int sNextFakeDeviceId;
108 };
109 
110 #endif // INPUTROUTER_H
virtual bool routeControllerEvent(ControllerEvent *event)
Routes the given ControllerEvent.
bool conflictsWithExistingFactories(const ControllerFactory &factory) const
Returns whether or not factory conficts (i.e. intersects) with ControllerFactorys previously added to...
void onControllerDisconnect(int deviceId)
Notifies the ControllerManager of device disconnections for all VirtualControllers associated with th...
Base interface for constructing virtual controllers from a deviceId.
Definition: ControllerFactory.h:34
void clearFactories()
Clears all ControllerFactorys used for routing by this InputRouter.
A platform independent event generated by controller device.
Definition: ControllerEvent.h:34
void addControllerFactory(ControllerFactory *factory)
Adds a ControllerFactory to route by.
InputRouter()
Constructs an empty InputRouter.
Routes ControllerEvents according to inherent ControllerFactory specifications.
Definition: InputRouter.h:40
bool hasFactoryRoutes() const
Returns whether or not this InputRouter contains any ControllerFactorys to route by.
Definition: InputRouter.h:76