]> git.sesse.net Git - vlc/blob - projects/macosx/framework/Sources/VLCExtensionsManager.m
2cae205d6135f5085fb84f4e57afee59b12ba8ae
[vlc] / projects / macosx / framework / Sources / VLCExtensionsManager.m
1 //
2 //  VLCExtensionsManager.m
3 //  VLCKit
4 //
5 //  Created by Pierre d'Herbemont on 1/26/10.
6 //  Copyright 2010 __MyCompanyName__. All rights reserved.
7 //
8
9 #import "VLCExtensionsManager.h"
10 #import "VLCExtension.h"
11 #import "VLCLibrary.h"
12 #import "VLCLibVLCBridging.h"
13 #import <vlc_extensions.h>
14
15 #define _instance ((extensions_manager_t *)instance)
16
17 static int DialogCallback( vlc_object_t *p_this, const char *psz_variable,
18                           vlc_value_t old_val, vlc_value_t new_val,
19                           void *param )
20 {
21
22     VLCExtensionsManager *self = param;
23     assert(self);
24     assert(new_val.p_address);
25
26     extension_dialog_t *dialog = new_val.p_address;
27
28     NSLog(@"dialog callback");
29     return VLC_SUCCESS;
30 }
31
32 @implementation VLCExtensionsManager
33 static VLCExtensionsManager *sharedManager = nil;
34
35 + (VLCExtensionsManager *)sharedManager
36 {
37     if (!sharedManager)
38     {
39         /* Initialize a shared instance */
40         sharedManager = [[self alloc] init];
41     }
42     return sharedManager;
43 }
44
45 - (void)dealloc
46 {
47     vlc_object_t *libvlc = libvlc_get_vlc_instance([VLCLibrary sharedInstance]);
48     var_DelCallback(libvlc, "dialog-extension", DialogCallback, NULL);
49     vlc_object_release(libvlc);
50
51     module_unneed(_instance, _instance->p_module);
52     vlc_object_release(_instance);
53
54     [super dealloc];
55 }
56
57 - (NSArray *)extensions
58 {
59     if (!instance)
60     {
61         vlc_object_t *libvlc = libvlc_get_vlc_instance([VLCLibrary sharedInstance]);
62         instance = vlc_object_create(libvlc, sizeof(extensions_manager_t));
63         if (!_instance)
64         {
65             vlc_object_release(libvlc);
66             return nil;
67         }
68         vlc_object_attach(_instance, libvlc);
69
70         _instance->p_module = module_need(_instance, "extension", NULL, false);
71         NSAssert(_instance->p_module, @"Unable to load extensions module");
72
73         var_Create(libvlc, "dialog-extension", VLC_VAR_ADDRESS);
74         var_AddCallback(libvlc, "dialog-extension", DialogCallback, self);
75         vlc_object_release(libvlc);
76     }
77
78     NSMutableArray *array = [NSMutableArray array];
79     extension_t *ext;
80     FOREACH_ARRAY(ext, _instance->extensions)
81         VLCExtension *extension = [[VLCExtension alloc] initWithInstance:ext];
82         [array addObject:extension];
83         [extension release];
84     FOREACH_END()
85     return array;
86 }
87
88 - (void)runExtension:(VLCExtension *)extension
89 {
90     extension_t *ext = [extension instance];
91     NSLog(@"extension_TriggerOnly = %d", extension_TriggerOnly(_instance, ext));
92     NSLog(@"extension_IsActivated = %d", extension_IsActivated(_instance, ext));
93
94     if(extension_TriggerOnly(_instance, ext))
95         extension_Trigger(_instance, ext);
96     else
97     {
98         if(!extension_IsActivated(_instance, ext))
99             extension_Activate(_instance, ext);
100     }
101 }
102 @end