\section{Scribble Examples}
\label{sec:example}

Scribble can be utilised to express communication protocols from a
wide range of application domains. In this section we present two
examples, taken from web services \cite{CDL} and 
from multikernel OS
\cite{AnimeshTrivedi09,BBDHIPRSS09}.

\PARA{Web services: Travel Agent.}
\textsf{Travel Agent} is an interaction scenario designed by
the WS-CDL Working Group~\cite{CDL}, intended to represent
general concepts common to many applications of
web services. It comprises multiple participants -- a client, a
travel agent and a number of service providers -- and involves
complex branching and repetition in the interaction
flow. Figure~\ref{fig:ws-travel} gives an informal description
of the interaction behaviour among the participants.

% \lstinputlisting[caption={Travel Agent protocol in
% Scribble (2).}, label={fig:ws-travel-scrib2}, float=*]{ws-travel2.scrib}

\input{ws-travel} 

% \lstinputlisting[caption={Travel Agent protocol in
% Scribble.}, label={fig:ws-travel-scrib}, float=*]{ws-travel1.scrib}

\begin{figure}[h!]
%\centering
\lstinputlisting{ws-travel1.scrib}
%\lstinputlisting{ws-travel2.scrib}
%\vspace{-3.2mm}
\caption{Travel Agent: \textsf{ReserveTravel} protocol in \scribble.}
\label{fig:ws-travel-scrib1}
%\vspace{5mm}
\end{figure} 

\begin{figure}
%\centering
%\lstinputlisting{ws-travel1.scrib}
\lstinputlisting{ws-travel2.scrib}
%\vspace{-3.2mm}
\caption{Travel Agent: \textsf{PurchaseTravel} protocol in \scribble.}
\label{fig:ws-travel-scrib2}
%\vspace{5mm}
\end{figure} 

%In Figures~\ref{fig:ws-travel-scrib1}, \ref{fig:ws-travel-scrib2} 
We present a specification of \textsf{Travel Agent} protocol in
{\scribble} in two parts with: \textsf{ReserveTravel} protocol
(Figure~\ref{fig:ws-travel-scrib1}), by which the client enquires
about and reserves travel services with the help of an agent, and
\textsf{PurchaseTravel} protocol (Figure~\ref{fig:ws-travel-scrib2}) for
subsequent service booking interaction.  \textsf{PurchaseTravel} is
parametric in the number of service providers that the agent
communicates with in the preceding \textsf{ReserveTravel} protocol.
%%%
The specification makes use of recursion to represent
arbitrary repetition of a series of interactions. In
\textsf{ReserveTravel} protocol, lines 6-13 correspond to
steps 1 and 2a in Figure~\ref{fig:ws-travel}, lines 15-21 to
steps 2b, 3 and 4a. Line 21 uses a nested protocol,
\name{PurchaseTravel}, which describes a successful purchase
of travel services by the client (steps 5, 6 and 7 of
Figure~\ref{fig:ws-travel}). 
%The protocol \name{PurchaseTravel} is relegated to Appendix A.


%%% Or can be in Appendix A. Now it is put there.

% In \textsf{PurchaseTravel} protocol,
% Listing~\ref{fig:ws-travel-scrib2} covers successful
% purchase of travel services by the client, corresponding to
% steps 5 and 6 in Figure~\ref{fig:ws-travel}.

\PARA{Multikernel OS: Distributed USB Manager.}
Next we present a protocol from a distributed USB manager in
Barrelfish multi-kernel OS \cite{AnimeshTrivedi09,BBDHIPRSS09},
consisting of three primary modules that
cooperate via explicit message passing:
\begin{itemize}
\item {\em EHCI host controller driver (HCD)}. The host
  driver manages interaction with the host controller
  hardware and provides a high-level interface for
  communicating with the hardware.
\item {\em Client device driver}. The client driver carries out
  interaction with a USB device and exposes services of the device to
  applications.
\item {\em USB manager}. The manager is responsible for coordination
  of the modules and allocation of resources.
\end{itemize} 
The USB manager has the most complex communication logic among
these modules, performing orchestration of other
components. In Figure~\ref{fig:multios-usb} we informally
describe a USB device {\tt Plug\_Unplug} protocol.

\input{multios-usb}

% \lstinputlisting[caption={PlugUnplug protocol in Scribble.}, label={fig:multios-usb-scrib}, float=*]{multios-usb.scrib}
\begin{figure} 
\lstinputlisting{multios-usb.scrib}
\caption{PlugUnplug protocol in \scribble.}
\label{fig:multios-usb-scrib}
\end{figure} 

Figure~\ref{fig:multios-usb-scrib} presents a specification
of {\tt Plug\_Unplug} protocol in {\scribble}. The
interaction has a linear structure and its subtlety lies in
the correct interleaving of control messages
(\name{ctrl\_exe}) with data commands ({\name{dctrl\_exe})
  between the USB manager and HCD.
\newpage
% \subsection{OOI Cyberinfrastructure: Command Instrument}

% The OOI architecture \cite{ooi} comprises a large catalogue of communication
% protocols among distributed instruments and stakeholders. These
% protocols need to be unambiguously specified for the implementation
% and runtime monitoring of the communication within the
% infrastructure. We are presently working with the OOI team on the
% application of \name{Scribble} for that purpose. A short example in
% Listing~\ref{fig:ooi-cmdinstr-scrib} presents a \name{Scribble}
% specification of an OOI protocol for issuing commands to an instrument via
% its controlling agent.
% ((intro to OOI distributed architechture and importance of protocol
% specification, role of Scribble))
% \lstinputlisting[caption={Command an Instrument protocol in
% Scribble.}, label={fig:ooi-cmdinstr-scrib}, float=*]{ooi-cmdinstr.scrib}
%\[ \] \pagebreak
%%% Local Variables: 
%%% mode: latex
%%% TeX-master: "main"
%%% End: 
