/* * ----------------------------------------------------------------------------- * "THE BEER-WARE LICENSE" (Revision 42): * wrote this file. As long as you retain this notice you can * do whatever you want with this stuff. If we meet some day, and you think this * stuff is worth it, you can buy me a beer in return. Jakob Stoklund Olesen * ----------------------------------------------------------------------------- */ #import // A YAMessageQueue allows asynchronous communication between threads without // the archiving done by distributed objects. Each YAMessageQueue instance // delivers mesages on one thread, determined by the deliverInCurrentThread // message. @interface YAMessageQueue : NSObject { NSLock *lock; NSMutableArray *queue; CFRunLoopRef runLoop; CFRunLoopSourceRef runLoopSource; } // Return the default message queue for the current thread. + (YAMessageQueue*)defaultQueue; // Create queue ready for receiving messages, but not delivering any yet. - (id)init; // Register queue with the current run loop so all messages are delivered in // the current thread. Only call once. The queue will be set as the default // for the thread if there is not already one. - (void)deliverInCurrentThread; // Create an autoreleased proxy for target that delivers messages // asynchronously. The proxy is thread safe - it can be used from multiple // threads. - (id)proxyForTarget:(id)target; @end // These are the proxies returned by proxyForTarget: @interface YAMessageQueueingProxy : NSProxy { id target; YAMessageQueue *queue; Protocol *protocol; } // It is OK to create proxies with this initializer, but it is easier to use // -[YAMessageQueue proxyForTarget:] // The target and queue are both retained by the proxy. - (id)initWithTarget:target queue:(YAMessageQueue*)queue; // If a protocol is set, the target will not be touched in the calling thread. // (Except retain/release). If no protocol is set, // -[methodSignatureForSelector:] will be sent to the target in the calling // thread. // This method is not thread safe. - (void)setProtocolForProxy:(Protocol *)aProtocol; // Set a new target - it will be retained // This method is not thread safe. - (void)setTargetForProxy:(id)target; @end