15 #include <json-glib/json-glib.h>
17 #include <mlops-agent-interface.h>
35 g_autofree gchar *scheme = NULL;
36 g_autofree gchar *uri = g_value_dup_string (val);
45 scheme = g_uri_parse_scheme (uri);
46 if (!scheme || g_strcmp0 (
URI_SCHEME, scheme)) {
47 return g_steal_pointer (&uri);
50 uri_hier_part = g_strstr_len (uri, -1,
":");
51 while (*uri_hier_part ==
':' || *uri_hier_part ==
'/') {
63 parts = g_strsplit_set (uri_hier_part,
"/", 0);
65 enum MODEL_PART_CONSTANTS
67 MODEL_PART_IDX_NAME = 1,
68 MODEL_PART_IDX_VERSION = 2,
69 MODEL_VERSION_MIN = 1,
70 MODEL_VERSION_MAX = 255,
72 const size_t NUM_PARTS_MODEL = 3;
75 num_parts = g_strv_length (parts);
82 g_autofree gchar *name = g_strdup (parts[MODEL_PART_IDX_NAME]);
83 g_autofree gchar *stringified_json = NULL;
84 g_autoptr (JsonParser) json_parser = NULL;
87 if (num_parts < NUM_PARTS_MODEL - 1) {
95 if (num_parts == NUM_PARTS_MODEL - 1) {
96 rcode = ml_agent_model_get_activated (name, &stringified_json);
98 guint version = strtoul (parts[MODEL_PART_IDX_VERSION], NULL, 10);
99 rcode = ml_agent_model_get (name, version, &stringified_json);
104 (
"Failed to get the stringified JSON using the given URI(%s)", uri);
108 json_parser = json_parser_new ();
110 if (!json_parser_load_from_data (json_parser, stringified_json, -1, &err)) {
111 nns_loge (
"Failed to parse the stringified JSON while "
112 "get the model's path: %s",
113 (err ? err->message :
"unknown reason"));
116 g_clear_error (&err);
119 const gchar *path = NULL;
123 jroot = json_parser_get_root (json_parser);
125 nns_loge (
"Failed to get JSON root node while get the model's path");
129 jobj = json_node_get_object (jroot);
132 (
"Failed to get JSON object from the root node while get the model's path");
138 (
"Failed to get the model's path from the given URI: "
139 "There is no key named, %s, in the JSON object",
145 if (path == NULL || !g_strcmp0 (path,
"")) {
147 (
"Failed to get the model's path from the given URI: "
153 return g_strdup (path);
159 g_clear_error (&err);
162 return g_strdup (uri);