Handles the callback system This function checks whether there are messages on all urbi connections associated with a callback. If yes, it parses them and calls the associated callbacks functions with an urbiMessage structure as argument n specifies an upper limit of the number of messages which can be processed in one call of processEvents (this is for allowing to give the control back if there are too many messages) timeout specifies the number of milliseconds during which the function waits before returning when there are no messages on the input if timeout == -1, then the function returns immediately if there are no messages or else returns the number of callBacks that have been called if timeout == -2, then the function never returns
0001 function r = urbiProcessEvents(n, timeout) 0002 % Handles the callback system 0003 % This function checks whether there are messages on all urbi connections 0004 % associated with a callback. 0005 % If yes, it parses them and calls the associated callbacks functions with 0006 % an urbiMessage structure as argument 0007 % 0008 % n specifies an upper limit of the number of messages which can be processed 0009 % in one call of processEvents (this is for allowing to give the 0010 % control back if there are too many messages) 0011 % 0012 % timeout specifies the number of milliseconds during which the function 0013 % waits before returning when there are no messages on the input 0014 % if timeout == -1, then the function returns immediately if there are 0015 % no messages or else returns the number of callBacks that have been called 0016 % if timeout == -2, then the function never returns 0017 0018 global Internal_Call_Back_Array Internal_Call_Back_connections 0019 0020 % Initialise callback number to null 0021 r = 0; 0022 connections = size(Internal_Call_Back_connections, 2); 0023 % update the timeout control 0024 t = cputime; 0025 while (1) 0026 for i=1:connections 0027 con = Internal_Call_Back_connections(i); 0028 % Listen to the connection where callbacks are defined 0029 string = pnet(con, 'readline', 'noblock'); 0030 % display(string) ; 0031 0032 if (~isempty(string)) 0033 ans_string = strread(string, '%s'); 0034 [timeStamp, tag] = strread(ans_string{1}, '[%u:%s]', 'whitespace', ']'); 0035 %display(ans_string) ; 0036 0037 Array = Internal_Call_Back_Array{con + 1}; 0038 for i=1:size(Array, 1) 0039 if (strcmp(tag, Array(i).tag)) 0040 % Make the function argument 0041 C = Array(i); 0042 0043 %Call the Callback function 0044 if ( ~feval(C.function, urbiFullParse(ans_string, timeStamp, con)) ) 0045 deleteCallBack(con, C.id); 0046 % Connection number may have changed 0047 connections = size (Internal_Call_Back_connections, 2); 0048 end; 0049 0050 r = r + 1; 0051 if (r == n) 0052 % We've reached the callback limit 0053 return; 0054 end; 0055 end; 0056 end; 0057 % update the timeout control 0058 t = cputime; 0059 else 0060 if ((((cputime - t) * 1000 > timeout) | (timeout == -1)) & (timeout ~= -2)) 0061 return; 0062 end; 0063 end; 0064 end; 0065 end;