Vuo  2.1.1
VuoSyphonServerNotifier.m
Go to the documentation of this file.
1 
10 #import "VuoApp.h"
11 #import "VuoSyphon.h"
13 
14 #ifndef NS_RETURNS_INNER_POINTER
15 #define NS_RETURNS_INNER_POINTER
16 #endif
17 #import <Syphon.h>
18 
19 #import <objc/message.h>
20 
21 #ifdef VUO_COMPILER
23  "title" : "VuoSyphonServerNotifier",
24  "dependencies" : [
25  "VuoSyphon",
26  "Syphon.framework",
27  "objc",
28  "AppKit.framework"
29  ]
30  });
31 #endif
32 
33 
37 @interface VuoSyphonServerNotifierInternal : NSObject
38 {
42 }
43 
44 - (id)init;
45 - (void)setNotificationFunction:(void (*)(VuoList_VuoSyphonServerDescription))serversChangedCallback;
46 - (void)setNotificationObject:(id)object method:(SEL)method;
47 - (void)start;
48 - (void)stop;
49 
50 @end
51 
52 
53 @implementation VuoSyphonServerNotifierInternal
54 
58 - (id)init
59 {
60  if (self = [super init])
61  {
64  serversChangedMethod = NULL;
65  }
66  return self;
67 }
68 
72 - (void)setNotificationFunction:(void (*)(VuoList_VuoSyphonServerDescription))_serversChangedCallback
73 {
74  serversChangedCallback = _serversChangedCallback;
75 
76  [serversChangedObject release];
78  serversChangedMethod = NULL;
79 }
80 
84 - (void)setNotificationObject:(id)object method:(SEL)method
85 {
86  serversChangedObject = [object retain];
87  serversChangedMethod = method;
88 
90 }
91 
95 - (void)serversChanged
96 {
98 
100  serversChangedCallback(descriptions);
101  else if (serversChangedMethod)
102  objc_msgSend(serversChangedObject, serversChangedMethod, descriptions);
103 }
104 
108 -(void) syphonServerAnnounced:(NSNotification *)notif
109 {
110  [self serversChanged];
111 }
112 
116 -(void) syphonServerUpdated:(NSNotification *)notif
117 {
118  [self serversChanged];
119 }
120 
124 -(void) syphonServerRetired:(NSNotification *)notif
125 {
126  [self serversChanged];
127 }
128 
132 - (void)start
133 {
134  VuoApp_init(false);
135 
136  [[NSNotificationCenter defaultCenter] addObserver:self
137  selector:@selector(syphonServerAnnounced:)
138  name:SyphonServerAnnounceNotification
139  object:nil];
140 
141  [[NSNotificationCenter defaultCenter] addObserver:self
142  selector:@selector(syphonServerUpdated:)
143  name:SyphonServerUpdateNotification
144  object:nil];
145 
146  [[NSNotificationCenter defaultCenter] addObserver:self
147  selector:@selector(syphonServerRetired:)
148  name:SyphonServerRetireNotification
149  object:nil];
150 }
151 
155 - (void)stop
156 {
157  [[NSNotificationCenter defaultCenter] removeObserver:self name:SyphonServerAnnounceNotification object:nil];
158  [[NSNotificationCenter defaultCenter] removeObserver:self name:SyphonServerUpdateNotification object:nil];
159  [[NSNotificationCenter defaultCenter] removeObserver:self name:SyphonServerRetireNotification object:nil];
160 }
161 
165 - (void)dealloc
166 {
167  [serversChangedObject release];
168  [super dealloc];
169 }
170 
171 @end
172 
173 
178 {
180 }
181 
186 {
187  VuoSyphonServerNotifierInternal *serverNotifier = [[VuoSyphonServerNotifierInternal alloc] init];
188  VuoRegister(serverNotifier, VuoSyphonServerNotifier_free);
189  return serverNotifier;
190 }
191 
197 {
198  [(VuoSyphonServerNotifierInternal *)serverNotifier setNotificationFunction:serversChanged];
199 }
200 
205  id object, SEL method)
206 {
207  [(VuoSyphonServerNotifierInternal *)serverNotifier setNotificationObject:object method:method];
208 }
209 
214 {
216 }
217 
222 {
224 }