1 #include "OISConfig.h" 2 #ifdef OIS_WIN32_WIIMOTE_SUPPORT 3 /* 4 The zlib/libpng License 5 6 Copyright (c) 2005-2007 Phillip Castaneda (pjcast -- www.wreckedgames.com) 7 8 This software is provided 'as-is', without any express or implied warranty. In no event will 9 the authors be held liable for any damages arising from the use of this software. 10 11 Permission is granted to anyone to use this software for any purpose, including commercial 12 applications, and to alter it and redistribute it freely, subject to the following 13 restrictions: 14 15 1. The origin of this software must not be misrepresented; you must not claim that 16 you wrote the original software. If you use this software in a product, 17 an acknowledgment in the product documentation would be appreciated but is 18 not required. 19 20 2. Altered source versions must be plainly marked as such, and must not be 21 misrepresented as being the original software. 22 23 3. This notice may not be removed or altered from any source distribution. 24 */ 25 #ifndef OIS_WiiMoteFactoryCreator_H 26 #define OIS_WiiMoteFactoryCreator_H 27 28 #include "OISPrereqs.h" 29 #include "OISFactoryCreator.h" 30 #include <deque> 31 32 //Forward declare boost classes used 33 namespace boost 34 { 35 class thread; 36 class mutex; 37 } 38 39 namespace OIS 40 { 41 //Forward declare local classes 42 class WiiMote; 43 44 //! Max amount of Wiis we will attempt to find 45 #define OIS_cWiiMote_MAX_WIIS 4 46 47 /** WiiMote Factory Creator Class */ 48 class _OISExport WiiMoteFactoryCreator : public FactoryCreator 49 { 50 public: 51 WiiMoteFactoryCreator(); 52 ~WiiMoteFactoryCreator(); 53 54 //FactoryCreator Overrides 55 /** @copydoc FactoryCreator::deviceList */ 56 DeviceList freeDeviceList(); 57 58 /** @copydoc FactoryCreator::totalDevices */ 59 int totalDevices(Type iType); 60 61 /** @copydoc FactoryCreator::freeDevices */ 62 int freeDevices(Type iType); 63 64 /** @copydoc FactoryCreator::vendorExist */ 65 bool vendorExist(Type iType, const std::string & vendor); 66 67 /** @copydoc FactoryCreator::createObject */ 68 Object* createObject(InputManager* creator, Type iType, bool bufferMode, const std::string & vendor = ""); 69 70 /** @copydoc FactoryCreator::destroyObject */ 71 void destroyObject(Object* obj); 72 73 //! Local method used to return controller to pool 74 void _returnWiiMote(int id); 75 76 protected: 77 //! Internal - threaded method 78 bool _updateWiiMotesThread(); 79 80 //! String name of this vendor 81 std::string mVendorName; 82 83 //! queue of open wiimotes (int represents index into hid device) 84 std::deque<int> mFreeWiis; 85 86 //! Number of total wiimotes 87 int mCount; 88 89 //! Boost thread execution object (only alive when at least 1 wiimote is alive) 90 boost::thread *mtThreadHandler; 91 92 //! Gaurds access to the Active WiiMote List 93 boost::mutex *mtWiiMoteListMutex; 94 95 //! List of created (active) WiiMotes 96 std::vector<WiiMote*> mtInUseWiiMotes; 97 98 //! Used to signal thread running or not 99 volatile bool mtThreadRunning; 100 }; 101 } 102 #endif //OIS_WiiMoteFactoryCreator_H 103 #endif 104