Lets explore how to use inter-process communication (IPC) between components:
Here's what it looks like at runtime:
When we show the static view of components inside executables, it looks like this:
Note that each interface has
In our example, the client and server both use the same friendly name "hello" for their interfaces, and must use the same protocol (or they wouldn't be able to communicate with each other!).
First, create a directory for our little project and change directories:
$ mkdir helloIPC $ cd helloIPC
Next, define the interface protocol to use between the client and the server.
To create our greet function-call API, we create a definition file called "greet.api".
$ gedit greet.api
Add this inside greet.api:
FUNCTION Greet ( );
This will declare a function called Greet
that takes no arguments and returns nothing.
Next, create a server component called greetServer
that offers a greeting service called "hello" to be accessed using our simple "greet" API. Do this by creating a file called "Component.cdef" in a new directory called "greetServer".
$ mkdir greetServer $ gedit greetServer/Component.cdef
greetServer/Component.cdef should contain the following:
This declares that the component named greetServer
(the name of the directory is the name of the component) provides a service called hello
accessed using the API defined in greet.api
where the source code can be found in the file greetServer.c
.
To implement the server (in C), create a file greetServer/greetServer.c
:
$ gedit greetServer/greetServer.c
Make it contain the following:
The file interfaces.h
is auto-generated based on the contents of greet.api
and greetServer's Component.cdef
. It'll contain a prototype of the function hello_Greet()
, which we implemented in greetServer.c
.
The function hello_Greet()
will be called when a client binds to our hello
service and calls the function Greet()
. The name hello_Greet
follows this pattern:
<interface-name> '_' <api-function-name>
The <interface-name> is the name given to the provided interface. In our example, it's the name hello
before the =
in the line hello
=
greet.api
.
Now that we have a server, let's create a client to use its service.
First, create a directory for the greetClient
component and a file in it called Component.cdef:
$ mkdir greetClient $ gedit greetClient/Component.cdef
greetClient/Component.cdef should contain:
To implement the client using C, create a file called greetClient/greetClient.c
:
$ gedit greetClient/greetClient.c
Make it contain the following:
The interfaces.h
file the client includes is different than the one the server uses. This client one is specially generated based on the contents of greetClient/Component.cdef
and greet.api
.
In the client, we use the component initializer to call hello_Greet()
at start-up.
You can add a message to the COMPONENT_INIT so the logs will show the client calling the server:
You can create an Application Definition .adef file with an Extern section to declare it's available for binding:
You only need to do this if you want to leave your interface unbound, and bind it later in the System Definition .sdef file Bindings section.
Copyright (C) Sierra Wireless Inc. Use of this work is subject to license.