cmake build system: visiblity support for clang
[supercollider.git] / Help / Control / NotificationCenter.html
blob3bdb1f8fe0d325218b45245630503d1648be4964
1 <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
2 <html>
3 <head>
4 <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
5 <meta http-equiv="Content-Style-Type" content="text/css">
6 <title></title>
7 <meta name="Generator" content="Cocoa HTML Writer">
8 <meta name="CocoaVersion" content="824.47">
9 <style type="text/css">
10 p.p1 {margin: 0.0px 0.0px 0.0px 0.0px; font: 18.0px Helvetica}
11 p.p2 {margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px Helvetica; min-height: 14.0px}
12 p.p3 {margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px Helvetica}
13 p.p4 {margin: 0.0px 0.0px 0.0px 0.0px; font: 9.0px Monaco; color: #001fb3}
14 p.p5 {margin: 0.0px 0.0px 0.0px 0.0px; font: 9.0px Monaco}
15 p.p6 {margin: 0.0px 0.0px 0.0px 0.0px; font: 9.0px Monaco; min-height: 12.0px}
16 p.p7 {margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px Helvetica; color: #000000; min-height: 14.0px}
17 p.p8 {margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px Helvetica; color: #000000}
18 span.s1 {color: #000000}
19 span.s2 {color: #42691d}
20 span.Apple-tab-span {white-space:pre}
21 </style>
22 </head>
23 <body>
24 <p class="p1"><b>NotificationCenter</b></p>
25 <p class="p2"><br></p>
26 <p class="p3">One common OOP pattern is Model-View-Controller where one object (the controller) is a dependant of the model.<span class="Apple-converted-space">  </span>Every time the model changes it notifies all of its dependants.<span class="Apple-converted-space">  </span>In this case the model has a dictionary of dependants and iterates through those.</p>
27 <p class="p2"><br></p>
28 <p class="p3">Another common pattern is NotificationCenter wherein an object emits a notification and clients can register functions that will be executed when that notification happens.</p>
29 <p class="p2"><br></p>
30 <p class="p3">A Server emits a \newAllocators notification when it creates new node and bus allocators which it does when it quits or boots.</p>
31 <p class="p2"><br></p>
32 <p class="p4"><span class="s1"><span class="Apple-tab-span"> </span></span>NotificationCenter<span class="s1">.notify(</span>Server.default<span class="s1">,</span><span class="s2">\newAllocators</span><span class="s1">);</span></p>
33 <p class="p2"><br></p>
34 <p class="p3">You can listen for this:</p>
35 <p class="p2"><br></p>
36 <p class="p4"><span class="s1"><span class="Apple-tab-span"> </span></span>NotificationCenter<span class="s1">.register(</span>Server.default<span class="s1">,</span><span class="s2">\newAllocators</span><span class="s1">,</span><span class="s2">yourself</span><span class="s1">, {</span></p>
37 <p class="p5"><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span>// throw away all your node variables</p>
38 <p class="p5"><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span>// or stop the music</p>
39 <p class="p5"><span class="Apple-tab-span"> </span>});</p>
40 <p class="p6"><br></p>
41 <p class="p3">The Buffer class register a function to clear its info cache whenever a server restarts.<span class="Apple-converted-space">  </span>The server is emiting changed messages quite often (every 0.4 secs for the status updates), and the Buffer class is only interested in boot/quit events, so this is a more lightweight system for this purpose.</p>
42 <p class="p6"><br></p>
43 <p class="p7"><br></p>
44 <p class="p8"><b>*notify(object,message,args)</b></p>
45 <p class="p8"><span class="Apple-tab-span"> </span>The object emits a message and may also pass extra args</p>
46 <p class="p7"><span class="Apple-tab-span"> </span></p>
47 <p class="p8"><b>*register(object,message,listener,action)</b></p>
48 <p class="p8"><span class="Apple-tab-span"> </span>An interested client can register the action function for the object/message notification.</p>
49 <p class="p8"><span class="Apple-tab-span"> </span>A listener may only register one action per object/message notification.</p>
50 <p class="p7"><span class="Apple-tab-span"> </span></p>
51 <p class="p8"><b>*unregister(object,message,listener)</b></p>
52 <p class="p8"><span class="Apple-tab-span"> </span>Remove the registrations</p>
53 <p class="p7"><br></p>
54 <p class="p8"><b>*registerOneShot(object,message,listener,action)</b></p>
55 <p class="p8"><span class="Apple-tab-span"> </span>After the notification has been emited and handled, automatically unregister.</p>
56 <p class="p7"><span class="Apple-tab-span"> </span></p>
57 <p class="p8"><b>*registrationExists(object,message,listener)</b></p>
58 <p class="p8"><span class="Apple-tab-span"> </span>Simply confirms if a registration is already in place</p>
59 <p class="p6"><br></p>
60 <p class="p6"><span class="Apple-tab-span"> </span></p>
61 </body>
62 </html>