FreeStick  0.3
Cross Platform Open Sorce Joystick Lib
FSBaseManager.h
Go to the documentation of this file.
1 /**************************************************************************
2 Created by Alan Uthoff on 10/8/2013
3 Copyright (C) 2013.
4 
5 This Code is free software; you can redistribute it and/or
6 modify it under the terms of the zlib/libpng License as published
7 by the Free Software Foundation; either
8 version 2.1 of the License, or (at your option) any later version.
9 This software is provided 'as-is', without any express or implied warranty.
10 
11 In no event will the authors be held liable for any damages arising from the use of this software.
12 
13 Permission is granted to anyone to use this software for any purpose,
14 including commercial applications, and to alter it and redistribute
15 it freely, subject to the following restrictions:
16 
17 1. The origin of this software must not be misrepresented;
18 you must not claim that you wrote the original software.
19 If you use this software in a product, an acknowledgment
20 in the product documentation would be appreciated but is not required.
21 
22 2. Altered source versions must be plainly marked as such,
23 and must not be misrepresented as being the original software.
24 
25 3. This notice may not be removed or altered from any source distribution.
26 **************************************************************************/
27 
28 #pragma once
29 #include <vector>
30 #include <unordered_map>
31 #include "../Interfaces/IFSJoystickListener.h"
32 #include "../Interfaces/IFSJoystickInfo.h"
33 #include "../Interfaces/IFSDevice.h"
34 #include "../baseClasses/FSBaseDevice.h"
35 #include "../baseClasses/FSBaseEvent.h"
36 #include "../Interfaces/IFSDeviceIDCreator.h"
37 #include <stdlib.h>
38 #include <new>
39 #include <limits>
71 namespace freestick
72 {
73 
80  {
81 
82  public:
83  FSBaseManager();
84  virtual ~FSBaseManager();
93  virtual void ListenForAllJoysticksForEventTypes(unsigned int eventFlags,IFSJoystickListener & listener);
94 
95  virtual void UnListenForAllJoysticksForEventTypes(unsigned int eventFlags,IFSJoystickListener & listener);
96 
97  // void ListenForJoystick(IFSJoystickListener & listener,unsigned int deviceID,FSDeviceInput input){};
98 
99  // void UnListenForJoystick(IFSJoystickListener & listener ,unsigned int deviceID,FSDeviceInput input){};
100 
101 
102  inline float convertRawToNormalizedRanger(double value,minMaxNumber maxValue,minMaxNumber minValue);
103  virtual void init() ;
104  virtual void init(IFSDeviceIDCreator * idCreator);
105 #ifdef __APPLE__
106 #pragma mark -Advance API
107 #endif
108  virtual const FSBaseDevice * getDevice(idNumber deviceID);
109  private:
110  std::unordered_multimap<FreeStickEventType,std::pair<IFSJoystickListener *,bool> > _joystickDeviceListeners;
111  typedef std::unordered_multimap<FreeStickEventType,std::pair<IFSJoystickListener *,bool> >::iterator joystickDeviceListenersItr;
112 
113  std::unordered_map<unsigned int,std::multimap<FreeStickEventType,IFSJoystickListener * > > _joystickDeviceInputListeners;
114  std::vector<IFSJoystickListener *> allJoystickListeners;
115  IFSDeviceIDCreator * _devicIDCreator; //if not null called to get next decice id from
116  std::vector<std::pair<FreeStickEventType,IFSJoystickListener * > > _listenersToCleanUp;
117  protected:
118  std::unordered_map<unsigned int, FSBaseDevice * > deviceMap;
119  //void ListenForAllJoysticks(IFSJoystickListener & listener){ ListenForJoystick(listener,0,AllInputs);}
120  // void UnListenForAllJoysticks(IFSJoystickListener & listener){ UnListenForJoystick(listener,0,AllInputs);}
123 
126  virtual void addDevice(FSBaseDevice * device);
127  virtual void removeDevice(FSBaseDevice * device);
128  virtual void inputOnDeviceChanged(FreeStickEventType eventType,FSEventAction eventAction,FSDeviceInput inputType,idNumber deviceID,idNumber deviceControlID,int newValue,int oldValue,minMaxNumber min,minMaxNumber max);
129  virtual void inputOnDeviceChangedWithNormilzedValues(FreeStickEventType eventType, FSEventAction eventAction, FSDeviceInput inputType, idNumber deviceID, idNumber deviceControlID, float newValue, float oldValue);
130  virtual elementID getNextID();
131  void updateEvent(FSBaseEvent & event);
132 
133  };
134 }
Definition: IFSJoystickListener.h:34
void RemoveListenerForEventType(FreeStickEventType eventType, IFSJoystickListener &listener)
Definition: FSBaseManager.cpp:178
virtual void inputOnDeviceChangedWithNormilzedValues(FreeStickEventType eventType, FSEventAction eventAction, FSDeviceInput inputType, idNumber deviceID, idNumber deviceControlID, float newValue, float oldValue)
Definition: FSBaseManager.cpp:297
void ListenForJoystickEvent(FreeStickEventType eventType, IFSJoystickListener &listener)
FSEventAction
Definition: IFSEvent.h:46
virtual void init()
Definition: FSBaseManager.cpp:41
virtual void UnListenForAllJoysticksForEventTypes(unsigned int eventFlags, IFSJoystickListener &listener)
Definition: FSBaseManager.cpp:116
virtual const FSBaseDevice * getDevice(idNumber deviceID)
Definition: FSBaseManager.cpp:72
virtual void ListenForAllJoysticksForEventTypes(unsigned int eventFlags, IFSJoystickListener &listener)
This is the base manager.
Definition: FSBaseManager.cpp:80
float convertRawToNormalizedRanger(double value, minMaxNumber maxValue, minMaxNumber minValue)
Definition: FSBaseManager.cpp:283
uint32_t idNumber
Definition: FSTypes.h:33
FreeStickEventType
Definition: IFSEvent.h:36
Definition: IFSDeviceIDCreator.h:30
FSBaseManager()
Definition: FSBaseManager.cpp:36
void UnListenForAllJoysticksForEventType(FreeStickEventType eventType, IFSJoystickListener &listener)
Definition: FSBaseManager.cpp:156
std::unordered_map< unsigned int, FSBaseDevice * > deviceMap
Definition: FSBaseManager.h:118
Definition: FSBaseDevice.h:32
Definition: FSBaseEvent.h:33
virtual ~FSBaseManager()
Definition: FSBaseManager.cpp:56
uint64_t deviceID
Definition: FSTypes.h:37
virtual elementID getNextID()
Definition: FSBaseManager.cpp:343
virtual void addDevice(FSBaseDevice *device)
Definition: FSBaseManager.cpp:318
virtual void removeDevice(FSBaseDevice *device)
Definition: FSBaseManager.cpp:328
void updateEvent(FSBaseEvent &event)
Definition: FSBaseManager.cpp:212
unsigned int elementID
Definition: FSTypes.h:36
virtual void inputOnDeviceChanged(FreeStickEventType eventType, FSEventAction eventAction, FSDeviceInput inputType, idNumber deviceID, idNumber deviceControlID, int newValue, int oldValue, minMaxNumber min, minMaxNumber max)
Definition: FSBaseManager.cpp:313
Definition: FSBaseDevice.h:35
void ListenForAllJoysticksForEventType(FreeStickEventType eventType, IFSJoystickListener &listener)
Definition: FSBaseManager.cpp:199
This is the base manager.
Definition: FSBaseManager.h:79
FSDeviceInput
Definition: IFSDevice.h:31
int32_t minMaxNumber
Definition: FSTypes.h:34