Skip to content

Commit 2db4850

Browse files
committed
New alternate zeroMQ request->response wrapper for Matlab: zeroMQrr.
1 parent 2c574d4 commit 2db4850

9 files changed

Lines changed: 545 additions & 0 deletions

File tree

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
% compile 0MQ matlab request->response (zeroMQrr)
2+
3+
% 1. find the correct locations of zermoMQ librearies and heaers
4+
if strfind(computer,'PCWIN')
5+
Codefolder=mfilename('fullpath');
6+
Codefolder=Codefolder(1:(end-length(mfilename()-1)));
7+
libraryName = 'libzmq-v110-mt-3_2_2';
8+
if strcmp(computer,'PCWIN64')
9+
libFolder = [Codefolder, '/Resources/windows-libs/ZeroMQ/lib_x64'];
10+
else
11+
libFolder = [Codefolder, '/Resources/windows-libs/ZeroMQ/lib_x86'];
12+
end
13+
headerFolder = [Codefolder, '/Resources/windows-libs/ZeroMQ/include'];
14+
elseif strcmp(computer,'GLNX86') || strcmp(computer,'GLNXA64')
15+
libraryName = 'zmq';
16+
if ~isempty(dir(['/usr/local/lib/lib' libraryName '*']))
17+
libFolder = '/usr/local/lib';
18+
headerFolder = '??';
19+
else
20+
error('compile:matlab_zeroMQrr','please add the paths to your zeroMQ libraries and headers');
21+
end
22+
elseif strcmp(computer,'MACI64')
23+
libraryName = 'zmq';
24+
%iterate trough some options
25+
if ~isempty(dir(['/usr/local/Cellar/zeromq/4.1.4/lib/lib' libraryName '*'])) %should prob. iterate to find the newest version
26+
libFolder = '/usr/local/Cellar/zeromq/4.1.4/lib';
27+
headerFolder = '/usr/local/Cellar/zeromq/4.1.4/include';
28+
% elseif ~isempty(dir(['/usr/local/lib/lib' libraryName '*']))
29+
% libFolder = '/usr/local/lib';
30+
% headerFolder = '??';
31+
else
32+
error('compile:matlab_zeroMQrr','please add the paths to your zeroMQ libraries and headers');
33+
end
34+
35+
end
36+
37+
cppFile = 'zeroMQrr/zeroMQrr.cpp';
38+
% 2. compile
39+
eval(['mex ' cppFile ' -I',headerFolder,' -L',libFolder,' -l',libraryName] )
File renamed without changes.

Resources/Matlab/zeroMQrr.m

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
%
2+
% zeroMQrr provides a simple wrapper around the zeromq library with a
3+
% request->response scenario in mind
4+
%
5+
% Usage:
6+
%
7+
% zeroMQrr('Command',...);
8+
%
9+
% zeroMQrr('Send',url, request, [blocking=0]);
10+
% When blocking is true, zeroMQrr waits for and returns the response
11+
% [response, dialogue]=zeroMQrr('Send',url, request, 1);
12+
% When blocking is 0 (default) zeroMQrr adds the request to a queue and returns the time the request was added to that queue. See 'GetResponses'
13+
% [timeRequestAdded]=zeroMQrr('Send',url, request, 0);
14+
%
15+
% dialogue = zeroMQrr('GetResponses', [wairForEmptyQueue=1])
16+
% Retirieves responses collected for requests send in non blocking mode. If wairForEmptyQueue>0, the function waits for the last queued request to get a response.
17+
% dialogue is a struct with the fields: request, response, timeRequestAdded, timeRequestSent, timeResponeRecieved
18+
% At the moment this cannot get filtered by the url of the request yet.
19+
%
20+
% zeroMQrr('CloseAll')
21+
% closes all open sockets and the queue thread if open.
22+
%
23+
%
24+
% zeroMQrr('CloseThread')
25+
% closes the queue thread if open
26+
%
27+
% url = zeroMQrr('StartConnectThread', url)
28+
% This function is not neccessary and for backward compatability only. It simply returns the url of the input as previous versions required a handle instead of the url if the 'Send' command
29+
%
30+
% currently only tested on OSX. To compile you need the zeromq library
31+
% installed (e.g. using brew on OSX) and the libraries set correctly in
32+
% compile_matlab_wrapper
33+
%
34+
% Copyright (c) 2008 Shay Ohayon, California Institute of Technology.
35+
% This file is a part of a free software. you can redistribute it and/or modify
36+
% it under the terms of the GNU General Public License as published by
37+
% the Free Software Foundation (see GPL.txt)
38+
%
39+
% Changes to allow receiving responses by Jonas Kn?ll, 2016
26.9 KB
Binary file not shown.

0 commit comments

Comments
 (0)