Skip to content

Commit

Permalink
- support for macOS 10.13 (High Sierra)
Browse files Browse the repository at this point in the history
- thread-safety Hardening is enabled by default for macOS 10.5 or later
- ARC support
- pragma modernization
- fixed typos
  • Loading branch information
felix-schwarz committed Sep 27, 2017
1 parent 6609bca commit 33a32ab
Show file tree
Hide file tree
Showing 9 changed files with 298 additions and 143 deletions.
2 changes: 2 additions & 0 deletions .gitignore
@@ -0,0 +1,2 @@
.DS_Store

11 changes: 9 additions & 2 deletions Example/HIDRemoteExample.xcodeproj/project.pbxproj
Expand Up @@ -18,8 +18,8 @@
DC74BB2C107E2D7600616791 /* remoteButtonSelect.png in Resources */ = {isa = PBXBuildFile; fileRef = DC74BB25107E2D7600616791 /* remoteButtonSelect.png */; };
DC74BB2D107E2D7600616791 /* remoteButtonUp.png in Resources */ = {isa = PBXBuildFile; fileRef = DC74BB26107E2D7600616791 /* remoteButtonUp.png */; };
DC74BB2E107E2D7600616791 /* remoteButtonRight.png in Resources */ = {isa = PBXBuildFile; fileRef = DC74BB27107E2D7600616791 /* remoteButtonRight.png */; };
DC77207B10876E1A00FC8000 /* DemoController.m in Sources */ = {isa = PBXBuildFile; fileRef = DC77207810876E1A00FC8000 /* DemoController.m */; };
DC77207C10876E1A00FC8000 /* main.m in Sources */ = {isa = PBXBuildFile; fileRef = DC77207A10876E1A00FC8000 /* main.m */; };
DC77207B10876E1A00FC8000 /* DemoController.m in Sources */ = {isa = PBXBuildFile; fileRef = DC77207810876E1A00FC8000 /* DemoController.m */; settings = {COMPILER_FLAGS = "-fno-objc-arc"; }; };
DC77207C10876E1A00FC8000 /* main.m in Sources */ = {isa = PBXBuildFile; fileRef = DC77207A10876E1A00FC8000 /* main.m */; settings = {COMPILER_FLAGS = "-fno-objc-arc"; }; };
DC7B03411A94B10900A0F571 /* Carbon.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = DCDC22EE1080AB18001813E3 /* Carbon.framework */; };
DCDC1AC9107E3066001813E3 /* HIDRemote.m in Sources */ = {isa = PBXBuildFile; fileRef = DCDC1AC8107E3066001813E3 /* HIDRemote.m */; };
DCDC1ACE107E3075001813E3 /* IOKit.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = DCDC1ACD107E3075001813E3 /* IOKit.framework */; };
Expand Down Expand Up @@ -279,6 +279,9 @@
isa = XCBuildConfiguration;
buildSettings = {
ALWAYS_SEARCH_USER_PATHS = NO;
CLANG_ENABLE_OBJC_ARC = NO;
"CLANG_ENABLE_OBJC_ARC[arch=i386]" = NO;
"CLANG_ENABLE_OBJC_ARC[arch=x86_64]" = YES;
COPY_PHASE_STRIP = NO;
GCC_DYNAMIC_NO_PIC = NO;
GCC_ENABLE_FIX_AND_CONTINUE = YES;
Expand All @@ -289,6 +292,7 @@
GCC_VERSION = "";
INFOPLIST_FILE = "HIDRemoteExample-Info.plist";
INSTALL_PATH = "$(HOME)/Applications";
MACOSX_DEPLOYMENT_TARGET = 10.6;
PRODUCT_NAME = "HID Remote Example";
};
name = Debug;
Expand All @@ -297,12 +301,15 @@
isa = XCBuildConfiguration;
buildSettings = {
ALWAYS_SEARCH_USER_PATHS = NO;
"CLANG_ENABLE_OBJC_ARC[arch=i386]" = NO;
"CLANG_ENABLE_OBJC_ARC[arch=x86_64]" = YES;
DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym";
GCC_MODEL_TUNING = G5;
GCC_PRECOMPILE_PREFIX_HEADER = YES;
GCC_PREFIX_HEADER = HIDRemoteExample_Prefix.pch;
INFOPLIST_FILE = "HIDRemoteExample-Info.plist";
INSTALL_PATH = "$(HOME)/Applications";
MACOSX_DEPLOYMENT_TARGET = 10.6;
PRODUCT_NAME = "HID Remote Example";
};
name = Release;
Expand Down
Binary file not shown.
@@ -0,0 +1,91 @@
<?xml version="1.0" encoding="UTF-8"?>
<Scheme
LastUpgradeVersion = "0730"
version = "1.3">
<BuildAction
parallelizeBuildables = "YES"
buildImplicitDependencies = "YES">
<BuildActionEntries>
<BuildActionEntry
buildForTesting = "YES"
buildForRunning = "YES"
buildForProfiling = "YES"
buildForArchiving = "YES"
buildForAnalyzing = "YES">
<BuildableReference
BuildableIdentifier = "primary"
BlueprintIdentifier = "8D1107260486CEB800E47090"
BuildableName = "HID Remote Example.app"
BlueprintName = "HIDRemoteExample"
ReferencedContainer = "container:HIDRemoteExample.xcodeproj">
</BuildableReference>
</BuildActionEntry>
</BuildActionEntries>
</BuildAction>
<TestAction
buildConfiguration = "Debug"
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
shouldUseLaunchSchemeArgsEnv = "YES">
<Testables>
</Testables>
<MacroExpansion>
<BuildableReference
BuildableIdentifier = "primary"
BlueprintIdentifier = "8D1107260486CEB800E47090"
BuildableName = "HID Remote Example.app"
BlueprintName = "HIDRemoteExample"
ReferencedContainer = "container:HIDRemoteExample.xcodeproj">
</BuildableReference>
</MacroExpansion>
<AdditionalOptions>
</AdditionalOptions>
</TestAction>
<LaunchAction
buildConfiguration = "Debug"
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
launchStyle = "0"
useCustomWorkingDirectory = "NO"
ignoresPersistentStateOnLaunch = "NO"
debugDocumentVersioning = "YES"
debugServiceExtension = "internal"
allowLocationSimulation = "YES">
<BuildableProductRunnable
runnableDebuggingMode = "0">
<BuildableReference
BuildableIdentifier = "primary"
BlueprintIdentifier = "8D1107260486CEB800E47090"
BuildableName = "HID Remote Example.app"
BlueprintName = "HIDRemoteExample"
ReferencedContainer = "container:HIDRemoteExample.xcodeproj">
</BuildableReference>
</BuildableProductRunnable>
<AdditionalOptions>
</AdditionalOptions>
</LaunchAction>
<ProfileAction
buildConfiguration = "Release"
shouldUseLaunchSchemeArgsEnv = "YES"
savedToolIdentifier = ""
useCustomWorkingDirectory = "NO"
debugDocumentVersioning = "YES">
<BuildableProductRunnable
runnableDebuggingMode = "0">
<BuildableReference
BuildableIdentifier = "primary"
BlueprintIdentifier = "8D1107260486CEB800E47090"
BuildableName = "HID Remote Example.app"
BlueprintName = "HIDRemoteExample"
ReferencedContainer = "container:HIDRemoteExample.xcodeproj">
</BuildableReference>
</BuildableProductRunnable>
</ProfileAction>
<AnalyzeAction
buildConfiguration = "Debug">
</AnalyzeAction>
<ArchiveAction
buildConfiguration = "Release"
revealArchiveInOrganizer = "YES">
</ArchiveAction>
</Scheme>
@@ -0,0 +1,22 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>SchemeUserState</key>
<dict>
<key>HIDRemoteExample.xcscheme</key>
<dict>
<key>orderHint</key>
<integer>0</integer>
</dict>
</dict>
<key>SuppressBuildableAutocreation</key>
<dict>
<key>8D1107260486CEB800E47090</key>
<dict>
<key>primary</key>
<true/>
</dict>
</dict>
</dict>
</plist>
71 changes: 42 additions & 29 deletions HIDRemote/HIDRemote.h 100644 → 100755
@@ -1,32 +1,32 @@
//
// HIDRemote.h
// HIDRemote V1.4 (18th February 2015)
// HIDRemote.m
// HIDRemote V1.6 (27th September 2017)
//
// Created by Felix Schwarz on 06.04.07.
// Copyright 2007-2015 IOSPIRIT GmbH. All rights reserved.
// Copyright 2007-2017 IOSPIRIT GmbH. All rights reserved.
//
// The latest version of this class is available at
// http://www.iospirit.com/developers/hidremote/
//
// ** LICENSE *************************************************************************
//
// Copyright (c) 2007-2014 IOSPIRIT GmbH (http://www.iospirit.com/)
// Copyright (c) 2007-2017 IOSPIRIT GmbH (http://www.iospirit.com/)
// All rights reserved.
//
//
// Redistribution and use in source and binary forms, with or without modification,
// are permitted provided that the following conditions are met:
//
//
// * Redistributions of source code must retain the above copyright notice, this list
// of conditions and the following disclaimer.
//
//
// * Redistributions in binary form must reproduce the above copyright notice, this
// list of conditions and the following disclaimer in the documentation and/or other
// materials provided with the distribution.
//
//
// * Neither the name of IOSPIRIT GmbH nor the names of its contributors may be used to
// endorse or promote products derived from this software without specific prior
// written permission.
//
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY
// EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
// OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT
Expand All @@ -40,7 +40,6 @@
//
// ************************************************************************************


// ************************************************************************************
// ********************************** DOCUMENTATION ***********************************
// ************************************************************************************
Expand All @@ -67,6 +66,15 @@
#include <Carbon/Carbon.h>
#endif

#ifndef HIDREMOTE_THREADSAFETY_HARDENED_NOTIFICATION_HANDLING
#if MAC_OS_X_VERSION_MIN_REQUIRED >= MAC_OS_X_VERSION_10_5
// Enable thread-safe notification handling by default if deploying to OS X >= 10.5
#define HIDREMOTE_THREADSAFETY_HARDENED_NOTIFICATION_HANDLING 1
#else
#define HIDREMOTE_THREADSAFETY_HARDENED_NOTIFICATION_HANDLING 0
#endif
#endif

#include <unistd.h>
#include <mach/mach.h>
#include <sys/types.h>
Expand All @@ -81,8 +89,10 @@
#include <IOKit/hidsystem/IOHIDParameter.h>
#include <IOKit/hidsystem/IOHIDShared.h>

#pragma mark -- Enums / Codes --
#pragma mark - Enums / Codes

#ifndef HID_REMOTE_MODE_ENUM
#define HID_REMOTE_MODE_ENUM 1
typedef enum
{
kHIDRemoteModeNone = 0L,
Expand All @@ -94,6 +104,7 @@ typedef enum
kHIDRemoteModeExclusiveAuto // Try to acquire an exclusive lock on the remote whenever the application has focus. Temporarily release control over the
// remote when another application has focus (RECOMMENDED)
} HIDRemoteMode;
#endif /* HID_REMOTE_MODE_ENUM */

typedef enum
{
Expand Down Expand Up @@ -161,7 +172,7 @@ typedef enum

@class HIDRemote;

#pragma mark -- Delegate protocol (mandatory) --
#pragma mark - Delegate protocol (mandatory)
@protocol HIDRemoteDelegate

// Notification of button events
Expand Down Expand Up @@ -209,8 +220,7 @@ typedef enum
@end


#pragma mark -- Actual header file for class --

#pragma mark - Actual header file for class
@interface HIDRemote : NSObject
{
// IOMasterPort
Expand Down Expand Up @@ -270,21 +280,21 @@ typedef enum
BOOL _isStopping;

// Thread safety
#ifdef HIDREMOTE_THREADSAFETY_HARDENED_NOTIFICATION_HANDLING /* #define HIDREMOTE_THREADSAFETY_HARDENED_NOTIFICATION_HANDLING if you're running your HIDRemote instance on a background thread (requires OS X 10.5 or later) */
#if HIDREMOTE_THREADSAFETY_HARDENED_NOTIFICATION_HANDLING /* #define HIDREMOTE_THREADSAFETY_HARDENED_NOTIFICATION_HANDLING if you're running your HIDRemote instance on a background thread (requires OS X 10.5 or later) */
NSThread *_runOnThread;
#endif
}

#pragma mark -- PUBLIC: Shared HID Remote --
#pragma mark - PUBLIC: Shared HID Remote
+ (HIDRemote *)sharedHIDRemote;

#pragma mark -- PUBLIC: System Information --
#pragma mark - PUBLIC: System Information
+ (BOOL)isCandelairInstalled;
+ (BOOL)isCandelairInstallationRequiredForRemoteMode:(HIDRemoteMode)remoteMode;
+ (SInt32)OSXVersion;
- (HIDRemoteAluminumRemoteSupportLevel)aluminiumRemoteSystemSupportLevel;

#pragma mark -- PUBLIC: Interface / API --
#pragma mark - PUBLIC: Interface / API
- (BOOL)startRemoteControl:(HIDRemoteMode)hidRemoteMode;
- (void)stopRemoteControl;

Expand All @@ -307,7 +317,7 @@ typedef enum
- (void)setUnusedButtonCodes:(NSArray *)newArrayWithUnusedButtonCodesAsNSNumbers;
- (NSArray *)unusedButtonCodes;

#pragma mark -- PUBLIC: Expert APIs --
#pragma mark - PUBLIC: Expert APIs
- (void)setEnableSecureEventInputWorkaround:(BOOL)newEnableSecureEventInputWorkaround;
- (BOOL)enableSecureEventInputWorkaround;

Expand All @@ -317,41 +327,41 @@ typedef enum
- (BOOL)isApplicationTerminating;
- (BOOL)isStopping;

#pragma mark -- PRIVATE: HID Event handling --
#pragma mark - PRIVATE: HID Event handling
- (void)_handleButtonCode:(HIDRemoteButtonCode)buttonCode isPressed:(BOOL)isPressed hidAttribsDict:(NSMutableDictionary *)hidAttribsDict;
- (void)_sendButtonCode:(HIDRemoteButtonCode)buttonCode isPressed:(BOOL)isPressed hidAttribsDict:(NSMutableDictionary *)hidAttribsDict;
- (void)_hidEventFor:(io_service_t)hidDevice from:(IOHIDQueueInterface **)interface withResult:(IOReturn)result;

#pragma mark -- PRIVATE: Service setup and destruction --
#pragma mark - PRIVATE: Service setup and destruction
- (BOOL)_prematchService:(io_object_t)service;
- (HIDRemoteButtonCode)buttonCodeForUsage:(unsigned int)usage usagePage:(unsigned int)usagePage;
- (BOOL)_setupService:(io_object_t)service;
- (void)_destructService:(io_object_t)service;

#pragma mark -- PRIVATE: Distributed notifiations handling --
#pragma mark - PRIVATE: Distributed notifiations handling
- (void)_postStatusWithAction:(NSString *)action;
- (void)_handleNotifications:(NSNotification *)notification;
- (void)_setSendStatusNotifications:(BOOL)doSend;
- (BOOL)_sendStatusNotifications;

#pragma mark -- PRIVATE: Application becomes active / inactive handling for kHIDRemoteModeExclusiveAuto --
#pragma mark - PRIVATE: Application becomes active / inactive handling for kHIDRemoteModeExclusiveAuto
- (void)_appStatusChanged:(NSNotification *)notification;
- (void)_delayedAutoRecovery:(NSTimer *)aTimer;

#pragma mark -- PRIVATE: Notification handling --
#pragma mark - PRIVATE: Notification handling
- (void)_serviceMatching:(io_iterator_t)iterator;
- (void)_serviceNotificationFor:(io_service_t)service messageType:(natural_t)messageType messageArgument:(void *)messageArgument;
- (void)_updateSessionInformation;
- (void)_secureInputNotificationFor:(io_service_t)service messageType:(natural_t)messageType messageArgument:(void *)messageArgument;

@end

#pragma mark -- Information attribute keys --
#pragma mark - Information attribute keys
extern NSString *kHIDRemoteManufacturer;
extern NSString *kHIDRemoteProduct;
extern NSString *kHIDRemoteTransport;

#pragma mark -- Internal/Expert attribute keys (AKA: don't touch these unless you really, really, REALLY know what you do) --
#pragma mark - Internal/Expert attribute keys (AKA: don't touch these unless you really, really, REALLY know what you do)
extern NSString *kHIDRemoteCFPluginInterface;
extern NSString *kHIDRemoteHIDDeviceInterface;
extern NSString *kHIDRemoteCookieButtonCodeLUT;
Expand All @@ -365,14 +375,14 @@ extern NSString *kHIDRemoteSimulateHoldEventsOriginButtonCode;
extern NSString *kHIDRemoteAluminumRemoteSupportLevel;
extern NSString *kHIDRemoteAluminumRemoteSupportOnDemand;

#pragma mark -- Distributed notifications --
#pragma mark - Distributed notifications
extern NSString *kHIDRemoteDNHIDRemotePing;
extern NSString *kHIDRemoteDNHIDRemoteRetry;
extern NSString *kHIDRemoteDNHIDRemoteStatus;

extern NSString *kHIDRemoteDNHIDRemoteRetryGlobalObject;

#pragma mark -- Distributed notifications userInfo keys and values --
#pragma mark - Distributed notifications userInfo keys and values
extern NSString *kHIDRemoteDNStatusHIDRemoteVersionKey;
extern NSString *kHIDRemoteDNStatusPIDKey;
extern NSString *kHIDRemoteDNStatusModeKey;
Expand All @@ -385,8 +395,11 @@ extern NSString *kHIDRemoteDNStatusActionStop;
extern NSString *kHIDRemoteDNStatusActionUpdate;
extern NSString *kHIDRemoteDNStatusActionNoNeed;

#pragma mark -- Driver compatibility flags --
#pragma mark - Driver compatibility flags
#ifndef HID_REMOTE_COMPATIBILITY_FLAGS_ENUM
#define HID_REMOTE_COMPATIBILITY_FLAGS_ENUM 1
typedef enum
{
kHIDRemoteCompatibilityFlagsStandardHIDRemoteDevice = 1L,
} HIDRemoteCompatibilityFlags;
#endif /* HID_REMOTE_COMPATIBILITY_FLAGS_ENUM */

0 comments on commit 33a32ab

Please sign in to comment.