#ifndef _IOHIDSYSTEM_H
#define _IOHIDSYSTEM_H
#include <IOKit/IOTimerEventSource.h>
#include <IOKit/IOInterruptEventSource.h>
#include <IOKit/IOService.h>
#include <IOKit/IOMessage.h>
#include <IOKit/IOUserClient.h>
#include <IOKit/IOWorkLoop.h>
#include <IOKit/IOCommandGate.h>
#include <IOKit/IOBufferMemoryDescriptor.h>
#include <IOKit/pwr_mgt/IOPM.h>
#include <IOKit/graphics/IOGraphicsDevice.h>
#include <IOKit/hidsystem/IOHIDevice.h>
#include <IOKit/hidsystem/IOHIDShared.h>
#include <IOKit/hidsystem/IOHIDTypes.h>
#include <IOKit/hidsystem/IOLLEvent.h>
#include "ev_keymap.h"
#define sub_iokit_hidsystem err_sub(14)
#define kIOHIDSystem508MouseClickMessage iokit_family_msg(sub_iokit_hidsystem, 1)
#define kIOHIDSystemDeviceSeizeRequestMessage iokit_family_msg(sub_iokit_hidsystem, 2)
class IOHIDSystem : public IOService
{
OSDeclareDefaultStructors(IOHIDSystem);
friend class IOHIDUserClient;
friend class IOHIDParamUserClient;
private:
IOWorkLoop * workLoop;
IOTimerEventSource * timerES;
IOTimerEventSource * vblES;
IOInterruptEventSource * eventConsumerES;
IOCommandGate * cmdGate;
IOUserClient * serverConnect;
IOUserClient * paramConnect;
IONotifier * publishNotify;
IONotifier * terminateNotify;
OSArray * ioHIDevices;
mach_port_t eventPort; mach_port_t _specialKeyPort[NX_NUM_SCANNED_SPECIALKEYS]; void *eventMsg;
IOBufferMemoryDescriptor * globalMemory;
vm_offset_t shmem_addr; vm_size_t shmem_size;
volatile void *evs; volatile EvGlobals *evg; int lleqSize;
vm_size_t evScreenSize; void *evScreen; volatile void *lastShmemPtr; int screens; UInt32 cursorScreens; UInt32 cursorPinScreen; Bounds cursorPin; Bounds workSpace; Point pointerLoc; Point pointerDelta; Point clickLoc; Point clickSpaceThresh; int clickState; unsigned char lastPressure; bool lastProximity;
SInt32 curVolume; SInt32 dimmedBrightness; SInt32 curBright; SInt32 autoDimmed; bool evOpenCalled; bool evInitialized; bool eventsOpen; bool cursorStarted; bool cursorEnabled; bool cursorCoupled; bool cursorPinned;
short leftENum; short rightENum;
AbsoluteTime thisPeriodicRun;
AbsoluteTime periodicEventDelta; AbsoluteTime clickTime; AbsoluteTime clickTimeThresh;
AbsoluteTime autoDimPeriod; AbsoluteTime autoDimTime;
AbsoluteTime waitSustain; AbsoluteTime waitSusTime; AbsoluteTime waitFrameRate; AbsoluteTime waitFrameTime;
AbsoluteTime lastRelativeEventTime; AbsoluteTime lastRelativeMoveTime;
AbsoluteTime lastEventTime;
SInt32 postDeltaX, accumDX;
SInt32 postDeltaY, accumDY;
bool needSetCursorPosition;
bool needToKickEventConsumer;
IOService * displayManager; IOPMPowerFlags displayState;
IOService * rootDomain;
AbsoluteTime stateChangeDeadline;
OSDictionary * savedParameters;
char * registryName; UInt32 maxWaitCursorFrame; UInt32 firstWaitCursorFrame;
UInt32 cachedEventFlags;
OSDictionary * cachedButtonStates;
private:
void vblEvent(void);
static void _vblEvent(OSObject *self, IOTimerEventSource *sender);
inline short getUniqueEventNum();
virtual IOReturn powerStateDidChangeTo( IOPMPowerFlags, unsigned long, IOService * );
void _resetMouseParameters();
void _resetKeyboardParameters();
void initShmem();
void postEvent(int what,
Point * location,
AbsoluteTime ts,
NXEventData * myData);
void evDispatch(
EvCmd evcmd);
void evSpecialKeyMsg(unsigned key,
unsigned dir,
unsigned f,
unsigned l);
void kickEventConsumer();
static void _periodicEvents(IOHIDSystem * self,
IOTimerEventSource *timer);
static void doSpecialKeyMsg(IOHIDSystem * self,
struct evioSpecialKeyMsg *msg);
static void doKickEventConsumer(IOHIDSystem * self);
static bool publishNotificationHandler( void * target,
void * ref, IOService * newService );
static bool terminateNotificationHandler( void * target,
void * ref, IOService * service );
static void makeNumberParamProperty( OSDictionary * dict, const char * key,
unsigned long long number, unsigned int bits );
static void makeInt32ArrayParamProperty( OSDictionary * dict, const char * key,
UInt32 * array, unsigned int count );
private:
void scheduleNextPeriodicEvent();
void periodicEvents(IOTimerEventSource *timer);
bool startCursor();
bool resetCursor();
void showWaitCursor();
void hideWaitCursor();
void animateWaitCursor();
void changeCursor(int frame);
int pointToScreen(Point * p);
void setBrightness(int b);
int brightness();
void setAutoDimBrightness(int b);
int autoDimBrightness();
int currentBrightness();
void doAutoDim();
void undoAutoDim();
void forceAutoDimState(bool dim);
void setAudioVolume(int v);
void setUserAudioVolume(int v);
int audioVolume();
inline void setBrightness();
inline void showCursor();
inline void hideCursor();
inline void moveCursor();
void attachDefaultEventSources();
void detachEventSources();
bool registerEventSource(IOHIDevice * source);
void setCursorPosition(Point * newLoc, bool external, OSObject * sender=0);
void _setButtonState(int buttons,
AbsoluteTime ts,
OSObject * sender);
void _setCursorPosition(Point * newLoc, bool external, OSObject * sender=0);
void _postMouseMoveEvent(int what,
Point * location,
AbsoluteTime theClock,
OSSymbol * senderKey=0);
void createParameters( void );
public:
static IOHIDSystem * instance();
virtual bool init(OSDictionary * properties = 0);
virtual IOHIDSystem * probe(IOService * provider,
SInt32 * score);
virtual bool start(IOService * provider);
virtual IOReturn message(UInt32 type, IOService * provider,
void * argument);
virtual void free();
virtual IOWorkLoop *getWorkLoop() const;
virtual IOReturn evOpen(void);
virtual IOReturn evClose(void);
virtual IOReturn setProperties( OSObject * properties );
virtual IOReturn setParamProperties(OSDictionary * dict);
virtual bool updateProperties(void);
virtual bool serializeProperties( OSSerialize * s ) const;
virtual IOReturn createShmem(void*,void*,void*,void*,void*,void*);
virtual void setEventPort(mach_port_t port);
virtual IOReturn setSpecialKeyPort(
int special_key,
mach_port_t key_port);
virtual mach_port_t specialKeyPort(int special_key);
virtual IOReturn newUserClient(task_t owningTask,
void * security_id,
UInt32 type,
IOUserClient ** handler);
public:
virtual void relativePointerEvent(int buttons,
int dx,
int dy,
AbsoluteTime ts);
virtual void absolutePointerEvent(int buttons,
Point * newLoc,
Bounds * bounds,
bool proximity,
int pressure,
int stylusAngle,
AbsoluteTime ts);
virtual void scrollWheelEvent(short deltaAxis1,
short deltaAxis2,
short deltaAxis3,
AbsoluteTime ts);
virtual void tabletEvent(NXEventData *tabletData,
AbsoluteTime ts);
virtual void proximityEvent(NXEventData *proximityData,
AbsoluteTime ts);
public:
virtual void keyboardEvent(unsigned eventType,
unsigned flags,
unsigned key,
unsigned charCode,
unsigned charSet,
unsigned origCharCode,
unsigned origCharSet,
unsigned keyboardType,
bool repeat,
AbsoluteTime ts);
virtual void keyboardSpecialEvent( unsigned eventType,
unsigned flags,
unsigned key,
unsigned flavor,
UInt64 guid,
bool repeat,
AbsoluteTime ts);
virtual void updateEventFlags(unsigned flags);
private:
void _scaleLocationToCurrentScreen(Point *location, Bounds *bounds);
static void _relativePointerEvent(IOHIDSystem * self,
int buttons,
int dx,
int dy,
AbsoluteTime ts,
OSObject * sender,
void * refcon);
static void _absolutePointerEvent(IOHIDSystem * self,
int buttons,
Point * newLoc,
Bounds * bounds,
bool proximity,
int pressure,
int stylusAngle,
AbsoluteTime ts,
OSObject * sender,
void * refcon);
static void _scrollWheelEvent( IOHIDSystem *self,
short deltaAxis1,
short deltaAxis2,
short deltaAxis3,
AbsoluteTime ts,
OSObject * sender,
void * refcon);
static void _tabletEvent( IOHIDSystem *self,
NXEventData *tabletData,
AbsoluteTime ts,
OSObject * sender,
void * refcon);
static void _proximityEvent( IOHIDSystem *self,
NXEventData *proximityData,
AbsoluteTime ts,
OSObject * sender,
void * refcon);
static void _keyboardEvent( IOHIDSystem * self,
unsigned eventType,
unsigned flags,
unsigned key,
unsigned charCode,
unsigned charSet,
unsigned origCharCode,
unsigned origCharSet,
unsigned keyboardType,
bool repeat,
AbsoluteTime ts,
OSObject * sender,
void * refcon);
static void _keyboardSpecialEvent(IOHIDSystem * self,
unsigned eventType,
unsigned flags,
unsigned key,
unsigned flavor,
UInt64 guid,
bool repeat,
AbsoluteTime ts,
OSObject * sender,
void * refcon);
static void _updateEventFlags( IOHIDSystem * self,
unsigned flags,
OSObject * sender,
void * refcon);
public:
virtual IOReturn setEventsEnable(void*,void*,void*,void*,void*,void*);
virtual IOReturn setCursorEnable(void*,void*,void*,void*,void*,void*);
virtual IOReturn extPostEvent(void*,void*,void*,void*,void*,void*);
virtual IOReturn extSetMouseLocation(void*,void*,void*,void*,void*,void*);
virtual IOReturn extGetButtonEventNum(void*,void*,void*,void*,void*,void*);
IOReturn extSetBounds( IOGBounds * bounds );
public:
virtual int registerScreen(IOGraphicsDevice * instance,
Bounds * bp);
virtual void unregisterScreen(int index);
public:
virtual Bounds * workspaceBounds();
private:
void relativePointerEvent( int buttons,
int dx,
int dy,
AbsoluteTime ts,
OSObject * sender);
void absolutePointerEvent( int buttons,
Point * newLoc,
Bounds * bounds,
bool proximity,
int pressure,
int stylusAngle,
AbsoluteTime ts,
OSObject * sender);
void scrollWheelEvent( short deltaAxis1,
short deltaAxis2,
short deltaAxis3,
AbsoluteTime ts,
OSObject * sender);
void tabletEvent( NXEventData * tabletData,
AbsoluteTime ts,
OSObject * sender);
void proximityEvent( NXEventData * proximityData,
AbsoluteTime ts,
OSObject * sender);
void keyboardEvent(unsigned eventType,
unsigned flags,
unsigned key,
unsigned charCode,
unsigned charSet,
unsigned origCharCode,
unsigned origCharSet,
unsigned keyboardType,
bool repeat,
AbsoluteTime ts,
OSObject * sender);
void keyboardSpecialEvent( unsigned eventType,
unsigned flags,
unsigned key,
unsigned flavor,
UInt64 guid,
bool repeat,
AbsoluteTime ts,
OSObject * sender);
void updateEventFlags(unsigned flags, OSObject * sender);
static IOReturn doEvClose (IOHIDSystem *self);
IOReturn evCloseGated (void);
static IOReturn doResetMouseParameters (IOHIDSystem *self);
void resetMouseParametersGated (void);
static IOReturn doUnregisterScreen (IOHIDSystem *self, void * arg0);
void unregisterScreenGated (int index);
static IOReturn doCreateShmem (IOHIDSystem *self, void * arg0);
IOReturn createShmemGated (void * p1);
static IOReturn doRelativePointerEvent (IOHIDSystem *self, void * args);
void relativePointerEventGated(int buttons,
int dx,
int dy,
AbsoluteTime ts,
OSObject * sender);
static IOReturn doAbsolutePointerEvent (IOHIDSystem *self, void * args);
void absolutePointerEventGated (int buttons,
Point * newLoc,
Bounds * bounds,
bool proximity,
int pressure,
int stylusAngle,
AbsoluteTime ts,
OSObject * sender);
static IOReturn doScrollWheelEvent(IOHIDSystem *self, void * args);
void scrollWheelEventGated (short deltaAxis1,
short deltaAxis2,
short deltaAxis3,
AbsoluteTime ts,
OSObject * sender);
static IOReturn doTabletEvent (IOHIDSystem *self, void * arg0, void * arg1, void * arg2);
void tabletEventGated ( NXEventData *tabletData,
AbsoluteTime ts,
OSObject * sender);
static IOReturn doProximityEvent (IOHIDSystem *self, void * arg0, void * arg1, void * arg2);
void proximityEventGated ( NXEventData *proximityData,
AbsoluteTime ts,
OSObject * sender);
static IOReturn doKeyboardEvent (IOHIDSystem *self, void * args);
void keyboardEventGated (unsigned eventType,
unsigned flags,
unsigned key,
unsigned charCode,
unsigned charSet,
unsigned origCharCode,
unsigned origCharSet,
unsigned keyboardType,
bool repeat,
AbsoluteTime ts,
OSObject * sender);
static IOReturn doKeyboardSpecialEvent (IOHIDSystem *self, void * args);
void keyboardSpecialEventGated (
unsigned eventType,
unsigned flags,
unsigned key,
unsigned flavor,
UInt64 guid,
bool repeat,
AbsoluteTime ts,
OSObject * sender);
static IOReturn doUpdateEventFlags (IOHIDSystem *self, void * arg0, void * arg1);
void updateEventFlagsGated (unsigned flags, OSObject * sender);
static IOReturn doNewUserClient (IOHIDSystem *self, void * arg0, void * arg1,
void * arg2, void * arg3);
IOReturn newUserClientGated (task_t owningTask,
void * security_id,
UInt32 type,
IOUserClient ** handler);
static IOReturn doSetCursorEnable (IOHIDSystem *self, void * arg0);
IOReturn setCursorEnableGated (void * p1);
static IOReturn doExtPostEvent (IOHIDSystem *self, void * arg0);
IOReturn extPostEventGated (void * p1);
static IOReturn doExtSetMouseLocation (IOHIDSystem *self, void * args);
IOReturn extSetMouseLocationGated (void * args);
static IOReturn doExtGetButtonEventNum (IOHIDSystem *self, void * arg0, void * arg1);
IOReturn extGetButtonEventNumGated (void * p1, void * p2);
static bool doUpdateProperties (IOHIDSystem *self);
bool updatePropertiesGated (void);
static IOReturn doSetParamProperties (IOHIDSystem *self, void * arg0);
IOReturn setParamPropertiesGated (OSDictionary * dict);
};
#endif