contrib/rpc_examples: Add (dis)connect methods
Add these methods such that the OpenOcd class can also be used outside of a 'with' statement. Change-Id: I927c93fff2dc05cc74daa56360a7262e736a639f Signed-off-by: Marc Schink <openocd-dev@marcschink.de> Reviewed-on: http://openocd.zylin.com/5189 Tested-by: jenkins Reviewed-by: Antonio Borneo <borneo.antonio@gmail.com> Reviewed-by: Tomas Vanek <vanekt@fbl.cz>
This commit is contained in:
parent
6568d29cc1
commit
223c28f9b9
|
@ -49,10 +49,16 @@ class OpenOcd:
|
||||||
self.sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
|
self.sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
|
||||||
|
|
||||||
def __enter__(self):
|
def __enter__(self):
|
||||||
self.sock.connect((self.tclRpcIp, self.tclRpcPort))
|
self.connect()
|
||||||
return self
|
return self
|
||||||
|
|
||||||
def __exit__(self, type, value, traceback):
|
def __exit__(self, type, value, traceback):
|
||||||
|
self.disconnect()
|
||||||
|
|
||||||
|
def connect(self):
|
||||||
|
self.sock.connect((self.tclRpcIp, self.tclRpcPort))
|
||||||
|
|
||||||
|
def disconnect(self):
|
||||||
try:
|
try:
|
||||||
self.send("exit")
|
self.send("exit")
|
||||||
finally:
|
finally:
|
||||||
|
|
Loading…
Reference in New Issue