00001 /***************************************************************************** 00002 * AppleRemote.h 00003 * AppleRemote 00004 * $Id: 12e8ca3bd01e21dc22a7b8cc7e85fcbb04f3ee74 $ 00005 * 00006 * Created by Martin Kahr on 11.03.06 under a MIT-style license. 00007 * Copyright (c) 2006 martinkahr.com. All rights reserved. 00008 * 00009 * Permission is hereby granted, free of charge, to any person obtaining a 00010 * copy of this software and associated documentation files (the "Software"), 00011 * to deal in the Software without restriction, including without limitation 00012 * the rights to use, copy, modify, merge, publish, distribute, sublicense, 00013 * and/or sell copies of the Software, and to permit persons to whom the 00014 * Software is furnished to do so, subject to the following conditions: 00015 * 00016 * The above copyright notice and this permission notice shall be included 00017 * in all copies or substantial portions of the Software. 00018 * 00019 * THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 00020 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 00021 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 00022 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 00023 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 00024 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 00025 * THE SOFTWARE. 00026 * 00027 ***************************************************************************** 00028 * 00029 * Note that changes made by any members or contributors of the VideoLAN team 00030 * (i.e. changes that were checked in exclusively into one of VideoLAN's source code 00031 * repositories) are licensed under the GNU General Public License version 2, 00032 * or (at your option) any later version. 00033 * Thus, the following statements apply to our changes: 00034 * 00035 * Copyright (C) 2006-2007 the VideoLAN team 00036 * Authors: Eric Petit <titer@m0k.org> 00037 * Felix Kühne <fkuehne at videolan dot org> 00038 * 00039 * This program is free software; you can redistribute it and/or modify 00040 * it under the terms of the GNU General Public License as published by 00041 * the Free Software Foundation; either version 2 of the License, or 00042 * (at your option) any later version. 00043 * 00044 * This program is distributed in the hope that it will be useful, 00045 * but WITHOUT ANY WARRANTY; without even the implied warranty of 00046 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00047 * GNU General Public License for more details. 00048 * 00049 * You should have received a copy of the GNU General Public License 00050 * along with this program; if not, write to the Free Software 00051 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA. 00052 *****************************************************************************/ 00053 00054 #import <Cocoa/Cocoa.h> 00055 #import <mach/mach.h> 00056 #import <mach/mach_error.h> 00057 #import <IOKit/IOKitLib.h> 00058 #import <IOKit/IOCFPlugIn.h> 00059 #import <IOKit/hid/IOHIDLib.h> 00060 #import <IOKit/hid/IOHIDKeys.h> 00061 00062 enum AppleRemoteEventIdentifier 00063 { 00064 kRemoteButtonVolume_Plus =1<<1, 00065 kRemoteButtonVolume_Minus =1<<2, 00066 kRemoteButtonMenu =1<<3, 00067 kRemoteButtonPlay =1<<4, 00068 kRemoteButtonRight =1<<5, 00069 kRemoteButtonLeft =1<<6, 00070 kRemoteButtonRight_Hold =1<<7, 00071 kRemoteButtonLeft_Hold =1<<8, 00072 kRemoteButtonMenu_Hold =1<<9, 00073 kRemoteButtonPlay_Sleep =1<<10, 00074 kRemoteControl_Switched =1<<11, 00075 kRemoteButtonVolume_Plus_Hold =1<<12, 00076 kRemoteButtonVolume_Minus_Hold =1<<13, 00077 k2009RemoteButtonPlay =1<<14, 00078 k2009RemoteButtonFullscreen =1<<15 00079 }; 00080 typedef enum AppleRemoteEventIdentifier AppleRemoteEventIdentifier; 00081 00082 /* Encapsulates usage of the apple remote control 00083 This class is implemented as a singleton as there is exactly one remote per machine (until now) 00084 The class is not thread safe 00085 */ 00086 @interface AppleRemote : NSObject { 00087 IOHIDDeviceInterface** hidDeviceInterface; 00088 IOHIDQueueInterface** queue; 00089 NSMutableArray* allCookies; 00090 NSMutableDictionary* cookieToButtonMapping; 00091 CFRunLoopSourceRef eventSource; 00092 00093 BOOL openInExclusiveMode; 00094 BOOL simulatePlusMinusHold; 00095 BOOL processesBacklog; 00096 00097 /* state for simulating plus/minus hold */ 00098 BOOL lastEventSimulatedHold; 00099 AppleRemoteEventIdentifier lastPlusMinusEvent; 00100 NSTimeInterval lastPlusMinusEventTime; 00101 00102 int remoteId; 00103 unsigned int clickCountEnabledButtons; 00104 NSTimeInterval maxClickTimeDifference; 00105 NSTimeInterval lastClickCountEventTime; 00106 AppleRemoteEventIdentifier lastClickCountEvent; 00107 unsigned int eventClickCount; 00108 00109 IBOutlet id delegate; 00110 } 00111 00112 - (int) remoteId; 00113 00114 - (BOOL) isRemoteAvailable; 00115 00116 - (BOOL) isListeningToRemote; 00117 - (void) setListeningToRemote: (BOOL) value; 00118 00119 - (BOOL) isOpenInExclusiveMode; 00120 - (void) setOpenInExclusiveMode: (BOOL) value; 00121 00122 /* click counting makes it possible to recognize if the user has pressed a button repeatedly 00123 * click counting does delay each event as it has to wait if there is another event (second click) 00124 * therefore there is a slight time difference (maximumClickCountTimeDifference) between a single click 00125 * of the user and the call of your delegate method 00126 * click counting can be enabled individually for specific buttons. Use the property clickCountEnableButtons 00127 * to set the buttons for which click counting shall be enabled */ 00128 - (BOOL) clickCountingEnabled; 00129 - (void) setClickCountingEnabled: (BOOL) value; 00130 00131 - (unsigned int) clickCountEnabledButtons; 00132 - (void) setClickCountEnabledButtons: (unsigned int)value; 00133 00134 /* the maximum time difference till which clicks are recognized as multi clicks */ 00135 - (NSTimeInterval) maximumClickCountTimeDifference; 00136 - (void) setMaximumClickCountTimeDifference: (NSTimeInterval) timeDiff; 00137 00138 /* When your application needs to much time on the main thread when processing an event other events 00139 * may already be received which are put on a backlog. As soon as your main thread 00140 * has some spare time this backlog is processed and may flood your delegate with calls. 00141 * Backlog processing is turned off by default. */ 00142 - (BOOL) processesBacklog; 00143 - (void) setProcessesBacklog: (BOOL) value; 00144 00145 /* Sets an NSApplication delegate which starts listening when application is becoming active 00146 * and stops listening when application resigns being active. 00147 * If an NSApplication delegate has been already set all method calls will be forwarded to this delegate, too. */ 00148 - (BOOL) listeningOnAppActivate; 00149 - (void) setListeningOnAppActivate: (BOOL) value; 00150 00151 /* Simulating plus/minus hold does deactivate sending of individual requests for plus/minus pressed down/released. 00152 * Instead special hold events are being triggered when the user is pressing and holding plus/minus for a small period. 00153 * With simulating enabled the plus/minus buttons do behave as the left/right buttons */ 00154 - (BOOL) simulatesPlusMinusHold; 00155 - (void) setSimulatesPlusMinusHold: (BOOL) value; 00156 00157 /* Delegates are not retained */ 00158 - (void) setDelegate: (id) delegate; 00159 - (id) delegate; 00160 00161 - (IBAction) startListening: (id) sender; 00162 - (IBAction) stopListening: (id) sender; 00163 @end 00164 00165 @interface AppleRemote (Singleton) 00166 00167 + (AppleRemote*) sharedRemote; 00168 00169 @end 00170 00171 /* Method definitions for the delegate of the AppleRemote class */ 00172 @interface NSObject(NSAppleRemoteDelegate) 00173 00174 - (void) appleRemoteButton: (AppleRemoteEventIdentifier)buttonIdentifier pressedDown: (BOOL) pressedDown clickCount: (unsigned int) count; 00175 00176 @end 00177 00178 @interface AppleRemote (PrivateMethods) 00179 - (void) setRemoteId: (int) aValue; 00180 - (NSDictionary*) cookieToButtonMapping; 00181 - (IOHIDQueueInterface**) queue; 00182 - (IOHIDDeviceInterface**) hidDeviceInterface; 00183 - (void) handleEventWithCookieString: (NSString*) cookieString sumOfValues: (SInt32) sumOfValues; 00184 @end 00185 00186 @interface AppleRemote (IOKitMethods) 00187 - (io_object_t) findAppleRemoteDevice; 00188 - (IOHIDDeviceInterface**) createInterfaceForDevice: (io_object_t) hidDevice; 00189 - (BOOL) initializeCookies; 00190 - (BOOL) openDevice; 00191 @end 00192 00193 /* A NSApplication delegate which is used to activate and deactivate listening to the remote control 00194 * dependent on the activation state of your application. 00195 * All events are delegated to the original NSApplication delegate if necessary */ 00196 @interface AppleRemoteApplicationDelegate : NSObject { 00197 id applicationDelegate; 00198 } 00199 00200 - (id) initWithApplicationDelegate: (id) delegate; 00201 - (id) applicationDelegate; 00202 @end
1.5.6