Package vtrace :: Module rmi
[hide private]
[frames] | no frames]

Source Code for Module vtrace.rmi

  1  """ 
  2  Cobra integration for remote debugging 
  3  """ 
  4  # Copyright (C) 2007 Invisigoth - See LICENSE file for details 
  5  import os 
  6  import socket 
  7  import hashlib 
  8   
  9  import vtrace 
 10  import cobra 
 11   
 12  callback_daemon = None 
 13   
14 -def getTracerFactory():
15 """ 16 Return a TracerFactory proxy object from the remote server 17 """ 18 return cobra.CobraProxy("cobra://%s:%d/TracerFactory" % (vtrace.remote, vtrace.port))
19
20 -class TraceProxyFactory:
21 """ 22 A "factory" object for creating tracers and 23 wrapping them up in a proxy instance to the 24 *local* server. This object is shared out 25 via the pyro server for vtrace clients. 26 """
27 - def getTrace(self):
28 trace = vtrace.getTrace() 29 host,port = cobra.getLocalInfo() 30 unique = vtrace.cobra_daemon.shareObject(trace) 31 trace.proxy = cobra.CobraProxy("cobra://%s:%d/%s" % (host,port,unique)) 32 return unique
33
34 - def releaseTrace(self, proxy):
35 """ 36 When a remote system is done with a trace 37 and wants the server to clean him up, hand 38 the proxy object to this. 39 """ 40 t = vtrace.cobra_daemon.unshareObject(proxy.__dict__.get("__cobra_name", None)) 41 if t != None: 42 t.release()
43
44 -class RemoteTrace(cobra.CobraProxy):
45
46 - def __init__(self, *args, **kwargs):
47 cobra.CobraProxy.__init__(self, *args, **kwargs) 48 self.__dict__['_remote_released'] = False
49
50 - def isRemote(self):
51 return True
52
53 - def buildNewTrace(self):
54 return getRemoteTrace()
55
56 - def release(self):
57 self.__dict__['_remote_released'] = True 58 getTracerFactory().releaseTrace(self)
59
60 - def __del__(self):
61 if not self.__dict__['_remote_released']: 62 print 'RemoteTrace del w/o release()!'
63
64 -def getCallbackProxy(trace, notifier):
65 """ 66 Get a proxy object to reference *notifier* from the 67 perspective of *trace*. The trace is specified so 68 we may check on our side of the connected socket to 69 give him the best possible ip address... 70 """ 71 global callback_daemon 72 port = getCallbackPort() 73 host, nothing = trace._cobra_getsock().getSockName() 74 unique = callback_daemon.getSharedName(notifier) 75 if unique == None: 76 unique = callback_daemon.shareObject(notifier) 77 return cobra.CobraProxy("cobra://%s:%d/%s" % (host, port, unique))
78
79 -def getCallbackPort():
80 """ 81 If necissary, start a callback daemon. Return the 82 ephemeral port it was bound on. 83 """ 84 global callback_daemon 85 if callback_daemon == None: 86 callback_daemon = cobra.CobraDaemon(port=0) 87 callback_daemon.fireThread() 88 return callback_daemon.port
89
90 -def startCobraDaemon():
91 if vtrace.cobra_daemon == None: 92 vtrace.cobra_daemon = cobra.CobraDaemon(port=vtrace.port) 93 vtrace.cobra_daemon.fireThread()
94
95 -def getRemoteTrace():
96 factory = getTracerFactory() 97 unique = factory.getTrace() 98 return RemoteTrace("cobra://%s:%d/%s" % (vtrace.remote, vtrace.port, unique))
99
100 -def releaseRemoteTrace(proxy):
101 getTracerFactory().releaseTrace(proxy)
102
103 -def startVtraceServer():
104 """ 105 Fire up the pyro server and share out our 106 "trace factory" 107 """ 108 startCobraDaemon() 109 factory = TraceProxyFactory() 110 vtrace.cobra_daemon.shareObject(factory, "TracerFactory") 111 return vtrace.cobra_daemon
112