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

[Tizen] Use message port to communicate #348

Merged
merged 1 commit into from
Jul 9, 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
2 changes: 2 additions & 0 deletions Tizen.web/ImageClassificationOffloading/js/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import {
GetImgPath,
loadLabelInfo,
startHybridService,
startMessagePort,
} from "./utils.js";

let fHandle = null;
Expand Down Expand Up @@ -161,6 +162,7 @@ window.onload = async function () {
const networkType = await getNetworkType();
ip = await getIpAddress(networkType);
labels = loadLabelInfo();
startMessagePort();
startHybridService();
document.getElementById("start_local").addEventListener("click", function () {
runLocal();
Expand Down
19 changes: 19 additions & 0 deletions Tizen.web/ImageClassificationOffloading/js/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -132,3 +132,22 @@ export function startHybridService() {
console.log("Get AppContext failed, " + e);
}
}

export function startMessagePort() {
try {
const gLocalMessagePort =
tizen.messageport.requestLocalMessagePort("MESSAGE_PORT");
gLocalMessagePort.addMessagePortListener(function (data) {
for (var i = 0; i < data.length; i++) {
var key = data[i].key;
switch (key) {
case "command":
console.log("key:" + key + " / value:" + data[i].value);
break;
}
}
});
} catch (e) {
console.log("Failed to create local message port " + e.name);
}
}
2 changes: 2 additions & 0 deletions Tizen.web/ImageClassificationOffloadingService/inc/main.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,5 +16,7 @@
#endif
#define LOG_TAG "image_classification_offloading_service"

#define REMOTE_APP_ID "EQmf4iSfpX.ImageClassificationOffloading"
#define PORT_NAME "MESSAGE_PORT"

#endif /* __IMAGECLASSIFICATIONOFFLOADINGSERVICE_H__ */
20 changes: 20 additions & 0 deletions Tizen.web/ImageClassificationOffloadingService/src/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
*/

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

Expand Down Expand Up @@ -44,5 +46,23 @@ int main(int argc, char *argv[]) {

dlog_print(DLOG_ERROR, LOG_TAG,
"Image classification offloading service start");

bool found;
int ret = message_port_check_remote_port(REMOTE_APP_ID, PORT_NAME, &found);

if (ret != MESSAGE_PORT_ERROR_NONE || !found) {
dlog_print(DLOG_ERROR, LOG_TAG, "Failed to check remote port");
}

/* Todo: Send network information to ui application */
bundle *b = bundle_create();
bundle_add_str(b, "command", "connected");
ret = message_port_send_message(REMOTE_APP_ID, PORT_NAME, b);
if (ret != MESSAGE_PORT_ERROR_NONE) {
dlog_print(DLOG_ERROR, LOG_TAG, "Failed to send message to %s:%s",
REMOTE_APP_ID, PORT_NAME);
}
bundle_free(b);

return service_app_main(argc, argv, &event_callback, NULL);
}