Fixed windows getIdle

This commit is contained in:
Adolfo Gómez García 2019-12-04 14:59:46 +01:00
parent 3ed5d26245
commit 6402106d85
6 changed files with 17 additions and 15 deletions

View File

@ -186,7 +186,6 @@ class UDSServerApi(UDSApi):
return types.InitializationResultType(
own_token=r['own_token'],
unique_id=r['unique_id'].lower() if r['unique_id'] else None,
max_idle=r['max_idle'],
os=types.ActorOsConfigurationType(
action=os['action'],
name=os['name'],
@ -234,7 +233,12 @@ class UDSServerApi(UDSApi):
'username': username
}
result = self._doPost('login', payload)
return types.LoginResultInfoType(ip=result['ip'], hostname=result['hostname'], dead_line=result['dead_line'])
return types.LoginResultInfoType(
ip=result['ip'],
hostname=result['hostname'],
dead_line=result['dead_line'],
max_idle=result['max_idle']
)
def logout(self, own_token: str, username: str) -> None:
payload = {

View File

@ -232,7 +232,6 @@ class CommonService: # pylint: disable=too-many-instance-attributes
own_token=initResult.own_token,
config=types.ActorDataConfigurationType(
unique_id=initResult.unique_id,
max_idle=initResult.max_idle,
os=initResult.os
)
)

View File

@ -27,7 +27,6 @@ class ActorOsConfigurationType(typing.NamedTuple):
class ActorDataConfigurationType(typing.NamedTuple):
unique_id: typing.Optional[str] = None
max_idle: typing.Optional[int] = None
os: typing.Optional[ActorOsConfigurationType] = None
class ActorConfigurationType(typing.NamedTuple):
@ -51,14 +50,13 @@ class ActorConfigurationType(typing.NamedTuple):
class InitializationResultType(typing.NamedTuple):
own_token: typing.Optional[str] = None
unique_id: typing.Optional[str] = None
max_idle: typing.Optional[int] = None
os: typing.Optional[ActorOsConfigurationType] = None
class LoginResultInfoType(typing.NamedTuple):
ip: str
hostname: str
dead_line: typing.Optional[int]
max_idle: typing.Optional[int] = None # Not provided by broker
max_idle: typing.Optional[int] # Not provided by broker
class CertificateInfoType(typing.NamedTuple):
private_key: str

View File

@ -210,8 +210,9 @@ def getIdleDuration() -> float:
return 0
# if lastInputInfo.dwTime > 1000000000: # Value toooo high, nonsense...
# return 0
millis = ctypes.windll.kernel32.GetTickCount() - lastInputInfo.dwTime # @UndefinedVariable
if millis < 0 or millis > 1000000000:
current = ctypes.c_uint(ctypes.windll.kernel32.GetTickCount())
millis = current.value - lastInputInfo.dwTime # @UndefinedVariable
if millis < 0:
return 0
return millis / 1000.0
except Exception as e:

View File

@ -215,8 +215,9 @@ def getIdleDuration():
return 0
# if lastInputInfo.dwTime > 1000000000: # Value toooo high, nonsense...
# return 0
millis = ctypes.windll.kernel32.GetTickCount() - lastInputInfo.dwTime # @UndefinedVariable
if millis < 0 or millis > 1000000000:
current = ctypes.c_uint(ctypes.windll.kernel32.GetTickCount())
millis = current.value - lastInputInfo.dwTime # @UndefinedVariable
if millis < 0:
return 0
return millis / 1000.0
except Exception as e:

View File

@ -210,18 +210,14 @@ class Initiialize(ActorV3Action):
# Managed by UDS, get initialization data from osmanager and return it
# Set last seen actor version
userService.setProperty('actor_version', self._params['version'])
maxIdle = None
osData: typing.MutableMapping[str, typing.Any] = {}
osManager = userService.getOsManagerInstance()
if osManager:
maxIdle = osManager.maxIdle()
logger.debug('Max idle: %s', maxIdle)
osData = osManager.actorData(userService)
return ActorV3Action.actorResult({
'own_token': userService.uuid,
'unique_id': userService.unique_id,
'max_idle': maxIdle,
'os': osData
})
except ActorToken.DoesNotExist:
@ -316,13 +312,16 @@ class Login(ActorV3Action):
osManager = userService.getOsManagerInstance()
if osManager:
osManager.loggedIn(userService, self._params.get('username') or '')
maxIdle = osManager.maxIdle()
logger.debug('Max idle: %s', maxIdle)
ip, hostname = userService.getConnectionSource()
deadLine = userService.deployed_service.getDeadline()
return ActorV3Action.actorResult({
'ip': ip,
'hostname': hostname,
'dead_line': deadLine
'dead_line': deadLine,
'max_idle': maxIdle
})
class Logout(ActorV3Action):