VLCExtensionsManager.m 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  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. #import "VLCExtensionsManager.h"
  9. #import "VLCExtension.h"
  10. #import "VLCLibrary.h"
  11. #import "VLCLibVLCBridging.h"
  12. #import <vlc_extensions.h>
  13. #define _instance ((extensions_manager_t *)instance)
  14. static int DialogCallback( vlc_object_t *p_this, const char *psz_variable,
  15. vlc_value_t old_val, vlc_value_t new_val,
  16. void *param )
  17. {
  18. VLCExtensionsManager *self = param;
  19. assert(self);
  20. assert(new_val.p_address);
  21. extension_dialog_t *dialog = new_val.p_address;
  22. NSLog(@"dialog callback");
  23. return VLC_SUCCESS;
  24. }
  25. @implementation VLCExtensionsManager
  26. static VLCExtensionsManager *sharedManager = nil;
  27. + (VLCExtensionsManager *)sharedManager
  28. {
  29. if (!sharedManager)
  30. {
  31. /* Initialize a shared instance */
  32. sharedManager = [[self alloc] init];
  33. }
  34. return sharedManager;
  35. }
  36. - (void)dealloc
  37. {
  38. vlc_object_t *libvlc = libvlc_get_vlc_instance([VLCLibrary sharedInstance]);
  39. var_DelCallback(libvlc, "dialog-extension", DialogCallback, NULL);
  40. vlc_object_release(libvlc);
  41. module_unneed(_instance, _instance->p_module);
  42. vlc_object_release(_instance);
  43. [super dealloc];
  44. }
  45. - (NSArray *)extensions
  46. {
  47. if (!instance)
  48. {
  49. vlc_object_t *libvlc = libvlc_get_vlc_instance([VLCLibrary sharedInstance]);
  50. instance = vlc_object_create(libvlc, sizeof(extensions_manager_t));
  51. if (!_instance)
  52. {
  53. vlc_object_release(libvlc);
  54. return nil;
  55. }
  56. vlc_object_attach(_instance, libvlc);
  57. _instance->p_module = module_need(_instance, "extension", NULL, false);
  58. NSAssert(_instance->p_module, @"Unable to load extensions module");
  59. var_Create(libvlc, "dialog-extension", VLC_VAR_ADDRESS);
  60. var_AddCallback(libvlc, "dialog-extension", DialogCallback, self);
  61. vlc_object_release(libvlc);
  62. }
  63. NSMutableArray *array = [NSMutableArray array];
  64. extension_t *ext;
  65. FOREACH_ARRAY(ext, _instance->extensions)
  66. VLCExtension *extension = [[VLCExtension alloc] initWithInstance:ext];
  67. [array addObject:extension];
  68. [extension release];
  69. FOREACH_END()
  70. return array;
  71. }
  72. - (void)runExtension:(VLCExtension *)extension
  73. {
  74. extension_t *ext = [extension instance];
  75. NSLog(@"extension_TriggerOnly = %d", extension_TriggerOnly(_instance, ext));
  76. NSLog(@"extension_IsActivated = %d", extension_IsActivated(_instance, ext));
  77. if(extension_TriggerOnly(_instance, ext))
  78. extension_Trigger(_instance, ext);
  79. else
  80. {
  81. if(!extension_IsActivated(_instance, ext))
  82. extension_Activate(_instance, ext);
  83. }
  84. }
  85. @end