root/juggler/branches/2.2/modules/gadgeteer/gadget/Type/Command.h
| Revision 19729, 5.5 kB (checked in by patrick, 2 years 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_COMMAND_H_ |
| 28 | #define _GADGET_COMMAND_H_ |
| 29 | |
| 30 | #include <gadget/gadgetConfig.h> |
| 31 | #include <vector> |
| 32 | #include <boost/concept_check.hpp> /* for ignore_unused_variable_warning */ |
| 33 | #include <jccl/Config/ConfigElementPtr.h> |
| 34 | #include <gadget/Type/DigitalData.h> |
| 35 | #include <gadget/Type/SampleBuffer.h> |
| 36 | #include <vpr/IO/SerializableObject.h> |
| 37 | #include <gadget/Util/DeviceSerializationTokens.h> |
| 38 | |
| 39 | |
| 40 | namespace gadget |
| 41 | { |
| 42 | |
| 43 | const unsigned short MSG_DATA_COMMAND = 423; |
| 44 | |
| 45 | typedef DigitalData CommandData; |
| 46 | |
| 47 | /** \class Command Command.h gadget/Type/Command.h |
| 48 | * |
| 49 | * Command is the abstract base class for devices that translate spoken |
| 50 | * commends into integer-identified commands. Drivers for all such |
| 51 | * devices must derive from this class (through gadget::InputMixer). This |
| 52 | * is in addition to gadget::Input. gadget::Input provides pure virtual |
| 53 | * function constraints in the following functions: startSampling(), |
| 54 | * stopSampling(), sample(), and updateData(). |
| 55 | * |
| 56 | * gadget::Command adds the function getCommandData() for retreiving the |
| 57 | * received commands. This is similar to the additions made by |
| 58 | * gadget::Position and gadget::Analog. |
| 59 | * |
| 60 | * @see Input, InputMixer |
| 61 | */ |
| 62 | class GADGET_CLASS_API Command : public vpr::SerializableObject |
| 63 | { |
| 64 | public: |
| 65 | typedef gadget::SampleBuffer<CommandData> SampleBuffer_t; |
| 66 | |
| 67 | public: |
| 68 | /* Constructor/Destructors */ |
| 69 | Command() |
| 70 | { |
| 71 | ; |
| 72 | } |
| 73 | |
| 74 | virtual ~Command() |
| 75 | { |
| 76 | ; |
| 77 | } |
| 78 | |
| 79 | virtual bool config(jccl::ConfigElementPtr e) |
| 80 | { |
| 81 | boost::ignore_unused_variable_warning(e); |
| 82 | return true; |
| 83 | } |
| 84 | |
| 85 | /** |
| 86 | * Gets the command data for the given devNum. |
| 87 | * |
| 88 | * @return Command 0 or 1, if devNum makes sense. |
| 89 | * -1 is returned if function fails or if devNum is out of range. |
| 90 | * @note If devNum is out of range, function will fail, possibly issuing |
| 91 | * an error to a log or console - but will not ASSERT. |
| 92 | */ |
| 93 | const CommandData getCommandData(int devNum = 0); |
| 94 | |
| 95 | /** |
| 96 | * Helper method to add a collection of command samples to the sample |
| 97 | * buffers. This MUST be called by all command devices to add new |
| 98 | * samples. |
| 99 | * |
| 100 | * @post The given command samples are added to the buffers. |
| 101 | * |
| 102 | * @param digSample A vector of CommandData objects that represent the |
| 103 | * newest samples taken. |
| 104 | */ |
| 105 | void addCommandSample(const std::vector< CommandData >& digSample) |
| 106 | { |
| 107 | // Locks and then swaps the indices. |
| 108 | mCommandSamples.lock(); |
| 109 | mCommandSamples.addSample(digSample); |
| 110 | mCommandSamples.unlock(); |
| 111 | } |
| 112 | |
| 113 | /** |
| 114 | * Swaps the command data buffers. |
| 115 | * |
| 116 | * @post If the ready queue has values, then those values are copied from |
| 117 | * the ready queue to the stable queue. If not, then stable queue |
| 118 | * is not changed. |
| 119 | */ |
| 120 | void swapCommandBuffers() |
| 121 | { |
| 122 | mCommandSamples.swapBuffers(); |
| 123 | } |
| 124 | |
| 125 | /** |
| 126 | * Returns the current stable sample buffers for this device. |
| 127 | */ |
| 128 | const SampleBuffer_t::buffer_t& getCommandDataBuffer() |
| 129 | { |
| 130 | return mCommandSamples.stableBuffer(); |
| 131 | } |
| 132 | |
| 133 | virtual std::string getInputTypeName() |
| 134 | { |
| 135 | return std::string("Command"); |
| 136 | } |
| 137 | |
| 138 | /** |
| 139 | * Serializes this object into the given object writer. |
| 140 | * |
| 141 | * @param writer The object writer to which this object will be |
| 142 | * serialized. |
| 143 | * |
| 144 | * @throw vpr::IOException is thrown if serialization fails. |
| 145 | */ |
| 146 | virtual void writeObject(vpr::ObjectWriter* writer); |
| 147 | |
| 148 | /** |
| 149 | * De-serializes this object. |
| 150 | * |
| 151 | * @param reader The object reader from which this object will be |
| 152 | * de-serialized. |
| 153 | * |
| 154 | * @throw vpr::IOException is thrown if de-serialization fails. |
| 155 | */ |
| 156 | virtual void readObject(vpr::ObjectReader* reader); |
| 157 | |
| 158 | protected: |
| 159 | // gadget::SampleBuffer<T> is not copyable, so neither are we. |
| 160 | Command(const gadget::Command&) |
| 161 | : vpr::SerializableObject() |
| 162 | {;} |
| 163 | |
| 164 | void operator=(const gadget::Command&) {;} |
| 165 | |
| 166 | private: |
| 167 | SampleBuffer_t mCommandSamples; /**< Command samples */ |
| 168 | CommandData mDefaultValue; /**< Default command value to return */ |
| 169 | }; |
| 170 | |
| 171 | } // End of gadget namespace |
| 172 | |
| 173 | #endif /* _GADGET_COMMAND_H_ */ |
Note: See TracBrowser for help on using the browser.
