Branch libreoffice-5-0-4
[LibreOffice.git] / apple_remote / source / KeyspanFrontRowControl.m
blobc637aa9cf9c7dac994ed90176936adecb2319720
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  *****************************************************************************/
32 #import "KeyspanFrontRowControl.h"
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>
39 @implementation KeyspanFrontRowControl
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 send 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         */
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;
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);
69         CFNumberRef numberRefVendor = CFNumberCreate(kCFAllocatorDefault, kCFNumberSInt32Type, &idVendor);
70     if ( numberRefVendor )
71     {
72         CFDictionaryAddValue(hidMatchDictionary, CFSTR(kIOHIDVendorIDKey), numberRefVendor);
73         CFRelease(numberRefVendor);
74         }
76     CFNumberRef numberRefProduct = CFNumberCreate(kCFAllocatorDefault, kCFNumberSInt32Type, &idProduct);
77     if ( numberRefProduct )
78     {
79         CFDictionaryAddValue(hidMatchDictionary, CFSTR(kIOHIDProductIDKey), numberRefProduct);
80         CFRelease(numberRefProduct);
81         }
83         // Now search I/O Registry for matching devices.
84         ioReturnValue = IOServiceGetMatchingServices(kIOMasterPortDefault, hidMatchDictionary, &hidObjectIterator);
86         if ((ioReturnValue == kIOReturnSuccess) && (hidObjectIterator != 0)) {
87                 hidDevice = IOIteratorNext(hidObjectIterator);
88         }
90         // release the iterator
91     if ( hidObjectIterator )
92         IOObjectRelease(hidObjectIterator);
94         return hidDevice;
98 @end
100 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */