All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
Language-Independent APIs

Legato components can export APIs for other components to use. This can be done the conventional way, by writing a C header file to define the interface, for example. But, a C header file can only be used by components that are written in C, and functions defined in a C header file can only be implemented by C code. Furthermore, C compilers won't generate IPC code for you, so unless you write your own, your API implementation and its user are forced to run inside the same process. This can severely limit the reusability of components and can force the use of a programming language that is not ideally suited to a particular problem domain or developer skill set. It also leaves inter-process communication (IPC) to be implemented manually, which can be time-consuming and fraught with bugs and security issues.

To alleviate these problems, Legato provides a very simple form of interface definition language (IDL) that is similar to C but that helps the programmer define their API such that it can be used in multiple different programming languages.

These IDL files are called API definition (.api) files.

These .api files are processed by the ifgen build tool, which generates function definitions and IPC code in an implementation language chosen by the component writer. Most of the time, developers don't need to know anything about ifgen, though, because it is automatically run by other build tools, as needed.

Note
Although the only language supported today is C, the plan is that the client and server can be written in different languages, multiple clients can be written in different languages, and multiple server implementations can be written in different languages; and none of them would have to include any IPC code or language translation layer.

When writing a client of an API, the programmer

  • imports the API into their component (add the .api file to the import: section of the component's Component.cdef file)
  • include/import the generated code into their program (e.g., in C: #include "interfaces.h")
  • call the functions in the API

This will automatically take care of IPC connection opening/closing, message buffer allocation/release, message passing, synchronization between client and server threads/processes, and sandbox security access control.

When writing a server of an API, the programmer

  • exports the API from their component (add the .api file to the export: section of the component's Component.cdef file)
  • include/import the generated code into their program (e.g., in C: #include "interfaces.h")
  • implement the functions in the API

The server's functions will be called automatically when the client calls the auto-generated client-side versions of those functions.

For more information:

API Definition Syntax
C Language Support
Definition Files


Copyright (C) Sierra Wireless, Inc. 2014. All rights reserved. Use of this work is subject to license.