diff options
| -rw-r--r-- | exports/exports.go | 22 | ||||
| -rw-r--r-- | state.go | 18 | ||||
| -rw-r--r-- | wrappers/python/src/__init__.py | 2 | ||||
| -rw-r--r-- | wrappers/python/src/main.py | 17 |
4 files changed, 59 insertions, 0 deletions
diff --git a/exports/exports.go b/exports/exports.go index 576e980..434bfbd 100644 --- a/exports/exports.go +++ b/exports/exports.go @@ -141,6 +141,28 @@ func SetProfileID(name *C.char, data *C.char) *C.char { return C.CString(ErrorToString(profileErr)) } +//export SetDisconnected +func SetDisconnected(name *C.char) *C.char { + nameStr := C.GoString(name) + state, stateErr := GetVPNState(nameStr) + if stateErr != nil { + return C.CString(ErrorToString(stateErr)) + } + setDisconnectedErr := state.SetDisconnected() + return C.CString(ErrorToString(setDisconnectedErr)) +} + +//export SetConnected +func SetConnected(name *C.char) *C.char { + nameStr := C.GoString(name) + state, stateErr := GetVPNState(nameStr) + if stateErr != nil { + return C.CString(ErrorToString(stateErr)) + } + setConnectedErr := state.SetConnected() + return C.CString(ErrorToString(setConnectedErr)) +} + //export FreeString func FreeString(addr *C.char) { C.free(unsafe.Pointer(addr)) @@ -180,6 +180,24 @@ func (state *VPNState) SetProfileID(profileID string) error { return nil } +func (state *VPNState) SetConnected() error { + if !state.FSM.HasTransition(internal.CONNECTED) { + return &internal.FSMWrongStateTransitionError{Got: state.FSM.Current, Want: internal.CONNECTED} + } + + state.FSM.GoTransition(internal.CONNECTED) + return nil +} + +func (state *VPNState) SetDisconnected() error { + if !state.FSM.HasTransition(internal.HAS_CONFIG) { + return &internal.FSMWrongStateTransitionError{Got: state.FSM.Current, Want: internal.HAS_CONFIG} + } + + state.FSM.GoTransition(internal.HAS_CONFIG) + return nil +} + type StateSetProfileError struct { ProfileID string Err error diff --git a/wrappers/python/src/__init__.py b/wrappers/python/src/__init__.py index 1df305b..e417371 100644 --- a/wrappers/python/src/__init__.py +++ b/wrappers/python/src/__init__.py @@ -42,6 +42,8 @@ lib.CancelOAuth.argtypes, lib.CancelOAuth.restype = [c_char_p], c_void_p lib.SetProfileID.argtypes, lib.SetProfileID.restype = [c_char_p, c_char_p], c_void_p # We have to use c_void_p instead of c_char_p to free it properly # See https://stackoverflow.com/questions/13445568/python-ctypes-how-to-free-memory-getting-invalid-pointer-error +lib.SetConnected.argtypes, lib.SetConnected.restype = [c_char_p], c_void_p +lib.SetDisconnected.argtypes, lib.SetDisconnected.restype = [c_char_p], c_void_p lib.FreeString.argtypes, lib.FreeString.restype = [c_void_p], None diff --git a/wrappers/python/src/main.py b/wrappers/python/src/main.py index 5474ade..9c2fb41 100644 --- a/wrappers/python/src/main.py +++ b/wrappers/python/src/main.py @@ -43,6 +43,18 @@ def Connect(name, url): data_error = lib.Connect(name_bytes, url_bytes) return GetDataError(data_error) +def SetConnected(name): + name_bytes = name.encode("utf-8") + ptr_err = lib.SetConnected(name_bytes) + err_string = GetPtrString(ptr_err) + return err_string + +def SetDisconnected(name): + name_bytes = name.encode("utf-8") + ptr_err = lib.SetDisconnected(name_bytes) + err_string = GetPtrString(ptr_err) + return err_string + # This has to be global as otherwise the callback is not alive callback_function = None @@ -85,6 +97,11 @@ class EduVPN(object): def connect(self, url): return Connect(self.name, url) + def set_disconnected(self): + return SetDisconnected(self.name) + + def set_connected(self): + return SetConnected(self.name) @property def event(self): |
