Vuo  2.3.2
VuoSyphonServerNotifier.m
Go to the documentation of this file.
1 
10 #import "VuoApp.h"
11 #import "VuoSyphon.h"
13 
14 #include "VuoMacOSSDKWorkaround.h"
15 #import <Syphon.h>
16 
17 #import <objc/message.h>
18 
19 #ifdef VUO_COMPILER
21  "title" : "VuoSyphonServerNotifier",
22  "dependencies" : [
23  "VuoSyphon",
24  "Syphon.framework",
25  "objc",
26  "AppKit.framework"
27  ]
28  });
29 #endif
30 
31 
35 @interface VuoSyphonServerNotifierInternal : NSObject
36 {
40 }
41 
42 - (id)init;
43 - (void)setNotificationFunction:(void (*)(VuoList_VuoSyphonServerDescription))serversChangedCallback;
44 - (void)setNotificationObject:(id)object method:(SEL)method;
45 - (void)start;
46 - (void)stop;
47 
48 @end
49 
50 
51 @implementation VuoSyphonServerNotifierInternal
52 
56 - (id)init
57 {
58  if (self = [super init])
59  {
62  serversChangedMethod = NULL;
63  }
64  return self;
65 }
66 
70 - (void)setNotificationFunction:(void (*)(VuoList_VuoSyphonServerDescription))_serversChangedCallback
71 {
72  serversChangedCallback = _serversChangedCallback;
73 
74  [serversChangedObject release];
76  serversChangedMethod = NULL;
77 }
78 
82 - (void)setNotificationObject:(id)object method:(SEL)method
83 {
84  serversChangedObject = [object retain];
85  serversChangedMethod = method;
86 
88 }
89 
93 - (void)serversChanged
94 {
96 
98  serversChangedCallback(descriptions);
99  else if (serversChangedMethod)
100  ((void (*)(id, SEL, const void *))objc_msgSend)(serversChangedObject, serversChangedMethod, descriptions);
101 }
102 
106 -(void) syphonServerAnnounced:(NSNotification *)notif
107 {
108  [self serversChanged];
109 }
110 
114 -(void) syphonServerUpdated:(NSNotification *)notif
115 {
116  [self serversChanged];
117 }
118 
122 -(void) syphonServerRetired:(NSNotification *)notif
123 {
124  [self serversChanged];
125 }
126 
130 - (void)start
131 {
132  VuoApp_init(false);
133 
134  [[NSNotificationCenter defaultCenter] addObserver:self
135  selector:@selector(syphonServerAnnounced:)
136  name:SyphonServerAnnounceNotification
137  object:nil];
138 
139  [[NSNotificationCenter defaultCenter] addObserver:self
140  selector:@selector(syphonServerUpdated:)
141  name:SyphonServerUpdateNotification
142  object:nil];
143 
144  [[NSNotificationCenter defaultCenter] addObserver:self
145  selector:@selector(syphonServerRetired:)
146  name:SyphonServerRetireNotification
147  object:nil];
148 }
149 
153 - (void)stop
154 {
155  [[NSNotificationCenter defaultCenter] removeObserver:self name:SyphonServerAnnounceNotification object:nil];
156  [[NSNotificationCenter defaultCenter] removeObserver:self name:SyphonServerUpdateNotification object:nil];
157  [[NSNotificationCenter defaultCenter] removeObserver:self name:SyphonServerRetireNotification object:nil];
158 }
159 
163 - (void)dealloc
164 {
165  [serversChangedObject release];
166  [super dealloc];
167 }
168 
169 @end
170 
171 
176 {
178 }
179 
184 {
185  VuoSyphonServerNotifierInternal *serverNotifier = [[VuoSyphonServerNotifierInternal alloc] init];
186  VuoRegister(serverNotifier, VuoSyphonServerNotifier_free);
187  return serverNotifier;
188 }
189 
195 {
196  [(VuoSyphonServerNotifierInternal *)serverNotifier setNotificationFunction:serversChanged];
197 }
198 
203  id object, SEL method)
204 {
205  [(VuoSyphonServerNotifierInternal *)serverNotifier setNotificationObject:object method:method];
206 }
207 
212 {
214 }
215 
220 {
222 }