-
Notifications
You must be signed in to change notification settings - Fork 24
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* feat: check graph in ten_runtime --------- Co-authored-by: Hu Yueh-Wei <wei.hu.tw@gmail.com>
- Loading branch information
Showing
52 changed files
with
1,498 additions
and
64 deletions.
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
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,19 @@ | ||
// | ||
// Copyright © 2024 Agora | ||
// This file is part of TEN Framework, an open source project. | ||
// Licensed under the Apache License, Version 2.0, with certain conditions. | ||
// Refer to the "LICENSE" file in the root directory for more information. | ||
// | ||
#pragma once | ||
|
||
#include "ten_runtime/ten_config.h" | ||
|
||
#include <stdbool.h> | ||
|
||
#include "ten_utils/lib/error.h" | ||
#include "ten_utils/lib/json.h" | ||
|
||
typedef struct ten_app_t ten_app_t; | ||
|
||
TEN_RUNTIME_PRIVATE_API bool ten_app_check_start_graph_cmd_json( | ||
ten_app_t *self, ten_json_t *start_graph_cmd_json, ten_error_t *err); |
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 |
---|---|---|
|
@@ -12,4 +12,6 @@ glob("app") { | |
"msg_interface", | ||
"ten_env", | ||
] | ||
|
||
public_deps = [ "//core/src/ten_rust:ten_rust_binding" ] | ||
} |
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,51 @@ | ||
// | ||
// Copyright © 2024 Agora | ||
// This file is part of TEN Framework, an open source project. | ||
// Licensed under the Apache License, Version 2.0, with certain conditions. | ||
// Refer to the "LICENSE" file in the root directory for more information. | ||
// | ||
#include "include_internal/ten_runtime/app/graph.h" | ||
|
||
#include "include_internal/ten_runtime/app/app.h" | ||
#include "include_internal/ten_runtime/app/base_dir.h" | ||
#include "include_internal/ten_runtime/common/constant_str.h" | ||
#include "include_internal/ten_rust/ten_rust.h" | ||
#include "ten_runtime/app/app.h" | ||
#include "ten_utils/macro/memory.h" | ||
|
||
bool ten_app_check_start_graph_cmd_json(ten_app_t *self, | ||
ten_json_t *start_graph_cmd_json, | ||
ten_error_t *err) { | ||
TEN_ASSERT(self && ten_app_check_integrity(self, true), "Should not happen."); | ||
TEN_ASSERT(start_graph_cmd_json, "Invalid argument."); | ||
|
||
const char *base_dir = ten_app_get_base_dir(self); | ||
|
||
// The pkg_info of extensions in the graph is read from the ten_packages | ||
// directory under the base dir of app. If the base dir is not set, the app | ||
// might be running in a thread, ex: the smoke testing. In this case, we can | ||
// not retrieve the enough information to check the graph. | ||
if (!base_dir || ten_c_string_is_empty(base_dir)) { | ||
TEN_LOGD("The base dir of app [%s] is not set, skip checking graph.", | ||
ten_app_get_uri(self)); | ||
return true; | ||
} | ||
|
||
bool free_json_string = false; | ||
const char *graph_json_str = ten_json_to_string( | ||
start_graph_cmd_json, TEN_STR_UNDERLINE_TEN, &free_json_string); | ||
|
||
const char *err_msg = NULL; | ||
bool rc = ten_rust_check_graph_for_app(base_dir, graph_json_str, &err_msg); | ||
|
||
if (free_json_string) { | ||
TEN_FREE(graph_json_str); | ||
} | ||
|
||
if (!rc) { | ||
ten_error_set(err, TEN_ERRNO_INVALID_GRAPH, err_msg); | ||
ten_rust_free_cstring(err_msg); | ||
} | ||
|
||
return rc; | ||
} |
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
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
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
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
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
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,38 @@ | ||
// | ||
// Copyright © 2024 Agora | ||
// This file is part of TEN Framework, an open source project. | ||
// Licensed under the Apache License, Version 2.0, with certain conditions. | ||
// Refer to the "LICENSE" file in the root directory for more information. | ||
// | ||
use std::ffi::{c_char, CStr, CString}; | ||
|
||
#[no_mangle] | ||
pub extern "C" fn ten_rust_check_graph_for_app( | ||
app_base_dir: *const c_char, | ||
graph_json: *const c_char, | ||
out_err_msg: *mut *const c_char, | ||
) -> bool { | ||
assert!(!app_base_dir.is_null(), "Invalid argument."); | ||
assert!(!graph_json.is_null(), "Invalid argument."); | ||
|
||
let c_app_base_dir = unsafe { CStr::from_ptr(app_base_dir) }; | ||
let c_graph_json = unsafe { CStr::from_ptr(graph_json) }; | ||
|
||
let rust_app_base_dir = c_app_base_dir.to_str().unwrap(); | ||
let rust_graph_json = c_graph_json.to_str().unwrap(); | ||
|
||
let ret = crate::pkg_info::ten_rust_check_graph_for_app( | ||
rust_app_base_dir, | ||
rust_graph_json, | ||
); | ||
if ret.is_err() { | ||
let err_msg = ret.err().unwrap().to_string(); | ||
let c_err_msg = | ||
CString::new(err_msg).expect("Failed to allocate memory."); | ||
unsafe { | ||
*out_err_msg = c_err_msg.into_raw(); | ||
} | ||
return false; | ||
} | ||
true | ||
} |
Oops, something went wrong.