1 /*****************************************************************************
2 * intf.m: MacOS X interface module
3 *****************************************************************************
4 * Copyright (C) 2002-2007 the VideoLAN team
7 * Authors: Jon Lech Johansen <jon-vl@nanocrew.net>
8 * Christophe Massiot <massiot@via.ecp.fr>
9 * Derk-Jan Hartman <hartman at videolan.org>
10 * Felix Kühne <fkuehne at videolan dot org>
12 * This program is free software; you can redistribute it and/or modify
13 * it under the terms of the GNU General Public License as published by
14 * the Free Software Foundation; either version 2 of the License, or
15 * (at your option) any later version.
17 * This program is distributed in the hope that it will be useful,
18 * but WITHOUT ANY WARRANTY; without even the implied warranty of
19 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 * GNU General Public License for more details.
22 * You should have received a copy of the GNU General Public License
23 * along with this program; if not, write to the Free Software
24 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
25 *****************************************************************************/
27 /*****************************************************************************
29 *****************************************************************************/
30 #include <stdlib.h> /* malloc(), free() */
31 #include <sys/param.h> /* for MAXPATHLEN */
37 #include <vlc_common.h>
41 #include <vlc_input.h>
45 /*****************************************************************************
47 *****************************************************************************/
48 static void Run ( intf_thread_t *p_intf );
50 /*****************************************************************************
51 * OpenIntf: initialize interface
52 *****************************************************************************/
53 int OpenIntf ( vlc_object_t *p_this )
55 intf_thread_t *p_intf = (intf_thread_t*) p_this;
57 p_intf->p_sys = malloc( sizeof( intf_sys_t ) );
58 if( p_intf->p_sys == NULL )
63 memset( p_intf->p_sys, 0, sizeof( *p_intf->p_sys ) );
66 p_intf->b_should_run_on_first_thread = true;
71 /*****************************************************************************
72 * CloseIntf: destroy interface
73 *****************************************************************************/
74 void CloseIntf ( vlc_object_t *p_this )
76 intf_thread_t *p_intf = (intf_thread_t*) p_this;
78 free( p_intf->p_sys );
82 typedef struct CPSProcessSerNum
88 extern OSErr CPSGetCurrentProcess( CPSProcessSerNum *psn);
89 extern OSErr CPSEnableForegroundOperation( CPSProcessSerNum *psn, UInt32 _arg2, UInt32 _arg3, UInt32 _arg4, UInt32 _arg5);
90 extern OSErr CPSSetFrontProcess( CPSProcessSerNum *psn);
92 /*****************************************************************************
93 * KillerThread: Thread that kill the application
94 *****************************************************************************/
95 static void * KillerThread( void *user_data )
97 NSAutoreleasePool * o_pool = [[NSAutoreleasePool alloc] init];
99 intf_thread_t *p_intf = user_data;
101 vlc_object_lock ( p_intf );
102 while( vlc_object_alive( p_intf ) )
103 vlc_object_wait( p_intf );
104 vlc_object_unlock( p_intf );
106 msg_Dbg( p_intf, "Killing the Mac OS X module" );
108 /* We are dead, terminate */
109 [NSApp terminate: nil];
114 /*****************************************************************************
116 *****************************************************************************/
117 static void Run( intf_thread_t *p_intf )
121 /* Do it again - for some unknown reason, vlc_thread_create() often
122 * fails to go to real-time priority with the first launched thread
124 vlc_thread_set_priority( p_intf, VLC_THREAD_PRIORITY_LOW );
126 /* Make sure the "force quit" menu item does quit instantly.
127 * VLC overrides SIGTERM which is sent by the "force quit"
128 * menu item to make sure deamon mode quits gracefully, so
129 * we un-override SIGTERM here. */
131 sigaddset( &set, SIGTERM );
132 pthread_sigmask( SIG_UNBLOCK, &set, NULL );
134 /* Setup a thread that will monitor the module killing */
135 pthread_t killer_thread;
136 pthread_create( &killer_thread, NULL, KillerThread, p_intf );
138 CPSProcessSerNum PSN;
139 NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
140 [NSApplication sharedApplication];
141 if (!CPSGetCurrentProcess(&PSN))
142 if (!CPSEnableForegroundOperation(&PSN,0x03,0x3C,0x2C,0x1103))
143 if (!CPSSetFrontProcess(&PSN))
144 [NSApplication sharedApplication];
147 pthread_join( killer_thread, NULL );