1 /*****************************************************************************
2 * VLCEventManager.h: VLCKit.framework VLCEventManager header
3 *****************************************************************************
4 * Copyright (C) 2007 Pierre d'Herbemont
5 * Copyright (C) 2007 the VideoLAN team
8 * Authors: Pierre d'Herbemont <pdherbemont # videolan.org>
10 * This program is free software; you can redistribute it and/or modify
11 * it under the terms of the GNU General Public License as published by
12 * the Free Software Foundation; either version 2 of the License, or
13 * (at your option) any later version.
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 General Public License for more details.
20 * You should have received a copy of the GNU General Public License
21 * along with this program; if not, write to the Free Software
22 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
23 *****************************************************************************/
28 * The VLCEventManager class provides a safe way for inter-thread communications.
30 @interface VLCEventManager : NSObject
32 NSMutableArray *messageQueue; //< Holds a queue of messages.
33 NSMutableArray *pendingMessagesOnMainThread; //< Holds the message that are being posted on main thread.
34 NSLock *pendingMessagesLock;
35 pthread_t dispatcherThread; //< Thread responsible for dispatching messages.
36 pthread_mutex_t queueLock; //< Queue lock.
37 pthread_cond_t signalData; //< Data lock.
42 * Returns the shared VLCEventManager. There should only be one instance of this class.
43 * \return Shared event manager.
49 * Sends a message to the target's delegate on the main thread.
50 * \discussion The main thread is the one in which the main run loop is run, which usually
51 * means the one in which the NSApplication object receives events. The method is performed
52 * when the main thread runs the run loop in one of the common run loop modes (as specified
53 * in the CFRunLoop documentation).
55 * The receiver is retained until the call is finished.
56 * \param aTarget The target object who's delegate should receive the specified message.
57 * \param aSelector A selector that identifies the method to invoke. The method should not
58 * have a significant return value and should take a single argument of type NSNotification,
61 * See “Selectors” for a description of the SEL type.
62 * \param aNotificiationName The name of the notification that should be sent to the
63 * distributed notification center.
65 - (void)callOnMainThreadDelegateOfObject:(id)aTarget
66 withDelegateMethod:(SEL)aSelector
67 withNotificationName:(NSString *)aNotificationName;
70 * Sends a message to the target on the main thread.
71 * \discussion The main thread is the one in which the main run loop is run, which usually
72 * means the one in which the NSApplication object receives events. The method is performed
73 * when the main thread runs the run loop in one of the common run loop modes (as specified
74 * in the CFRunLoop documentation).
76 * The receiver and arg are retained until the call is finished.
77 * \param aTarget The target object who should receive the specified message.
78 * \param aSelector A selector that identifies the method to invoke. The method should not
79 * have a significant return value and should take a single argument of type id,
82 * See “Selectors” for a description of the SEL type.
83 * \param arg The argument to pass in the message. Pass nil if the method does not take an
85 * distributed notification center.
87 - (void)callOnMainThreadObject:(id)aTarget
88 withMethod:(SEL)aSelector
89 withArgumentAsObject:(id)arg;
91 - (void)cancelCallToObject:(id)target;