VLCEventManager.h 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  1. /*****************************************************************************
  2. * VLCEventManager.h: VLCKit.framework VLCEventManager header
  3. *****************************************************************************
  4. * Copyright (C) 2007 Pierre d'Herbemont
  5. * Copyright (C) 2007 VLC authors and VideoLAN
  6. * $Id$
  7. *
  8. * Authors: Pierre d'Herbemont <pdherbemont # videolan.org>
  9. *
  10. * This program is free software; you can redistribute it and/or modify it
  11. * under the terms of the GNU Lesser General Public License as published by
  12. * the Free Software Foundation; either version 2.1 of the License, or
  13. * (at your option) any later version.
  14. *
  15. * This program is distributed in the hope that it will be useful,
  16. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  17. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  18. * GNU Lesser General Public License for more details.
  19. *
  20. * You should have received a copy of the GNU Lesser General Public License
  21. * along with this program; if not, write to the Free Software Foundation,
  22. * Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
  23. *****************************************************************************/
  24. #import <pthread.h>
  25. /**
  26. * The VLCEventManager class provides a safe way for inter-thread communications.
  27. */
  28. @interface VLCEventManager : NSObject
  29. {
  30. NSMutableArray *messageQueue; //< Holds a queue of messages.
  31. NSMutableArray *pendingMessagesOnMainThread; //< Holds the message that are being posted on main thread.
  32. NSLock *pendingMessagesLock;
  33. pthread_t dispatcherThread; //< Thread responsible for dispatching messages.
  34. pthread_mutex_t queueLock; //< Queue lock.
  35. pthread_cond_t signalData; //< Data lock.
  36. }
  37. /* Factories */
  38. /**
  39. * Returns the shared VLCEventManager. There should only be one instance of this class.
  40. * \return Shared event manager.
  41. */
  42. + (id)sharedManager;
  43. /* Operations */
  44. /**
  45. * Sends a message to the target's delegate on the main thread.
  46. * \discussion The main thread is the one in which the main run loop is run, which usually
  47. * means the one in which the NSApplication object receives events. The method is performed
  48. * when the main thread runs the run loop in one of the common run loop modes (as specified
  49. * in the CFRunLoop documentation).
  50. *
  51. * The receiver is retained until the call is finished.
  52. * \param aTarget The target object who's delegate should receive the specified message.
  53. * \param aSelector A selector that identifies the method to invoke. The method should not
  54. * have a significant return value and should take a single argument of type NSNotification,
  55. * or no arguments.
  56. *
  57. * See “Selectors” for a description of the SEL type.
  58. * \param aNotificiationName The name of the notification that should be sent to the
  59. * distributed notification center.
  60. */
  61. - (void)callOnMainThreadDelegateOfObject:(id)aTarget
  62. withDelegateMethod:(SEL)aSelector
  63. withNotificationName:(NSString *)aNotificationName;
  64. /**
  65. * Sends a message to the target on the main thread.
  66. * \discussion The main thread is the one in which the main run loop is run, which usually
  67. * means the one in which the NSApplication object receives events. The method is performed
  68. * when the main thread runs the run loop in one of the common run loop modes (as specified
  69. * in the CFRunLoop documentation).
  70. *
  71. * The receiver and arg are retained until the call is finished.
  72. * \param aTarget The target object who should receive the specified message.
  73. * \param aSelector A selector that identifies the method to invoke. The method should not
  74. * have a significant return value and should take a single argument of type id,
  75. * or no arguments.
  76. *
  77. * See “Selectors” for a description of the SEL type.
  78. * \param arg The argument to pass in the message. Pass nil if the method does not take an
  79. * argument.
  80. * distributed notification center.
  81. */
  82. - (void)callOnMainThreadObject:(id)aTarget
  83. withMethod:(SEL)aSelector
  84. withArgumentAsObject:(id)arg;
  85. - (void)cancelCallToObject:(id)target;
  86. @end