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 md5 
  6  import os 
  7  import socket 
  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 = md5.md5(os.urandom(20)).hexdigest() 31 vtrace.cobra_daemon.shareObject(trace, unique) 32 trace.proxy = cobra.CobraProxy("cobra://%s:%d/%s" % (host,port,unique)) 33 return unique
34
35 - def releaseTrace(self, proxy):
36 """ 37 When a remote system is done with a trace 38 and wants the server to clean him up, hand 39 the proxy object to this. 40 """ 41 t = vtrace.cobra_daemon.unshareObject(proxy.__dict__.get("__cobra_name", None)) 42 if t != None: 43 t.release()
44
45 -class RemoteTrace(cobra.CobraProxy):
46
47 - def __init__(self, *args, **kwargs):
48 cobra.CobraProxy.__init__(self, *args, **kwargs) 49 self.__dict__['_remote_released'] = False
50
51 - def isRemote(self):
52 return True
53
54 - def buildNewTrace(self):
55 return getRemoteTrace()
56
57 - def release(self):
58 self.__dict__['_remote_released'] = True 59 getTracerFactory().releaseTrace(self)
60
61 - def __del__(self):
62 if not self.__dict__['_remote_released']: 63 print 'RemoteTrace del w/o release()!'
64
65 -def getCallbackProxy(trace, notifier):
66 """ 67 Get a proxy object to reference *notifier* from the 68 perspective of *trace*. The trace is specified so 69 we may check on our side of the connected socket to 70 give him the best possible ip address... 71 """ 72 global callback_daemon 73 port = getCallbackPort() 74 host, nothing = trace._cobra_getsock().getSockName() 75 unique = callback_daemon.getSharedName(notifier) 76 if unique == None: 77 unique = md5.md5(os.urandom(20)).hexdigest() 78 callback_daemon.shareObject(notifier, unique) 79 return cobra.CobraProxy("cobra://%s:%d/%s" % (host, port, unique))
80
81 -def getCallbackPort():
82 """ 83 If necissary, start a callback daemon. Return the 84 ephemeral port it was bound on. 85 """ 86 global callback_daemon 87 if callback_daemon == None: 88 callback_daemon = cobra.CobraDaemon(port=0) 89 callback_daemon.fireThread() 90 return callback_daemon.port
91
92 -def startCobraDaemon():
93 if vtrace.cobra_daemon == None: 94 vtrace.cobra_daemon = cobra.CobraDaemon(port=vtrace.port) 95 vtrace.cobra_daemon.fireThread()
96
97 -def getRemoteTrace():
98 factory = getTracerFactory() 99 unique = factory.getTrace() 100 return RemoteTrace("cobra://%s:%d/%s" % (vtrace.remote, vtrace.port, unique))
101
102 -def releaseRemoteTrace(proxy):
103 getTracerFactory().releaseTrace(proxy)
104
105 -def startVtraceServer():
106 """ 107 Fire up the pyro server and share out our 108 "trace factory" 109 """ 110 startCobraDaemon() 111 factory = TraceProxyFactory() 112 vtrace.cobra_daemon.shareObject(factory, "TracerFactory") 113 return vtrace.cobra_daemon
114