Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Launch native service in web application #345

Merged
merged 2 commits into from
Jul 6, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion Tizen.web/ImageClassificationOffloading/js/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import {
GetMaxIdx,
GetImgPath,
loadLabelInfo,
startHybridService,
} from "./utils.js";

let fHandle = null;
Expand Down Expand Up @@ -160,7 +161,7 @@ window.onload = async function () {
const networkType = await getNetworkType();
ip = await getIpAddress(networkType);
labels = loadLabelInfo();

startHybridService();
document.getElementById("start_local").addEventListener("click", function () {
runLocal();
});
Expand Down
60 changes: 60 additions & 0 deletions Tizen.web/ImageClassificationOffloading/js/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
* @author Yelin Jeong <[email protected]>
*/

let gServiceAppId = "EQmf4iSfpX.imageclassificationoffloadingservice";

/**
* Get currently used network type
* @returns the network type
Expand Down Expand Up @@ -72,3 +74,61 @@ export function loadLabelInfo() {
const labelList = fHandle.readString();
return labelList.split("\n");
}

function launchServiceApp() {
function onSuccess() {
console.log("Service App launched successfully");
}

function onError(err) {
console.error("Service App launch failed", err);
}

try {
console.log("Launching [" + gServiceAppId + "] ...");
tizen.application.launch(gServiceAppId, onSuccess, onError);
} catch (exc) {
console.error("Exception while launching HybridServiceApp: " + exc.message);
}
}

function onGetAppsContextSuccess(contexts) {
let i = 0;
let appInfo = null;

for (i = 0; i < contexts.length; i = i + 1) {
try {
appInfo = tizen.application.getAppInfo(contexts[i].appId);
} catch (exc) {
console.error("Exception while getting application info " + exc.message);
}

if (appInfo.id === gServiceAppId) {
break;
}
}

if (i >= contexts.length) {
console.log("Service App not found, Trying to launch service app");
launchServiceApp();
}
}

function onGetAppsContextError(err) {
console.error("getAppsContext exc", err);
}

/**
* Starts obtaining information about applications
* that are currently running on a device.
*/
export function startHybridService() {
try {
tizen.application.getAppsContext(
onGetAppsContextSuccess,
onGetAppsContextError,
);
} catch (e) {
console.log("Get AppContext failed, " + e);
}
}
658 changes: 658 additions & 0 deletions Tizen.web/ImageClassificationOffloadingService/.cproject

Large diffs are not rendered by default.

5 changes: 5 additions & 0 deletions Tizen.web/ImageClassificationOffloadingService/.exportMap
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
global: main;
_IO_*;
local: *;
};
46 changes: 46 additions & 0 deletions Tizen.web/ImageClassificationOffloadingService/.project
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
<?xml version="1.0" encoding="UTF-8"?>
<projectDescription>
<name>ImageClassificationOffloadingService</name>
<comment></comment>
<projects>
</projects>
<buildSpec>
<buildCommand>
<name>org.eclipse.cdt.managedbuilder.core.genmakebuilder</name>
<arguments>
</arguments>
</buildCommand>
<buildCommand>
<name>org.eclipse.cdt.managedbuilder.core.ScannerConfigBuilder</name>
<triggers>full,incremental,</triggers>
<arguments>
</arguments>
</buildCommand>
</buildSpec>
<natures>
<nature>org.eclipse.cdt.core.cnature</nature>
<nature>org.eclipse.cdt.core.ccnature</nature>
<nature>org.eclipse.cdt.managedbuilder.core.managedBuildNature</nature>
<nature>org.eclipse.cdt.managedbuilder.core.ScannerConfigNature</nature>
</natures>
<filteredResources>
<filter>
<id>1719816172307</id>
<name></name>
<type>26</type>
<matcher>
<id>org.eclipse.ui.ide.multiFilter</id>
<arguments>1.0-projectRelativePath-matches-false-false-*/.tpk</arguments>
</matcher>
</filter>
<filter>
<id>1719816172309</id>
<name></name>
<type>6</type>
<matcher>
<id>org.eclipse.ui.ide.multiFilter</id>
<arguments>1.0-name-matches-false-false-project_def.prop</arguments>
</matcher>
</filter>
</filteredResources>
</projectDescription>
12 changes: 12 additions & 0 deletions Tizen.web/ImageClassificationOffloadingService/.tproject
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<tproject xmlns="http://www.tizen.org/tproject">
<platforms>
<platform>
<name>tizen-8.0</name>
</platform>
</platforms>
<package>
<blacklist/>
<resFallback autoGen="true"/>
</package>
</tproject>
20 changes: 20 additions & 0 deletions Tizen.web/ImageClassificationOffloadingService/inc/main.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
/**
* @file main.h
* @date 04 Jul 2024
* @brief Tizen native service for hybrid application
* @author Yelin Jeong <[email protected]>
* @bug No known bugs.
*/

#ifndef __IMAGECLASSIFICATIONOFFLOADINGSERVICE_H__
#define __IMAGECLASSIFICATIONOFFLOADINGSERVICE_H__

#include <dlog.h>

#ifdef LOG_TAG
#undef LOG_TAG
#endif
#define LOG_TAG "image_classification_offloading_service"


#endif /* __IMAGECLASSIFICATIONOFFLOADINGSERVICE_H__ */
11 changes: 11 additions & 0 deletions Tizen.web/ImageClassificationOffloadingService/project_def.prop
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
APPNAME = imageclassificationoffloadingservice

type = app
profile = tizen-8.0

USER_SRCS = src/main.c
USER_DEFS =
USER_INC_DIRS = inc
USER_OBJS =
USER_LIBS =
USER_EDCS =
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
48 changes: 48 additions & 0 deletions Tizen.web/ImageClassificationOffloadingService/src/main.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
/**
* @file main.c
* @date 04 Jul 2024
* @brief Tizen native service for hybrid application
* @author Yelin Jeong <[email protected]>
* @bug No known bugs.
*/

#include "main.h"
#include <service_app.h>
#include <tizen.h>

/**
* @brief Service app create callback
*/
static bool _create_cb(void* user_data){
dlog_print(DLOG_INFO, LOG_TAG, "Callback create\n");
return true;
}

/**
* @brief Service app terminate callback
*/
static void _terminate_cb(void* user_data){
dlog_print(DLOG_INFO, LOG_TAG, "Callback terminate\n");
}

/**
* @brief Service app app control callback
*/
static void _app_control_cb(app_control_h app_control, void* user_data){
dlog_print(DLOG_INFO, LOG_TAG, "Callback app_control\n");
}

/**
* @brief Main function.
*/
int main(int argc, char *argv[]) {
service_app_lifecycle_callback_s event_callback = {
.create = _create_cb,
.terminate = _terminate_cb,
.app_control = _app_control_cb
};

dlog_print(DLOG_ERROR, LOG_TAG,
"Image classification offloading service start");
return service_app_main(argc, argv, &event_callback, NULL);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns="http://tizen.org/ns/packages" api-version="8.0" package="EQmf4iSfpX" version="1.0.0">
<profile name="tizen" />
<service-application appid="EQmf4iSfpX.imageclassificationoffloadingservice" exec="imageclassificationoffloadingservice" type="capp" multiple="false" taskmanage="false" nodisplay="true">
<icon>imageclassificationoffloadingservice.png</icon>
<label>imageclassificationoffloadingservice</label>
</service-application>
</manifest>