def filterAndSwitch(self, path, windowid, default, wait):
# Given a path to an addon, and/or a window ID, determine if it's associated with a particular VPN and
# switch to that VPN. Return True when the switch has happened or False if there's a problem switching
# (or there's no VPN that's been set up). If the connected VPN is the VPN that's been identifed as being
# required, or no filter is found, just return True without messing with the connection. The default
# parameter is a boolean indicating if the default VPN should be connected to if no filter is found.
# The wait parameter will determine if the function returns once the connection has been made, or if it's
# fire and forget (in which case True will be returned regardless).
if not self.isVPNSetUp():
return False
connection = self.isFiltered(path, windowid)
# Switch to the default connection if there's no filter
if connection == -1 and default :
xbmc.log(msg="VPN Mgr API : Reconnecting to the default", level=xbmc.LOGDEBUG)
return self.defaultVPN(wait)
if connection == 0:
if self.getConnected() == "": return True
xbmc.log(msg="VPN Mgr API : Disconnecting due to filter " + path + " or window ID " + str(windowid), level=xbmc.LOGDEBUG)
self.setAPICommand("Disconnect")
if wait: return self.waitForConnection("")
if connection > 0:
connection = connection - 1
if self.primary_vpns[connection] == "": return False
if self.getConnected() == self.primary_vpns[connection]: return True
xbmc.log(msg="VPN Mgr API : Connecting to " + self.primary_vpns[connection] + " due to filter " + path + " or window ID " + str(windowid), level=xbmc.LOGDEBUG)
self.setAPICommand(self.primary_vpns[connection])
if wait: return self.waitForConnection(self.primary_vpns[connection])
return True
评论列表
文章目录