52 #import <Cocoa/Cocoa.h> 55 #ifndef MAC_OS_X_VERSION_10_9 56 #define MAC_OS_X_VERSION_10_9 1090 59 #ifndef MAC_OS_X_VERSION_10_10 60 #define MAC_OS_X_VERSION_10_10 101000 63 #if MAC_OS_X_VERSION_MIN_REQUIRED < MAC_OS_X_VERSION_10_10 66 #include <Carbon/Carbon.h> 69 #ifndef HIDREMOTE_THREADSAFETY_HARDENED_NOTIFICATION_HANDLING 70 #if MAC_OS_X_VERSION_MIN_REQUIRED >= MAC_OS_X_VERSION_10_5 72 #define HIDREMOTE_THREADSAFETY_HARDENED_NOTIFICATION_HANDLING 1 74 #define HIDREMOTE_THREADSAFETY_HARDENED_NOTIFICATION_HANDLING 0 79 #include <mach/mach.h> 80 #include <sys/types.h> 82 #include <IOKit/IOKitLib.h> 83 #include <IOKit/IOCFPlugIn.h> 84 #include <IOKit/IOMessage.h> 85 #include <IOKit/hid/IOHIDKeys.h> 86 #include <IOKit/hid/IOHIDLib.h> 87 #include <IOKit/hid/IOHIDUsageTables.h> 88 #include <IOKit/hidsystem/IOHIDLib.h> 89 #include <IOKit/hidsystem/IOHIDParameter.h> 90 #include <IOKit/hidsystem/IOHIDShared.h> 92 #pragma mark - Enums / Codes 94 #ifndef HID_REMOTE_MODE_ENUM 95 #define HID_REMOTE_MODE_ENUM 1 98 kHIDRemoteModeNone = 0L,
102 kHIDRemoteModeExclusive,
104 kHIDRemoteModeExclusiveAuto
112 kHIDRemoteButtonCodeNone = 0L,
115 kHIDRemoteButtonCodeUp,
116 kHIDRemoteButtonCodeDown,
117 kHIDRemoteButtonCodeLeft,
118 kHIDRemoteButtonCodeRight,
119 kHIDRemoteButtonCodeCenter,
120 kHIDRemoteButtonCodeMenu,
123 kHIDRemoteButtonCodePlay,
126 kHIDRemoteButtonCodeCodeMask = 0xFFL,
127 kHIDRemoteButtonCodeHoldMask = (1L << 16L),
128 kHIDRemoteButtonCodeSpecialMask = (1L << 17L),
129 kHIDRemoteButtonCodeAluminumMask = (1L << 21L),
132 kHIDRemoteButtonCodeUpHold = (kHIDRemoteButtonCodeHoldMask|kHIDRemoteButtonCodeUp),
133 kHIDRemoteButtonCodeDownHold = (kHIDRemoteButtonCodeHoldMask|kHIDRemoteButtonCodeDown),
134 kHIDRemoteButtonCodeLeftHold = (kHIDRemoteButtonCodeHoldMask|kHIDRemoteButtonCodeLeft),
135 kHIDRemoteButtonCodeRightHold = (kHIDRemoteButtonCodeHoldMask|kHIDRemoteButtonCodeRight),
136 kHIDRemoteButtonCodeCenterHold = (kHIDRemoteButtonCodeHoldMask|kHIDRemoteButtonCodeCenter),
137 kHIDRemoteButtonCodeMenuHold = (kHIDRemoteButtonCodeHoldMask|kHIDRemoteButtonCodeMenu),
140 kHIDRemoteButtonCodePlayHold = (kHIDRemoteButtonCodeHoldMask|kHIDRemoteButtonCodePlay),
143 kHIDRemoteButtonCodePlus = kHIDRemoteButtonCodeUp,
144 kHIDRemoteButtonCodePlusHold = kHIDRemoteButtonCodeUpHold,
145 kHIDRemoteButtonCodeMinus = kHIDRemoteButtonCodeDown,
146 kHIDRemoteButtonCodeMinusHold = kHIDRemoteButtonCodeDownHold,
147 kHIDRemoteButtonCodePlayPause = kHIDRemoteButtonCodeCenter,
148 kHIDRemoteButtonCodePlayPauseHold = kHIDRemoteButtonCodeCenterHold,
151 kHIDRemoteButtonCodeIDChanged = (kHIDRemoteButtonCodeSpecialMask|(1L << 18L)),
152 #ifdef _HIDREMOTE_EXTENSIONS 153 #define _HIDREMOTE_EXTENSIONS_SECTION 1 154 #include "HIDRemoteAdditions.h" 155 #undef _HIDREMOTE_EXTENSIONS_SECTION 157 } HIDRemoteButtonCode;
161 kHIDRemoteModelUndetermined = 0L,
162 kHIDRemoteModelWhitePlastic,
163 kHIDRemoteModelAluminum
168 kHIDRemoteAluminumRemoteSupportLevelNone = 0L,
169 kHIDRemoteAluminumRemoteSupportLevelEmulation,
170 kHIDRemoteAluminumRemoteSupportLevelNative
171 } HIDRemoteAluminumRemoteSupportLevel;
175 #pragma mark - Delegate protocol (mandatory) 180 eventWithButton:(HIDRemoteButtonCode)buttonCode
181 isPressed:(BOOL)isPressed
182 fromHardwareWithAttributes:(NSMutableDictionary *)attributes;
188 remoteIDChangedOldID:(SInt32)old
190 forHardwareWithAttributes:(NSMutableDictionary *)attributes;
194 foundNewHardwareWithAttributes:(NSMutableDictionary *)attributes;
197 failedNewHardwareWithError:(NSError *)error;
200 releasedHardwareWithAttributes:(NSMutableDictionary *)attributes;
206 inspectNewHardwareWithService:(io_service_t)service
207 prematchResult:(BOOL)prematchResult;
212 lendExclusiveLockToApplicationWithInfo:(NSDictionary *)applicationInfo;
215 exclusiveLockReleasedByApplicationWithInfo:(NSDictionary *)applicationInfo;
218 shouldRetryExclusiveLockWithInfo:(NSDictionary *)applicationInfo;
223 #pragma mark - Actual header file for class 227 mach_port_t _masterPort;
230 IONotificationPortRef _notifyPort;
231 CFRunLoopSourceRef _notifyRLSource;
234 io_iterator_t _matchingServicesIterator;
237 io_object_t _secureInputNotification;
240 NSMutableDictionary *_serviceAttribMap;
245 NSTimer *_autoRecoveryTimer;
248 NSObject <HIDRemoteDelegate> *_delegate;
251 SInt32 _lastSeenRemoteID;
252 HIDRemoteModel _lastSeenModel;
253 SInt32 _lastSeenModelRemoteID;
256 NSArray *_unusedButtonCodes;
259 BOOL _simulateHoldEvents;
262 BOOL _secureEventInputWorkAround;
263 UInt64 _lastSecureEventInputPIDSum;
264 uid_t _lastFrontUserSession;
265 BOOL _lastScreenIsLocked;
268 BOOL _exclusiveLockLending;
269 BOOL _sendExclusiveResourceReuseNotification;
270 NSNumber *_waitForReturnByPID;
271 NSNumber *_returnToPID;
275 BOOL _sendStatusNotifications;
276 NSString *_pidString;
279 BOOL _applicationIsTerminating;
283 #if HIDREMOTE_THREADSAFETY_HARDENED_NOTIFICATION_HANDLING 284 NSThread *_runOnThread;
288 #pragma mark - PUBLIC: Shared HID Remote 291 #pragma mark - PUBLIC: System Information 292 + (BOOL)isCandelairInstalled;
293 + (BOOL)isCandelairInstallationRequiredForRemoteMode:(HIDRemoteMode)remoteMode;
294 + (SInt32)OSXVersion;
295 - (HIDRemoteAluminumRemoteSupportLevel)aluminiumRemoteSystemSupportLevel;
297 #pragma mark - PUBLIC: Interface / API 298 - (BOOL)startRemoteControl:(HIDRemoteMode)hidRemoteMode;
299 - (void)stopRemoteControl;
302 - (HIDRemoteMode)startedInMode;
304 - (unsigned)activeRemoteControlCount;
306 - (SInt32)lastSeenRemoteControlID;
308 - (void)setLastSeenModel:(HIDRemoteModel)aModel;
309 - (HIDRemoteModel)lastSeenModel;
311 - (void)setDelegate:(NSObject <HIDRemoteDelegate> *)newDelegate;
312 - (NSObject <HIDRemoteDelegate> *)delegate;
314 - (void)setSimulateHoldEvents:(BOOL)newSimulateHoldEvents;
315 - (BOOL)simulateHoldEvents;
317 - (void)setUnusedButtonCodes:(NSArray *)newArrayWithUnusedButtonCodesAsNSNumbers;
318 - (NSArray *)unusedButtonCodes;
320 #pragma mark - PUBLIC: Expert APIs 321 - (void)setEnableSecureEventInputWorkaround:(BOOL)newEnableSecureEventInputWorkaround;
322 - (BOOL)enableSecureEventInputWorkaround;
324 - (void)setExclusiveLockLendingEnabled:(BOOL)newExclusiveLockLendingEnabled;
325 - (BOOL)exclusiveLockLendingEnabled;
327 - (BOOL)isApplicationTerminating;
330 #pragma mark - PRIVATE: HID Event handling 331 - (void)_handleButtonCode:(HIDRemoteButtonCode)buttonCode isPressed:(BOOL)isPressed hidAttribsDict:(NSMutableDictionary *)hidAttribsDict;
332 - (void)_sendButtonCode:(HIDRemoteButtonCode)buttonCode isPressed:(BOOL)isPressed hidAttribsDict:(NSMutableDictionary *)hidAttribsDict;
333 - (void)_hidEventFor:(io_service_t)hidDevice from:(IOHIDQueueInterface **)interface withResult:(IOReturn)result;
335 #pragma mark - PRIVATE: Service setup and destruction 336 - (BOOL)_prematchService:(io_object_t)service;
337 - (HIDRemoteButtonCode)buttonCodeForUsage:(
unsigned int)usage usagePage:(
unsigned int)usagePage;
338 - (BOOL)_setupService:(io_object_t)service;
339 - (void)_destructService:(io_object_t)service;
341 #pragma mark - PRIVATE: Distributed notifiations handling 342 - (void)_postStatusWithAction:(NSString *)action;
343 - (void)_handleNotifications:(NSNotification *)notification;
344 - (void)_setSendStatusNotifications:(BOOL)doSend;
345 - (BOOL)_sendStatusNotifications;
347 #pragma mark - PRIVATE: Application becomes active / inactive handling for kHIDRemoteModeExclusiveAuto 348 - (void)_appStatusChanged:(NSNotification *)notification;
349 - (void)_delayedAutoRecovery:(NSTimer *)aTimer;
351 #pragma mark - PRIVATE: Notification handling 352 - (void)_serviceMatching:(io_iterator_t)iterator;
353 - (void)_serviceNotificationFor:(io_service_t)service messageType:(natural_t)messageType messageArgument:(
void *)messageArgument;
354 - (void)_updateSessionInformation;
355 - (void)_secureInputNotificationFor:(io_service_t)service messageType:(natural_t)messageType messageArgument:(
void *)messageArgument;
359 #pragma mark - Information attribute keys 360 extern NSString *kHIDRemoteManufacturer;
361 extern NSString *kHIDRemoteProduct;
362 extern NSString *kHIDRemoteTransport;
364 #pragma mark - Internal/Expert attribute keys (AKA: don't touch these unless you really, really, REALLY know what you do) 365 extern NSString *kHIDRemoteCFPluginInterface;
366 extern NSString *kHIDRemoteHIDDeviceInterface;
367 extern NSString *kHIDRemoteCookieButtonCodeLUT;
368 extern NSString *kHIDRemoteHIDQueueInterface;
369 extern NSString *kHIDRemoteServiceNotification;
370 extern NSString *kHIDRemoteCFRunLoopSource;
371 extern NSString *kHIDRemoteLastButtonPressed;
372 extern NSString *kHIDRemoteService;
373 extern NSString *kHIDRemoteSimulateHoldEventsTimer;
374 extern NSString *kHIDRemoteSimulateHoldEventsOriginButtonCode;
375 extern NSString *kHIDRemoteAluminumRemoteSupportLevel;
376 extern NSString *kHIDRemoteAluminumRemoteSupportOnDemand;
378 #pragma mark - Distributed notifications 379 extern NSString *kHIDRemoteDNHIDRemotePing;
380 extern NSString *kHIDRemoteDNHIDRemoteRetry;
381 extern NSString *kHIDRemoteDNHIDRemoteStatus;
383 extern NSString *kHIDRemoteDNHIDRemoteRetryGlobalObject;
385 #pragma mark - Distributed notifications userInfo keys and values 386 extern NSString *kHIDRemoteDNStatusHIDRemoteVersionKey;
387 extern NSString *kHIDRemoteDNStatusPIDKey;
388 extern NSString *kHIDRemoteDNStatusModeKey;
389 extern NSString *kHIDRemoteDNStatusUnusedButtonCodesKey;
390 extern NSString *kHIDRemoteDNStatusRemoteControlCountKey;
391 extern NSString *kHIDRemoteDNStatusReturnToPIDKey;
392 extern NSString *kHIDRemoteDNStatusActionKey;
393 extern NSString *kHIDRemoteDNStatusActionStart;
394 extern NSString *kHIDRemoteDNStatusActionStop;
395 extern NSString *kHIDRemoteDNStatusActionUpdate;
396 extern NSString *kHIDRemoteDNStatusActionNoNeed;
398 #pragma mark - Driver compatibility flags 399 #ifndef HID_REMOTE_COMPATIBILITY_FLAGS_ENUM 400 #define HID_REMOTE_COMPATIBILITY_FLAGS_ENUM 1 403 kHIDRemoteCompatibilityFlagsStandardHIDRemoteDevice = 1L,
404 } HIDRemoteCompatibilityFlags;
Definition: HIDRemote.h:176
Definition: HIDRemote.h:224