Main Page | Class Hierarchy | Alphabetical List | Class List | Directories | File List | Class Members | File Members | Related Pages

PhxRawInputEngine.h

Go to the documentation of this file.
00001 #ifndef PHX_RAW_INPUT_ENGINE_H
00002 #define PHX_RAW_INPUT_ENGINE_H
00003 
00011 #include <Phx/PhxConfig.h>
00012 #include <Phx/PhxTypes.h>
00013 #include <Phx/Core/PhxNamedInterface.h>
00014 #include <Phx/Util/PhxListeners.h>
00015 #include <Phx/Util/PhxLocks.h>
00016 #include <vector>
00017 
00018 namespace Phx {
00019 
00032   class RawInputEngine : public NamedInterface {
00033     class ButtonStateClass;
00034     class ButtonIdentifierClass;
00035     class AxisIdentifierClass;
00036   public:
00037     const static NamedInterface::Type INTERFACE_TYPE;
00038     const static String               INTERFACE_TYPE_NAME;
00039 
00040     const static NamedInterface::Identifier RAW_INPUT_ENGINE_IDENTIFIER;
00041     const static String                     RAW_INPUT_ENGINE_NAME;
00042 
00044     typedef uint32_t AxisState;
00046     typedef ValueType<AxisIdentifierClass, uint32_t>  AxisIdentifier;
00048     const static AxisIdentifier  INVALID_AXIS_IDENTIFIER;
00049 
00051     typedef ValueType<ButtonIdentifierClass, uint32_t>  ButtonIdentifier;
00053     const static ButtonIdentifier  INVALID_BUTTON_IDENTIFIER;
00054 
00056     typedef ValueType<ButtonStateClass, uint32_t> ButtonState;
00058     const static ButtonState PRESSED;
00060     const static ButtonState RELEASED;
00061 
00062 
00063     class Driver;
00064     class Client;
00065     
00066     virtual ~RawInputEngine() {}
00067 
00072     class Listener : public BaseListener<RawInputEngine, Listener> {
00073     public:
00074       virtual void onNewDriver(const String& driverName) = 0;
00075       virtual void onDeleteDriver(const String& driverName) = 0;
00076     };
00077 
00093     virtual Ptr<Driver> newDriver(const String& driverName) = 0;
00094 
00107     virtual Ptr<Client> newClient(const String& driverName) = 0;
00108 
00117     virtual std::vector<String> driverNames(void) const = 0;
00118 
00126     virtual void listener(Listener* listener) = 0;
00127   };
00128 
00133   class RawInputEngine::Driver : public LockedPtrInterface<Driver> {
00134   public:
00135     typedef RawInputEngine::ButtonIdentifier ButtonIdentifier;
00136     typedef RawInputEngine::AxisIdentifier   AxisIdentifier;
00137     typedef RawInputEngine::ButtonState ButtonState;
00138     typedef RawInputEngine::AxisState   AxisState;
00139 
00140     // virtual destructor
00141     virtual ~Driver() {}
00142 
00150     class Listener : public BaseListener<Driver, Listener> {
00151     public:
00155       virtual void onUpdate(void) = 0;
00156     };
00157 
00163     virtual void listener(Listener* listener) = 0;
00164     
00181     virtual void buttonName(ButtonIdentifier button, const String& name) = 0;
00182     
00190     virtual String buttonName(ButtonIdentifier button) const = 0;
00191     
00192     // virtual ButtonIdentifier nameButton(const String& name) = 0;
00193     
00203     virtual void buttonState(ButtonIdentifier button, ButtonState state) = 0;
00204     
00212     virtual ButtonState buttonState(ButtonIdentifier button) const = 0;
00213     
00229     virtual void axisName(AxisIdentifier axis, const String& name) = 0;
00230     
00238     virtual String axisName(AxisIdentifier axis) const = 0;
00239 
00240     // virtual AxisIdentifier nameAxis(const String& name) = 0;
00241     
00251     virtual void axisState(AxisIdentifier axis, AxisState state) = 0;
00252     
00260     virtual AxisState axisState(AxisIdentifier axis) const = 0;
00261 
00266     const String& name() const { return mName; }
00267 
00268   protected:
00269     void setName(const String& name) { mName = name; }
00270   private:
00271     String mName;
00272   };
00273 
00282   class RawInputEngine::Client : public LockedPtrInterface<Client> {
00283   public:
00284     typedef RawInputEngine::ButtonIdentifier ButtonIdentifier;
00285     typedef RawInputEngine::AxisIdentifier   AxisIdentifier;
00286     typedef RawInputEngine::ButtonState ButtonState;
00287     typedef RawInputEngine::AxisState   AxisState;
00288 
00289     // virtual destructor
00290     virtual ~Client() {}
00291 
00301     class Listener : public BaseListener<Client, Listener> {
00302     public:
00303       virtual void onAxisState(AxisIdentifier axis) = 0;
00304       virtual void onButtonState(ButtonIdentifier button) = 0;
00305     };
00306 
00313     virtual void listener(Listener* listener) = 0;
00314 
00324     virtual String buttonName(ButtonIdentifier button) const = 0;
00325 
00334     virtual ButtonState buttonState(ButtonIdentifier button) const = 0;
00335 
00348     virtual ButtonState previousButtonState(ButtonIdentifier button) const = 0;
00349 
00358     virtual String axisName(AxisIdentifier axis) const = 0;
00359 
00368     virtual AxisState axisState(AxisIdentifier axis) const = 0;
00369 
00382     virtual AxisState previousAxisState(AxisIdentifier axis) const = 0;
00383 
00391     virtual std::vector<ButtonIdentifier> buttonIdentifiers(void) const = 0;
00392 
00400     virtual std::vector<AxisIdentifier> axisIdentifiers(void) const = 0;
00401 
00407     const String& driverName() const { return mDriverName; }
00408 
00409   protected:
00410     void setDriverName(const String& driverName) { mDriverName = driverName; }
00411   private:
00412     String mDriverName;
00413   };
00414   
00415   
00416   // drivers
00417   //   digital buttons
00418   //   analogue axes
00419   
00420   // clients
00421   //   button press, release, hold notification
00422   //   
00423   
00424   // binder drivers
00425   //   digital buttons -> buttons, actions
00426   //   analogue axes -> sticks, dials, cursors
00427   //   digital buttons -> sticks, dials, cursors
00428 
00429 
00430   //                gui binders
00431   //                   V
00432   //             logical-raw binder
00433   //              ^             |
00434   //              |             V 
00435   //           raw input     logical input --> clients
00436   //
00437 
00438   // Notes:
00439   // Current interface uses sub-interfaces to provide a mechanism through
00440   // which drivers deposit their input into the InputEngine.  Alternative:
00441   // Have drivers implement an accessory interface to the InputEngine and
00442   // allow the InputEngine to poll that interface.
00443   //
00444   // Current method:
00445   // Pros
00446   //   Easy to understand;  no interface for driver to implement.
00447   //   Allows driver to be given time for its update from within input layer.
00448   //   Also allows driver to deposit its own 
00449   //
00450 
00451 
00452 }; // namespace Phx
00453 
00454 #endif /* PHX_RAW_INPUT_ENGINE_H */

Generated on Mon Jul 10 19:45:28 2006 for Phoenix OSFS by  doxygen 1.4.2