1 /*****************************************************************************
\r
2 * eyetv.m: small class to control the notification parts of the EyeTV plugin
\r
3 *****************************************************************************
\r
4 * Copyright (C) 2006-2007 the VideoLAN team
\r
7 * Authors: Felix Kühne <fkuehne at videolan dot org>
\r
9 * This program is free software; you can redistribute it and/or modify
\r
10 * it under the terms of the GNU General Public License as published by
\r
11 * the Free Software Foundation; either version 2 of the License, or
\r
12 * (at your option) any later version.
\r
14 * This program is distributed in the hope that it will be useful,
\r
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
\r
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
\r
17 * GNU General Public License for more details.
\r
19 * You should have received a copy of the GNU General Public License
\r
20 * along with this program; if not, write to the Free Software
\r
21 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
\r
22 *****************************************************************************/
\r
25 /* for apple event interaction [carbon] */
\r
26 #import <ApplicationServices/ApplicationServices.h>
\r
27 /* for various VLC core related calls */
30 @implementation VLCEyeTVController
\r
32 static VLCEyeTVController *_o_sharedInstance = nil;
\r
34 + (VLCEyeTVController *)sharedInstance
\r
36 return _o_sharedInstance ? _o_sharedInstance : [[self alloc] init];
\r
41 if (_o_sharedInstance) {
\r
44 _o_sharedInstance = [super init];
\r
46 [[NSDistributedNotificationCenter defaultCenter]
48 selector: @selector(globalNotificationReceived:)
\r
50 object: @"VLCEyeTVSupport"
\r
51 suspensionBehavior: NSNotificationSuspensionBehaviorDeliverImmediately];
\r
54 return _o_sharedInstance;
\r
57 - (void)globalNotificationReceived: (NSNotification *)theNotification
\r
59 msg_Dbg( VLCIntf, "notification received in VLC with name %s and object %s",
60 [[theNotification name] UTF8String], [[theNotification object] UTF8String] );
\r
62 /* update our info on the used device */
\r
63 if( [[theNotification name] isEqualToString: @"DeviceAdded"] )
\r
64 b_deviceConnected = YES;
\r
65 if( [[theNotification name] isEqualToString: @"DeviceRemoved"] )
\r
66 b_deviceConnected = NO;
\r
68 /* is eyetv running? */
\r
69 if( [[theNotification name] isEqualToString: @"PluginInit"] )
\r
70 b_eyeTVactive = YES;
\r
71 if( [[theNotification name] isEqualToString: @"PluginQuit"] )
\r
75 - (BOOL)isEyeTVrunning
\r
77 return b_eyeTVactive;
\r
80 - (BOOL)isDeviceConnected
\r
82 return b_deviceConnected;
\r
91 stat = LSFindApplicationForInfo ( 'EyTV',
\r
92 CFSTR("com.elgato.eyetv"),
\r
97 msg_Err( VLCIntf, "finding EyeTV failed with error code %i", (int)stat );
\r
99 stat = LSOpenFSRef( &eyetvPath, NULL );
\r
100 if( stat != noErr )
\r
101 msg_Err( VLCIntf, "opening EyeTV failed with error code %i", (int)stat );
\r
105 - (void)switchChannelUp:(BOOL)b_yesOrNo
\r
108 AppleEvent ourAE = {typeNull, nil};
\r
109 AEBuildError theBuildError;
\r
110 const OSType eyetvSignature = 'EyTV'; /* carbon FOURCC style */
\r
111 OSType eyetvCommand;
\r
113 if( b_yesOrNo == YES )
\r
115 eyetvCommand = 'Chup'; /* same style */
\r
116 msg_Dbg( VLCIntf, "telling eyetv to switch 1 channel up" );
\r
120 eyetvCommand = 'Chdn'; /* same style again */
\r
121 msg_Dbg( VLCIntf, "telling eyetv to switch 1 channel down" );
\r
124 err = AEBuildAppleEvent(
\r
125 /* EyeTV script suite */ eyetvSignature,
\r
126 /* command */ eyetvCommand,
\r
127 /* signature type */ typeApplSignature,
\r
128 /* signature */ &eyetvSignature,
\r
129 /* signature size */ sizeof(eyetvSignature),
\r
130 /* basic return id */ kAutoGenerateReturnID,
\r
131 /* generic transaction id */ kAnyTransactionID,
\r
132 /* to-be-created AE */ &ourAE,
\r
133 /* get some possible errors */ &theBuildError,
\r
134 /* got no params for now */ "" );
\r
135 if( err != aeBuildSyntaxNoErr )
\r
137 msg_Err( VLCIntf, "Error %i encountered while trying to the build the AE to launch eyetv.\n" \
\r
138 "additionally, the following info was returned: AEBuildErrorCode:%i at pos:%i",
\r
139 (int)err, theBuildError.fError, theBuildError.fErrorPos);
\r
143 msg_Dbg( VLCIntf, "AE created successfully, trying to send now" );
\r
145 err = AESendMessage(
\r
146 /* our AE */ &ourAE,
\r
147 /* no need for a response-AE */ NULL,
\r
148 /* we neither want a response nor user interaction */ kAENoReply | kAENeverInteract,
\r
149 /* we don't need a special time-out */ kAEDefaultTimeout );
\r
151 msg_Err( VLCIntf, "Error %i encountered while trying to tell EyeTV to switch channel", (int)err );
\r
153 err = AEDisposeDesc(&ourAE);
\r
156 - (void)selectChannel: (int)theChannelNum
\r
160 - (int)getNumberOfChannels
\r
165 - (NSString *)getNameOfChannel: (int)theChannelNum
\r
167 return @"dummy name";
\r