root/juggler/branches/2.2/modules/gadgeteer/gadget/Type/DeviceFactory.h
| Revision 20244, 3.2 kB (checked in by patrick, 1 year ago) | |
|---|---|
| |
| Line | |
|---|---|
| 1 | /*************** <auto-copyright.pl BEGIN do not edit this line> ************** |
| 2 | * |
| 3 | * VR Juggler is (C) Copyright 1998-2007 by Iowa State University |
| 4 | * |
| 5 | * Original Authors: |
| 6 | * Allen Bierbaum, Christopher Just, |
| 7 | * Patrick Hartling, Kevin Meinert, |
| 8 | * Carolina Cruz-Neira, Albert Baker |
| 9 | * |
| 10 | * This library is free software; you can redistribute it and/or |
| 11 | * modify it under the terms of the GNU Library General Public |
| 12 | * License as published by the Free Software Foundation; either |
| 13 | * version 2 of the License, or (at your option) any later version. |
| 14 | * |
| 15 | * This library is distributed in the hope that it will be useful, |
| 16 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 17 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| 18 | * Library General Public License for more details. |
| 19 | * |
| 20 | * You should have received a copy of the GNU Library General Public |
| 21 | * License along with this library; if not, write to the |
| 22 | * Free Software Foundation, Inc., 59 Temple Place - Suite 330, |
| 23 | * Boston, MA 02111-1307, USA. |
| 24 | * |
| 25 | *************** <auto-copyright.pl END do not edit this line> ***************/ |
| 26 | |
| 27 | #ifndef _GADGET_DEVICE_FACTORY_H_ |
| 28 | #define _GADGET_DEVICE_FACTORY_H_ |
| 29 | //#pragma once |
| 30 | |
| 31 | #include <gadget/gadgetConfig.h> |
| 32 | #include <vector> |
| 33 | #include <jccl/Config/ConfigElementPtr.h> |
| 34 | #include <vpr/Util/Singleton.h> |
| 35 | |
| 36 | #include <gadget/Type/DeviceConstructorBase.h> |
| 37 | |
| 38 | #include <vpr/Util/Assert.h> |
| 39 | |
| 40 | namespace gadget |
| 41 | { |
| 42 | |
| 43 | /** \class DeviceFactory DeviceFactory.h gadget/Type/DeviceFactory.h |
| 44 | * |
| 45 | * Object used for creating devices. |
| 46 | * @note Singleton |
| 47 | */ |
| 48 | class GADGET_CLASS_API DeviceFactory |
| 49 | { |
| 50 | private: |
| 51 | /** Singleton so must be private. */ |
| 52 | DeviceFactory() |
| 53 | { |
| 54 | mConstructors = std::vector<DeviceConstructorBase*>(0); |
| 55 | vprASSERT(mConstructors.size() == 0); |
| 56 | } |
| 57 | |
| 58 | ~DeviceFactory(); |
| 59 | |
| 60 | /** |
| 61 | * Performs static loading of devices that cannot be loaded through the |
| 62 | * dynamic plug-in mechanism. |
| 63 | * |
| 64 | * @post Devices known to the system statically at initialization time are |
| 65 | * loaded. |
| 66 | */ |
| 67 | void loadKnownDevices(); |
| 68 | |
| 69 | public: |
| 70 | void registerDevice(DeviceConstructorBase* constructor); |
| 71 | |
| 72 | /** |
| 73 | * Queries if the factory knows about the given device. |
| 74 | * @pre element != NULL, element is a valid element. |
| 75 | * @param element The element we are requesting about knowledge to create. |
| 76 | * @return true if the factory knows how to create the device; false if not. |
| 77 | */ |
| 78 | bool recognizeDevice(jccl::ConfigElementPtr element); |
| 79 | |
| 80 | /** |
| 81 | * Loads the specified device. |
| 82 | * @pre recognizeDevice(element) == true. |
| 83 | * @param element The specification of the device to load. |
| 84 | * @return NULL is returned if the device failed to load. |
| 85 | * Otherwise, a pointer to the loaded device is returned. |
| 86 | */ |
| 87 | Input* loadDevice(jccl::ConfigElementPtr element); |
| 88 | |
| 89 | private: |
| 90 | /** |
| 91 | * Finds a constructor for the given device type. |
| 92 | * @return -1 is returned if the constructor is not found. |
| 93 | * Otherwise, the index of the constructor is returned. |
| 94 | */ |
| 95 | int findConstructor(jccl::ConfigElementPtr element); |
| 96 | |
| 97 | void debugDump(); |
| 98 | |
| 99 | |
| 100 | private: |
| 101 | std::vector<DeviceConstructorBase*> mConstructors; /**< List of the device constructors */ |
| 102 | |
| 103 | vprSingletonHeaderWithInitFunc(DeviceFactory, loadKnownDevices); |
| 104 | }; |
| 105 | |
| 106 | } // end namespace gadget |
| 107 | |
| 108 | #endif |
Note: See TracBrowser for help on using the browser.
