Skip to content

Commit 7f8530c

Browse files
committed
[Android] replace app data path
Add internal function to replace app data path for android. Signed-off-by: Jaeyun Jung <[email protected]>
1 parent 9e15563 commit 7f8530c

File tree

6 files changed

+50
-13
lines changed

6 files changed

+50
-13
lines changed

c/src/ml-api-common.c

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1169,6 +1169,28 @@ _ml_replace_string (gchar * source, const gchar * what, const gchar * to,
11691169
return result;
11701170
}
11711171

1172+
/**
1173+
* @brief Converts predefined entity.
1174+
*/
1175+
gchar *
1176+
_ml_convert_predefined_entity (const gchar * str)
1177+
{
1178+
gchar *converted = g_strdup (str);
1179+
1180+
#if defined(__ANDROID__)
1181+
{
1182+
extern const char *nnstreamer_native_get_data_path (void);
1183+
1184+
const char *data_path = nnstreamer_native_get_data_path ();
1185+
1186+
converted = _ml_replace_string (converted, "@APP_DATA_PATH@", data_path,
1187+
NULL, NULL);
1188+
}
1189+
#endif
1190+
1191+
return converted;
1192+
}
1193+
11721194
/**
11731195
* @brief error reporting infra
11741196
*/

c/src/ml-api-inference-pipeline.c

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -614,8 +614,8 @@ cleanup_resource (gpointer data)
614614
* @brief Converts predefined element in pipeline description.
615615
*/
616616
static int
617-
convert_element (ml_pipeline_h pipe, const gchar * description, gchar ** result,
618-
gboolean is_internal)
617+
convert_description (ml_pipeline_h pipe, const gchar * description,
618+
gchar ** result, gboolean is_internal)
619619
{
620620
gchar *converted;
621621
int status = ML_ERROR_NONE;
@@ -626,7 +626,7 @@ convert_element (ml_pipeline_h pipe, const gchar * description, gchar ** result,
626626
/* init null */
627627
*result = NULL;
628628

629-
converted = g_strdup (description);
629+
converted = _ml_convert_predefined_entity (description);
630630

631631
/* convert pre-defined element for Tizen */
632632
status = convert_tizen_element (pipe, &converted, is_internal);
@@ -1020,12 +1020,11 @@ construct_pipeline_internal (const char *pipeline_description,
10201020
create_internal_hash (pipe_h);
10211021

10221022
/* convert predefined element and launch the pipeline */
1023-
status =
1024-
convert_element ((ml_pipeline_h) pipe_h, pipeline_description,
1023+
status = convert_description ((ml_pipeline_h) pipe_h, pipeline_description,
10251024
&description, is_internal);
10261025
if (status != ML_ERROR_NONE) {
10271026
_ml_error_report_continue
1028-
("ml_pipeline_construct error: failed while converting pipeline description for GStreamer w/ convert_element() function, which has returned %d",
1027+
("ml_pipeline_construct error: failed while converting pipeline description for GStreamer w/ convert_description() function, which has returned %d",
10291028
status);
10301029
goto failed;
10311030
}

c/src/ml-api-inference-single.c

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -944,6 +944,7 @@ ml_single_open_custom (ml_single_h * single, ml_single_preset * info)
944944
ml_nnfw_type_e nnfw;
945945
ml_nnfw_hw_e hw;
946946
const gchar *fw_name;
947+
g_autofree gchar *converted_models = NULL;
947948
gchar **list_models;
948949
guint i, num_models;
949950
char *hw_name;
@@ -963,11 +964,12 @@ ml_single_open_custom (ml_single_h * single, ml_single_preset * info)
963964
nnfw = info->nnfw;
964965
hw = info->hw;
965966
fw_name = _ml_get_nnfw_subplugin_name (nnfw);
967+
converted_models = _ml_convert_predefined_entity (info->models);
966968

967969
/**
968970
* 1. Determine nnfw and validate model file
969971
*/
970-
list_models = g_strsplit (info->models, ",", -1);
972+
list_models = g_strsplit (converted_models, ",", -1);
971973
num_models = g_strv_length (list_models);
972974
for (i = 0; i < num_models; i++)
973975
g_strstrip (list_models[i]);
@@ -1069,7 +1071,7 @@ ml_single_open_custom (ml_single_h * single, ml_single_preset * info)
10691071
}
10701072
hw_name = _ml_nnfw_to_str_prop (hw);
10711073
g_object_set (filter_obj, "framework", fw_name, "accelerator", hw_name,
1072-
"model", info->models, NULL);
1074+
"model", converted_models, NULL);
10731075
g_free (hw_name);
10741076

10751077
if (info->custom_option) {

c/src/ml-api-internal.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -275,6 +275,13 @@ int _ml_tensors_data_clone_no_alloc (const ml_tensors_data_s * data_src, ml_tens
275275
*/
276276
gchar * _ml_replace_string (gchar * source, const gchar * what, const gchar * to, const gchar * delimiters, guint * count);
277277

278+
/**
279+
* @brief Converts predefined entity.
280+
* @param[in] str The input string.
281+
* @return Newly allocated string. The returned string should be freed with g_free().
282+
*/
283+
gchar * _ml_convert_predefined_entity (const gchar * str);
284+
278285
/**
279286
* @brief Compares the given tensors information.
280287
* @details If the function returns an error, @a equal is not changed.

c/src/ml-api-service-agent-client.c

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -429,6 +429,7 @@ ml_service_model_register (const char *name, const char *path,
429429
{
430430
int ret = ML_ERROR_NONE;
431431
g_autofree gchar *app_info = NULL;
432+
g_autofree gchar *converted = NULL;
432433

433434
check_feature_state (ML_FEATURE_SERVICE);
434435

@@ -443,13 +444,14 @@ ml_service_model_register (const char *name, const char *path,
443444
}
444445
*version = 0U;
445446

446-
ret = _ml_service_check_path (path);
447+
converted = _ml_convert_predefined_entity (path);
448+
ret = _ml_service_check_path (converted);
447449
if (ret != ML_ERROR_NONE)
448450
return ret;
449451

450452
app_info = _get_app_info ();
451453

452-
ret = ml_agent_model_register (name, path, activate,
454+
ret = ml_agent_model_register (name, converted, activate,
453455
description ? description : "", app_info ? app_info : "", version);
454456
if (ret < 0) {
455457
_ml_error_report ("Failed to invoke the method model_register.");
@@ -675,6 +677,7 @@ ml_service_resource_add (const char *name, const char *path,
675677
{
676678
int ret = ML_ERROR_NONE;
677679
g_autofree gchar *app_info = NULL;
680+
g_autofree gchar *converted = NULL;
678681

679682
check_feature_state (ML_FEATURE_SERVICE);
680683

@@ -683,13 +686,14 @@ ml_service_resource_add (const char *name, const char *path,
683686
"The parameter, 'name' is NULL. It should be a valid string.");
684687
}
685688

686-
ret = _ml_service_check_path (path);
689+
converted = _ml_convert_predefined_entity (path);
690+
ret = _ml_service_check_path (converted);
687691
if (ret != ML_ERROR_NONE)
688692
return ret;
689693

690694
app_info = _get_app_info ();
691695

692-
ret = ml_agent_resource_add (name, path, description ? description : "",
696+
ret = ml_agent_resource_add (name, converted, description ? description : "",
693697
app_info ? app_info : "");
694698
if (ret < 0) {
695699
_ml_error_report ("Failed to invoke the method resource_add.");

c/src/ml-api-service.c

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -306,6 +306,7 @@ ml_service_new (const char *config, ml_service_h * handle)
306306
ml_service_s *mls;
307307
ml_service_type_e service_type = ML_SERVICE_TYPE_UNKNOWN;
308308
g_autofree gchar *json_string = NULL;
309+
g_autofree gchar *contents = NULL;
309310
g_autoptr (JsonParser) parser = NULL;
310311
g_autoptr (GError) err = NULL;
311312
JsonNode *root;
@@ -328,11 +329,13 @@ ml_service_new (const char *config, ml_service_h * handle)
328329
"The parameter, config, is invalid. It should be a valid path.");
329330
}
330331

331-
if (!g_file_get_contents (config, &json_string, NULL, NULL)) {
332+
if (!g_file_get_contents (config, &contents, NULL, NULL)) {
332333
_ml_error_report_return (ML_ERROR_IO_ERROR,
333334
"Failed to read configuration file '%s'.", config);
334335
}
335336

337+
json_string = _ml_convert_predefined_entity (contents);
338+
336339
parser = json_parser_new ();
337340
if (!parser) {
338341
_ml_error_report_return (ML_ERROR_OUT_OF_MEMORY,

0 commit comments

Comments
 (0)