Associate a callback to "mytag" on the connection "con" This function will associate a function f to a tag on a given connection. If the function urbiProcessEvent reads a message with this tag on this connection, the function f will be called with a urbiMessage as argument: urbiCallBackAction = f(urbiMessage) with : urbiMessage.timeStamp : the time stamp of the message urbiMessage.tag : the tag of the message urbiMessage.type : the type of the message: 'numeric', 'string', 'system', 'image', 'sound', or 'otherBIN') if type == numeric, then urbiMessage.value (the numeric value of the message) if type == string, then urbiMessage.value (the string value of the message) if type == system, then urbiMessage.value (the string value of the system message) if type == image, then urbiMessage.image is the same as the result of urbiGetImage(con) (with the fields matrix, width, height, timeStamp) if type == sound, then urbiMessage.sound is the same as the result of urbiGetSound(con, length) (with the fields samples, Fs, nbits, length) if type == otherBIN then urbiMessage.bin (the vector of bytes of the BIN info) The callback function f should return either 0, and in this case the callback is deleted, or 1, and in this case the callback continues, urbiSetCallBack returns an id for the callback so that later on it can be deleted manually using urbiDeleteCallBack(callBackId);
0001 function callBackId = urbiSetCallback(con, f, mytag) 0002 % Associate a callback to "mytag" on the connection "con" 0003 % This function will associate a function f to a tag on a given connection. 0004 % If the function urbiProcessEvent reads a message with this tag on this 0005 % connection, the function f will be called with a urbiMessage as argument: 0006 % 0007 % urbiCallBackAction = f(urbiMessage) 0008 % 0009 % with : 0010 % urbiMessage.timeStamp : the time stamp of the message 0011 % urbiMessage.tag : the tag of the message 0012 % urbiMessage.type : the type of the message: 'numeric', 'string', 0013 % 'system', 'image', 'sound', or 'otherBIN') 0014 % 0015 % if type == numeric, then urbiMessage.value (the numeric value of the message) 0016 % if type == string, then urbiMessage.value (the string value of the message) 0017 % if type == system, then urbiMessage.value (the string value of the system message) 0018 % if type == image, then urbiMessage.image is the same as the result of urbiGetImage(con) 0019 % (with the fields matrix, width, height, timeStamp) 0020 % if type == sound, then urbiMessage.sound is the same as the result of urbiGetSound(con, length) 0021 % (with the fields samples, Fs, nbits, length) 0022 % if type == otherBIN then urbiMessage.bin (the vector of bytes of the BIN info) 0023 % 0024 % The callback function f should return either 0, and in this case the callback is deleted, 0025 % or 1, and in this case the callback continues, 0026 % 0027 % urbiSetCallBack returns an id for the callback so that later on it can be 0028 % deleted manually using urbiDeleteCallBack(callBackId); 0029 0030 global Internal_Call_Back_Array Internal_Call_Back_connections 0031 persistent Internal_Call_Back_identificator 0032 0033 if (size(Internal_Call_Back_identificator, 1) == 0) 0034 % First call return id zero 0035 Internal_Call_Back_identificator = 0; 0036 Internal_Call_Back_connections = con; 0037 Internal_Call_Back_Array{con + 1} = []; 0038 else 0039 % Other calls increase the next id 0040 Internal_Call_Back_identificator = Internal_Call_Back_identificator + 1; 0041 if (~ismember(con, Internal_Call_Back_connections)) 0042 Internal_Call_Back_connections = [con Internal_Call_Back_connections]; 0043 Internal_Call_Back_Array{con + 1} = []; 0044 end; 0045 end; 0046 0047 Internal_Call_Back_Array{con + 1} = [Internal_Call_Back_Array{con + 1} ; 0048 struct('id', Internal_Call_Back_identificator, 'function', f, 'tag', mytag) ]; 0049 callBackId = Internal_Call_Back_identificator; 0050