%% Forwarding vs. Sending a Message
% 
% This example shows the difference between forwarding a message and
% resending another message with the same data. 

% Copyright 2006-2015 The MathWorks, Inc.

%% 
%
mdlName = 'sf_msg_forwarding';
open_system(mdlName);

%%
% The chart "Producer" outputs a single message at every time step with a
% constantly increasing data. 

open_system([mdlName '/Producer']);

%% 
% These messages are processed by the "Forwarder" chart. Every time step,
% this chart removes a single message from its input queue. 

open_system([mdlName '/Forwarder']);

%% 
% If the message data is divisible by 2, then it modifies the data of that
% message and then forwards it along to "Consumer1":
% 
%   M.data = M.data + 3;
%   forward(M, Mout1);
% 
% If the message data is odd, it creates a new message "Mout2" and sends it
% to "Consumer2": 
%    
%   Mout2.data = M.data;
%   send(Mout2);
% 
% The difference between forwarding and sending a new message is evident on
% the Sequence Viewer. When you select the message between "Producer" and
% "Forwarder" with data 0 (shown with the label "M(0)"), the Sequence
% Viewer
% also highlights the message between "Forwarder" and "Consumer1". Notice
% the hint "2 items" in the top right corner.
% 
% <<sf_msg_forwarding_message_viewer1.png>>
% 
% On the other hand, if you select "M(1)" between "Producer" and
% "Forwarder", it is the only message line highlighted because the message
% with the same data between "Forwarder" and "Consumer2" is an entirely
% different message.
% 
% <<sf_msg_forwarding_message_viewer2.png>>

close_system(mdlName);