1/*
2 *
3 * @APPLE_LICENSE_HEADER_START@
4 *
5 * Copyright (c) 1999-2003 Apple Computer, Inc.  All Rights Reserved.
6 *
7 * This file contains Original Code and/or Modifications of Original Code
8 * as defined in and that are subject to the Apple Public Source License
9 * Version 2.0 (the 'License'). You may not use this file except in
10 * compliance with the License. Please obtain a copy of the License at
11 * http://www.opensource.apple.com/apsl/ and read it before using this
12 * file.
13 *
14 * The Original Code and all software distributed under the License are
15 * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
16 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
17 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
18 * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
19 * Please see the License for the specific language governing rights and
20 * limitations under the License.
21 *
22 * @APPLE_LICENSE_HEADER_END@
23 */
24
25#ifndef _IOKIT_HID_IOHIDELEMENTPRIVATE_H
26#define _IOKIT_HID_IOHIDELEMENTPRIVATE_H
27
28#include <libkern/c++/OSArray.h>
29#include <IOKit/hidsystem/IOHIDDescriptorParser.h>
30#include "IOHIDElement.h"
31#include "IOHIDParserPriv.h"
32#include "IOHIDLibUserClient.h"
33#include "IOHIDDevice.h"
34
35class IOHIDDevice;
36class IOHIDEventQueue;
37
38enum {
39    kIOHIDTransactionStateIdle,
40    kIOHIDTransactionStatePending,
41};
42
43//===========================================================================
44// An object that describes a single HID element.
45
46class IOHIDElementPrivate: public IOHIDElement
47{
48    OSDeclareDefaultStructors( IOHIDElementPrivate )
49
50protected:
51    IOHIDDevice            *_owner;
52    IOHIDElementType        _type;
53    IOHIDElementCookie      _cookie;
54    IOHIDElementPrivate    *_nextReportHandler;
55    IOHIDElementValue      *_elementValue;
56    void                   *_elementValueLocation;
57    IOHIDElementPrivate    *_parent;
58    OSArray                *_childArray;
59    OSArray                *_queueArray;
60    UInt32                  _flags;
61    IOHIDElementCollectionType  _collectionType;
62
63    UInt32                  _reportSize;
64    UInt32                  _reportCount;
65    UInt32                  _reportStartBit;
66    UInt32                  _reportBits;
67    UInt32                  _reportID;
68
69    UInt32                  _usagePage;
70    UInt32                  _usageMin;
71    UInt32                  _usageMax;
72    UInt32                  _rangeIndex;
73
74    UInt32                  _logicalMin;
75    UInt32                  _logicalMax;
76    UInt32                  _physicalMin;
77    UInt32                  _physicalMax;
78
79    UInt32                  _unitExponent;
80    UInt32                  _units;
81
82    UInt32                  _transactionState;
83
84    OSData                 *_dataValue;
85
86    IOHIDElementPrivate    *_duplicateReportHandler;
87
88    IOHIDElementPrivate    *_arrayReportHandler;
89    IOHIDElementPrivate   **_rollOverElementPtr;
90    OSDictionary           *_colArrayReportHandlers;
91    OSArray                *_arrayItems;
92    OSArray                *_duplicateElements;
93    UInt32                 *_oldArraySelectors;
94
95    bool                    _isInterruptReportHandler;
96
97    bool                    _shouldTickleActivity;
98
99    struct {
100        SInt32     satMin;
101        SInt32     satMax;
102        SInt32     dzMin;
103        SInt32     dzMax;
104        SInt32     min;
105        SInt32     max;
106        IOFixed    gran;
107    } _calibration;
108
109    UInt32                  _previousValue;
110
111    virtual bool init( IOHIDDevice * owner, IOHIDElementType type );
112
113    virtual void free();
114
115    virtual IOHIDElementPrivate * newSubElement( UInt16 rangeIndex ) const;
116
117    virtual bool createSubElements();
118
119    virtual IOHIDElementPrivate * arrayHandlerElement(
120                                IOHIDDevice *    owner,
121                                IOHIDElementType type,
122                                IOHIDElementPrivate * child,
123                                IOHIDElementPrivate * parent);
124
125    OSDictionary*  createProperties() const;
126
127    virtual IOByteCount        getByteSize();
128
129    virtual void            setupResolution();
130
131    void setDataBits(OSData *data);
132
133    unsigned int    iteratorSize() const;
134    bool            initIterator(void * iterationContext) const;
135    bool            getNextObjectForIterator(void      * iterationContext,
136                                             OSObject ** nextObject) const;
137
138
139public:
140    static IOHIDElementPrivate * buttonElement(
141                                IOHIDDevice *    owner,
142                                IOHIDElementType type,
143                                HIDButtonCapabilitiesPtr button,
144                                IOHIDElementPrivate *   parent = 0 );
145
146    static IOHIDElementPrivate * valueElement(
147                                IOHIDDevice *    owner,
148                                IOHIDElementType type,
149                                HIDValueCapabilitiesPtr  value,
150                                IOHIDElementPrivate *   parent = 0 );
151
152    static IOHIDElementPrivate * collectionElement(
153                                IOHIDDevice *        owner,
154                                IOHIDElementType     type,
155                                HIDCollectionExtendedNodePtr collection,
156                                IOHIDElementPrivate *       parent = 0 );
157
158    static IOHIDElementPrivate * reportHandlerElement(
159                                IOHIDDevice *        owner,
160                                IOHIDElementType     type,
161                                UInt32               reportID,
162                                UInt32               reportBits );
163
164    virtual bool serialize( OSSerialize * s ) const;
165
166    virtual bool fillElementStruct(IOHIDElementStruct *element);
167
168    virtual bool addChildElement( IOHIDElementPrivate * child, bool arrayHeader = false );
169
170    virtual bool processReport( UInt8                       reportID,
171                                void *                      reportData,
172                                UInt32                      reportBits,
173                                const AbsoluteTime *        timestamp,
174                                IOHIDElementPrivate **      next    = 0,
175                                IOOptionBits                options = 0 );
176
177    virtual bool createReport( UInt8           reportID,
178                               void *        reportData, // report should be allocated outside this method
179                               UInt32 *        reportLength,
180                               IOHIDElementPrivate ** next );
181
182    virtual bool processArrayReport(UInt8         reportID,
183                                    void *               reportData,
184                                    UInt32               reportBits,
185                                    const AbsoluteTime * timestamp);
186
187    virtual bool createDuplicateReport(UInt8           reportID,
188                               void *        reportData, // report should be allocated outside this method
189                               UInt32 *        reportLength);
190
191    virtual bool createArrayReport(UInt8           reportID,
192                               void *        reportData, // report should be allocated outside this method
193                               UInt32 *        reportLength);
194
195    virtual void setArrayElementValue(UInt32 index, UInt32 value);
196
197    virtual bool setMemoryForElementValue(
198                                    IOVirtualAddress        address,
199                                    void *                  location);
200
201    virtual IOHIDElementPrivate * setNextReportHandler( IOHIDElementPrivate * element );
202
203    virtual void setRollOverElementPtr(IOHIDElementPrivate ** rollOverElementPtr);
204    virtual UInt32 getElementValueSize() const;
205
206    virtual UInt32 getRangeCount() const;
207    virtual UInt32 getStartingRangeIndex() const;
208
209    virtual bool getReportType( IOHIDReportType * reportType ) const;
210
211    virtual UInt32 setReportSize( UInt32 numberOfBits );
212
213    inline bool shouldTickleActivity() const
214    { return _shouldTickleActivity; }
215
216    virtual bool addEventQueue( IOHIDEventQueue * queue );
217    virtual bool removeEventQueue( IOHIDEventQueue * queue );
218    virtual bool hasEventQueue( IOHIDEventQueue * queue );
219
220    inline IOHIDElementPrivate * getNextReportHandler() const
221    { return _nextReportHandler; }
222
223    inline IOHIDDevice * getOwner() const
224    { return _owner; }
225
226    inline UInt32 getRangeIndex() const
227    { return _rangeIndex; }
228
229    inline IOHIDElementValue * getElementValue() const
230    { return _elementValue;}
231
232    inline void setTransactionState(UInt32 state)
233    { _transactionState = state;}
234
235    inline UInt32 getTransactionState() const
236    { return _transactionState; }
237
238    virtual void setOutOfBoundsValue();
239
240    virtual bool matchProperties(OSDictionary * matching);
241
242    virtual IOHIDElementCookie              getCookie();
243    virtual IOHIDElementType                getType();
244    virtual IOHIDElementCollectionType      getCollectionType();
245    virtual OSArray *                       getChildElements();
246    virtual IOHIDElement *                  getParentElement();
247    virtual UInt32                          getUsagePage();
248    virtual UInt32                          getUsage();
249    virtual UInt32                          getReportID();
250    virtual UInt32                          getReportSize();
251    virtual UInt32                          getReportCount();
252    virtual UInt32                          getFlags();
253    virtual UInt32                          getLogicalMin();
254    virtual UInt32                          getLogicalMax();
255    virtual UInt32                          getPhysicalMin();
256    virtual UInt32                          getPhysicalMax();
257    virtual UInt32                          getUnit();
258    virtual UInt32                          getUnitExponent();
259    virtual AbsoluteTime                    getTimeStamp();
260    virtual UInt32                          getValue();
261    virtual UInt32                          getValue(IOOptionBits options);
262    virtual OSData *                        getDataValue();
263    virtual void                            setValue(UInt32 value);
264    virtual void                            setDataValue(OSData * value);
265    virtual bool                            conformsTo(UInt32 usagePage, UInt32 usage=0);
266    virtual void                            setCalibration(UInt32 min=0, UInt32 max=0, UInt32 saturationMin=0, UInt32 saturationMax=0, UInt32 deadZoneMin=0, UInt32 deadZoneMax=0, IOFixed granularity=0);
267    virtual UInt32                          getScaledValue(IOHIDValueScaleType type=kIOHIDValueScaleTypePhysical);
268    virtual IOFixed                         getScaledFixedValue(IOHIDValueScaleType type=kIOHIDValueScaleTypePhysical);
269
270    unsigned int getCount() const;
271    unsigned int getCapacity() const;
272    unsigned int getCapacityIncrement() const;
273    unsigned int setCapacityIncrement(unsigned increment);
274    unsigned int ensureCapacity(unsigned int newCapacity);
275    void flushCollection();
276    virtual unsigned setOptions(unsigned   options,
277                                unsigned   mask,
278                                void     * context = 0);
279    virtual OSCollection *copyCollection(OSDictionary * cycleDict = 0);
280};
281
282#endif /* !_IOKIT_HID_IOHIDELEMENTPRIVATE_H */
283