Skip to main content

Overview

The Conversor interface is defined using ZeroC ICE’s Slice language. Slice (Specification Language for ICE) is an interface definition language (IDL) that allows you to define language-agnostic interfaces for distributed applications.

Conversor.ice File

The complete interface definition is located in backend/Conversor.ice:
backend/Conversor.ice
module Conversor
{
    exception UnidadInvalidaException
    {
        string mensaje;
    };

    interface ConversorUnidades
    {
        double convertirTemperatura(double valor, string desde, string hasta)
            throws UnidadInvalidaException;

        double convertirLongitud(double valor, string desde, string hasta)
            throws UnidadInvalidaException;

        double convertirPeso(double valor, string desde, string hasta)
            throws UnidadInvalidaException;

        double convertirVelocidad(double valor, string desde, string hasta)
            throws UnidadInvalidaException;

        string unidadesDisponibles(string categoria)
            throws UnidadInvalidaException;
    };
};

Module and Exception

Conversor
module
The main module that encapsulates all interface definitions and exceptions.
UnidadInvalidaException
exception
Custom exception thrown when invalid units or categories are provided.Fields:
  • mensaje (string): Descriptive error message explaining what went wrong
ICE exceptions are type-safe and can be caught specifically on the client side, allowing for proper error handling in distributed systems.

Interface Methods

The ConversorUnidades interface defines five remote methods:

convertirTemperatura

double convertirTemperatura(double valor, string desde, string hasta)
    throws UnidadInvalidaException;
valor
double
required
The temperature value to convert
desde
string
required
Source unit: celsius, fahrenheit, or kelvin
hasta
string
required
Target unit: celsius, fahrenheit, or kelvin
Returns: Converted temperature value as a double

convertirLongitud

double convertirLongitud(double valor, string desde, string hasta)
    throws UnidadInvalidaException;
valor
double
required
The length/distance value to convert
desde
string
required
Source unit: m (meters), km (kilometers), mi (miles), or ft (feet)
hasta
string
required
Target unit: m, km, mi, or ft
Returns: Converted length value as a double

convertirPeso

double convertirPeso(double valor, string desde, string hasta)
    throws UnidadInvalidaException;
valor
double
required
The weight/mass value to convert
desde
string
required
Source unit: kg (kilograms), lb (pounds), or g (grams)
hasta
string
required
Target unit: kg, lb, or g
Returns: Converted weight value as a double

convertirVelocidad

double convertirVelocidad(double valor, string desde, string hasta)
    throws UnidadInvalidaException;
valor
double
required
The velocity/speed value to convert
desde
string
required
Source unit: kmh (km/hour), mph (miles/hour), or ms (meters/second)
hasta
string
required
Target unit: kmh, mph, or ms
Returns: Converted velocity value as a double

unidadesDisponibles

string unidadesDisponibles(string categoria)
    throws UnidadInvalidaException;
categoria
string
required
The category name: temperatura, longitud, peso, or velocidad
Returns: Comma-separated string of available units for the category
This method is useful for building dynamic UIs that show users which units are available for conversion.

Code Generation

Once the Slice file is defined, use the slice2py compiler to generate Python stubs:
slice2py Conversor.ice
This generates the Conversor module with:
  • Interface proxies for client-side calls
  • Servant base classes for server-side implementation
  • Exception classes
  • Marshaling/unmarshaling code
The generated code should not be manually edited. Always modify the .ice file and regenerate the stubs.

Next Steps

Server Implementation

Learn how to implement the servant class

Client Usage

See how to connect and make remote calls

Build docs developers (and LLMs) love