]> git.sesse.net Git - vlc/blob - modules/gui/minimal_macosx/intf.m
Removed useless vlc_thread_set_priority() calls in macosx code.
[vlc] / modules / gui / minimal_macosx / intf.m
1 /*****************************************************************************
2  * intf.m: MacOS X interface module
3  *****************************************************************************
4  * Copyright (C) 2002-2007 the VideoLAN team
5  * $Id$
6  *
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>
11  *
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.
16  *
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.
21  *
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  *****************************************************************************/
26
27 /*****************************************************************************
28  * Preamble
29  *****************************************************************************/
30 #include <stdlib.h>                                      /* malloc(), free() */
31 #include <sys/param.h>                                    /* for MAXPATHLEN */
32 #include <string.h>
33 #ifdef HAVE_CONFIG_H
34 # include "config.h"
35 #endif
36
37 #include <vlc_common.h>
38
39 #include <vlc_keys.h>
40
41 #include <vlc_input.h>
42 #import <vlc_interface.h>
43
44 #import <intf.h>
45
46 /*****************************************************************************
47  * Local prototypes.
48  *****************************************************************************/
49 static void Run ( intf_thread_t *p_intf );
50
51 /*****************************************************************************
52  * OpenIntf: initialize interface
53  *****************************************************************************/
54 int OpenIntf ( vlc_object_t *p_this )
55 {
56     intf_thread_t *p_intf = (intf_thread_t*) p_this;
57
58     p_intf->p_sys = malloc( sizeof( intf_sys_t ) );
59     if( p_intf->p_sys == NULL )
60     {
61         return VLC_ENOMEM;
62     }
63
64     memset( p_intf->p_sys, 0, sizeof( *p_intf->p_sys ) );
65
66     p_intf->pf_run = Run;
67     p_intf->b_should_run_on_first_thread = true;
68
69     return VLC_SUCCESS;
70 }
71
72 /*****************************************************************************
73  * CloseIntf: destroy interface
74  *****************************************************************************/
75 void CloseIntf ( vlc_object_t *p_this )
76 {
77     intf_thread_t *p_intf = (intf_thread_t*) p_this;
78
79     free( p_intf->p_sys );
80 }
81
82 /* Dock Connection */
83 typedef struct CPSProcessSerNum
84 {
85         UInt32                lo;
86         UInt32                hi;
87 } CPSProcessSerNum;
88
89 extern OSErr    CPSGetCurrentProcess( CPSProcessSerNum *psn);
90 extern OSErr    CPSEnableForegroundOperation( CPSProcessSerNum *psn, UInt32 _arg2, UInt32 _arg3, UInt32 _arg4, UInt32 _arg5);
91 extern OSErr    CPSSetFrontProcess( CPSProcessSerNum *psn);
92
93 /*****************************************************************************
94  * KillerThread: Thread that kill the application
95  *****************************************************************************/
96 static void * KillerThread( void *user_data )
97 {
98     NSAutoreleasePool * o_pool = [[NSAutoreleasePool alloc] init];
99
100     intf_thread_t *p_intf = user_data;
101
102     vlc_mutex_init( &p_intf->p_sys->lock );
103     vlc_cond_init( &p_intf->p_sys->wait );
104
105     vlc_mutex_lock ( &p_intf->p_sys->lock );
106     while( vlc_object_alive( p_intf ) )
107         vlc_cond_wait( &p_intf->p_sys->wait, &p_intf->p_sys->lock );
108     vlc_mutex_unlock( &p_intf->p_sys->lock );
109
110     vlc_mutex_destroy( &p_intf->p_sys->lock );
111     vlc_cond_destroy( &p_intf->p_sys->wait );
112
113     msg_Dbg( p_intf, "Killing the Minimal Mac OS X module" );
114
115     /* We are dead, terminate */
116     [NSApp terminate: nil];
117     [o_pool release];
118     return NULL;
119 }
120
121 /*****************************************************************************
122  * Run: main loop
123  *****************************************************************************/
124 static void Run( intf_thread_t *p_intf )
125 {
126     sigset_t set;
127
128     /* Make sure the "force quit" menu item does quit instantly.
129      * VLC overrides SIGTERM which is sent by the "force quit"
130      * menu item to make sure deamon mode quits gracefully, so
131      * we un-override SIGTERM here. */
132     sigemptyset( &set );
133     sigaddset( &set, SIGTERM );
134     pthread_sigmask( SIG_UNBLOCK, &set, NULL );
135
136     /* Setup a thread that will monitor the module killing */
137     pthread_t killer_thread;
138     pthread_create( &killer_thread, NULL, KillerThread, p_intf );
139
140     CPSProcessSerNum PSN;
141     NSAutoreleasePool   *pool = [[NSAutoreleasePool alloc] init];
142     [NSApplication sharedApplication];
143     if (!CPSGetCurrentProcess(&PSN))
144         if (!CPSEnableForegroundOperation(&PSN,0x03,0x3C,0x2C,0x1103))
145             if (!CPSSetFrontProcess(&PSN))
146                 [NSApplication sharedApplication];
147     [NSApp run];
148
149     pthread_join( killer_thread, NULL );
150
151     [pool release];
152 }
153