-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathExptClient.m
86 lines (81 loc) · 2.58 KB
/
ExptClient.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
%% wrapper for ExptClient.py
classdef ExptClient < handle
properties
client;
end
methods(Access = private)
function self = ExptClient(url)
[path, ~, ~] = fileparts(mfilename('fullpath'));
pyglob = py.dict(pyargs('mat_srcpath', path, 'url', url));
try
py.exec('from ExptClient import ExptClient', pyglob);
catch
py.exec('import sys; sys.path.append(mat_srcpath)', pyglob);
py.exec('from ExptClient import ExptClient', pyglob);
end
self.client = py.eval('ExptClient(url)', pyglob);
end
end
methods
function res = send_imgs(self, img)
shape = size(img);
res = self.client.send_imgs(img(:)', shape);
end
function res = send_config(self, dateStamp, timeStamp)
% date and timeStamp should be strings.
res = self.client.send_config(dateStamp, timeStamp);
end
function res = send_end_seq(self, data)
res = self.client.send_end_seq(int64(data));
end
function result = recv_reply(self)
cleanup = register_cleanup(self);
while 1
res = self.client.recv_reply();
if res ~= py.None
cleanup.disable()
result = int64(res);
return
end
end
end
function wait_reply(self)
cleanup = register_cleanup(self);
while ~self.client.wait_reply()
end
cleanup.disable();
end
% function wait(self, id)
% cleanup = register_cleanup(self);
% self.poster.wait_send(id);
% while ~self.poster.wait_reply()
% end
% cleanup.disable();
% end
function recreate_sock(self)
self.client.recreate_sock();
end
function cleanup = register_cleanup(self)
cleanup = FacyOnCleanup(@recreate_sock, self);
end
end
properties(Constant, Access=private)
cache = containers.Map();
end
methods(Static)
function dropAll()
remove(ExptClient.cache, keys(ExptClient.cache));
end
function res = get(url)
cache = ExptClient.cache;
if isKey(cache, url)
res = cache(url);
if ~isempty(res) && isvalid(res)
return;
end
end
res = ExptClient(url);
cache(url) = res;
end
end
end