Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix for backwards compatibility, new feature ROIs and RODs for AutoFocus and new timeout mechanic for all clients #34

Merged
merged 18 commits into from
Apr 4, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
18 commits
Select commit Hold shift + click to select a range
8429898
Fixed backwards compatibility and added new unittests for device client
Galoshi Mar 26, 2024
5005ac2
Added new feature for usage of ROIs and RODs for AutoFocus
Galoshi Mar 26, 2024
e92e4df
Fixed backwards compatibility
Galoshi Mar 26, 2024
f0131e4
Added new config flag importDeviceConfigUnittests for avoiding applic…
Galoshi Mar 26, 2024
498bfb4
Set config flag importDeviceConfigUnittests to default value True
Galoshi Mar 26, 2024
5968368
Incrementing setup.py version from 0.4 to 0.5
Galoshi Mar 26, 2024
da511aa
Moved module imports to top level for RPC client
Mar 27, 2024
c402920
Setting default ip in config file for unittests
Mar 27, 2024
a1a6a86
Changed input argument saturatedRatio for method startCalculateExposu…
Mar 27, 2024
18696db
Modified timeout mechanic for RPC so timeout is only set for its own …
Mar 27, 2024
f45574b
Removed method socket_exception_handler which is not needed anymore s…
Mar 27, 2024
3985d90
Replaced unsecure method eval() to json.loads()
Mar 27, 2024
4d73fe6
Fixed proxy issues for RPC timeout mechanic
Mar 27, 2024
f66a283
Replaced update methods for startCalculateExposureTime and startCalcu…
Mar 27, 2024
b07a070
Removed method rpc_exception_handler which is not needed anymore sinc…
Mar 27, 2024
3f24e51
Removed unnecessary comments in RPC client
Mar 28, 2024
a75903d
Fixed stack overflow error for overloaded __gettattr__ proxy method, …
Apr 4, 2024
8f1f108
Fixed versionioning of package so it equals the tagged package
Apr 4, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 15 additions & 13 deletions source/rpc/proxy.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,40 +2,40 @@
import xmlrpc.client
from contextlib import contextmanager
from threading import Timer
# from .session import Session
# from .edit import Edit
# from .application import Application
# from .imager import Imager

SOCKET_TIMEOUT = 10


class BaseProxy(object):
"""Base class for all proxies."""

def __init__(self, url, timeout=SOCKET_TIMEOUT):
def __init__(self, address, url, timeout=SOCKET_TIMEOUT):
"""Initialize the actual xmlrpc.client.ServerProxy from given url.

Args:
address (str): ip address of host
url (str): url for xmlrpc.client.ServerProxy
timeout (float): argument can be a non-negative floating point number
expressing seconds, or None. If None, SOCKET_TIMEOUT value is used as default
"""
try:
socket.setdefaulttimeout(timeout)
self.__transport = xmlrpc.client.Transport()
self.__transport.make_connection(host=address)
getattr(self.__transport, "_connection")[1].timeout = timeout
self.__proxy = xmlrpc.client.ServerProxy(uri=url, transport=self.__transport)
except TimeoutError:
socket.setdefaulttimeout(None)
self.close()

@property
def timeout(self):
if self.__transport._connection[1]:
return self.__transport._connection[1].timeout
if getattr(self.__transport, "_connection")[1]:
return getattr(self.__transport, "_connection")[1].timeout
return socket.getdefaulttimeout

@timeout.setter
def timeout(self, value):
if self.__transport._connection[1]:
self.__transport._connection[1].timeout = value
if getattr(self.__transport, "_connection")[1]:
getattr(self.__transport, "_connection")[1].timeout = value

@property
def proxy(self):
Expand All @@ -54,23 +54,25 @@ def __getattr__(self, name):
def close(self):
self.__transport.close()
self.__transport = None
self.__connection = None
self.__proxy = None


class MainProxy(BaseProxy):
"""Proxy representing mainProxy."""

def __init__(self, url, timeout, device):
def __init__(self, address, url, timeout, device):
"""Initialize main proxy member, device and baseURL.

Args:
url (str): url for BaseProxy
device (obj): device
"""
self.address = address
self.baseURL = url
self.device = device

super(MainProxy, self).__init__(url, timeout)
super(MainProxy, self).__init__(address, url, timeout)

@contextmanager
def requestSession(self, password='', session_id='0' * 32):
Expand Down
14 changes: 14 additions & 0 deletions tests/test_rpc.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import time
from unittest import TestCase
import numpy as np
import socket
from source import O2x5xxRPCDevice
from tests.utils import *
from .config import *

Expand Down Expand Up @@ -40,6 +42,18 @@ def setUp(self) -> None:
def tearDown(self) -> None:
pass

def test_timeout_with_invalid_ip(self):
TIMEOUT_VALUES = [1, 2, 5]
for timeout_value in TIMEOUT_VALUES:
start_time = time.time()
with self.assertRaises(socket.timeout):
with O2x5xxRPCDevice("192.168.0.5", timeout=timeout_value) as device:
device.rpc.getParameter("ActiveApplication")
Galoshi marked this conversation as resolved.
Show resolved Hide resolved
end_time = time.time()
duration_secs = end_time - start_time
self.assertLess(duration_secs, timeout_value+1)
self.assertGreater(duration_secs, timeout_value-1)
Galoshi marked this conversation as resolved.
Show resolved Hide resolved

def test_getParameter(self):
with O2x5xxRPCDevice(deviceAddress) as rpc:
result = rpc.getParameter(value="DeviceType")
Expand Down