* @retval #ML_ERROR_PERMISSION_DENIED The application does not have the privilege to access to the storage.
* @retval #ML_ERROR_INVALID_PARAMETER Given parameter is invalid.
* @retval #ML_ERROR_IO_ERROR The operation of DB or filesystem has failed.
+ *
+ * Here is an example of the usage:
+ * @code
+ * // The machine-learning service API for model provides a method to share model files those can be used for ML application.
+ *
+ * /// Model Provider APP
+ * const gchar *key = "imgcls-mobilenet"; // The name shared among ML applications.
+ * gchar *model_path = g_strdup_printf ("%s/%s", app_get_shared_resource_path (), "mobilenet_v2.tflite"); // Provide the absolute file path.
+ * const bool is_active = true; // Parameter deciding whether to activate this model or not.
+ * const gchar *description = "This is the description of mobilenet_v2 model ..."; // Model description parameter.
+ * unsigned int version; // Out parameter for the version of registered model.
+ *
+ * // Register the model via ML Service API.
+ * int status;
+ * status = ml_service_model_register (key, model_path, is_active, description, &version);
+ * if (status != ML_ERROR_NONE) {
+ * // Handle error case.
+ * }
+ *
+ * /// Model Consumer APP
+ * const gchar *key = "imgcls-mobilenet"; // The name shared among ML applications.
+ * gchar *model_path; // Out parameter for the path of registered model.
+ * ml_information_h activated_model_info; // The ml_information handle for the activated model.
+ *
+ * // Get the model which is registered and activated by ML Service API.
+ * int status;
+ * status = ml_service_model_get_activated (key, &activated_model_info);
+ * if (status == ML_ERROR_NONE) {
+ * // Get the path of the model.
+ * gchar *activated_model_path;
+ * status = ml_information_get (activated_model_info, "path", (void **) &activated_model_path);
+ * model_path = g_strdup (activated_model_path);
+ * } else {
+ * // Handle error case.
+ * }
+ *
+ * ml_information_destroy (activated_model_info); // Release the information handle.
+ *
+ * // Do ML things with the variable `model_path`.
+ * @endcode
*/
int ml_service_model_register (const char *name, const char *path, const bool activate, const char *description, unsigned int *version);
/**
* @brief Gets the information of neural network model with given @a name and @a version.
* @since_tizen 8.0
- * @remarks If the function succeeds, the @a info should be released using ml_option_destroy().
+ * @remarks If the function succeeds, the @a info should be released using ml_information_destroy().
* @param[in] name The unique name to indicate the model.
* @param[in] version The version of registered model.
- * @param[out] info The handle of model.
+ * @param[out] info The handle of model information.
* @return 0 on success. Otherwise a negative error value.
* @retval #ML_ERROR_NONE Successful.
* @retval #ML_ERROR_NOT_SUPPORTED Not supported.
* @retval #ML_ERROR_IO_ERROR The operation of DB or filesystem has failed.
* @retval #ML_ERROR_OUT_OF_MEMORY Failed to allocate required memory.
*/
-int ml_service_model_get (const char *name, const unsigned int version, ml_option_h *info);
+int ml_service_model_get (const char *name, const unsigned int version, ml_information_h *info);
/**
* @brief Gets the information of activated neural network model with given @a name.
* @since_tizen 8.0
- * @remarks If the function succeeds, the @a info should be released using ml_option_destroy().
+ * @remarks If the function succeeds, the @a info should be released using ml_information_destroy().
* @param[in] name The unique name to indicate the model.
* @param[out] info The handle of activated model.
* @return 0 on success. Otherwise a negative error value.
* @retval #ML_ERROR_IO_ERROR The operation of DB or filesystem has failed.
* @retval #ML_ERROR_OUT_OF_MEMORY Failed to allocate required memory.
*/
-int ml_service_model_get_activated (const char *name, ml_option_h *info);
+int ml_service_model_get_activated (const char *name, ml_information_h *info);
/**
* @brief Gets the list of neural network model with given @a name.
* @since_tizen 8.0
- * @remarks If the function succeeds, each handle in @a info_list should be released using ml_option_destroy().
+ * @remarks If the function succeeds, the @a info_list should be released using ml_information_list_destroy().
* @param[in] name The unique name to indicate the model.
- * @param[out] info_list The handles of registered model.
- * @param[out] num Total number of registered model.
+ * @param[out] info_list The handle of list of registered models.
* @return 0 on success. Otherwise a negative error value.
* @retval #ML_ERROR_NONE Successful.
* @retval #ML_ERROR_NOT_SUPPORTED Not supported.
* @retval #ML_ERROR_IO_ERROR The operation of DB or filesystem has failed.
* @retval #ML_ERROR_OUT_OF_MEMORY Failed to allocate required memory.
*/
-int ml_service_model_get_all (const char *name, ml_option_h *info_list[], unsigned int *num);
+int ml_service_model_get_all (const char *name, ml_information_list_h *info_list);
/**
* @brief Deletes a model information with given @a name and @a version from machine learning service.
"It is highly suggested that `%s` before it is set."
/**
- * @brief Build ml_option_h from json cstring.
+ * @brief Build ml_information_h from json cstring.
*/
static gint
-_build_ml_opt_from_json_cstr (const gchar * jcstring, ml_option_h * opt)
+_build_ml_info_from_json_cstr (const gchar * jcstring, ml_information_h * _info)
{
g_autoptr (GError) err = NULL;
g_autoptr (JsonParser) parser = NULL;
GList *l;
gint ret;
- if (NULL == opt) {
+ if (NULL == _info) {
_ml_error_report_return (ML_ERROR_INVALID_PARAMETER,
"The argument for 'opt' should not be NULL.");
}
- if (NULL != *opt) {
+ if (NULL != *_info) {
_ml_logw (WARN_MSG_DPTR_SET_OVER, "opt");
- *opt = NULL;
+ *_info = NULL;
}
parser = json_parser_new ();
return ML_ERROR_INVALID_PARAMETER;
}
- ret = ml_option_create (opt);
+ ret = _ml_information_create (_info);
if (ML_ERROR_NONE != ret) {
return ret;
}
const gchar *key = l->data;
const gchar *val = json_object_get_string_member (jobj, key);
- ml_option_set (*opt, key, g_strdup (val), g_free);
+ _ml_information_set (*_info, key, g_strdup (val), g_free);
}
return ML_ERROR_NONE;
* @brief Parse app_info and update path (for model from rpk). Only for Tizen Applications.
*/
static int
-_parse_app_info_and_update_path (ml_option_h ml_info)
+_parse_app_info_and_update_path (ml_information_h ml_info)
{
int ret = ML_ERROR_NONE;
JsonObject *j_object;
/* parsing app_info and fill path (for rpk) */
- ret = ml_option_get (ml_info, "app_info", (void **) &app_info);
+ ret = ml_information_get (ml_info, "app_info", (void **) &app_info);
if (ret != ML_ERROR_NONE) {
_ml_error_report ("Failed to get app_info from the model info.");
return ret;
const gchar *res_type =
json_object_get_string_member (j_object, "res_type");
- ret = ml_option_get (ml_info, "path", (void **) &ori_path);
+ ret = ml_information_get (ml_info, "path", (void **) &ori_path);
if (ret != ML_ERROR_NONE) {
_ml_error_report ("Failed to get path from the model info.");
return ret;
}
new_path = g_strdup_printf ("%s/%s", global_resource_path, ori_path);
- ret = ml_option_set (ml_info, "path", new_path, g_free);
+ ret = _ml_information_set (ml_info, "path", new_path, g_free);
if (ret != ML_ERROR_NONE) {
_ml_error_report ("Failed to set path to the model info.");
return ret;
*/
int
ml_service_model_get (const char *name, const unsigned int version,
- ml_option_h * info)
+ ml_information_h * info)
{
int ret = ML_ERROR_NONE;
- ml_option_h _info = NULL;
+ ml_information_h _info = NULL;
g_autoptr (GError) err = NULL;
g_autofree gchar *description = NULL;
}
if (*info != NULL) {
- _ml_logw (WARN_MSG_DPTR_SET_OVER, "ml_option_h info = NULL");
+ _ml_logw (WARN_MSG_DPTR_SET_OVER, "ml_information_h info = NULL");
}
*info = NULL;
return ret;
}
- ret = _build_ml_opt_from_json_cstr (description, &_info);
+ ret = _build_ml_info_from_json_cstr (description, &_info);
if (ML_ERROR_NONE != ret) {
- _ml_error_report ("Failed to convert json string to ml_option_h.");
+ _ml_error_report ("Failed to convert json string to ml_information_h.");
goto error;
}
error:
if (ML_ERROR_NONE != ret && _info) {
- ml_option_destroy (_info);
+ ml_information_destroy (_info);
}
return ret;
* @brief Gets the information of activated neural network model with given @a name.
*/
int
-ml_service_model_get_activated (const char *name, ml_option_h * info)
+ml_service_model_get_activated (const char *name, ml_information_h * info)
{
int ret = ML_ERROR_NONE;
- ml_option_h _info = NULL;
+ ml_information_h _info = NULL;
g_autoptr (GError) err = NULL;
g_autofree gchar *description = NULL;
}
if (*info != NULL) {
- _ml_logw (WARN_MSG_DPTR_SET_OVER, "ml_option_h info = NULL");
+ _ml_logw (WARN_MSG_DPTR_SET_OVER, "ml_information_h info = NULL");
}
*info = NULL;
return ret;
}
- ret = _build_ml_opt_from_json_cstr (description, &_info);
+ ret = _build_ml_info_from_json_cstr (description, &_info);
if (ML_ERROR_NONE != ret) {
- _ml_error_report ("Failed to convert json string to ml_option_h.");
+ _ml_error_report ("Failed to convert json string to ml_information_h.");
goto error;
}
error:
if (ret != ML_ERROR_NONE && _info) {
- ml_option_destroy (_info);
+ ml_information_destroy (_info);
}
return ret;
* @brief Gets the list of neural network model with given @a name.
*/
int
-ml_service_model_get_all (const char *name, ml_option_h * info_list[],
- unsigned int *num)
+ml_service_model_get_all (const char *name, ml_information_list_h * info_list)
{
g_autofree gchar *description = NULL;
g_autoptr (GError) err = NULL;
- ml_option_h *_info_list = NULL;
+ ml_info_list_s *_info_list = NULL;
int ret = ML_ERROR_NONE;
guint i, n;
}
*info_list = NULL;
- if (NULL == num) {
- _ml_error_report_return (ML_ERROR_INVALID_PARAMETER,
- "The parameter 'num' should not be NULL.");
- }
- *num = 0;
-
ret = ml_agent_dbus_interface_model_get_all (name, &description, &err);
if (ML_ERROR_NONE != ret || !description) {
_ml_error_report ("Failed to invoke the method model_get_all (%s).",
return ret;
}
+ _info_list = g_try_new0 (ml_info_list_s, 1);
+ if (NULL == _info_list) {
+ _ml_error_report ("Failed to allocate memory for ml_info_list.");
+ return ML_ERROR_OUT_OF_MEMORY;
+ }
+
{
g_autoptr (JsonParser) parser = NULL;
JsonNode *rnode = NULL;
"Failed to retrieve the length of the json array.");
}
- _info_list = g_try_new0 (ml_option_h, n);
- if (!_info_list) {
+ _info_list->info = g_try_new0 (ml_info_s *, n);
+ if (!_info_list->info) {
+ g_free (_info_list);
_ml_error_report_return (ML_ERROR_OUT_OF_MEMORY,
- "Failed to allocate memory for list of ml_option_h. Out of memory?");
+ "Failed to allocate memory for list of ml_information_h. Out of memory?");
}
+ _info_list->length = n;
for (i = 0; i < n; i++) {
g_autoptr (GList) members = NULL;
JsonObject *jobj = NULL;
GList *l;
- if (ML_ERROR_NONE != ml_option_create (&_info_list[i])) {
+ if (ML_ERROR_NONE !=
+ _ml_information_create ((ml_information_h *) & _info_list->info[i])) {
_ml_error_report
- ("Failed to allocate memory for ml_option_h. Out of memory?");
+ ("Failed to allocate memory for ml_information. Out of memory?");
n = i;
ret = ML_ERROR_OUT_OF_MEMORY;
goto error;
const gchar *key = l->data;
const gchar *val = json_object_get_string_member (jobj, key);
- ml_option_set (_info_list[i], key, g_strdup (val), g_free);
+ _ml_information_set (_info_list->info[i], key, g_strdup (val), g_free);
}
- if (_parse_app_info_and_update_path (_info_list[i]) != 0) {
+ if (_parse_app_info_and_update_path ((ml_information_h)
+ _info_list->info[i]) != 0) {
_ml_error_report ("Failed to parse app_info and update path.");
ret = ML_ERROR_INVALID_PARAMETER;
goto error;
}
*info_list = _info_list;
- *num = n;
return ML_ERROR_NONE;
error:
if (_info_list) {
for (i = 0; i < n; i++) {
- if (_info_list[i]) {
- ml_option_destroy (_info_list[i]);
+ if (_info_list->info[i]) {
+ ml_information_destroy (_info_list->info[i]);
}
}
+ g_free (_info_list->info);
g_free (_info_list);
}