Note
In this tutorial, we use the CMake to build the project. But you can use any other tools for the build.
In this tutorial, we use the CMake to build the project. But you can use any other tools for the build.
External native services are 3rd party native services that must be installed on the webOS target device. External native services must be packaged in a dummy app. Therefore, before creating the native service, make sure you have a dummy app to package with the external native service.
This page describes the steps to develop an external native service using Sample Code Repository and CLI. For detailed information on the CLI commands used in this tutorial, see CLI commands.
The directory structure of the sample service must be as follows:
native-services/external/
├── com.sample.echo/
│ ├── appinfo.json
│ ├── icon.png
│ ├── index.html
│ └── script.js
├── com.sample.echo.service/
│ ├── src/
│ │ └── main.c
│ ├── CMakeLists.txt
│ └── services.json
└── README.md
Developing an external native service requires the following steps:
Make sure you have completed the steps in Native Development Kit Setup.
Download the sample repository, move into samples/native-services/external/com.sample.echo.service
directory.
$ git clone https://github.com/webosose/samples
$ cd samples/native-services/external/com.sample.echo.service
First, define the functionality of the native service on the source code.
In this section, we will briefly explain webOS specific parts in com.sample.echo.service/src/main.c
.
main.c | ||
---|---|---|
|
A brief explanation of the above file:
lunaservice.h
header file to use luna service. For detailed information about luna service, see luna-service2 Library API Reference and Introduction to LS2 API.echo
method.echo
method. This method will return the input as you typed.This section describes how to prepare the configuration files required to build and test the native service.
Services are required to have metadata before they can be packaged. This metadata is stored in a file called services.json
, which is used by the webOS device to identify the service, its executable file, and other information that is needed to run the service.
services.json | ||
---|---|---|
|
A brief explanation of the above file:
com.sample.echo
, then the service ID must be com.sample.echo.myservice
.For more details, see services.json.
CMakeLists.txt
file is used by CMake to generate the Makefile to build the project. This file specifies the source, header, and UI files included in the project.
CMakeLists.txt | ||
---|---|---|
|
A brief explanation of the above file:
services.json
file to the output folder.For more details, see CMake Reference Documentation.
You are now ready to build the native service. Perform the following steps:
Go to your project directory (com.sample.echo.service
).
Create a build directory and go to the directory.
$ mkdir BUILD
$ cd BUILD
Execute the cmake
command. Then execute the make
command. A pkg_<YOUR_ARCHITECTURE>
directory will be created in your project folder (com.sample.echo.service
).
$ cmake ..
$ make
After building the native service, it must be packaged as an IPK file. Make sure the services.json
file is available because it is required when packaging an external native service for webOS OSE.
To package the native service, use the ares-package
command. The packaged file is generated in the current directory.
$ cd ..
$ ares-package ../com.sample.echo ./pkg_arm64
In the above command, ../com.sample.echo
is the dummy app directory and ./pkg_arm64
is the native service directory which contains services.json
file. You can use an absolute or relative path. For more details on using ares-package
, see ares-package.
The native service must be installed along with a dummy app.
For details on installing the dummy app, see Installing the Web App.
If the native service is successfully installed, you can try running the native service on the target device.
To run the native service, use the following command on the target device’s terminal:
root@raspberrypi4-64:/sysroot/home/root# luna-send -f -n 1 luna://com.sample.echo.service/echo '{"input":"Hello, webOS OSE!"}'
The response will be:
{
"echoMessage": "Hello, webOS OSE!",
"returnValue": true
}
When echo
method of com.sample.echo.service
is called, the service returns input
, the delivered parameter, as echoMessage
.
Contents