From f588641f09d5e3b774a3597ebbe80b92879dd655 Mon Sep 17 00:00:00 2001 From: jwijenbergh Date: Tue, 29 Mar 2022 15:55:45 +0200 Subject: State: Add a deregister method for cleanup --- exports/exports.go | 6 ++++++ src/state.go | 8 ++++++++ wrappers/python/eduvpncommon/__init__.py | 1 + wrappers/python/eduvpncommon/main.py | 5 +++++ 4 files changed, 20 insertions(+) diff --git a/exports/exports.go b/exports/exports.go index 4e998bf..5a4d7b9 100644 --- a/exports/exports.go +++ b/exports/exports.go @@ -39,6 +39,12 @@ func Register(name *C.char, config_directory *C.char, stateCallback C.PythonCB) return C.CString(ErrorToString(registerErr)) } +//export Deregister +func Deregister() { + state := eduvpn.GetVPNState() + state.Deregister() +} + func ErrorToString(error error) string { if error == nil { return "" diff --git a/src/state.go b/src/state.go index c146e61..a48d13d 100644 --- a/src/state.go +++ b/src/state.go @@ -36,6 +36,14 @@ func (state *VPNState) Register(name string, directory string, stateCallback fun return nil } +func (state *VPNState) Deregister() { + // Close the log file + state.CloseLog() + + // Re-initialize everything + state = &VPNState{} +} + func (state *VPNState) Connect(url string) (string, error) { if state.Server == nil { state.Server = &Server{} diff --git a/wrappers/python/eduvpncommon/__init__.py b/wrappers/python/eduvpncommon/__init__.py index faa311d..4c1872f 100644 --- a/wrappers/python/eduvpncommon/__init__.py +++ b/wrappers/python/eduvpncommon/__init__.py @@ -34,6 +34,7 @@ VPNStateChange = CFUNCTYPE(None, c_char_p, c_char_p, c_char_p) # Exposed functions lib.Connect.argtypes, lib.Connect.restype = [c_char_p], DataError +lib.Deregister.argtypes, lib.Deregister.restype = [], None lib.Register.argtypes, lib.Register.restype = [c_char_p, c_char_p, VPNStateChange], None lib.GetOrganizationsList.argtypes, lib.GetOrganizationsList.restype = [], DataError lib.GetServersList.argtypes, lib.GetServersList.restype = [], DataError diff --git a/wrappers/python/eduvpncommon/main.py b/wrappers/python/eduvpncommon/main.py index 9e1f25e..16d7baa 100644 --- a/wrappers/python/eduvpncommon/main.py +++ b/wrappers/python/eduvpncommon/main.py @@ -19,6 +19,8 @@ def Register(name, config_directory, state_callback): err_string = GetPtrString(ptr_err) return err_string +def Deregister(): + return lib.Deregister() def GetDiscoServers(): servers, serversErr = GetDataError(lib.GetServersList()) @@ -52,6 +54,9 @@ class EduVPN(object): self.config_directory = config_directory register_callback(self) + def __del__(self): + Deregister() + def register(self) -> bool: return Register(self.name, self.config_directory, callback_function) == "" -- cgit v1.2.3