001    // RawMemoryFloatAccess.java, created by wbeebee
002    // Copyright (C) 2001 Wes Beebee <wbeebee@mit.edu>
003    // Licensed under the terms of the GNU GPL; see COPYING for details.
004    package javax.realtime;
005    
006    /** This class holds methods for accessing a raw memory area by
007     *  float and double types. Implementations are required to
008     *  implement this class if and only if the underlying Java
009     *  Virtual Machine supports floating point data types.
010     *  <p>
011     *  Many of the constructors and methods in this class throw
012     *  <code>OffsetOutOfBoundsException</code>. This exception means
013     *  that the value given in the offset parameter is either negative
014     *  or outside the memory area.
015     *  <p>
016     *  Many of the constructors and methods in this class throw
017     *  <code>SizeOutOfBoundsException</code>. This exception means
018     *  that the value given in the size parameter is either negative,
019     *  larger than an allowable range, or would cause an accessor
020     *  method to access an address outside of the memory area.
021     */
022    public class RawMemoryFloatAccess extends RawMemoryAccess {
023        
024        private long base, size;
025        private Runnable logic;
026    
027        /** Create a <code>RawMemoryFloatAccess</code> object using the given parameters.
028         *
029         *  @param type An <code>Object</code> representing the type of memory required
030         *              (e.g., <i>dma, shared</i>) - used to define the base address
031         *              and control the mapping.
032         *  @param size The size of the area in bytes.
033         *  @throws java.lang.SecurityException The application doesn't have permissions
034         *                                      to access physical memory or the given
035         *                                      type of memory.
036         *  @throws OffsetOutOfBoundsException The address is invalid.
037         *  @throws SizeOutOfBoundsException The size is negative or extends into an
038         *                                   invalid range of memory.
039         *  @throws UnsupportedPhysicalMemoryException Thrown if the underlying hardware
040         *                                             does not support the given type.
041         *  @throws MemoryTypeConflictException The specified base does not point to memory
042         *                                      that matches the request type, or if
043         *                                      <code>type</code> specifies attributes with
044         *                                      a conflict.
045         */
046        public RawMemoryFloatAccess(Object type, long size)
047            throws SecurityException, OffsetOutOfBoundsException,
048                   SizeOutOfBoundsException,
049                   UnsupportedPhysicalMemoryException,
050                   MemoryTypeConflictException {
051            // TODO
052    
053            // This line inserted only to make everything compile!
054            super(type, size);
055        }
056    
057        /** Create a <code>RawMemoryFloatAccess</code> object using the given parameters.
058         *
059         *  @param type An <code>Object</code> representing the type of memory required
060         *              (e.g., <i>dma, shared</i>) - used to define the base address
061         *              and control the mapping.
062         *  @param base The physical memory address of the area.
063         *  @param size The size of the area in bytes.
064         *  @throws java.lang.SecurityException The application doesn't have permissions
065         *                                      to access physical memory or the given
066         *                                      type of memory.
067         *  @throws OffsetOutOfBoundsException The address is invalid.
068         *  @throws SizeOutOfBoundsException The size is negative or extends into an
069         *                                   invalid range of memory.
070         *  @throws UnsupportedPhysicalMemoryException Thrown if the underlying hardware
071         *                                             does not support the given type.
072         *  @throws MemoryTypeConflictException The specified base does not point to memory
073         *                                      that matches the request type, or if
074         *                                      <code>type</code> specifies attributes with
075         *                                      a conflict.
076         */
077        public RawMemoryFloatAccess(Object type, long base, long size)
078            throws SecurityException, OffsetOutOfBoundsException,
079                   SizeOutOfBoundsException,
080                   UnsupportedPhysicalMemoryException,
081                   MemoryTypeConflictException {
082            this(type, size);
083            this.base = base;
084        }
085    
086    
087        // CONSTRUCTORS NOT IN SPECS
088    
089        protected RawMemoryFloatAccess(long base, long size) {
090            super(base, size);
091        }
092    
093        /** Constructor reserved for use by the memory object factory. 
094         */
095        protected RawMemoryFloatAccess(RawMemoryAccess memory, long base,
096                                       long size) {
097            super(memory, base, size);
098        }
099        
100        /** type - An object representing the type of the memory required
101         *         (dma, shared) - used to define the base address and control
102         *         the mapping.
103         *  size - the size of the area in bytes.
104         */
105        public static RawMemoryFloatAccess createFloatAccess(Object type, 
106                                                             long size) 
107            throws SecurityException, OffsetOutOfBoundsException,
108                   SizeOutOfBoundsException, UnsupportedPhysicalMemoryException
109        {
110            /** Completely bogus */
111            return new RawMemoryFloatAccess(1000, size);
112        }
113    
114        /** type - An object representing the type of the memory required
115         *         (dma, shared) - used to define the base address and control
116         *         the mapping.
117         *  base - The physical memory address of the area.
118         *  size - the size of the area in bytes.
119         */
120        public static RawMemoryFloatAccess createFloatAccess(Object type,
121                                                             long base,
122                                                             long size) 
123            throws SecurityException, OffsetOutOfBoundsException,
124                   SizeOutOfBoundsException, UnsupportedPhysicalMemoryException
125        {
126            /** Totally bogus */
127            return new RawMemoryFloatAccess(base, size);
128        }
129    
130    
131        /** Gets the double at the given offset.
132         *
133         *  @param offset The offset t which to write the value.
134         *  @return The double value.
135         *  @throws OffsetOutOfBoundsException The address is invalid.
136         *  @throws SizeOutOfBoundsException The size is negative or extends
137         *                                   into an invalid range of memory.
138         */
139        public double getDouble(long offset)
140            throws OffsetOutOfBoundsException, SizeOutOfBoundsException {
141            // TODO
142    
143            return 0;
144        }
145    
146        /** Gets <code>number</code> double values starting at the given 
147         *  <code>offset</code> in this, and assigns them into the
148         *  <code>double</code> array starting at position <code>low</code>.
149         *
150         *  @param offset The offset at which to start reading.
151         *  @param doubles The array into which the read items are placed.
152         *  @param low The offset which is the starting point in the given
153         *             array for the read items to be placed.
154         *  @param number The number of items to read.
155         *  @throws OffsetOutOfBoundsException The address is invalid.
156         *  @throws SizeOutOfBoundsException The size is negative or extends
157         *                                   into an invalid range of memory.
158         */
159        public void getDoubles(long offset, double[] doubles,
160                               int low, int number)
161            throws OffsetOutOfBoundsException, SizeOutOfBoundsException {
162            for (int i = 0; i < number; i++)
163                doubles[low + i] = getDouble(offset + i);
164        }
165        
166        /** Gets the float at the given offset.
167         *
168         *  @param offset The offset at which to get the value.
169         *  @return The float value.
170         *  @throws OffsetOutOfBoundsException The address is invalid.
171         *  @throws SizeOutOfBoundsException The size is negative or extends
172         *                                   into an invalid range or memory.
173         */
174        public float getFloat(long offset)
175            throws OffsetOutOfBoundsException, SizeOutOfBoundsException {
176            // TODO
177    
178            return 0;
179        }
180    
181        /** Gets <code>number</code> float values sstarting at the give
182         *  <code>offset</code> in this, and assign them into the byte
183         *  array starting at position <code>low</code>.
184         *
185         *  @param offset The offset at which to start reading.
186         *  @param floats The array into which the read items are placed.
187         *  @param low The offset which is the starting point in the given array
188         *             for the read items to be placed.
189         *  @param number The number of items to read.
190         *  @throws OffsetOutOfBoundsException The address is invalid.
191         *  @throws SizeOutOfBoundsException The size is negative or extends
192         *                                   into an invalid range of memory.
193         */
194        public void getFloats(long offset, float[] floats,
195                              int low, int number)
196            throws OffsetOutOfBoundsException, SizeOutOfBoundsException {
197            for (int i = 0; i < number; i++)
198                floats[low + i] = getFloat(offset + i);
199        }
200    
201        /** Sets the double at the given offset.
202         *
203         *  @param offset The offset at which to set the value.
204         *  @param value The value which will be written.
205         *  @throws OffsetOutOfBoundsException The address is invalid.
206         *  @throws SizeOutOfBoundsException The size is negative or extends
207         *                                   into an invalid range of memory.
208         */
209        public void setDouble(long offset, double value)
210            throws OffsetOutOfBoundsException, SizeOutOfBoundsException {
211            // TODO
212        }
213    
214        /** Sets <code>number</code> double values starting at the given offset
215         *  in this from the double array starting at position <code>low</code>.
216         *
217         *  @param offset The offset at which to start writing.
218         *  @param doubles The array from which the items are obtained.
219         *  @param low The offset which is the starting point in the given array
220         *             for the items to be obtained.
221         *  @param number The number of items to write.
222         *  @throws OffsetOutOfBoundsException The address is invalid.
223         *  @throws SizeOutOfBoundsException The size is negative or extends
224         *                                   into an invalid range of memory.
225         */
226        public void setDoubles(long offset, double[] doubles,
227                               int low, int number) 
228            throws OffsetOutOfBoundsException, SizeOutOfBoundsException {
229            for (int i = 0; i < number; i++)
230                setDouble(offset + i, doubles[low + i]);
231        }
232    
233        /** Sets the float at the given offset.
234         *
235         *  @param offset The offset at which to write the value.
236         *  @param value The value which will be written.
237         *  @throws OffsetOutOfBoundsException The address is invalid.
238         *  @throws SizeOutOfBoundsException The size is negative or extends
239         *                                   into an invalid range of memory.
240         */
241        public void setFloat(long offset, float value)
242            throws OffsetOutOfBoundsException, SizeOutOfBoundsException {
243            // TODO
244        }
245    
246        /** Set <code>number</code> float values starting at the given offset
247         *  in this from the float array starting at position <code>low</code>.
248         *
249         *  @param offset The offset at which to start writing.
250         *  @param floats The array from which the items are obtained.
251         *  @param low The offset which is the starting poing in the given array
252         *             for the items to be obtained.
253         *  @param number The number of items to write.
254         *  @throws OffsetOutOfBoundsException The address is invalid.
255         *  @throws SizeOutOfBoundsException The size is negative or extends
256         *                                   into an invalid range of memory.
257         */
258        public void setFloats(long offset, float[] floats,  
259                              int low, int number)
260            throws OffsetOutOfBoundsException, SizeOutOfBoundsException {
261            for (int i = 0; i < number; i++)
262                setFloat(offset + i, floats[low + i]);
263        }
264    }