Build and Test

Version added 2018-03-07 20:32:00| Modified 12-Apr-2018

After developing the service, you must build the service and verify its functionality.

 

Add Recipe File 

webOS OSE uses OpenEmbedded of Yocto project to build its components. You must write a recipe that configures the build environment. For more details about the recipe, see Yocto project reference manual.

  • Create and update the file : <native-service-name>.bb

  • Directory : build-webos/meta-webosose/meta-webos/recipes-webos/<native-service-name>

where <native-service-name> is the name of the native service. For the sample web app, <native-service-name> must be replaced by 'com.example.native.service'.

SUMMARY = "Native service sample"
AUTHOR = "Author's name <Author's e-mail>"
LICENSE = "Apache-2.0"
LIC_FILES_CHKSUM = "file://${COMMON_LICENSE_DIR}/Apache-2.0;md5=89aea4e17d99a7cacdbeed46a0096b10"
 
DEPENDS= "glib-2.0 luna-service2"
 
WEBOS_VERSION = "0.0.1"
PR = "r0"
 
inherit webos_component
inherit webos_submissions
inherit webos_cmake
inherit webos_system_bus

A brief explanation of the above file:

  • Lines(1~4) : Basic descriptions of the component.

  • Line(6) : Add GLib and LS2 as dependencies.

  • Line(8) : Version of the component. For the webOS OSE component, this field is mandatory.

  • Line(9) : Revision version of the recipe. Each recipe requires a counter to track its modification history. Make sure that you increment the version when you edit the recipe, unless you only change the value of the WEBOS_VERSION field or comments.

  • Line(11) : Inherits common functions of webOS OSE. For all components of webOS OSE, this entry is required.

  • Line(12) : Inherit the WEBOS_VERSION value. If you develop your component on a local repository, this entry is required.

  • Line(13) : Instructs OpenEmbedded that the component uses CMake for configuration, which is the preferred choice for webOS components.

  • Line(14) : To register component as service and install LS2 configuration files.

 

Configure Local Source Directory

To build a component that is located on the local system, you must specify the directory information.

  • Update the file : webos-local.conf

  • Directory : build-webos

For the sample native service (com.example.native.service), you must provide the local path where the source exists.

INHERIT += "externalsrc"
EXTERNALSRC_pn-com.example.service.native = "/home/username/project/com.example.service.native/"
EXTERNALSRC_BUILD_pn-com.example.service.native = "/home/username/project/com.example.service.native/build/"
PR_append_pn-com.example.service.native =".local0"

A brief explanation of the above file:

  • Line(1) : Inherit externalsrc bbclass file.

  • Line(2) : The local source directory. The syntax of the property is EXTERNALSRC_pn-<component>. We recommend that you add trailing slash (/) at the end of local directory paths.

  • Line(3) : The local build directory. The syntax of the property is EXTERNALSRC_BUILD_pn-<component>. 

  • Line(4) : The appended revision version (PR) for building local source files. The syntax of the property is PR_append_pn-<component>. This property is optional.

 

Build, Run, and Verify

 

 

  1. Build the service.

    To build the component on the OpenEmbedded environment, enter the following commands on the shell.

    build-webos$ source oe-init-build-env
    build-webos$ bitbake com.example.service.native

    For more information, see Building webOS OSE.
     

  2. Copy the IPK to target.

    When the build is successful, oe-related directories are created under the root directory. These directories are linked to the directory where the build output is generated from the actual build-webos sub-directory.

    com.example.service.native
    ├── CMakeLists.txt
    ├── README.md
    ├── files
    │   ├── sysbus
    │   │   ├── com.example.service.native.api.json
    │   │   ├── com.example.service.native.perm.json
    │   │   ├── com.example.service.native.role.json.in
    │   │   └── com.example.service.native.service.in
    │   └── systemd
    │       └── com.example.service.native.service.in
    ├── main.cpp
    ├── oe-logs -> /home/username/build/build-webos/BUILD/work/raspberrypi3-webos-linux/com.example.service.native/0.0.1-r0.local0/temp
    ├── oe-workdir -> /home/username/build/build-webos/BUILD/work/raspberrypi3-webos-linux/com.example.service.native/0.0.1-r0.local0

    If you go to oe-workdir/deploy-ipks/raspberrypi3, you can see that com.example.service.native_0.0.1-r0.local0_raspberrypi3.ipk file.

    com.example.service.native/oe-workdir/deploy-ipks/raspberrypi3
    └── com.example.service.native_0.0.1-r0.local0_raspberrypi3.ipk

    Copy the IPK file to target using the 'scp' command.

    com.example.service.native/oe-workdir/deploy-ipks/raspberrypi3$ scp com.example.service.native_0.0.1-r0.local0_raspberrypi3.ipk root@192.168.0.12:/media/internal/downloads

     

  3. Install the service on the target.

    Connect to target with ssh and install com.example.service.native_0.0.1-r0.local0_raspberrypi3.ipk.

    $ ssh root@192.168.0.12
    root@raspberrypi3:~# cd /media/internal/downloads/
    root@raspberrypi3:/media/internal/downloads# opkg install com.example.service.native_0.0.1-r0.local0_raspberrypi3.ipk
    
    Installing com.example.service.native (0.0.1) on root.
    Configuring com.example.service.native.
    

     

  4. Discovery of LS2 configuration files.

    In order to make LS2 daemon scan the LS configuration files (service, role, permission) of com.example.service.native, enter 'ls-control' command or reboot target.

    root@raspberrypi3:/media/internal/downloads# ls-control scan-services
    
    telling hub to reload setting and rescan all directories

     

  5. Run the service.

    You can run the com.example.service.native using the systemd command.

    root@raspberrypi3:~# systemctl start com.example.service.native

     

  6. Verify the execution of the service.

    • Using systemctl

      You can check the PID and attribute of process executed by using the command 'systemctl status' command.

      [[0;1;32m●[[0m com.example.service.native.service - webos - "com.example.service.native.service"
         Loaded: loaded (/etc/systemd/system/com.example.service.native.service; static; vendor preset: enabled)
         Active: [[0;1;32mactive (running)[[0m since Thu 2018-02-22 02:47:31 PST; 5s ago
       Main PID: 857 (com.example.ser)
         CGroup: /system.slice/com.example.service.native.service
                 └─857 /usr/sbin/com.example.service.native
       
      Feb 22 02:47:31 raspberrypi3 systemd[1]: Started webos - "com.example.service.native.service".
      Feb 22 02:47:31 raspberrypi3 com.example.service.native[857]: Start com.example.service.native
      
    • Using ls-monitor

      You can use 'ls-monitor' to check whether the service is successfully registered. It also shows the methods available in the service. For more detail about ls-monitor, please see ls-monitor.

      root@raspberrypi3:/# ls-monitor -i com.example.service.native
       
      METHODS AND SIGNALS REGISTERED BY SERVICE 'com.example.service.native' WITH UNIQUE NAME 'nb9qs3qC' AT HUB
       
        "/":
            "hello": {"provides":["all","public"]}

 

Verify the Output

Verify the output of the "hello" Method. You can call a method by using the lun-send command: 

root@raspberrypi3:/# luna-send -n 1 -f luna://com.example.service.native/hello '{}'
{
    "answer": "Hello, Native Service!!",
    "returnValue": true
}

For more details, please see LS2 API development.

*Reference : If com.example.service.native is not registered successfully, you will see a return message as below.

root@raspberrypi3:~# luna-send -n 1 -f luna://com.example.service.native/hello '{}'
{
    "errorCode": -1,
    "returnValue": false,
    "errorText": "Service does not exist: com.example.service.native."
}

 

Specify Order of Execution on Target

To verify that the service can run automatically after rebooting. Add the service to the systemd's start execution list. This ensures that the service runs automatically without the 'systemctl start' command.

  • Update the file : webos-bd.target

  • Directory : /etc/systemd/system (on the target device)

[Unit]
Description="%n"
Wants=nyx-utils.service \
      second-screen-gateway.service \
      com.example.service.native.service
Except as noted, this content is licensed under Creative Commons Attribution 4.0 and sample code is licensed under Apache License 2.0.