root/juggler/branches/2.2/modules/gadgeteer/gadget/Type/CommandProxy.h

Revision 19729, 3.6 kB (checked in by patrick, 2 years ago)

Copyright update.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
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_COMMAND_PROXY_H_
28 #define _GADGET_COMMAND_PROXY_H_
29
30 #include <gadget/gadgetConfig.h>
31 #include <vpr/Util/Assert.h>
32 #include <gadget/Type/Proxy.h>
33 #include <gadget/Type/Command.h>
34
35 namespace gadget
36 {
37
38 /** \class CommandProxy CommandProxy.h gadget/Type/CommandProxy.h
39  *
40  * A proxy class to command-oriented devices, used by the Input Manager.
41  *
42  * A command proxy always points to a command-oriented device and unit number
43  * within that device.  The Input Manager can therefore keep an array of these
44  * around and treat them as command devices that only return a single
45  * sub-device's amount of data (one int).
46  *
47  * @see gagdet::Command
48  */
49 class GADGET_CLASS_API CommandProxy : public TypedProxy<Command>
50 {
51
52 public:
53    /** @name Construction/Destruction */
54    //@{
55    CommandProxy(const std::string& deviceName = "UnknownCommand",
56                 const int unitNum = -1)
57       : TypedProxy<Command>(deviceName)
58       , mUnitNum(unitNum)
59       , mData(0)
60    {;}
61
62    virtual ~CommandProxy()
63    {;}
64    //@}
65
66    virtual void updateData();
67
68    /** Returns the time of the last update. */
69    virtual vpr::Interval getTimeStamp() const
70    {
71       return mData.getTime();
72    }
73
74    /**
75     * Gets the command data.
76     */
77    int getData() const
78    {
79       // If we're stupefied, return 0, return the current command value.
80       return (isStupefied() ? 0 : mData.getDigital());
81    }
82
83    CommandData* getCommandData()
84    {
85       return &mData;
86    }
87
88    /**
89     * Returns a pointer to the gadget::Command object that we are proxying.
90     */
91    Command* getCommandPtr()
92    {
93       // If we're stupefied, return NULL.  Otherwise, return mTypedDevice.
94       return (isStupefied() ? NULL : mTypedDevice);
95    }
96
97    /**
98     * Returns the unit index into the string speech recognition device from
99     * which this proxy is reading data.
100     */
101    int getUnit() const
102    {
103       return mUnitNum;
104    }
105
106    static std::string getElementType();
107
108    bool config(jccl::ConfigElementPtr element);
109
110    virtual Input* getProxiedInputDevice()
111    {
112       if((NULL == mTypedDevice) || (mStupefied))
113       {
114          return NULL;
115       }
116
117       Input* ret_val = dynamic_cast<Input*>(mTypedDevice);
118       vprASSERT((ret_val != NULL) && "Cross-cast in Command failed");
119       return ret_val;
120    }
121
122 private:
123    int mUnitNum;     /**<  The sub-unit of the device we are working with */
124
125    /**
126     * Copy of the digital data we are dealing with.
127     * @see getData()
128     */
129    CommandData mData;
130 };
131
132 } // End of gadget namespace
133
134 #endif
Note: See TracBrowser for help on using the browser.