1 """
2 Vtrace notitifers base classes and examples
3
4 Vtrace supports the idea of callback notifiers which
5 get called whenever particular events occur in the target
6 process. Notifiers may be registered to recieve a callback
7 on any of the vtrace.NOTIFY_FOO events from vtrace. One notifier
8 *may* be registered with more than one trace, as the "notify"
9 method is passed a reference to the trace for which an event
10 has occured...
11
12 """
13
14
15 import vtrace
16 import traceback
17
19 """
20 The top level example notifier... Anything which registers
21 itself for trace events or tracegroup events should implement
22 the notify method as shown here.
23 """
24
26 """
27 All extenders *must* call this. Mostly because all the
28 goop necissary for the remote debugging stuff...
29 (if notifier is instantiated on server, all is well, if it's
30 on the client it needs a proxy...)
31 """
32 pass
33
35 """
36 An "internal" handler so if we need to do something
37 from an API perspective before calling the notify method
38 we can have a good "all at once" hook
39 """
40 self.notify(event, trace)
41
42 - def notify(self, event, trace):
43 print "Got event: %d from pid %d" % (event, trace.getPid())
44
46 - def notify(self, event, trace):
81
83 """
84 A notifier which will distributed notifications out to
85 locally registered notifiers so that remote tracer's notifier
86 callbacks only require once across the wire.
87 """
88
96
98 host,nothing = cobra.getCobraSocket(trace).getLocalName()
99
100 - def notify(self, event, trace):
102
104 """
105 Fire all our registerd local-notifiers
106 """
107 nlist = self.notifiers.get(vtrace.NOTIFY_ALL, [])
108 for notifier in nlist:
109 try:
110 notifier.handleEvent(event, trace)
111 except:
112 print "ERROR - Exception in notifier:",traceback.format_exc()
113
114 nlist = self.notifiers.get(event, [])
115 for notifier in nlist:
116 try:
117 notifier.handleEvent(event, trace)
118 except:
119 print "ERROR - Exception in notifier:",traceback.format_exc()
120
122 """
123 Register a sub-notifier to get the remote callback's via
124 our local delivery.
125 """
126 nlist = self.notifiers.get(event)
127 nlist.append(notif)
128
130 nlist = self.notifiers.get(event)
131 nlist.remove(notif)
132