Commit 104ac66f authored by David Fuhrmann's avatar David Fuhrmann

macosx: Move p_intf_thread getter out of VLCMain

VLCIntf now points to a static getter for the interface thread
pointer.

This fixes several problems: During initialization of
VLCMain, [VLCMain sharedInstance] is not ready yet when all other
objects are initialized inside VLCMains constructor. Due to the
way ARC works, the same applies to dealloc (the main shared instance
is nil already). But in both situations, we need VLCIntf for
callback (un)registration and potential logging.

The mac interface relies on static data in any case and does not
support multiple instantiations.
parent 3d3878d3
...@@ -156,7 +156,7 @@ static int InputEvent(vlc_object_t *p_this, const char *psz_var, ...@@ -156,7 +156,7 @@ static int InputEvent(vlc_object_t *p_this, const char *psz_var,
self = [super init]; self = [super init];
if(self) { if(self) {
o_main = o_mainObj; o_main = o_mainObj;
var_AddCallback(pl_Get([o_mainObj intf]), "input-current", InputThreadChanged, (__bridge void *)self); var_AddCallback(pl_Get(VLCIntf), "input-current", InputThreadChanged, (__bridge void *)self);
informInputChangedQueue = dispatch_queue_create("org.videolan.vlc.inputChangedQueue", DISPATCH_QUEUE_SERIAL); informInputChangedQueue = dispatch_queue_create("org.videolan.vlc.inputChangedQueue", DISPATCH_QUEUE_SERIAL);
......
...@@ -46,7 +46,11 @@ ...@@ -46,7 +46,11 @@
/***************************************************************************** /*****************************************************************************
* Local prototypes. * Local prototypes.
*****************************************************************************/ *****************************************************************************/
#define VLCIntf [[VLCMain sharedInstance] intf]
// deprecated macro
#define VLCIntf getIntf()
intf_thread_t *getIntf();
static NSString * VLCInputChangedNotification = @"VLCInputChangedNotification"; static NSString * VLCInputChangedNotification = @"VLCInputChangedNotification";
...@@ -76,14 +80,9 @@ static NSString * VLCInputChangedNotification = @"VLCInputChangedNotification"; ...@@ -76,14 +80,9 @@ static NSString * VLCInputChangedNotification = @"VLCInputChangedNotification";
@property (readonly) BOOL nativeFullscreenMode; @property (readonly) BOOL nativeFullscreenMode;
@property (nonatomic, readwrite) BOOL playlistUpdatedSelectorInQueue; @property (nonatomic, readwrite) BOOL playlistUpdatedSelectorInQueue;
+ (VLCMain *)createInstanceWithIntf:(intf_thread_t *)intf;
+ (VLCMain *)sharedInstance; + (VLCMain *)sharedInstance;
+ (void)killInstance; + (void)killInstance;
- (id)initWithIntf:(intf_thread_t *)intf;
- (intf_thread_t *)intf;
- (VLCMainMenu *)mainMenu; - (VLCMainMenu *)mainMenu;
- (VLCMainWindow *)mainWindow; - (VLCMainWindow *)mainWindow;
- (VLCBookmarks *)bookmarks; - (VLCBookmarks *)bookmarks;
......
...@@ -77,14 +77,23 @@ ...@@ -77,14 +77,23 @@
/***************************************************************************** /*****************************************************************************
* OpenIntf: initialize interface * OpenIntf: initialize interface
*****************************************************************************/ *****************************************************************************/
static intf_thread_t *p_interface_thread;
intf_thread_t *getIntf()
{
return p_interface_thread;
}
int OpenIntf (vlc_object_t *p_this) int OpenIntf (vlc_object_t *p_this)
{ {
@autoreleasepool { @autoreleasepool {
intf_thread_t *p_intf = (intf_thread_t*) p_this; intf_thread_t *p_intf = (intf_thread_t*) p_this;
p_interface_thread = p_intf;
msg_Dbg(p_intf, "Starting macosx interface"); msg_Dbg(p_intf, "Starting macosx interface");
[VLCApplication sharedApplication]; [VLCApplication sharedApplication];
[VLCMain createInstanceWithIntf: p_intf]; [VLCMain sharedInstance];
[NSBundle loadNibNamed:@"MainMenu" owner:[[VLCMain sharedInstance] mainMenu]]; [NSBundle loadNibNamed:@"MainMenu" owner:[[VLCMain sharedInstance] mainMenu]];
[[[VLCMain sharedInstance] mainWindow] makeKeyAndOrderFront:nil]; [[[VLCMain sharedInstance] mainWindow] makeKeyAndOrderFront:nil];
...@@ -99,6 +108,8 @@ void CloseIntf (vlc_object_t *p_this) ...@@ -99,6 +108,8 @@ void CloseIntf (vlc_object_t *p_this)
msg_Dbg(p_this, "Closing macosx interface"); msg_Dbg(p_this, "Closing macosx interface");
[[VLCMain sharedInstance] applicationWillTerminate:nil]; [[VLCMain sharedInstance] applicationWillTerminate:nil];
[VLCMain killInstance]; [VLCMain killInstance];
p_interface_thread = nil;
} }
} }
...@@ -179,17 +190,11 @@ static int ShowController(vlc_object_t *p_this, const char *psz_variable, ...@@ -179,17 +190,11 @@ static int ShowController(vlc_object_t *p_this, const char *psz_variable,
static VLCMain *sharedInstance = nil; static VLCMain *sharedInstance = nil;
+ (VLCMain *)sharedInstance + (VLCMain *)sharedInstance;
{
return sharedInstance;
}
+ (VLCMain *)createInstanceWithIntf:(intf_thread_t *)intf;
{ {
static dispatch_once_t pred; static dispatch_once_t pred;
dispatch_once(&pred, ^{ dispatch_once(&pred, ^{
sharedInstance = [[VLCMain alloc] initWithIntf:intf]; sharedInstance = [[VLCMain alloc] init];
}); });
return sharedInstance; return sharedInstance;
...@@ -200,11 +205,11 @@ static VLCMain *sharedInstance = nil; ...@@ -200,11 +205,11 @@ static VLCMain *sharedInstance = nil;
sharedInstance = nil; sharedInstance = nil;
} }
- (id)initWithIntf:(intf_thread_t *)intf; - (id)init
{ {
self = [super init]; self = [super init];
if (self) { if (self) {
p_intf = intf; p_intf = getIntf();
[VLCApplication sharedApplication].delegate = self; [VLCApplication sharedApplication].delegate = self;
...@@ -251,9 +256,9 @@ static VLCMain *sharedInstance = nil; ...@@ -251,9 +256,9 @@ static VLCMain *sharedInstance = nil;
return self; return self;
} }
- (intf_thread_t *)intf - (void)dealloc
{ {
return p_intf; msg_Dbg(VLCIntf, "Deinitializing VLCMain object");
} }
- (void)applicationWillFinishLaunching:(NSNotification *)aNotification - (void)applicationWillFinishLaunching:(NSNotification *)aNotification
...@@ -360,9 +365,6 @@ static VLCMain *sharedInstance = nil; ...@@ -360,9 +365,6 @@ static VLCMain *sharedInstance = nil;
_voutController = nil; _voutController = nil;
[_voutController.lock unlock]; [_voutController.lock unlock];
/* unsubscribe from libvlc's debug messages */
vlc_LogSet(p_intf->p_libvlc, NULL, NULL);
/* write cached user defaults to disk */ /* write cached user defaults to disk */
[[NSUserDefaults standardUserDefaults] synchronize]; [[NSUserDefaults standardUserDefaults] synchronize];
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment