LibreOffice Module apple_remote (master) 1
KeyspanFrontRowControl.m
Go to the documentation of this file.
1/* -*- Mode: ObjC; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2/*****************************************************************************
3 * KeyspanFrontRowControl.m
4 * RemoteControlWrapper
5 *
6 * Created by Martin Kahr on 11.03.06 under a MIT-style license.
7 * Copyright (c) 2006 martinkahr.com. All rights reserved.
8 *
9 * Code modified and adapted to OpenOffice.org
10 * by Eric Bachard on 11.08.2008 under the same License
11 *
12 * Permission is hereby granted, free of charge, to any person obtaining a
13 * copy of this software and associated documentation files (the "Software"),
14 * to deal in the Software without restriction, including without limitation
15 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
16 * and/or sell copies of the Software, and to permit persons to whom the
17 * Software is furnished to do so, subject to the following conditions:
18 *
19 * The above copyright notice and this permission notice shall be included
20 * in all copies or substantial portions of the Software.
21 *
22 * THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
23 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
24 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
25 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
26 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
27 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
28 * THE SOFTWARE.
29 *
30 *****************************************************************************/
31
33#import <mach/mach.h>
34#import <mach/mach_error.h>
35#import <IOKit/IOKitLib.h>
36#import <IOKit/IOCFPlugIn.h>
37#import <IOKit/hid/IOHIDKeys.h>
38
39@implementation KeyspanFrontRowControl
40
41- (void) setCookieMappingInDictionary: (NSMutableDictionary*) _cookieToButtonMapping {
42 [_cookieToButtonMapping setObject:[NSNumber numberWithInt:kRemoteButtonPlus] forKey:@"11_18_99_10_"];
43 [_cookieToButtonMapping setObject:[NSNumber numberWithInt:kRemoteButtonMinus] forKey:@"11_18_98_10_"];
44 [_cookieToButtonMapping setObject:[NSNumber numberWithInt:kRemoteButtonMenu] forKey:@"11_18_58_10_"];
45 [_cookieToButtonMapping setObject:[NSNumber numberWithInt:kRemoteButtonPlay] forKey:@"11_18_61_10_"];
46 [_cookieToButtonMapping setObject:[NSNumber numberWithInt:kRemoteButtonRight] forKey:@"11_18_96_10_"];
47 [_cookieToButtonMapping setObject:[NSNumber numberWithInt:kRemoteButtonLeft] forKey:@"11_18_97_10_"];
48 /* hold events are not being sent by this device
49 [_cookieToButtonMapping setObject:[NSNumber numberWithInt:kRemoteButtonRight_Hold] forKey:@"14_6_4_2_"];
50 [_cookieToButtonMapping setObject:[NSNumber numberWithInt:kRemoteButtonLeft_Hold] forKey:@"14_6_3_2_"];
51 [_cookieToButtonMapping setObject:[NSNumber numberWithInt:kRemoteButtonMenu_Hold] forKey:@"14_6_14_6_"];
52 [_cookieToButtonMapping setObject:[NSNumber numberWithInt:kRemoteButtonPlay_Sleep] forKey:@"18_14_6_18_14_6_"];
53 [_cookieToButtonMapping setObject:[NSNumber numberWithInt:kRemoteControl_Switched] forKey:@"19_"];
54 */
55}
56
57+ (io_object_t) findRemoteDevice {
58 CFMutableDictionaryRef hidMatchDictionary = NULL;
59 IOReturn ioReturnValue = kIOReturnSuccess;
60 io_iterator_t hidObjectIterator = 0;
61 io_object_t hidDevice = 0;
62 SInt32 idVendor = 1741;
63 SInt32 idProduct = 0x420;
64
65 // Set up a matching dictionary to search the I/O Registry by class
66 // name for all HID class devices
67 hidMatchDictionary = IOServiceMatching(kIOHIDDeviceKey);
68
69 CFNumberRef numberRefVendor = CFNumberCreate(kCFAllocatorDefault, kCFNumberSInt32Type, &idVendor);
70 if ( numberRefVendor )
71 {
72 CFDictionaryAddValue(hidMatchDictionary, CFSTR(kIOHIDVendorIDKey), numberRefVendor);
73 CFRelease(numberRefVendor);
74 }
75
76 CFNumberRef numberRefProduct = CFNumberCreate(kCFAllocatorDefault, kCFNumberSInt32Type, &idProduct);
77 if ( numberRefProduct )
78 {
79 CFDictionaryAddValue(hidMatchDictionary, CFSTR(kIOHIDProductIDKey), numberRefProduct);
80 CFRelease(numberRefProduct);
81 }
82
83 // Now search I/O Registry for matching devices.
84 SAL_WNODEPRECATED_DECLARATIONS_PUSH // kIOMasterPortDefault (12.0)
85 ioReturnValue = IOServiceGetMatchingServices(kIOMasterPortDefault, hidMatchDictionary, &hidObjectIterator);
87
88 if ((ioReturnValue == kIOReturnSuccess) && (hidObjectIterator != 0)) {
89 hidDevice = IOIteratorNext(hidObjectIterator);
90 }
91
92 // release the iterator
93 if ( hidObjectIterator )
94 IOObjectRelease(hidObjectIterator);
95
96 return hidDevice;
97
98}
99
100@end
101
102/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
return NULL
#define SAL_WNODEPRECATED_DECLARATIONS_POP
#define SAL_WNODEPRECATED_DECLARATIONS_PUSH