EMMulticastDelegate.h 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. #import <Foundation/Foundation.h>
  2. @class EMMulticastDelegateEnumerator;
  3. /**
  4. * This class provides multicast delegate functionality. That is:
  5. * - it provides a means for managing a list of delegates
  6. * - any method invocations to an instance of this class are automatically forwarded to all delegates
  7. *
  8. * For example:
  9. *
  10. * // Make this method call on every added delegate (there may be several)
  11. * [multicastDelegate cog:self didFindThing:thing];
  12. *
  13. * This allows multiple delegates to be added to an xmpp stream or any xmpp module,
  14. * which in turn makes development easier as there can be proper separation of logically different code sections.
  15. *
  16. * In addition, this makes module development easier,
  17. * as multiple delegates can usually be handled in a manner similar to the traditional single delegate paradigm.
  18. *
  19. * This class also provides proper support for GCD queues.
  20. * So each delegate specifies which queue they would like their delegate invocations to be dispatched onto.
  21. *
  22. * All delegate dispatching is done asynchronously (which is a critically important architectural design).
  23. **/
  24. @interface EMMulticastDelegate : NSObject
  25. - (void)addDelegate:(id)delegate delegateQueue:(dispatch_queue_t)delegateQueue;
  26. - (void)removeDelegate:(id)delegate delegateQueue:(dispatch_queue_t)delegateQueue;
  27. - (void)removeDelegate:(id)delegate;
  28. - (void)removeAllDelegates;
  29. - (NSUInteger)count;
  30. - (NSUInteger)countOfClass:(Class)aClass;
  31. - (NSUInteger)countForSelector:(SEL)aSelector;
  32. - (BOOL)hasDelegateThatRespondsToSelector:(SEL)aSelector;
  33. - (EMMulticastDelegateEnumerator *)delegateEnumerator;
  34. @end
  35. @interface EMMulticastDelegateEnumerator : NSObject
  36. - (NSUInteger)count;
  37. - (NSUInteger)countOfClass:(Class)aClass;
  38. - (NSUInteger)countForSelector:(SEL)aSelector;
  39. - (BOOL)getNextDelegate:(id *)delPtr delegateQueue:(dispatch_queue_t *)dqPtr;
  40. - (BOOL)getNextDelegate:(id *)delPtr delegateQueue:(dispatch_queue_t *)dqPtr ofClass:(Class)aClass;
  41. - (BOOL)getNextDelegate:(id *)delPtr delegateQueue:(dispatch_queue_t *)dqPtr forSelector:(SEL)aSelector;
  42. @end