1/*
2 * @APPLE_LICENSE_HEADER_START@
3 *
4 * Copyright (c) 1999-2009 Apple Computer, Inc.  All Rights Reserved.
5 *
6 * This file contains Original Code and/or Modifications of Original Code
7 * as defined in and that are subject to the Apple Public Source License
8 * Version 2.0 (the 'License'). You may not use this file except in
9 * compliance with the License. Please obtain a copy of the License at
10 * http://www.opensource.apple.com/apsl/ and read it before using this
11 * file.
12 *
13 * The Original Code and all software distributed under the License are
14 * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
15 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
16 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
17 * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
18 * Please see the License for the specific language governing rights and
19 * limitations under the License.
20 *
21 * @APPLE_LICENSE_HEADER_END@
22 */
23/* 	Copyright (c) 1992 NeXT Computer, Inc.  All rights reserved.
24 *
25 * EventDriver.h - Exported Interface Event Driver object.
26 *
27 *		The EventDriver is a pseudo-device driver.
28 *
29 * HISTORY
30 * 19 Mar 1992    Mike Paquette at NeXT
31 *      Created.
32 * 4  Aug 1993	  Erik Kay at NeXT
33 *	API cleanup
34 */
35
36#ifndef	_IOHIDSYSTEM_H
37#define _IOHIDSYSTEM_H
38
39#include <TargetConditionals.h>
40#include <IOKit/IOTimerEventSource.h>
41#include <IOKit/IOInterruptEventSource.h>
42#include <IOKit/IOService.h>
43#include <IOKit/IOMessage.h>
44#include <IOKit/IOUserClient.h>
45#include <IOKit/IOWorkLoop.h>
46#include <IOKit/IOCommandGate.h>
47#include <IOKit/IOBufferMemoryDescriptor.h>
48#include <IOKit/pwr_mgt/IOPM.h>
49#if TARGET_OS_EMBEDDED
50class IOGraphicsDevice;
51#else
52#include <IOKit/graphics/IOGraphicsDevice.h>
53#endif
54#include <IOKit/hidsystem/IOHIDevice.h>
55#include <IOKit/hidsystem/IOHIDShared.h>
56#include <IOKit/hidsystem/IOHIDTypes.h>
57#include <IOKit/hidsystem/IOLLEvent.h>
58#include <IOKit/IODataQueue.h>
59#include <IOKit/hidsystem/ev_keymap.h>		/* For NX_NUM_SCANNED_SPECIALKEYS */
60
61
62// The following messages should be unique across the entire system
63#ifndef sub_iokit_hidsystem
64#define sub_iokit_hidsystem                     err_sub(14)
65#endif
66
67#define kIOHIDSystem508MouseClickMessage        iokit_family_msg(sub_iokit_hidsystem, 1)
68#define kIOHIDSystemDeviceSeizeRequestMessage	iokit_family_msg(sub_iokit_hidsystem, 2)
69#define kIOHIDSystem508SpecialKeyDownMessage    iokit_family_msg(sub_iokit_hidsystem, 3)
70// 4 is used by IOHIDSecurePrompt
71#define kIOHIDSystemActivityTickle              iokit_family_msg(sub_iokit_hidsystem, 5)
72#define kIOHIDSystemUserHidActivity             iokit_family_msg(sub_iokit_hidsystem, 6)
73
74
75class IOHIDKeyboardDevice;
76class IOHIDPointingDevice;
77class IOHIDEvent;
78class IOFixedPoint64;
79
80class IOHIDSystem : public IOService
81{
82	OSDeclareDefaultStructors(IOHIDSystem);
83
84	friend class IOHIDUserClient;
85	friend class IOHIDParamUserClient;
86	friend class IOHIDEventSystemUserClient;
87
88private:
89	IOWorkLoop *		workLoop;
90	IOTimerEventSource          *periodicES;
91        IOInterruptEventSource * eventConsumerES;
92        IOInterruptEventSource * keyboardEQES;
93        IOCommandGate *		cmdGate;
94	IOUserClient *		serverConnect;
95	IOUserClient *		paramConnect;
96        IONotifier *		eventPublishNotify;
97        IONotifier *		eventTerminateNotify;
98        IONotifier *		publishNotify;
99        IONotifier *		terminateNotify;
100
101        OSArray *		ioHIDevices;
102    OSSet             * touchEventPosters;
103
104	// Ports on which we hold send rights
105	mach_port_t	eventPort;	// Send msg here when event queue
106					// goes non-empty
107    mach_port_t stackShotPort;
108	mach_port_t	_specialKeyPort[NX_NUM_SCANNED_SPECIALKEYS]; // Special key msgs
109	void		*eventMsg;	// Msg to be sent to Window Server.
110	void		*stackShotMsg;	// Msg to be sent to Stack Shot.
111
112	// Shared memory area information
113    IOBufferMemoryDescriptor * globalMemory;
114	uintptr_t	shmem_addr;	// kernel address of shared memory
115	vm_size_t	shmem_size;	// size of shared memory
116
117	// Pointers to structures which occupy the shared memory area.
118	volatile void	*evs;		// Pointer to private driver shmem
119	volatile EvGlobals *evg;	// Pointer to EvGlobals (shmem)
120	// Internal variables related to the shared memory area
121	int		lleqSize;	// # of entries in low-level queue
122                        // FIXME: why is this ivar lleqSize an ivar? {Dan]
123
124	// Screens list
125	vm_size_t	evScreenSize;	// Byte size of evScreen array
126	void		*evScreen;	// array of screens known to driver
127	volatile void	*lastShmemPtr;	// Pointer used to index thru shmem
128					// while assigning shared areas to
129					// drivers.
130	int		screens;	// running total of allocated screens
131	UInt32		cursorScreens;	// bit mask of screens with cursor present
132        UInt32		cursorPinScreen;// a screen to pin against
133	IOGBounds		cursorPin;	// Range to which cursor is pinned
134					// while on this screen.
135	IOGBounds		workSpace;	// IOGBounds of full workspace.
136	// Event Status state - This includes things like event timestamps,
137	// time til screen dim, and related things manipulated through the
138	// Event Status API.
139	//
140    struct ExpansionData;
141    ExpansionData   *_privateData;
142
143    IOGPoint	clickLoc;       // location of last mouse click
144    IOGPoint    clickSpaceThresh;// max mouse delta to be a doubleclick
145
146	int	clickState;	// Current click state
147
148	bool evOpenCalled;	// Has the driver been opened?
149	bool evInitialized;	// Has the first-open-only initialization run?
150    bool evStateChanging;   // Is the event system state changing.
151	bool eventsOpen;	// Boolean: has evmmap been called yet?
152	bool cursorStarted;	// periodic events running?
153	bool cursorEnabled;	// cursor positioning ok?
154	bool cursorCoupled;	// cursor positioning on pointer moves ok?
155	bool cursorPinned;	// cursor positioning on pointer moves ok?
156
157	short leftENum;		// Unique ID for last left down event
158	short rightENum;	// Unique ID for last right down event
159
160	// The periodic event mechanism timestamps and state
161	// are recorded here.
162    uint64_t clickTime;		// Timestamps used to determine doubleclicks
163    uint64_t clickTimeThresh;
164
165    uint64_t lastEventTime;
166    uint64_t lastUndimEvent;
167
168	// Flag used in scheduling periodic event callbacks
169	bool		needToKickEventConsumer;
170
171        IOService *	displayManager;	// points to display manager
172        IOPMPowerFlags	displayState;
173
174
175        IOService *	rootDomain;
176        AbsoluteTime	rootDomainStateChangeDeadline;
177        AbsoluteTime    displayStateChangeDeadline;
178        AbsoluteTime    displaySleepWakeupDeadline;
179        bool  displaySleepDrivenByPM;
180
181        OSDictionary *  savedParameters;	// keep user settings
182
183        const char *    registryName;		// cache our name
184        UInt32		maxWaitCursorFrame;	// animation frames
185	UInt32		firstWaitCursorFrame;	//
186
187        int		cachedEventFlags;
188        OSArray *  cachedButtonStates;
189
190        OSArray * systemInfo;
191
192        IOHIDPointingDevice * _hidPointingDevice;
193        IOHIDKeyboardDevice * _hidKeyboardDevice;
194
195        /* The consumed keys array stores key codes for which a key down event
196         * has been consumed and a corresponding key up event must be consumed
197         * when it arrives.
198         */
199        OSArray * consumedKeys;
200
201    OSObject * lastSender;
202
203        UInt32 scrollZoomMask;
204
205    bool setParamPropertiesInProgress;
206
207    OSSet * dataQueueSet;
208
209private:
210    UInt8 getSubtypeForSender(OSObject * sender);
211    void updateMouseEventForSender(OSObject * sender, NXEventData * evData);
212    void updateMouseMoveEventForSender(OSObject * sender, NXEventData * evData);
213    void updateScrollEventForSender(OSObject * sender, NXEventData * evData);
214
215  inline short getUniqueEventNum();
216
217  virtual IOReturn powerStateDidChangeTo( IOPMPowerFlags, unsigned long, IOService * );
218  static IOReturn powerStateHandler( void *target, void *refCon,
219               UInt32 messageType, IOService *service, void *messageArgument, vm_size_t argSize );
220 /* Resets */
221  void _resetMouseParameters();
222    void    _setScrollCountParameters(OSDictionary *newSettings = NULL);
223
224  /* Initialize the shared memory area */
225  void     initShmem(bool clean);
226  /* Dispatch low level events through shared memory to the WindowServer */
227  void postEvent(       int        what,
228          /* at */      IOFixedPoint64 *       location,
229          /* atTime */  AbsoluteTime  ts,
230          /* withData */NXEventData * myData,
231          /* sender */  OSObject *    sender   = 0,
232          /* pid */     UInt32        extPID   = 0,
233          /* processKEQ*/bool          processKEQ = true);
234  /* Dispatch mechanisms for screen state changes */
235  void evDispatch(
236            /* command */ EvCmd evcmd);
237  /* Dispatch mechanism for special key press */
238  void evSpecialKeyMsg(unsigned key,
239               /* direction */ unsigned dir,
240               /* flags */     unsigned f,
241               /* level */     unsigned l);
242  /* Message the event consumer to process posted events */
243  void kickEventConsumer();
244  void sendStackShotMessage(UInt32 flavor);
245
246  OSDictionary * createFilteredParamPropertiesForService(IOService * service, OSDictionary * dict);
247
248  static void _periodicEvents(IOHIDSystem * self,
249                              IOTimerEventSource *timer);
250
251  static void doSpecialKeyMsg(IOHIDSystem * self,
252					struct evioSpecialKeyMsg *msg);
253  static void doKickEventConsumer(IOHIDSystem * self);
254
255  static void doProcessKeyboardEQ(IOHIDSystem * self);
256  static void processKeyboardEQ(IOHIDSystem * self, AbsoluteTime * deadline = 0);
257
258  void doProcessNotifications(IOTimerEventSource *sender);
259  bool genericNotificationHandler(void * ref, IOService * newService, IONotifier * notifier );
260
261  static bool handlePublishNotification( void * target, IOService * newService );
262
263  static bool handleTerminateNotification( void * target, IOService * service );
264
265  static void makeNumberParamProperty( OSDictionary * dict, const char * key,
266                            unsigned long long number, unsigned int bits );
267
268  static void makeInt32ArrayParamProperty( OSDictionary * dict, const char * key,
269                            UInt32 * array, unsigned int count );
270
271/*
272 * HISTORICAL NOTE:
273 *   The following methods were part of the IOHIDSystem(Input) category;
274 *   the declarations have now been merged directly into this class.
275 *
276 * Exported Interface Event Driver object input services.
277 */
278
279private:
280  // Schedule next periodic run based on current event system state.
281  void scheduleNextPeriodicEvent();
282  // Message invoked to run periodic events.  This method runs in the workloop.
283  void periodicEvents(IOTimerEventSource *timer);
284  // Start the cursor running.
285  bool startCursor();
286  // Repin cursor location.
287  bool resetCursor();
288  // Wait Cursor machinery.
289  void showWaitCursor();
290  void hideWaitCursor();
291  void animateWaitCursor();
292  void changeCursor(int frame);
293  // Return screen number a point lies on.
294  int  pointToScreen(IOGPoint * p);
295
296  inline void showCursor();
297  inline void hideCursor();
298  inline void moveCursor();
299  void enableContinuousCursor();
300  void disableContinuousCursor();
301  // Claim ownership of event sources.
302  void attachDefaultEventSources();
303  // Give up ownership of event sources.
304  void detachEventSources();
305  bool registerEventSource(IOService * source);
306
307  // Set abs cursor position.
308  void setCursorPosition(IOGPoint * newLoc, bool external, OSObject * sender=0);
309  void _setButtonState(int buttons,
310                       /* atTime */ AbsoluteTime ts,
311                       OSObject * sender);
312  void _setCursorPosition(bool external = false, bool proximityChange = false, OSObject * sender=0);
313
314    static bool _idleTimeSerializerCallback(void * target, void * ref, OSSerialize *s);
315    static bool _displaySerializerCallback(void * target, void * ref, OSSerialize *s);
316
317  void _postMouseMoveEvent(int		what,
318                           AbsoluteTime	theClock,
319                           OSObject *	sender);
320  void createParameters( void );
321
322/* END HISTORICAL NOTE */
323
324public:
325  static IOHIDSystem * instance();     /* Return the current instance of the */
326				       /* EventDriver, or 0 if none. */
327  static void scaleLocationToCurrentScreen(IOGPoint *location, IOGBounds *bounds);
328
329  virtual bool init(OSDictionary * properties = 0);
330  virtual IOHIDSystem * probe(IOService *    provider,
331                              SInt32 * score);
332  virtual bool start(IOService * provider);
333  virtual IOReturn message(UInt32 type, IOService * provider,
334				void * argument);
335  virtual void free();
336  virtual bool attach( IOService * provider );
337  virtual void detach( IOService * provider );
338
339  virtual IOWorkLoop *getWorkLoop() const;
340
341  virtual IOReturn evOpen(void);
342  virtual IOReturn evClose(void);
343
344  virtual IOReturn  setProperties( OSObject * properties );
345  virtual IOReturn  setParamProperties(OSDictionary * dict);
346
347  /* Create the shared memory area */
348  virtual IOReturn createShmem(void*,void*,void*,void*,void*,void*);
349
350  /* register the IODataQueue for the new user events */
351  virtual IOReturn registerEventQueue(IODataQueue * queue);
352
353  /* Unregister the IODataQueue for the new user events */
354  virtual IOReturn unregisterEventQueue(IODataQueue * queue);
355
356  /* Set the port for event available notify msg */
357  virtual void     setEventPort(mach_port_t port);
358
359  /* Set if display sleep is driven by IOPMrootDomain */
360  void setDisplaySleepDrivenByPM(bool val);
361private:
362    static IOReturn doSetEventPort(IOHIDSystem *self, void *port_void, void *arg1, void *arg2, void *arg3);
363    void            setEventPortGated(mach_port_t port);
364public:
365
366  /* Set the port for the special key keypress msg */
367  virtual IOReturn setSpecialKeyPort(
368                     /* keyFlavor */ int         special_key,
369                     /* keyPort */   mach_port_t key_port);
370  virtual mach_port_t specialKeyPort(int special_key);
371
372
373  virtual IOReturn newUserClient(task_t         owningTask,
374                 /* withToken */ void *         security_id,
375                 /* ofType */    UInt32         type,
376                 /* withProps*/  OSDictionary *  properties,
377                 /* client */    IOUserClient ** handler);
378
379/*
380 * HISTORICAL NOTE:
381 *   The following methods were part of the IOHIPointingEvents protocol;
382 *   the declarations have now been merged directly into this class.
383 */
384
385public:
386  /* Mouse event reporting */
387  virtual void relativePointerEvent(int        buttons,
388                       /* deltaX */ int        dx,
389                       /* deltaY */ int        dy,
390                       /* atTime */ AbsoluteTime ts);
391
392  /* Tablet event reporting */
393  virtual void absolutePointerEvent(int        buttons,
394                 /* at */           IOGPoint *    newLoc,
395                 /* withBounds */   IOGBounds *bounds,
396                 /* inProximity */  bool       proximity,
397                 /* withPressure */ int        pressure,
398                 /* withAngle */    int        stylusAngle,
399                 /* atTime */       AbsoluteTime ts);
400
401  /* Mouse scroll wheel event reporting */
402  virtual void scrollWheelEvent(short deltaAxis1,
403                                short deltaAxis2,
404                                short deltaAxis3,
405                                AbsoluteTime ts);
406
407
408  virtual void tabletEvent(NXEventData *tabletData,
409                           AbsoluteTime ts);
410
411  virtual void proximityEvent(NXEventData *proximityData,
412                              AbsoluteTime ts);
413
414/*
415 * HISTORICAL NOTE:
416 *   The following methods were part of the IOHIKeyboardEvents protocol;
417 *   the declarations have now been merged directly into this class.
418 */
419
420public:
421  virtual void keyboardEvent(unsigned   eventType,
422      /* flags */            unsigned   flags,
423      /* keyCode */          unsigned   key,
424      /* charCode */         unsigned   charCode,
425      /* charSet */          unsigned   charSet,
426      /* originalCharCode */ unsigned   origCharCode,
427      /* originalCharSet */  unsigned   origCharSet,
428      /* keyboardType */     unsigned   keyboardType,
429      /* repeat */           bool       repeat,
430      /* atTime */           AbsoluteTime ts);
431
432  virtual void keyboardSpecialEvent(   unsigned   eventType,
433                    /* flags */        unsigned   flags,
434                    /* keyCode  */     unsigned   key,
435                    /* specialty */    unsigned   flavor,
436                    /* guid */ 	       UInt64     guid,
437                    /* repeat */       bool       repeat,
438                    /* atTime */       AbsoluteTime ts);
439
440  virtual void updateEventFlags(unsigned flags);  /* Does not generate events */
441
442
443
444
445private:
446
447  /*
448   * statics for upstream callouts
449   */
450
451  void _scaleLocationToCurrentScreen(IOFixedPoint64 &location, IOGBounds *bounds);
452
453  static void _relativePointerEvent(IOHIDSystem * self,
454				    int        buttons,
455                       /* deltaX */ int        dx,
456                       /* deltaY */ int        dy,
457                       /* atTime */ AbsoluteTime ts,
458                                    OSObject * sender,
459                                    void *     refcon);
460
461  /* Tablet event reporting */
462  static void _absolutePointerEvent(IOHIDSystem * self,
463				    int        buttons,
464                 /* at */           IOGPoint *    newLoc,
465                 /* withBounds */   IOGBounds *bounds,
466                 /* inProximity */  bool       proximity,
467                 /* withPressure */ int        pressure,
468                 /* withAngle */    int        stylusAngle,
469                 /* atTime */       AbsoluteTime ts,
470                                    OSObject * sender,
471                                    void *     refcon);
472
473  /* Mouse scroll wheel event reporting */
474  static void _scrollWheelEvent(    IOHIDSystem *self,
475                                    short      deltaAxis1,
476                                    short      deltaAxis2,
477                                    short      deltaAxis3,
478                                    IOFixed    fixedDelta1,
479                                    IOFixed    fixedDelta2,
480                                    IOFixed    fixedDelta3,
481                                    SInt32  pointDeltaAxis1,
482                                    SInt32  pointDeltaAxis2,
483                                    SInt32  pointDeltaAxis3,
484                                    UInt32  options,
485                                    AbsoluteTime ts,
486                                    OSObject * sender,
487                                    void *     refcon);
488
489  static void _tabletEvent(         IOHIDSystem *self,
490                                    NXEventData *tabletData,
491                                    AbsoluteTime ts,
492                                    OSObject * sender,
493                                    void *     refcon);
494
495  static void _proximityEvent(      IOHIDSystem *self,
496                                    NXEventData *proximityData,
497                                    AbsoluteTime ts,
498                                    OSObject * sender,
499                                    void *     refcon);
500
501  static void _keyboardEvent(       IOHIDSystem * self,
502                                    unsigned   eventType,
503            /* flags */             unsigned   flags,
504            /* keyCode */           unsigned   key,
505            /* charCode */          unsigned   charCode,
506            /* charSet */           unsigned   charSet,
507            /* originalCharCode */  unsigned   origCharCode,
508            /* originalCharSet */   unsigned   origCharSet,
509            /* keyboardType */      unsigned   keyboardType,
510            /* repeat */            bool       repeat,
511            /* atTime */            AbsoluteTime ts,
512                                    OSObject * sender,
513                                    void *     refcon);
514
515  static void _keyboardSpecialEvent(IOHIDSystem * self,
516                                    unsigned   eventType,
517                /* flags */         unsigned   flags,
518                /* keyCode  */      unsigned   key,
519                /* specialty */     unsigned   flavor,
520                /* guid */          UInt64     guid,
521                /* repeat */        bool       repeat,
522                /* atTime */        AbsoluteTime ts,
523                                    OSObject * sender,
524                                    void *     refcon);
525
526  static void _updateEventFlags(    IOHIDSystem * self,
527                                    unsigned   flags,
528                                    OSObject * sender,
529                                    void *     refcon);  /* Does not generate events */
530
531
532/*
533 * HISTORICAL NOTE:
534 *   The following methods were part of the IOUserClient protocol;
535 *   the declarations have now been merged directly into this class.
536 */
537
538public:
539
540  virtual IOReturn setEventsEnable(void*,void*,void*,void*,void*,void*);
541  virtual IOReturn setCursorEnable(void*,void*,void*,void*,void*,void*);
542  virtual IOReturn extPostEvent(void*,void*,void*,void*,void*,void*);
543  virtual IOReturn extSetMouseLocation(void*,void*,void*,void*,void*,void*);
544  virtual IOReturn extGetButtonEventNum(void*,void*,void*,void*,void*,void*);
545  IOReturn extSetBounds( IOGBounds * bounds );
546    IOReturn extGetStateForSelector(void*,void*,void*,void*,void*,void*);
547    IOReturn extSetStateForSelector(void*,void*,void*,void*,void*,void*);
548    IOReturn extRegisterVirtualDisplay(void*,void*,void*,void*,void*,void*);
549    IOReturn extUnregisterVirtualDisplay(void*,void*,void*,void*,void*,void*);
550    IOReturn extSetVirtualDisplayBounds(void*,void*,void*,void*,void*,void*);
551    IOReturn extGetUserHidActivityState(void*,void*,void*,void*,void*,void*);
552    IOReturn setContinuousCursorEnable(void*,void*,void*,void*,void*,void*);
553/*
554 * HISTORICAL NOTE:
555 *   The following methods were part of the IOScreenRegistration protocol;
556 *   the declarations have now been merged directly into this class.
557 *
558 * Methods exported by the EventDriver for display systems.
559 *
560 *	The screenRegister protocol is used by frame buffer drivers to register
561 *	themselves with the Event Driver.  These methods are called in response
562 *	to an _IOGetParameterInIntArray() call with "IO_Framebuffer_Register" or
563 *	"IO_Framebuffer_Unregister".
564 */
565
566public:
567  virtual int registerScreen(IOGraphicsDevice * instance,
568        /* bounds */         IOGBounds * bp,
569        /* virtual bounds */ IOGBounds * vbp);
570private:
571    static IOReturn doRegisterScreen(IOHIDSystem *self, IOGraphicsDevice *io_gd, IOGBounds *bp, IOGBounds * vbp, void *arg3);
572    IOReturn        registerScreenGated(IOGraphicsDevice *io_gd, IOGBounds *bp, IOGBounds * vbp, SInt32 *index);
573public:
574
575
576  virtual void unregisterScreen(int index);
577
578/*
579 * HISTORICAL NOTE:
580 *   The following methods were part of the IOWorkspaceBounds protocol;
581 *   the declarations have now been merged directly into this class.
582 *
583 * Absolute position input devices and some specialized output devices
584 * may need to know the bounding rectangle for all attached displays.
585 * The following method returns a IOGBounds* for the workspace.  Please note
586 * that the bounds are kept as signed values, and that on a multi-display
587 * system the minx and miny values may very well be negative.
588 */
589
590public:
591  virtual IOGBounds * workspaceBounds();
592
593/* END HISTORICAL NOTES */
594
595private:
596void relativePointerEvent(          int        buttons,
597                 /* deltaX */       int        dx,
598                 /* deltaY */       int        dy,
599                 /* atTime */       AbsoluteTime ts,
600                 /* senderID */     OSObject * sender);
601
602  /* Tablet event reporting */
603void absolutePointerEvent(          int        buttons,
604                 /* at */           IOGPoint *    newLoc,
605                 /* withBounds */   IOGBounds *bounds,
606                 /* inProximity */  bool       proximity,
607                 /* withPressure */ int        pressure,
608                 /* withAngle */    int        stylusAngle,
609                 /* atTime */       AbsoluteTime ts,
610                 /* senderID */     OSObject * sender);
611
612  /* Mouse scroll wheel event reporting */
613void scrollWheelEvent(	        short 	       deltaAxis1,
614                                short          deltaAxis2,
615                                short          deltaAxis3,
616                                IOFixed        fixedDelta1,
617                                IOFixed        fixedDelta2,
618                                IOFixed        fixedDelta3,
619                                SInt32         pointDeltaAxis1,
620                                SInt32         pointDeltaAxis2,
621                                SInt32         pointDeltaAxis3,
622                                UInt32         options,
623                                AbsoluteTime   ts,
624                                OSObject *     sender);
625
626void tabletEvent(	NXEventData * tabletData,
627                                AbsoluteTime ts,
628                                OSObject * sender);
629
630void proximityEvent(	NXEventData * proximityData,
631                                AbsoluteTime ts,
632                                OSObject * sender);
633
634void keyboardEvent(unsigned   eventType,
635      /* flags */            unsigned   flags,
636      /* keyCode */          unsigned   key,
637      /* charCode */         unsigned   charCode,
638      /* charSet */          unsigned   charSet,
639      /* originalCharCode */ unsigned   origCharCode,
640      /* originalCharSet */  unsigned   origCharSet,
641      /* keyboardType */     unsigned   keyboardType,
642      /* repeat */           bool       repeat,
643      /* atTime */           AbsoluteTime ts,
644      /* sender */           OSObject * sender);
645
646void keyboardSpecialEvent(   unsigned   eventType,
647      /* flags */        unsigned   flags,
648      /* keyCode  */     unsigned   key,
649      /* specialty */    unsigned   flavor,
650      /* guid */         UInt64     guid,
651      /* repeat */       bool       repeat,
652      /* atTime */       AbsoluteTime ts,
653      /* sender */       OSObject * sender);
654
655void updateEventFlags(unsigned flags, OSObject * sender);
656
657bool addConsumedKey(unsigned key);
658bool removeConsumedKey(unsigned key);
659
660/*
661 * COMMAND GATE COMPATIBILITY:
662 *   The following method is part of the work needed to make IOHIDSystem
663 *   compatible with IOCommandGate.  The use of IOCommandQueue has been
664 *   deprecated, thus requiring this move.  This should allow for less
665 *   context switching as all actions formerly run on the I/O Workloop
666 *   thread, will now be run on the caller thread.  The static methods
667 *   will be called from cmdGate->runAction and returns the appropriate
668 *   non-static helper method.  Arguments are stored in the void* array,
669 *   args, and are passed through.   Since we are returning in the static
670 *   function, gcc3 should translate that to one instruction, thus
671 *   minimizing cost.
672 */
673
674static	IOReturn	doEvClose (IOHIDSystem *self);
675        IOReturn	evCloseGated (void);
676
677static	IOReturn	doSetEventsEnablePre (IOHIDSystem *self, void *p1);
678        IOReturn	setEventsEnablePreGated (void *p1);
679
680static	IOReturn	doSetEventsEnablePost (IOHIDSystem *self, void *p1);
681        IOReturn	setEventsEnablePostGated (void *p1);
682
683static	IOReturn	doUnregisterScreen (IOHIDSystem *self, void * arg0, void *arg1);
684        IOReturn	unregisterScreenGated (int index, bool internal);
685
686static	IOReturn	doSetDisplayBounds (IOHIDSystem *self, void * arg0, void * arg1);
687        IOReturn	setDisplayBoundsGated (UInt32 index, IOGBounds *bounds);
688
689static	IOReturn	doCreateShmem (IOHIDSystem *self, void * arg0);
690        IOReturn	createShmemGated (void * p1);
691
692static	IOReturn	doRegisterEventQueue (IOHIDSystem *self, void * arg0);
693        IOReturn	registerEventQueueGated (void * p1);
694
695static	IOReturn	doUnregisterEventQueue (IOHIDSystem *self, void * arg0);
696        IOReturn	unregisterEventQueueGated (void * p1);
697
698static	IOReturn	doRelativePointerEvent (IOHIDSystem *self, void * args);
699        void		relativePointerEventGated(int buttons,
700                                                    int dx,
701                                                    int dy,
702                                                    SInt64 ts,
703                                                    OSObject * sender);
704
705static	IOReturn	doAbsolutePointerEvent (IOHIDSystem *self, void * args);
706        void 		absolutePointerEventGated (int buttons,
707                                                    IOGPoint *    newLoc,
708                                                    IOGBounds *bounds,
709                                                    bool       proximity,
710                                                    int        pressure,
711                                                    int        stylusAngle,
712                                                    AbsoluteTime ts,
713                                                    OSObject * sender);
714
715static	IOReturn	doScrollWheelEvent(IOHIDSystem *self, void * args);
716        void		scrollWheelEventGated (short deltaAxis1,
717                                                short deltaAxis2,
718                                                short deltaAxis3,
719                                               IOFixed  fixedDelta1,
720                                               IOFixed  fixedDelta2,
721                                               IOFixed  fixedDelta3,
722                                               SInt32   pointDeltaAxis1,
723                                               SInt32   pointDeltaAxis2,
724                                               SInt32   pointDeltaAxis3,
725                                               UInt32   options,
726                                                AbsoluteTime ts,
727                                                OSObject * sender);
728
729static	IOReturn	doTabletEvent (IOHIDSystem *self, void * arg0, void * arg1, void * arg2);
730        void		tabletEventGated (	NXEventData *tabletData,
731                                                AbsoluteTime ts,
732                                                OSObject * sender);
733
734static	IOReturn	doProximityEvent (IOHIDSystem *self, void * arg0, void * arg1, void * arg2);
735        void		proximityEventGated (	NXEventData *proximityData,
736                                                AbsoluteTime ts,
737                                                OSObject * sender);
738
739static	IOReturn	doKeyboardEvent (IOHIDSystem *self, void * args);
740        void		keyboardEventGated (unsigned   eventType,
741                                            unsigned   flags,
742                                            unsigned   key,
743                                            unsigned   charCode,
744                                            unsigned   charSet,
745                                            unsigned   origCharCode,
746                                            unsigned   origCharSet,
747                                            unsigned   keyboardType,
748                                            bool       repeat,
749                                            AbsoluteTime ts,
750                                            OSObject * sender);
751
752static	IOReturn	doKeyboardSpecialEvent (IOHIDSystem *self, void * args);
753        void		keyboardSpecialEventGated (
754                                            unsigned   eventType,
755                                            unsigned   flags,
756                                            unsigned   key,
757                                            unsigned   flavor,
758                                            UInt64     guid,
759                                            bool       repeat,
760                                            AbsoluteTime ts,
761                                            OSObject * sender);
762
763static	IOReturn	doUpdateEventFlags (IOHIDSystem *self, void * args);
764        void		updateEventFlagsGated (unsigned flags, OSObject * sender);
765
766static	IOReturn	doNewUserClient (IOHIDSystem *self, void * args);
767        IOReturn 	newUserClientGated (task_t owningTask,
768                                            void * security_id,
769                                            UInt32 type,
770                                            OSDictionary *  properties,
771                                            IOUserClient ** handler);
772
773static	IOReturn	doSetCursorEnable (IOHIDSystem *self, void * arg0);
774        IOReturn	setCursorEnableGated (void * p1);
775
776static	IOReturn	doSetContinuousCursorEnable (IOHIDSystem *self, void * arg0);
777        IOReturn	setContinuousCursorEnableGated (void * p1);
778
779static	IOReturn	doExtPostEvent(IOHIDSystem *self, void * arg0, void * arg1, void * arg2, void * arg3);
780        IOReturn	extPostEventGated (void * p1, void * p2, void * p3);
781
782static	IOReturn	doExtSetMouseLocation (IOHIDSystem *self, void * args);
783        IOReturn	extSetMouseLocationGated (void * args);
784
785static	IOReturn	doExtGetButtonEventNum (IOHIDSystem *self, void * arg0, void * arg1);
786        IOReturn	extGetButtonEventNumGated (void * p1, void * p2);
787
788static	IOReturn	doSetParamPropertiesPre (IOHIDSystem *self, void * arg0, void * arg1);
789        IOReturn	setParamPropertiesPreGated (OSDictionary * dict, OSIterator ** pOpenIter);
790
791static	IOReturn	doSetParamPropertiesPost (IOHIDSystem *self, void * arg0);
792        IOReturn	setParamPropertiesPostGated (OSDictionary * dict);
793
794static	IOReturn	doExtGetStateForSelector (IOHIDSystem *self, void *p1, void *p2);
795static	IOReturn	doExtSetStateForSelector (IOHIDSystem *self, void *p1, void *p2);
796        IOReturn    getCapsLockState(unsigned int *state_O);
797        IOReturn    setCapsLockState(unsigned int state_I);
798        IOReturn    getNumLockState(unsigned int *state_O);
799        IOReturn    setNumLockState(unsigned int state_I);
800
801/* END COMMAND GATE COMPATIBILITY */
802
803public:
804    virtual void setStackShotPort(mach_port_t port);
805
806    virtual UInt32 eventFlags();
807
808    virtual void dispatchEvent(IOHIDEvent *event, IOOptionBits options=0);
809
810    void updateHidActivity();
811    void hidActivityChecker();
812    static void reportUserHidActivity(IOHIDSystem *self, void *args );
813    void reportUserHidActivityGated(void *args );
814
815    static IOReturn getUserHidActivityState(IOHIDSystem *self, void *arg0);
816    IOReturn getUserHidActivityStateGated(void *state);
817};
818
819#endif /* !_IOHIDSYSTEM_H */
820