Annotation of XNU/iokit/IOKit/hidsystem/IOHIDSystem.h, revision 1.1.1.1

1.1       root        1: /*
                      2:  * Copyright (c) 1998-2000 Apple Computer, Inc. All rights reserved.
                      3:  *
                      4:  * @APPLE_LICENSE_HEADER_START@
                      5:  * 
                      6:  * The contents of this file constitute Original Code as defined in and
                      7:  * are subject to the Apple Public Source License Version 1.1 (the
                      8:  * "License").  You may not use this file except in compliance with the
                      9:  * License.  Please obtain a copy of the License at
                     10:  * http://www.apple.com/publicsource and read it before using this file.
                     11:  * 
                     12:  * This Original Code and all software distributed under the License are
                     13:  * distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, EITHER
                     14:  * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
                     15:  * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
                     16:  * FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT.  Please see the
                     17:  * License for the specific language governing rights and limitations
                     18:  * under the License.
                     19:  * 
                     20:  * @APPLE_LICENSE_HEADER_END@
                     21:  */
                     22: /*     Copyright (c) 1992 NeXT Computer, Inc.  All rights reserved. 
                     23:  *
                     24:  * EventDriver.h - Exported Interface Event Driver object.
                     25:  *
                     26:  *             The EventDriver is a pseudo-device driver.
                     27:  *
                     28:  * HISTORY
                     29:  * 19 Mar 1992    Mike Paquette at NeXT
                     30:  *      Created. 
                     31:  * 4  Aug 1993   Erik Kay at NeXT
                     32:  *     API cleanup
                     33:  */
                     34: 
                     35: #ifndef        _IOHIDSYSTEM_H
                     36: #define _IOHIDSYSTEM_H
                     37: 
                     38: #include <IOKit/IOTimerEventSource.h>
                     39: #include <IOKit/IOService.h>
                     40: #include <IOKit/IOUserClient.h>
                     41: #include <IOKit/IOWorkLoop.h>
                     42: #include <IOKit/IOCommandQueue.h>
                     43: #include <IOKit/IOBufferMemoryDescriptor.h>
                     44: #include <IOKit/graphics/IOGraphicsDevice.h>
                     45: #include <IOKit/hidsystem/IOHIDevice.h>
                     46: #include <IOKit/hidsystem/IOHIDShared.h>
                     47: #include <IOKit/hidsystem/IOHIDTypes.h>
                     48: #include <IOKit/hidsystem/IOLLEvent.h>
                     49: #include "ev_keymap.h"         /* For NX_NUM_SCANNED_SPECIALKEYS */
                     50: 
                     51: typedef void (*IOHIDAction)(OSObject *, void *);
                     52: 
                     53: class IOHIDSystem : public IOService
                     54: {
                     55:        OSDeclareDefaultStructors(IOHIDSystem);
                     56: 
                     57:        friend class IOHIDUserClient;
                     58:        friend class IOHIDParamUserClient;
                     59: 
                     60: private:
                     61:        IOLock *        driverLock;
                     62: 
                     63:        IOWorkLoop *            workLoop;
                     64:        IOTimerEventSource *    timerES;
                     65:        IOCommandQueue *        cmdQ;
                     66:        IOUserClient *          serverConnect;
                     67:        IOUserClient *          paramConnect;
                     68:         IONotifier *           publishNotify;
                     69: 
                     70:        // Ports on which we hold send rights
                     71:        mach_port_t     eventPort;      // Send msg here when event queue
                     72:                                        // goes non-empty
                     73:        mach_port_t     _specialKeyPort[NX_NUM_SCANNED_SPECIALKEYS]; // Special key msgs
                     74:        void            *eventMsg;      // Msg to be sent to Window Server.
                     75: 
                     76:        // Shared memory area information
                     77:         IOBufferMemoryDescriptor * globalMemory;
                     78:        vm_offset_t     shmem_addr;     // kernel address of shared memory
                     79:        vm_size_t       shmem_size;     // size of shared memory
                     80: 
                     81:        // Pointers to structures which occupy the shared memory area.
                     82:        volatile void   *evs;           // Pointer to private driver shmem
                     83:        volatile EvGlobals *evg;        // Pointer to EvGlobals (shmem)
                     84:        // Internal variables related to the shared memory area
                     85:        int             lleqSize;       // # of entries in low-level queue
                     86:                         // FIXME: why is this ivar lleqSize an ivar? {Dan]
                     87: 
                     88:        // Screens list
                     89:        vm_size_t       evScreenSize;   // Byte size of evScreen array
                     90:        void            *evScreen;      // array of screens known to driver
                     91:        volatile void   *lastShmemPtr;  // Pointer used to index thru shmem
                     92:                                        // while assigning shared areas to
                     93:                                        // drivers.
                     94:        int             screens;        // running total of allocated screens
                     95:        int             currentScreen;  // Current active screen
                     96:        Bounds          cursorPin;      // Range to which cursor is pinned
                     97:                                        // while on this screen.
                     98:        Bounds          workSpace;      // Bounds of full workspace.
                     99:        // Event Status state - This includes things like event timestamps,
                    100:        // time til screen dim, and related things manipulated through the
                    101:        // Event Status API.
                    102:        //
                    103:        Point   pointerLoc;     // Current pointing device location
                    104:                                // The value leads evg->cursorLoc.
                    105:         Point  pointerDelta;   // The cumulative pointer delta values since
                    106:                                 // previous mouse move event was posted
                    107:        Point   clickLoc;       // location of last mouse click
                    108:        Point   clickSpaceThresh;       // max mouse delta to be a doubleclick
                    109:        int     clickState;     // Current click state
                    110:        unsigned char lastPressure;     // last pressure seen
                    111:        bool    lastProximity;  // last proximity state seen
                    112: 
                    113:        SInt32  curVolume;      // Value of volume setting.
                    114:        SInt32  dimmedBrightness;// Value of screen brightness when autoDim
                    115:                                // has turned on.
                    116:        SInt32  curBright;      // The current brightness is cached here while
                    117:                                // the driver is open.  This number is always
                    118:                                // the user-specified brightness level; if the
                    119:                                // screen is autodimmed, the actual brightness
                    120:                                // level in the monitor will be less.
                    121:        SInt32 autoDimmed;      // Is screen currently autodimmed?
                    122:        bool evOpenCalled;      // Has the driver been opened?
                    123:        bool evInitialized;     // Has the first-open-only initialization run?
                    124:        bool eventsOpen;        // Boolean: has evmmap been called yet?
                    125:        bool cursorStarted;     // periodic events running?
                    126:        bool cursorEnabled;     // cursor positioning ok?
                    127: 
                    128:        short leftENum;         // Unique ID for last left down event
                    129:        short rightENum;        // Unique ID for last right down event
                    130:        
                    131:        // The periodic event mechanism timestamps and state
                    132:        // are recorded here.
                    133:        AbsoluteTime thisPeriodicRun;
                    134:         AbsoluteTime periodicEventDelta;// Time between periodic events
                    135:                                         // todo: make infinite
                    136:         AbsoluteTime clickTime;                // Timestamps used to determine doubleclicks
                    137:         AbsoluteTime clickTimeThresh;
                    138:         AbsoluteTime autoDimPeriod;    // How long since last user action before
                    139:                                         // we autodim screen?  User preference item,
                    140:                                         // set by InitMouse and evsioctl
                    141:         AbsoluteTime autoDimTime;      // Time value when we will autodim screen,
                    142:                                         // if autoDimmed is 0.
                    143:                                         // Set in LLEventPost.
                    144: 
                    145:         AbsoluteTime waitSustain;      // Sustain time before removing cursor
                    146:         AbsoluteTime waitSusTime;      // Sustain counter
                    147:         AbsoluteTime waitFrameRate;    // Ticks per wait cursor frame
                    148:         AbsoluteTime waitFrameTime;    // Wait cursor frame timer
                    149: 
                    150:        // Flags used in scheduling periodic event callbacks
                    151:        bool            needSetCursorPosition;
                    152:        bool            needToKickEventConsumer;
                    153:        IOLock *        kickConsumerLock;
                    154:         
                    155: public:
                    156:         IOService * displayManager;                    // points to display manager
                    157: 
                    158: private:
                    159:   inline short getUniqueEventNum();
                    160: 
                    161:   /* Resets */
                    162:   void _resetMouseParameters();
                    163:   void _resetKeyboardParameters();
                    164: 
                    165:   /* Initialize the shared memory area */
                    166:   void     initShmem();
                    167:   /* Dispatch low level events through shared memory to the WindowServer */
                    168:   void postEvent(int           what,
                    169:           /* at */       Point *       location,
                    170:           /* atTime */   AbsoluteTime  ts,
                    171:           /* withData */ NXEventData * myData);
                    172:   /* Dispatch mechanisms for screen state changes */
                    173:   void evDispatch(int   screen,
                    174:             /* command */ EvCmd evcmd);
                    175:   /* Dispatch mechanism for special key press */
                    176:   void evSpecialKeyMsg(unsigned key,
                    177:                /* direction */ unsigned dir,
                    178:                /* flags */     unsigned f,
                    179:                /* level */     unsigned l);
                    180:   /* Message the event consumer to process posted events */
                    181:   void kickEventConsumer();
                    182:   IOReturn sendWorkLoopCommand(OSObject *  target,
                    183:                                        IOHIDAction action,
                    184:                                        void *      data);
                    185:   static void _doPerformInIOThread( void* self,
                    186:                                    void* target,
                    187:                                     void* action,
                    188:                                     void* data,
                    189:                                     void* unused);
                    190:   static void _periodicEvents(IOHIDSystem * self,
                    191:                               IOTimerEventSource *timer);
                    192: 
                    193:   static void _performSpecialKeyMsg(IOHIDSystem * self,
                    194:                                        struct evioSpecialKeyMsg *msg);
                    195:   static void _performKickEventConsumer(IOHIDSystem * self,void *);
                    196:  
                    197:   static bool publishNotificationHandler( IOHIDSystem * self, 
                    198:                                void * ref, IOService * newService );
                    199: 
                    200: /*
                    201:  * HISTORICAL NOTE:
                    202:  *   The following methods were part of the IOHIDSystem(Input) category;
                    203:  *   the declarations have now been merged directly into this class.
                    204:  *
                    205:  * Exported Interface Event Driver object input services.
                    206:  */
                    207: 
                    208: private:
                    209:   // Schedule next periodic run based on current event system state.
                    210:   void scheduleNextPeriodicEvent();
                    211:   // Message invoked to run periodic events.  This method runs in the workloop.
                    212:   void periodicEvents(IOTimerEventSource *timer);
                    213:   // Start the cursor running.
                    214:   bool startCursor();
                    215:   // Repin cursor location.
                    216:   bool resetCursor();
                    217:   // Wait Cursor machinery.
                    218:   void showWaitCursor();
                    219:   void hideWaitCursor();
                    220:   void animateWaitCursor();
                    221:   void changeCursor(int frame);
                    222:   // Return screen number a point lies on.
                    223:   int  pointToScreen(Point * p);
                    224:   // Set the undimmed brightness.
                    225:   void setBrightness(int b);
                    226:   // Return undimmed brightness.
                    227:   int  brightness();
                    228:   // Set the dimmed brightness.
                    229:   void setAutoDimBrightness(int b);
                    230:   // Return dimmed brightness.
                    231:   int  autoDimBrightness();
                    232:   // Return the current brightness.
                    233:   int  currentBrightness();
                    234:   // Dim all displays.
                    235:   void doAutoDim();
                    236:   // Return display brightness to normal.
                    237:   void undoAutoDim();
                    238:   // Force dim/undim.
                    239:   void forceAutoDimState(bool dim);
                    240:   // Audio volume control.
                    241:   void setAudioVolume(int v);
                    242:   // Audio volume control, from ext user.
                    243:   void setUserAudioVolume(int v);
                    244:   // Return audio volume.
                    245:   int  audioVolume();
                    246:   // Propagate state out to screens.
                    247:   void setBrightness();
                    248: 
                    249:   void showCursor();
                    250:   void hideCursor();
                    251:   void moveCursor();
                    252:   // Claim ownership of event sources.
                    253:   void attachDefaultEventSources();
                    254:   // Give up ownership of event sources.
                    255:   void detachEventSources();
                    256:   bool registerEventSource(IOHIDevice * source);
                    257: 
                    258:   // Set abs cursor position.
                    259:   void setCursorPosition(Point * newLoc);
                    260:   void _setButtonState(int buttons,
                    261:                        /* atTime */ AbsoluteTime ts);
                    262:   void _setCursorPosition(Point * newLoc);
                    263: 
                    264:   void _postMouseMoveEvent(int         what,
                    265:                            Point *     location,
                    266:                            AbsoluteTime        theClock);
                    267: 
                    268: /* END HISTORICAL NOTE */
                    269: 
                    270: public:
                    271:   static IOHIDSystem * instance();     /* Return the current instance of the */
                    272:                                       /* EventDriver, or 0 if none. */
                    273: 
                    274:   virtual bool init(OSDictionary * properties = 0);
                    275:   virtual IOHIDSystem * probe(IOService *    provider,
                    276:                               SInt32 * score);
                    277:   virtual bool start(IOService * provider);
                    278:   virtual IOReturn message(UInt32 type, IOService * provider,
                    279:                                void * argument);
                    280:   virtual void free();
                    281: 
                    282:   virtual IOWorkLoop *getWorkLoop() const;
                    283: 
                    284:   virtual IOReturn evOpen(void);
                    285:   virtual IOReturn evClose(void);
                    286: 
                    287:   virtual bool             updateProperties(void);
                    288:   virtual IOReturn  setParamProperties(OSDictionary * dict);
                    289:   virtual bool      serializeProperties( OSSerialize * s ) const;
                    290: 
                    291:   /* Create the shared memory area */
                    292:   virtual IOReturn createShmem(void*,void*,void*,void*,void*,void*);
                    293:   /* Set the port for event available notify msg */
                    294:   virtual void     setEventPort(mach_port_t port);
                    295:   /* Set the port for the special key keypress msg */
                    296:   virtual IOReturn setSpecialKeyPort(
                    297:                      /* keyFlavor */ int         special_key,
                    298:                      /* keyPort */   mach_port_t key_port);
                    299:   virtual mach_port_t specialKeyPort(int special_key);
                    300: 
                    301: 
                    302:   virtual IOReturn newUserClient(task_t         owningTask,
                    303:                  /* withToken */ void *         security_id,
                    304:                  /* ofType */    UInt32         type,
                    305:                  /* client */    IOUserClient ** handler);
                    306: 
                    307: /*
                    308:  * HISTORICAL NOTE:
                    309:  *   The following methods were part of the IOHIPointingEvents protocol;
                    310:  *   the declarations have now been merged directly into this class.
                    311:  */
                    312: 
                    313: public: 
                    314:   /* Mouse event reporting */
                    315:   virtual void relativePointerEvent(int        buttons,
                    316:                        /* deltaX */ int        dx,
                    317:                        /* deltaY */ int        dy,
                    318:                        /* atTime */ AbsoluteTime ts);
                    319: 
                    320:   /* Tablet event reporting */
                    321:   virtual void absolutePointerEvent(int        buttons,
                    322:                  /* at */           Point *    newLoc,
                    323:                  /* withBounds */   Bounds *   bounds,
                    324:                  /* inProximity */  bool       proximity,
                    325:                  /* withPressure */ int        pressure,
                    326:                  /* withAngle */    int        stylusAngle,
                    327:                  /* atTime */       AbsoluteTime ts);
                    328: 
                    329:   /* Mouse scroll wheel event reporting */
                    330:   virtual void scrollWheelEvent(short deltaAxis1,
                    331:                                 short deltaAxis2,
                    332:                                 short deltaAxis3,
                    333:                                 AbsoluteTime ts);
                    334:   
                    335: 
                    336:   virtual void tabletEvent(NXEventData *tabletData,
                    337:                            AbsoluteTime ts);
                    338: 
                    339:   virtual void proximityEvent(NXEventData *proximityData,
                    340:                               AbsoluteTime ts);
                    341: 
                    342: /*
                    343:  * HISTORICAL NOTE:
                    344:  *   The following methods were part of the IOHIKeyboardEvents protocol;
                    345:  *   the declarations have now been merged directly into this class.
                    346:  */
                    347: 
                    348: public:
                    349:   virtual void keyboardEvent(unsigned   eventType,
                    350:       /* flags */            unsigned   flags,
                    351:       /* keyCode */          unsigned   key,
                    352:       /* charCode */         unsigned   charCode,
                    353:       /* charSet */          unsigned   charSet,
                    354:       /* originalCharCode */ unsigned   origCharCode,
                    355:       /* originalCharSet */  unsigned   origCharSet,
                    356:       /* repeat */           bool       repeat,
                    357:       /* atTime */           AbsoluteTime ts);
                    358:   virtual void keyboardSpecialEvent(unsigned   eventType,
                    359:                     /* flags */     unsigned   flags,
                    360:                     /* keyCode  */  unsigned   key,
                    361:                     /* specialty */ unsigned   flavor,
                    362:                     /* atTime */    AbsoluteTime ts);
                    363:   virtual void updateEventFlags(unsigned flags);  /* Does not generate events */
                    364: 
                    365: 
                    366: 
                    367: 
                    368: private:
                    369: 
                    370:   /*
                    371:    * statics for upstream callouts
                    372:    */
                    373: 
                    374:   void _scaleLocationToCurrentScreen(Point *location, Bounds *bounds);  // Should this one be public???
                    375: 
                    376:   static void _relativePointerEvent( IOHIDSystem * self,
                    377:                                    int        buttons,
                    378:                        /* deltaX */ int        dx,
                    379:                        /* deltaY */ int        dy,
                    380:                        /* atTime */ AbsoluteTime ts);
                    381: 
                    382:   /* Tablet event reporting */
                    383:   static void _absolutePointerEvent(IOHIDSystem * self,
                    384:                                    int        buttons,
                    385:                  /* at */           Point *    newLoc,
                    386:                  /* withBounds */   Bounds *   bounds,
                    387:                  /* inProximity */  bool       proximity,
                    388:                  /* withPressure */ int        pressure,
                    389:                  /* withAngle */    int        stylusAngle,
                    390:                  /* atTime */       AbsoluteTime ts);
                    391: 
                    392:   /* Mouse scroll wheel event reporting */
                    393:   static void _scrollWheelEvent(IOHIDSystem *self,
                    394:                                 short deltaAxis1,
                    395:                                 short deltaAxis2,
                    396:                                 short deltaAxis3,
                    397:                                 AbsoluteTime ts);
                    398: 
                    399:   static void _tabletEvent(IOHIDSystem *self,
                    400:                            NXEventData *tabletData,
                    401:                            AbsoluteTime ts);
                    402: 
                    403:   static void _proximityEvent(IOHIDSystem *self,
                    404:                               NXEventData *proximityData,
                    405:                               AbsoluteTime ts);
                    406: 
                    407:   static void _keyboardEvent( IOHIDSystem * self,
                    408:                             unsigned   eventType,
                    409:       /* flags */            unsigned   flags,
                    410:       /* keyCode */          unsigned   key,
                    411:       /* charCode */         unsigned   charCode,
                    412:       /* charSet */          unsigned   charSet,
                    413:       /* originalCharCode */ unsigned   origCharCode,
                    414:       /* originalCharSet */  unsigned   origCharSet,
                    415:       /* repeat */           bool       repeat,
                    416:       /* atTime */           AbsoluteTime ts);
                    417:   static void _keyboardSpecialEvent( IOHIDSystem * self,
                    418:                                    unsigned   eventType,
                    419:                     /* flags */     unsigned   flags,
                    420:                     /* keyCode  */  unsigned   key,
                    421:                     /* specialty */ unsigned   flavor,
                    422:                     /* atTime */    AbsoluteTime ts);
                    423:   static void _updateEventFlags( IOHIDSystem * self,
                    424:                                unsigned flags);  /* Does not generate events */
                    425: 
                    426: 
                    427: /*
                    428:  * HISTORICAL NOTE:
                    429:  *   The following methods were part of the IOUserClient protocol;
                    430:  *   the declarations have now been merged directly into this class.
                    431:  */
                    432: 
                    433: public:
                    434: 
                    435:   virtual IOReturn setEventsEnable(void*,void*,void*,void*,void*,void*);
                    436:   virtual IOReturn setCursorEnable(void*,void*,void*,void*,void*,void*);
                    437:   virtual IOReturn extPostEvent(void*,void*,void*,void*,void*,void*);
                    438:   virtual IOReturn extSetMouseLocation(void*,void*,void*,void*,void*,void*);
                    439:   virtual IOReturn extGetButtonEventNum(void*,void*,void*,void*,void*,void*);
                    440: 
                    441: /*
                    442:  * HISTORICAL NOTE:
                    443:  *   The following methods were part of the IOScreenRegistration protocol;
                    444:  *   the declarations have now been merged directly into this class.
                    445:  *
                    446:  * Methods exported by the EventDriver for display systems.
                    447:  *
                    448:  *     The screenRegister protocol is used by frame buffer drivers to register
                    449:  *     themselves with the Event Driver.  These methods are called in response
                    450:  *     to an _IOGetParameterInIntArray() call with "IO_Framebuffer_Register" or
                    451:  *     "IO_Framebuffer_Unregister".
                    452:  */
                    453: 
                    454: public:
                    455:   virtual int registerScreen(IOGraphicsDevice * instance,
                    456:              /* bounds */    Bounds * bp);
                    457: //           /* shmem */     void **  addr,
                    458: //           /* size */      int *    size)
                    459:   virtual void unregisterScreen(int index);
                    460: 
                    461: /*
                    462:  * HISTORICAL NOTE:
                    463:  *   The following methods were part of the IOWorkspaceBounds protocol;
                    464:  *   the declarations have now been merged directly into this class.
                    465:  *
                    466:  * Absolute position input devices and some specialized output devices
                    467:  * may need to know the bounding rectangle for all attached displays.
                    468:  * The following method returns a Bounds* for the workspace.  Please note
                    469:  * that the bounds are kept as signed values, and that on a multi-display
                    470:  * system the minx and miny values may very well be negative.
                    471:  */
                    472: 
                    473: public:
                    474:   virtual Bounds * workspaceBounds();
                    475: 
                    476: /* END HISTORICAL NOTES */
                    477: };
                    478: 
                    479: #endif /* !_IOHIDSYSTEM_H */

unix.superglobalmegacorp.com

This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.