Search code examples
idl

What is IDL?


What is meant by IDL? I have googled it, and found out it stands for Interface Definition Language, which is used for interface definition for components. But, in practice, what is the purpose of IDL? Does Microsoft use it?


Solution

  • An interface definition language (IDL) is used to set up communications between clients and servers in remote procedure calls (RPC). There have been many variations of this such as Sun RPC, ONC RPC, DCE RPC and so on.

    Basically, you use an IDL to specify the interface between client and server so that the RPC mechanism can create the code stubs required to call functions across the network.

    RPC needs to create stub functions for the client and a server, using the IDL information. It's very similar to a function prototype in C but the end result is slightly different, such as in the following graphic:

    +----------------+
    | Client         |
    |  +----------+  |         +---------------+
    |  |   main   |  |         | Server        |
    |  |----------|  |         |  +----------+ |
    |  | stub_cli |----(comms)--->| stub_svr | |
    |  +----------+  |         |  |----------| |
    +----------------+         |  | function | |
                               |  +----------+ |
                               +---------------+
    

    In this example, instead of calling function in the same program, main calls a client stub function (with the same prototype as function) which is responsible for packaging up the information and getting it across the wire to another process, via the comms channel.

    This can be the same machine or a different machine, it doesn't really matter - one of the advantages of RPC is to be able to move servers around at will.

    In the server, there's a 'listener' process that will receive that information and pass it to the server. The server's stub receives the information, unpacks it and passes it to the real function.

    The real function then does what it needs to and returns to the server stub which can package up the return information (both return code and any [out] or [in,out] variables) and pass it back to the client stub.

    The client stub then unpacks that and passes it back to main.

    The actual details may differ a little but that explanation should be good enough for a conceptual overview.

    The actual IDL may look like:

    [   uuid(f9f6be21-fd32-5577-8f2d-0800132bd567),
        version(0),
        endpoint("ncadg_ip_udp:[1234]", "dds:[19]")
    ] interface function_iface {
        [idempotent] void function(
            [in] int handle,
            [out] int *status
        );
    }
    

    All that information at the top (for example, uuid or endpoint) is basically networking information used for connecting client and server. The "meat" of it is inside the interface section where the prototype is shown. This allows the IDL compiler to build the function client and server stub functions for compiling and linking with your client and server code to get RPC working.

    Microsoft does use IDL (I think they have a MIDL compiler) for COM stuff. I've also used third party products with MS operating systems, both DCE and ONC RPC.