2  * Copyright (c) 2019-2019 Apple Inc. All rights reserved.
 
   4  * @APPLE_OSREFERENCE_LICENSE_HEADER_START@
 
   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. The rights granted to you under the License
 
  10  * may not be used to create, or enable the creation or redistribution of,
 
  11  * unlawful or unlicensed copies of an Apple operating system, or to
 
  12  * circumvent, violate, or enable the circumvention or violation of, any
 
  13  * terms of an Apple operating system software license agreement.
 
  15  * Please obtain a copy of the License at
 
  16  * http://www.opensource.apple.com/apsl/ and read it before using this file.
 
  18  * The Original Code and all software distributed under the License are
 
  19  * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
 
  20  * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
 
  21  * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
 
  22  * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
 
  23  * Please see the License for the specific language governing rights and
 
  24  * limitations under the License.
 
  26  * @APPLE_OSREFERENCE_LICENSE_HEADER_END@
 
  29 #ifndef _IOKIT_UIOSERVICEDISPATCHSOURCE_H
 
  30 #define _IOKIT_UIOSERVICEDISPATCHSOURCE_H
 
  32 #include <DriverKit/IODispatchQueue.iig>
 
  33 #include <DriverKit/OSAction.iig>
 
  34 #include <DriverKit/IOService.iig>
 
  37 typedef void (^IOServiceNotificationBlock)(uint64_t type, IOService * service, uint64_t options);
 
  40         kIOServiceNotificationTypeTerminated = 0x00000000,
 
  41         kIOServiceNotificationTypeMatched    = 0x00000001,
 
  42         kIOServiceNotificationTypeLast       = kIOServiceNotificationTypeMatched,
 
  43         kIOServiceNotificationTypeNone       = 0xFFFFFFFF,
 
  46 class NATIVE KERNEL IOServiceNotificationDispatchSource : public IODispatchSource
 
  51      * @brief       Create an IOServiceNotificationDispatchSource for IOService matching and termination events.
 
  52      * @param       matching An IOService matching dictionary.
 
  53      * @param       options None defined, pass zero.
 
  54      * @param       queue IODispatchQueue the source is attached to. Note that the ServiceNotificationReady
 
  55      *              handler is invoked on the queue set for the target method
 
  56      *              of the OSAction, not this queue.
 
  57      * @param       source Created source with +1 retain count to be released by the caller.
 
  58      * @return      kIOReturnSuccess on success. See IOReturn.h for error codes.
 
  62                 OSDictionary      *     matching,
 
  64             IODispatchQueue   * queue,
 
  65                 IOServiceNotificationDispatchSource ** notification) LOCAL;
 
  74      * @brief       Control the enable state of the notification.
 
  75      * @param       enable Pass true to enable the source or false to disable.
 
  76      * @param       handler Optional block to be executed after the interrupt has been disabled and any pending
 
  77      *              interrupt handlers completed.
 
  78      * @return      kIOReturnSuccess on success. See IOReturn.h for error codes.
 
  81         SetEnableWithCompletion(
 
  83                 IODispatchSourceCancelHandler handler) override LOCAL;
 
  86      * @brief       Cancel all callbacks from the event source.
 
  87      * @discussion  After cancellation, the source can only be freed. It cannot be reactivated.
 
  88      * @param       handler Handler block to be invoked after any callbacks have completed.
 
  89      * @return      kIOReturnSuccess on success. See IOReturn.h for error codes.
 
  92         Cancel(IODispatchSourceCancelHandler handler) override LOCAL;
 
  95      * @brief       Set the handler block to run when the notification has become ready.
 
  96      * @param       action OSAction instance specifying the callback method. The OSAction object will be retained
 
  97      *              until SetHandler is called again or the event source is cancelled.
 
  98      *              The ServiceNotificationReady handler is invoked on the queue set for the target method of the
 
 100      * @return      kIOReturnSuccess on success. See IOReturn.h for error codes.
 
 102         virtual kern_return_t
 
 104         OSAction * action TYPE(ServiceNotificationReady));
 
 107      * @brief       Invoke a block for each notification available in response to ServiceNotificationReady.
 
 108      * @discussion  The IOService object passed to the notification is only retained for the duration of the block.
 
 109      *              It should be retained by the block code if used beyond the invocation.
 
 110      * @param       block to be invoked with each notification
 
 111      * @return      kIOReturnSuccess on success. See IOReturn.h for error codes.
 
 114         DeliverNotifications(IOServiceNotificationBlock block) LOCALONLY;
 
 117         virtual kern_return_t
 
 118         CheckForWork(bool synchronous) override LOCAL;
 
 121         ServiceNotificationReady(
 
 122                 OSAction  * action TARGET) LOCAL = 0;
 
 124         virtual kern_return_t
 
 125         CopyNextNotification(
 
 127                 IOService ** service,
 
 131 #endif /* ! _IOKIT_UIOSERVICEDISPATCHSOURCE_H */