Tizen Native API  8.0

The NNStreamer Service API provides interfaces to store and fetch the pipeline description for AI application developers.

Required Header

#include <nnstreamer/ml-api-service.h>

Overview

The NNStreamer Service API provides utility interfaces for AI application developers.

This function allows the following operations with NNStreamer:

  • Set and get the pipeline description with a given name.
  • Delete the pipeline description with a given name.

Note that this function set is supposed to be thread-safe.

Related Features

This function is related with the following features:

  • http://tizen.org/feature/machine_learning
  • http://tizen.org/feature/machine_learning.service

Functions

int ml_service_new (const char *config, ml_service_h *handle)
 Creates a handle for machine learning service using a configuration file.
int ml_service_set_event_cb (ml_service_h handle, ml_service_event_cb cb, void *user_data)
 Sets the callback which will be invoked when a new event occurs from machine learning service.
int ml_service_start (ml_service_h handle)
 Starts the process of machine learning service.
int ml_service_stop (ml_service_h handle)
 Stops the process of machine learning service.
int ml_service_get_input_information (ml_service_h handle, const char *name, ml_tensors_info_h *info)
 Gets the information of required input data.
int ml_service_get_output_information (ml_service_h handle, const char *name, ml_tensors_info_h *info)
 Gets the information of output data.
int ml_service_set_information (ml_service_h handle, const char *name, const char *value)
 Sets the information for machine learning service.
int ml_service_get_information (ml_service_h handle, const char *name, char **value)
 Gets the information from machine learning service.
int ml_service_request (ml_service_h handle, const char *name, const ml_tensors_data_h data)
 Adds an input data to process the model in machine learning service.
int ml_service_destroy (ml_service_h handle)
 Destroys the handle for machine learning service.
int ml_service_pipeline_set (const char *name, const char *pipeline_desc)
 Sets the pipeline description with a given name.
int ml_service_pipeline_get (const char *name, char **pipeline_desc)
 Gets the pipeline description with a given name.
int ml_service_pipeline_delete (const char *name)
 Deletes the pipeline description with a given name.
int ml_service_pipeline_launch (const char *name, ml_service_h *handle)
 Launches the pipeline of given service and gets the service handle.
int ml_service_pipeline_get_state (ml_service_h handle, ml_pipeline_state_e *state)
 Gets the state of given handle's pipeline.
int ml_service_query_create (ml_option_h option, ml_service_h *handle)
 Creates query service handle with given ml-option handle.
int ml_service_query_request (ml_service_h handle, const ml_tensors_data_h input, ml_tensors_data_h *output)
 Requests the query service to process the input and produce an output.
int ml_service_model_register (const char *name, const char *path, const bool activate, const char *description, unsigned int *version)
 Registers new information of a neural network model.
int ml_service_model_update_description (const char *name, const unsigned int version, const char *description)
 Updates the description of neural network model with given name and version.
int ml_service_model_activate (const char *name, const unsigned int version)
 Activates a neural network model with given name and version.
int ml_service_model_get (const char *name, const unsigned int version, ml_information_h *info)
 Gets the information of neural network model with given name and version.
int ml_service_model_get_activated (const char *name, ml_information_h *info)
 Gets the information of activated neural network model with given name.
int ml_service_model_get_all (const char *name, ml_information_list_h *info_list)
 Gets the list of neural network model with given name.
int ml_service_model_delete (const char *name, const unsigned int version)
 Deletes a model information with given name and version from machine learning service.
int ml_service_resource_add (const char *name, const char *path, const char *description)
 Adds new information of machine learning resources those contain images, audio samples, binary files, and so on.
int ml_service_resource_delete (const char *name)
 Deletes the information of the resources from machine learning service.
int ml_service_resource_get (const char *name, ml_information_list_h *res)
 Gets the information of the resources from machine learning service.

Typedefs

typedef void * ml_service_h
 A handle for ml-service instance.
typedef void(* ml_service_event_cb )(ml_service_event_e event, ml_information_h event_data, void *user_data)
 Callback for the event from machine learning service.

Typedef Documentation

typedef void(* ml_service_event_cb)(ml_service_event_e event, ml_information_h event_data, void *user_data)

Callback for the event from machine learning service.

Note that the handle of event data may be deallocated after the return and this is synchronously called. Thus, if you need the event data, copy the data and return fast. Do not spend too much time in the callback.

Since :
9.0
Remarks:
The event_data should not be released.
Parameters:
[in]eventThe event from machine learning service.
[in]event_dataThe handle of event data. If it is null, the event does not include data field.
[in]user_dataPrivate data for the callback.
typedef void* ml_service_h

A handle for ml-service instance.

Since :
7.0

Enumeration Type Documentation

Enumeration for the event types of machine learning service.

Since :
9.0
Enumerator:
ML_SERVICE_EVENT_UNKNOWN 

Unknown or invalid event type.

ML_SERVICE_EVENT_NEW_DATA 

New data is processed from machine learning service.


Function Documentation

Destroys the handle for machine learning service.

If given service handle is created by ml_service_pipeline_launch(), this requests machine learning agent to destroy the pipeline.

Since :
7.0
Parameters:
[in]handleThe handle of ml-service.
Returns:
0 on success. Otherwise a negative error value.
Return values:
ML_ERROR_NONESuccessful.
ML_ERROR_NOT_SUPPORTEDNot supported.
ML_ERROR_INVALID_PARAMETERThe parameter is invalid.
ML_ERROR_STREAMS_PIPEFailed to stop the process.
int ml_service_get_information ( ml_service_h  handle,
const char *  name,
char **  value 
)

Gets the information from machine learning service.

Note that a configuration file may not have such information field.

Since :
9.0
Remarks:
The value should be released using free().
Parameters:
[in]handleThe handle of ml-service.
[in]nameThe name to get the corresponding value.
[out]valueThe value of the name.
Returns:
0 on success. Otherwise a negative error value.
Return values:
ML_ERROR_NONESuccessful.
ML_ERROR_NOT_SUPPORTEDNot supported.
ML_ERROR_INVALID_PARAMETERThe parameter is invalid.
int ml_service_get_input_information ( ml_service_h  handle,
const char *  name,
ml_tensors_info_h info 
)

Gets the information of required input data.

Note that a model may not have such information if its input type is not determined statically.

Since :
9.0
Remarks:
The info should be released using ml_tensors_info_destroy().
Parameters:
[in]handleThe handle of ml-service.
[in]nameThe name of input node in the pipeline. You can set NULL if ml-service is constructed from model configuration.
[out]infoThe handle of input tensors information.
Returns:
0 on success. Otherwise a negative error value.
Return values:
ML_ERROR_NONESuccessful.
ML_ERROR_NOT_SUPPORTEDNot supported.
ML_ERROR_INVALID_PARAMETERThe parameter is invalid.
int ml_service_get_output_information ( ml_service_h  handle,
const char *  name,
ml_tensors_info_h info 
)

Gets the information of output data.

Note that a model may not have such information if its output is not determined statically.

Since :
9.0
Remarks:
The info should be released using ml_tensors_info_destroy().
Parameters:
[in]handleThe handle of ml-service.
[in]nameThe name of output node in the pipeline. You can set NULL if ml-service is constructed from model configuration.
[out]infoThe handle of output tensors information.
Returns:
0 on success. Otherwise a negative error value.
Return values:
ML_ERROR_NONESuccessful.
ML_ERROR_NOT_SUPPORTEDNot supported.
ML_ERROR_INVALID_PARAMETERThe parameter is invalid.
int ml_service_model_activate ( const char *  name,
const unsigned int  version 
)

Activates a neural network model with given name and version.

Since :
8.0
Parameters:
[in]nameThe unique name to indicate the model.
[in]versionThe version of registered model.
Returns:
0 on success. Otherwise a negative error value.
Return values:
ML_ERROR_NONESuccessful.
ML_ERROR_NOT_SUPPORTEDNot supported.
ML_ERROR_INVALID_PARAMETERGiven parameter is invalid.
ML_ERROR_IO_ERRORThe operation of DB or filesystem has failed.
int ml_service_model_delete ( const char *  name,
const unsigned int  version 
)

Deletes a model information with given name and version from machine learning service.

Since :
8.0
Remarks:
This does not remove the model file from file system. If version is 0, machine learning service will delete all information with given name.
Parameters:
[in]nameThe unique name to indicate the model.
[in]versionThe version of registered model.
Returns:
0 on success. Otherwise a negative error value.
Return values:
ML_ERROR_NONESuccessful.
ML_ERROR_NOT_SUPPORTEDNot supported.
ML_ERROR_INVALID_PARAMETERGiven parameter is invalid.
ML_ERROR_IO_ERRORThe operation of DB or filesystem has failed.
int ml_service_model_get ( const char *  name,
const unsigned int  version,
ml_information_h info 
)

Gets the information of neural network model with given name and version.

Since :
8.0
Remarks:
If the function succeeds, the info should be released using ml_information_destroy().
Parameters:
[in]nameThe unique name to indicate the model.
[in]versionThe version of registered model.
[out]infoThe handle of model information.
Returns:
0 on success. Otherwise a negative error value.
Return values:
ML_ERROR_NONESuccessful.
ML_ERROR_NOT_SUPPORTEDNot supported.
ML_ERROR_INVALID_PARAMETERGiven parameter is invalid.
ML_ERROR_IO_ERRORThe operation of DB or filesystem has failed.
ML_ERROR_OUT_OF_MEMORYFailed to allocate required memory.
int ml_service_model_get_activated ( const char *  name,
ml_information_h info 
)

Gets the information of activated neural network model with given name.

Since :
8.0
Remarks:
If the function succeeds, the info should be released using ml_information_destroy().
Parameters:
[in]nameThe unique name to indicate the model.
[out]infoThe handle of activated model.
Returns:
0 on success. Otherwise a negative error value.
Return values:
ML_ERROR_NONESuccessful.
ML_ERROR_NOT_SUPPORTEDNot supported.
ML_ERROR_INVALID_PARAMETERGiven parameter is invalid.
ML_ERROR_IO_ERRORThe operation of DB or filesystem has failed.
ML_ERROR_OUT_OF_MEMORYFailed to allocate required memory.
int ml_service_model_get_all ( const char *  name,
ml_information_list_h info_list 
)

Gets the list of neural network model with given name.

Since :
8.0
Remarks:
If the function succeeds, the info_list should be released using ml_information_list_destroy().
Parameters:
[in]nameThe unique name to indicate the model.
[out]info_listThe handle of list of registered models.
Returns:
0 on success. Otherwise a negative error value.
Return values:
ML_ERROR_NONESuccessful.
ML_ERROR_NOT_SUPPORTEDNot supported.
ML_ERROR_INVALID_PARAMETERGiven parameter is invalid.
ML_ERROR_IO_ERRORThe operation of DB or filesystem has failed.
ML_ERROR_OUT_OF_MEMORYFailed to allocate required memory.
int ml_service_model_register ( const char *  name,
const char *  path,
const bool  activate,
const char *  description,
unsigned int *  version 
)

Registers new information of a neural network model.

Since :
8.0
Remarks:
Only one model can be activated with given name. If same name is already registered in machine learning service, this returns no error and old model will be deactivated when the flag activate is true.
http://tizen.org/privilege/mediastorage is needed if model file is relevant to media storage.
http://tizen.org/privilege/externalstorage is needed if model file is relevant to external storage.
Parameters:
[in]nameThe unique name to indicate the model.
[in]pathThe path to neural network model.
[in]activateThe flag to set the model to be activated.
[in]descriptionNullable, description for neural network model.
[out]versionThe version of registered model.
Returns:
0 on success. Otherwise a negative error value.
Return values:
ML_ERROR_NONESuccessful.
ML_ERROR_NOT_SUPPORTEDNot supported.
ML_ERROR_PERMISSION_DENIEDThe application does not have the privilege to access to the storage.
ML_ERROR_INVALID_PARAMETERGiven parameter is invalid.
ML_ERROR_IO_ERRORThe operation of DB or filesystem has failed.

Here is an example of the usage:

 // The machine-learning service API for model provides a method to share model files those can be used for ML application.

 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.
 }

 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`.
int ml_service_model_update_description ( const char *  name,
const unsigned int  version,
const char *  description 
)

Updates the description of neural network model with given name and version.

Since :
8.0
Parameters:
[in]nameThe unique name to indicate the model.
[in]versionThe version of registered model.
[in]descriptionThe description for neural network model.
Returns:
0 on success. Otherwise a negative error value.
Return values:
ML_ERROR_NONESuccessful.
ML_ERROR_NOT_SUPPORTEDNot supported.
ML_ERROR_INVALID_PARAMETERGiven parameter is invalid.
ML_ERROR_IO_ERRORThe operation of DB or filesystem has failed.
int ml_service_new ( const char *  config,
ml_service_h handle 
)

Creates a handle for machine learning service using a configuration file.

Since :
9.0
Remarks:
http://tizen.org/privilege/mediastorage is needed if the configuration is relevant to media storage.
http://tizen.org/privilege/externalstorage is needed if the configuration is relevant to external storage.
The handle should be released using ml_service_destroy().
Parameters:
[in]configThe absolute path to configuration file.
[out]handleThe handle of ml-service.
Returns:
0 on success. Otherwise a negative error value.
Return values:
ML_ERROR_NONESuccessful.
ML_ERROR_NOT_SUPPORTEDNot supported.
ML_ERROR_PERMISSION_DENIEDThe application does not have the privilege to access to the media storage or external storage.
ML_ERROR_INVALID_PARAMETERThe parameter is invalid.
ML_ERROR_IO_ERRORFailed to parse the configuration file.
ML_ERROR_STREAMS_PIPEFailed to open the model.
ML_ERROR_OUT_OF_MEMORYFailed to allocate required memory.

Here is an example of the usage:

 // Callback function for the event from machine learning service.
 // Note that the handle of event data will be deallocated after the return and this is synchronously called.
 // Thus, if you need the event data, copy the data and return fast.
 // Do not spend too much time in the callback.
 static void
 _ml_service_event_cb (ml_service_event_e event, ml_information_h event_data, void *user_data)
 {
   ml_tensors_data_h data;
   void *_data;
   size_t _size;

   switch (event) {
     case ML_SERVICE_EVENT_NEW_DATA:
       // For the case of new data event, handle output data.
       ml_information_get (event_data, "data", &data);
       ml_tensors_data_get_tensor_data (data, 0, &_data, &_size);
       break;
     default:
       break;
   }
 }

 // The path to the configuration file.
 const char config_path[] = "/path/to/application/configuration/my_application_config.conf";

 // Create ml-service for model inference from configuration.
 ml_service_h handle;

 ml_service_new (config_path, &handle);
 ml_service_set_event_cb (handle, _ml_service_event_cb, NULL);

 // Get input information and allocate input buffer.
 ml_tensors_info_h input_info;
 void *input_buffer;
 size_t input_size;

 ml_service_get_input_information (handle, NULL, &input_info);

 ml_tensors_info_get_tensor_size (input_info, 0, &input_size);
 input_buffer = malloc (input_size);

 // Create input data handle.
 ml_tensors_data_h input;

 ml_tensors_data_create (input_info, &input);
 ml_tensors_data_set_tensor_data (input, 0, input_buffer, input_size);

 // Push input data into ml-service and process the output in the callback.
 ml_service_request (handle, NULL, input);

 // Finally, release all handles and allocated memories.
 ml_tensors_info_destroy (input_info);
 ml_tensors_data_destroy (input);
 ml_service_destroy (handle);
 free (input_buffer);
int ml_service_pipeline_delete ( const char *  name)

Deletes the pipeline description with a given name.

Since :
7.0
Parameters:
[in]nameThe unique name to delete.
Returns:
0 on success. Otherwise a negative error value.
Note:
If the name does not exist in the database, this function returns ML_ERROR_NONE without any errors.
Return values:
ML_ERROR_NONESuccessful.
ML_ERROR_NOT_SUPPORTEDNot supported.
ML_ERROR_INVALID_PARAMETERFail. The parameter is invalid.
ML_ERROR_IO_ERRORThe operation of DB or filesystem has failed.
int ml_service_pipeline_get ( const char *  name,
char **  pipeline_desc 
)

Gets the pipeline description with a given name.

Since :
7.0
Remarks:
If the function succeeds, pipeline_desc must be released using free().
Parameters:
[in]nameThe unique name to retrieve.
[out]pipeline_descThe pipeline corresponding with the given name.
Returns:
0 on success. Otherwise a negative error value.
Return values:
ML_ERROR_NONESuccessful.
ML_ERROR_NOT_SUPPORTEDNot supported.
ML_ERROR_INVALID_PARAMETERFail. The parameter is invalid.
ML_ERROR_IO_ERRORThe operation of DB or filesystem has failed.

Gets the state of given handle's pipeline.

Since :
7.0
Parameters:
[in]handleThe service handle.
[out]stateThe pipeline state.
Returns:
0 on Success. Otherwise a negative error value.
Return values:
ML_ERROR_NONESuccessful.
ML_ERROR_NOT_SUPPORTEDNot supported.
ML_ERROR_INVALID_PARAMETERFail. The parameter is invalid.
ML_ERROR_STREAMS_PIPEFailed to access the pipeline state.
int ml_service_pipeline_launch ( const char *  name,
ml_service_h handle 
)

Launches the pipeline of given service and gets the service handle.

This requests machine learning agent daemon to launch a new pipeline of given service. The pipeline of service name should be set.

Since :
7.0
Remarks:
The handle should be destroyed using ml_service_destroy().
Parameters:
[in]nameThe service name.
[out]handleNewly created service handle is returned.
Returns:
0 on Success. Otherwise a negative error value.
Return values:
ML_ERROR_NONESuccessful.
ML_ERROR_NOT_SUPPORTEDNot supported.
ML_ERROR_INVALID_PARAMETERFail. The parameter is invalid.
ML_ERROR_OUT_OF_MEMORYFailed to allocate required memory.
ML_ERROR_IO_ERRORThe operation of DB or filesystem has failed.
ML_ERROR_STREAMS_PIPEFailed to launch the pipeline.
int ml_service_pipeline_set ( const char *  name,
const char *  pipeline_desc 
)

Sets the pipeline description with a given name.

Since :
7.0
Remarks:
If the name already exists, the pipeline description is overwritten. Overwriting an existing description is restricted to APP/service that set it. However, users should keep their name unexposed to prevent unexpected overwriting.
Parameters:
[in]nameUnique name to retrieve the associated pipeline description.
[in]pipeline_descThe pipeline description to be stored.
Returns:
0 on success. Otherwise a negative error value.
Return values:
ML_ERROR_NONESuccessful.
ML_ERROR_NOT_SUPPORTEDNot supported.
ML_ERROR_INVALID_PARAMETERFail. The parameter is invalid.
ML_ERROR_IO_ERRORThe operation of DB or filesystem has failed.

Here is an example of the usage:

 const gchar my_pipeline[] = "videotestsrc is-live=true ! videoconvert ! tensor_converter ! tensor_sink async=false";
 gchar *pipeline;
 int status;
 ml_pipeline_h handle;

 // Set pipeline description.
 status = ml_service_pipeline_set ("my_pipeline", my_pipeline);
 if (status != ML_ERROR_NONE) {
   // handle error case
   goto error;
 }

 // Example to construct a pipeline with stored pipeline description.
 // Users may register intelligence pipelines for other processes and fetch such registered pipelines.
 // For example, a developer adds a pipeline which includes preprocessing and invoking a neural network model,
 // then an application can fetch and construct this for intelligence service.
 status = ml_service_pipeline_get ("my_pipeline", &pipeline);
 if (status != ML_ERROR_NONE) {
   // handle error case
   goto error;
 }

 status = ml_pipeline_construct (pipeline, NULL, NULL, &handle);
 if (status != ML_ERROR_NONE) {
   // handle error case
   goto error;
 }

 error:
 ml_pipeline_destroy (handle);
 g_free (pipeline);
int ml_service_query_create ( ml_option_h  option,
ml_service_h handle 
)

Creates query service handle with given ml-option handle.

Since :
7.0
Remarks:
The handle should be destroyed using ml_service_destroy().
Parameters:
[in]optionThe option used for creating query service.
[out]handleNewly created query service handle is returned.
Returns:
0 on Success. Otherwise a negative error value.
Return values:
ML_ERROR_NONESuccessful.
ML_ERROR_NOT_SUPPORTEDNot supported.
ML_ERROR_INVALID_PARAMETERFail. The parameter is invalid.
ML_ERROR_OUT_OF_MEMORYFailed to allocate required memory.
ML_ERROR_STREAMS_PIPEFailed to launch the pipeline.
ML_ERROR_TRY_AGAINThe pipeline is not ready yet.
int ml_service_query_request ( ml_service_h  handle,
const ml_tensors_data_h  input,
ml_tensors_data_h output 
)

Requests the query service to process the input and produce an output.

Since :
7.0
Remarks:
If the function succeeds, the output should be released using ml_tensors_data_destroy().
Parameters:
[in]handleThe query service handle created by ml_service_query_create().
[in]inputThe handle of input tensors.
[out]outputThe handle of output tensors.
Returns:
0 on success. Otherwise a negative error value.
Return values:
ML_ERROR_NONESuccessful.
ML_ERROR_NOT_SUPPORTEDNot supported.
ML_ERROR_INVALID_PARAMETERGiven parameter is invalid.
ML_ERROR_OUT_OF_MEMORYFailed to allocate required memory.
ML_ERROR_STREAMS_PIPEThe input is incompatible with the pipeline.
ML_ERROR_TRY_AGAINThe pipeline is not ready yet.
ML_ERROR_TIMED_OUTFailed to get output from the query service.
int ml_service_request ( ml_service_h  handle,
const char *  name,
const ml_tensors_data_h  data 
)

Adds an input data to process the model in machine learning service.

Since :
9.0
Parameters:
[in]handleThe handle of ml-service.
[in]nameThe name of input node in the pipeline. You can set NULL if ml-service is constructed from model configuration.
[in]dataThe handle of tensors data to be processed.
Returns:
0 on success. Otherwise a negative error value.
Return values:
ML_ERROR_NONESuccessful.
ML_ERROR_NOT_SUPPORTEDNot supported.
ML_ERROR_INVALID_PARAMETERThe parameter is invalid.
ML_ERROR_STREAMS_PIPEFailed to process the input data.
ML_ERROR_OUT_OF_MEMORYFailed to allocate required memory.
int ml_service_resource_add ( const char *  name,
const char *  path,
const char *  description 
)

Adds new information of machine learning resources those contain images, audio samples, binary files, and so on.

Since :
8.0
Remarks:
If same name is already registered in machine learning service, this returns no error and the list of resource files will be updated.
http://tizen.org/privilege/mediastorage is needed if model file is relevant to media storage.
http://tizen.org/privilege/externalstorage is needed if model file is relevant to external storage.
Parameters:
[in]nameThe unique name to indicate the resources.
[in]pathThe path to machine learning resources.
[in]descriptionNullable, description for machine learning resources.
Returns:
0 on success. Otherwise a negative error value.
Return values:
ML_ERROR_NONESuccessful.
ML_ERROR_NOT_SUPPORTEDNot supported.
ML_ERROR_PERMISSION_DENIEDThe application does not have the privilege to access to the storage.
ML_ERROR_INVALID_PARAMETERGiven parameter is invalid.
ML_ERROR_IO_ERRORThe operation of DB or filesystem has failed.

Here is an example of the usage:

 // The machine-learning resource API provides a method to share the data files those can be used for training or inferencing AI model.
 // Users may generate preprocessed data file, and add it into machine-learning service.
 // Then an application can fetch the data set for retraining an AI model.

 const char *my_resources[3] = {
   "/path/to/resources/my_res1.dat",
   "/path/to/resources/my_res2.dat"
   "/path/to/resources/my_res3.dat"
 };

 int status;
 unsigned int i, length;
 ml_information_list_h resources;
 ml_information_h res;
 char *path_to_resource;

 // Add resource files with name "my_resource".
 for (i = 0; i < 3; i++) {
   status = ml_service_resource_add ("my_resource", my_resources[i], "This is my resource data file.");
   if (status != ML_ERROR_NONE) {
     // Handle error case.
   }
 }

 // Get the resources with specific name.
 status = ml_service_resource_get ("my_resource", &resources);
 if (status != ML_ERROR_NONE) {
   // Handle error case.
 }

 status = ml_information_list_length (resources, &length);
 for (i = 0; i < length; i++) {
   status = ml_information_list_get (resources, i, &res);
   // Get the path of added resources.
   status = ml_information_get (res, "path", (void **) &path_to_resource);
 }

 // Release the information handle of resources.
 status = ml_information_list_destroy (resources);
int ml_service_resource_delete ( const char *  name)

Deletes the information of the resources from machine learning service.

Since :
8.0
Remarks:
This does not remove the resource files from file system.
Parameters:
[in]nameThe unique name to indicate the resources.
Returns:
0 on success. Otherwise a negative error value.
Return values:
ML_ERROR_NONESuccessful.
ML_ERROR_NOT_SUPPORTEDNot supported.
ML_ERROR_INVALID_PARAMETERGiven parameter is invalid.
ML_ERROR_IO_ERRORThe operation of DB or filesystem has failed.
int ml_service_resource_get ( const char *  name,
ml_information_list_h res 
)

Gets the information of the resources from machine learning service.

Since :
8.0
Remarks:
If the function succeeds, the res should be released using ml_information_list_destroy().
Parameters:
[in]nameThe unique name to indicate the resources.
[out]resThe handle of the machine learning resources.
Returns:
0 on success. Otherwise a negative error value.
Return values:
ML_ERROR_NONESuccessful.
ML_ERROR_NOT_SUPPORTEDNot supported.
ML_ERROR_INVALID_PARAMETERGiven parameter is invalid.
ML_ERROR_IO_ERRORThe operation of DB or filesystem has failed.
ML_ERROR_OUT_OF_MEMORYFailed to allocate required memory.
int ml_service_set_event_cb ( ml_service_h  handle,
ml_service_event_cb  cb,
void *  user_data 
)

Sets the callback which will be invoked when a new event occurs from machine learning service.

Since :
9.0
Parameters:
[in]handleThe handle of ml-service.
[in]cbThe callback to handle the event from ml-service.
[in]user_dataPrivate data for the callback. This value is passed to the callback when it's invoked.
Returns:
0 on success. Otherwise a negative error value.
Return values:
ML_ERROR_NONESuccessful.
ML_ERROR_NOT_SUPPORTEDNot supported.
ML_ERROR_INVALID_PARAMETERGiven parameter is invalid.
int ml_service_set_information ( ml_service_h  handle,
const char *  name,
const char *  value 
)

Sets the information for machine learning service.

Since :
9.0
Parameters:
[in]handleThe handle of ml-service.
[in]nameThe name to set the corresponding value.
[in]valueThe value of the name.
Returns:
0 on success. Otherwise a negative error value.
Return values:
ML_ERROR_NONESuccessful.
ML_ERROR_NOT_SUPPORTEDNot supported.
ML_ERROR_INVALID_PARAMETERThe parameter is invalid.
int ml_service_start ( ml_service_h  handle)

Starts the process of machine learning service.

Since :
7.0
Parameters:
[in]handleThe handle of ml-service.
Returns:
0 on success. Otherwise a negative error value.
Return values:
ML_ERROR_NONESuccessful.
ML_ERROR_NOT_SUPPORTEDNot supported.
ML_ERROR_INVALID_PARAMETERGiven parameter is invalid.
ML_ERROR_STREAMS_PIPEFailed to start the process.
int ml_service_stop ( ml_service_h  handle)

Stops the process of machine learning service.

Since :
7.0
Parameters:
[in]handleThe handle of ml-service.
Returns:
0 on success. Otherwise a negative error value.
Return values:
ML_ERROR_NONESuccessful.
ML_ERROR_NOT_SUPPORTEDNot supported.
ML_ERROR_INVALID_PARAMETERGiven parameter is invalid.
ML_ERROR_STREAMS_PIPEFailed to stop the process.