-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add new native service template for apollo profile
:Release Notes: - ares-generate: new native service template for apollo profile :Detailed Notes: - Update apollo-sdk-template.json to support native-service template - Add native-service template files: src/main.c, services.json, CMakeList.txt :Testing Performed: 1. Checked CLI unit test 2. Checked API unit test 3. Checked eslint 4. Check ares-generate using below command - $ares-config -p apollo >profile and config data is changed to apollo - $ares-generate -t native_service SERVICE_DIR >Generating native_service in SERVICE_DIR :Issues Addressed: N/A
- Loading branch information
nham.tran
committed
Oct 14, 2024
1 parent
ea2d52c
commit 81338f9
Showing
5 changed files
with
264 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
72 changes: 72 additions & 0 deletions
72
files/templates/apollo-sdk-templates/native-service/CMakeLists.txt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
# Copyright (c) 2020-2024 LG Electronics, Inc. | ||
# | ||
# Licensed under the Apache License, Version 2.0 (the "License"); | ||
# you may not use this file except in compliance with the License. | ||
# You may obtain a copy of the License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, | ||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
# See the License for the specific language governing permissions and | ||
# limitations under the License. | ||
# | ||
# SPDX-License-Identifier: Apache-2.0 | ||
|
||
cmake_minimum_required(VERSION 2.8.7) | ||
project(nativeService C) | ||
|
||
# set link directory | ||
#link_directories(${CMAKE_SOURCE_DIR}/pkg_$ENV{ARCH}/lib) | ||
|
||
# --- | ||
# add include files | ||
include_directories(${CMAKE_SOURCE_DIR}) | ||
include_directories(${CMAKE_SOURCE_DIR}/src) | ||
include_directories(${CMAKE_SOURCE_DIR}/include) | ||
|
||
# --- | ||
# find required packages | ||
include(FindPkgConfig) | ||
|
||
pkg_check_modules(GTHREAD2 REQUIRED gthread-2.0) | ||
include_directories(${GTHREAD2_INCLUDE_DIRS}) | ||
|
||
pkg_check_modules(PBNJSON REQUIRED pbnjson_c) | ||
include_directories(${PBNJSON_INCLUDE_DIRS}) | ||
|
||
# -- check for glib 2.0 | ||
pkg_check_modules(GLIB2 REQUIRED glib-2.0) | ||
include_directories(${GLIB2_INCLUDE_DIRS}) | ||
|
||
pkg_check_modules(LS2 REQUIRED luna-service2) | ||
include_directories(${LS2_INCLUDE_DIRS}) | ||
|
||
pkg_check_modules(PMLOG REQUIRED PmLogLib) | ||
include_directories(${PMLOG_INCLUDE_DIRS}) | ||
|
||
# --- | ||
# create executable file | ||
set(BIN_NAME echo_service) | ||
|
||
set(SRC_LIST | ||
${CMAKE_SOURCE_DIR}/src/main.c | ||
) | ||
|
||
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY "${CMAKE_SOURCE_DIR}/pkg_$ENV{OECORE_TARGET_ARCH}/") | ||
add_executable(${BIN_NAME} ${SRC_LIST}) | ||
|
||
# ignore shared library | ||
set(CMAKE_EXE_LINKER_FLAGS "-Wl,--allow-shlib-undefined") | ||
set_target_properties(${BIN_NAME} PROPERTIES LINKER_LANGUAGE C) | ||
|
||
target_link_libraries (${BIN_NAME} | ||
${GTHREAD2_LDFLAGS} | ||
${PBNJSON_LDFLAGS} | ||
${LS2_LDFLAGS} | ||
${GLIB2_LDFLAGS} | ||
${PMLOG_LDFLAGS} | ||
) | ||
|
||
file(COPY ${CMAKE_SOURCE_DIR}/services.json DESTINATION "${CMAKE_RUNTIME_OUTPUT_DIRECTORY}") |
11 changes: 11 additions & 0 deletions
11
files/templates/apollo-sdk-templates/native-service/services.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
{ | ||
"id": "com.domain.app.service", | ||
"description": "Native echo service", | ||
"engine": "native", | ||
"executable": "echo_service", | ||
"services": [ { | ||
"name": "com.domain.app.service", | ||
"description": "Native echo service" | ||
}] | ||
} | ||
|
144 changes: 144 additions & 0 deletions
144
files/templates/apollo-sdk-templates/native-service/src/main.c
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,144 @@ | ||
// Copyright (c) 2020-2024 LG Electronics, Inc. | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
// | ||
// SPDX-License-Identifier: Apache-2.0 | ||
|
||
#include <stdlib.h> | ||
#include <string.h> | ||
#include <glib.h> | ||
#include <stdio.h> | ||
#include <glib-object.h> | ||
#include <luna-service2/lunaservice.h> | ||
#include <pbnjson.h> | ||
|
||
// This service name | ||
#define SERVICE_NAME "SERVICE_ID" | ||
#define BUF_SIZE 64 | ||
|
||
// Main loop for aliving background service | ||
GMainLoop *gmainLoop; | ||
|
||
LSHandle *sh = NULL; | ||
LSMessage *message; | ||
|
||
// Declare of each method | ||
// All method format must be : bool function(LSHandle*, LSMessage*, void*) | ||
bool echo(LSHandle *sh, LSMessage *message, void *data); | ||
|
||
LSMethod sampleMethods[] = { | ||
{"echo", echo}, // luna://SERVICE_ID/echo | ||
}; | ||
|
||
|
||
/* | ||
* Define luna://SERVICE_ID/echo | ||
* - A method that always returns the same value | ||
* | ||
* +----------------------------+ +--------------------------------+ | ||
* | APP_ID | | SERVICE_ID | | ||
* | Foreground Application | | Background Service | | ||
* +----------------------------+ +--------------------------------+ | ||
* | | | ||
* | | | ||
* | 1. Request to luna://SERVICE_ID/echo | | ||
* | with parameters { input: "Hello, World!" } | | ||
* | | | ||
* | ---------------------------------------------------------------------> | | ||
* | | | ||
* | | | ||
* | 2. Response to APP_ID | | ||
* | with result '{ "echoMessage" : "Hello, World!" }' | | ||
* | | | ||
* | <--------------------------------------------------------------------- | | ||
* | | | ||
* \|/ \|/ | ||
* ' ' | ||
*/ | ||
bool echo(LSHandle *sh, LSMessage *message, void *data) | ||
{ | ||
LSError lserror; | ||
JSchemaInfo schemaInfo; | ||
jvalue_ref parsed = {0}, value = {0}; | ||
jvalue_ref jobj = {0}, jreturnValue = {0}; | ||
const char *input = NULL; | ||
char buf[BUF_SIZE] = {0, }; | ||
|
||
LSErrorInit(&lserror); | ||
|
||
// Initialize schema | ||
jschema_info_init (&schemaInfo, jschema_all(), NULL, NULL); | ||
|
||
// get message from LS2 and parsing to make object | ||
parsed = jdom_parse(j_cstr_to_buffer(LSMessageGetPayload(message)), DOMOPT_NOOPT, &schemaInfo); | ||
|
||
if (jis_null(parsed)) { | ||
j_release(&parsed); | ||
return true; | ||
} | ||
|
||
// Get value from payload.input | ||
value = jobject_get(parsed, j_cstr_to_buffer("input")); | ||
|
||
// JSON Object to string without schema validation check | ||
input = jvalue_tostring_simple(value); | ||
|
||
/** | ||
* JSON create test | ||
*/ | ||
jobj = jobject_create(); | ||
if (jis_null(jobj)) { | ||
j_release(&jobj); | ||
return true; | ||
} | ||
|
||
jreturnValue = jboolean_create(TRUE); | ||
jobject_set(jobj, j_cstr_to_buffer("returnValue"), jreturnValue); | ||
jobject_set(jobj, j_cstr_to_buffer("echoMessage"), value); | ||
|
||
LSMessageReply(sh, message, jvalue_tostring_simple(jobj), &lserror); | ||
|
||
j_release(&parsed); | ||
return true; | ||
} | ||
|
||
// Register background service and initialize | ||
int main(int argc, char* argv[]) | ||
{ | ||
LSError lserror; | ||
LSHandle *handle = NULL; | ||
bool bRetVal = FALSE; | ||
|
||
LSErrorInit(&lserror); | ||
|
||
// create a GMainLoop | ||
gmainLoop = g_main_loop_new(NULL, FALSE); | ||
|
||
bRetVal = LSRegister(SERVICE_NAME, &handle, &lserror); | ||
if (FALSE== bRetVal) { | ||
LSErrorFree( &lserror ); | ||
return 0; | ||
} | ||
sh = LSMessageGetConnection(message); | ||
|
||
LSRegisterCategory(handle,"/",sampleMethods, NULL, NULL, &lserror); | ||
|
||
LSGmainAttach(handle, gmainLoop, &lserror); | ||
|
||
// run to check continuously for new events from each of the event sources | ||
g_main_loop_run(gmainLoop); | ||
// Decreases the reference count on a GMainLoop object by one | ||
g_main_loop_unref(gmainLoop); | ||
|
||
return 0; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters