\section{Object-Based Protocol Implementation}\label{sec:oop}

The $x$-kernel provides an object-based framework for implementing
protocols, that is, the key abstractions of the $x$-kernel are
represented by objects. An object may be conveniently thought of as a
data structure with a collection of operations that are {\em
exported}, that is, made available for invocation by other objects.
Objects that have similar features are grouped into classes, with two
obvious object classes for a protocol implementation environment being
the {\em protocol} and the {\it message}.

To better understand the role played by the $x$-kernel, think of a
protocol as an abstract object, one that exports both a {\it service
interface} and a {\it peer-to-peer interface}.  The former defines the
operations by which other protocols on the same machine invoke the
services of this protocol, while the latter defines the form and
meaning of messages exchanged between peers (instances of the same
protocol running on different machines) to implement this service. In
a nutshell, the $x$-kernel provides a concrete representation for a
protocol's service interface.  While the protocol's specification
defines what it means to send or receive a message using the
protocol's service interface, the $x$-kernel defines the precise way
in which these operations are invoked in a given system. For example,
the $x$-kernel's operations for sending and receiving a message are
{\var xPush} and {\var xPop}, respectively. An $x$-kernel protocol
object would consist of an implementation of {\var xPush} and {\var
xPop} that adheres to what the protocol specification says it means to
send and receive messages using this protocol. In other words, the
protocol specification defines the {\it semantics} of the service
interface, while the $x$-kernel defines one possible {\it syntax} for
that interface.

The fashionableness of object-based programming has been accompanied
by a proliferation of object-oriented languages, of which C++ is
probably the most well known example. The $x$-kernel, however, is
written in C, which is not considered to be an object-oriented
language. To deal with this, the $x$-kernel provides its own object
infrastructure---the glue that makes it possible for one object to
invoke an operation on another object.  For example, when an object
invokes the operation {\var xOpen} on some protocol {\var p} ({\var
xOpen} is the $x$-kernel operation for opening a communication
channel) it includes {\var p} as one of the arguments to this
operation. The $x$-kernel's object infrastructure takes care of
invoking the actual procedure that implements this operation on
protocol {\var p}. In other words, the $x$-kernel uses {\var xOpen(p,
...)} in place of the more conventional notation for invoking an
operation on an object: {\var p.xOpen(...)}.
