Slice Compilation

4 min read

4 min read

4 min read

4 min read

4 min read

4 min read

4 min read

4 min read

4 min read

A Slice compiler produces source files that must be combined with application code to produce client and server executables.

The figure below shows the situation when both client and server are developed in C++. The Slice compiler generates two files from a Slice definition in a source file Greeter.ice: a header file (Greeter.h) and a source file (Greeter.cpp).

Compiling Slice in a shared C++ development environment A Slice developer writes Greeter.ice and compiles it into the shared generated files Greeter.h and Greeter.cpp. The generated-files group connects to both executables. Client.cpp connects to the client executable, Server.cpp connects to the server executable, and the Ice C++ runtime library connects to both. The client executable invokes the server executable using RPC. GENERATED FILES Slice developer Client developer Server developer SLICE Greeter.ice Slice-to-C++ compiler GENERATED Greeter.h GENERATED Greeter.cpp SOURCE Client.cpp SOURCE Server.cpp Ice C++ runtime library Client executable Server executable RPC

Compiling a Slice definition when the C++ client and server share a development environment.

  • The Greeter.h header file contains definitions that correspond to the types used in the Slice definition. It is included in the source code of both client and server to ensure that client and server agree about the types and interfaces used by the application.
  • The Greeter.cpp source file provides an API to the client for sending messages to remote objects. The client source code (Client.cpp, written by the client developer) contains the client-side application logic. The generated source code and the client code are compiled and linked into the client executable.

The Greeter.cpp source file also contains source code that provides an up-call interface from the Ice runtime into the server code written by the developer and provides the connection between the networking layer of Ice and the application code. The server implementation file (Server.cpp, written by the server developer) contains the server-side application logic (the object implementations, properly termed servants). The generated source code and the implementation source code are compiled and linked into the server executable.

Both client and server also link with an Ice library that provides the necessary runtime support.

Client and server cannot share any source or binary components if they are developed in different languages. For example, a client written in Java cannot include a C++ header file.

This figure shows the situation when a client written in Java and the corresponding server is written in C++. In this case, the client and server developers are completely independent: each developer uses their own development environment and language mapping, and the Slice definition is the only link between them.

Compiling Slice for a Java client and a C++ server A Slice developer writes Greeter.ice, which is compiled separately for a Java client and a C++ server. The Slice-to-Java compiler generates Java files, and the Slice-to-C++ compiler generates Greeter.h and Greeter.cpp. The generated Java files combine with Client.java and the Ice Java runtime library to build the client executable. Greeter.h and Greeter.cpp combine with Server.cpp and the Ice C++ runtime library to build the server executable. The client executable invokes the server executable using RPC. GENERATED FILES GENERATED FILES Slice developer Client developer Server developer SLICE Greeter.ice Slice-to-Java compiler Slice-to-C++ compiler GENERATED *.java GENERATED Greeter.h GENERATED Greeter.cpp SOURCE Client.java SOURCE Server.cpp Ice Java runtime library Client executable Server executable Ice C++ runtime library RPC

For Java, the Slice compiler creates a number of files whose names depend on the names of various Slice constructs. (These files are collectively referred to as *.java in the above figure.)