+ LoggerE("Could not save model to file: %d (%s)", ret_val,
+ ml_strerror(ret_val));
+ return PlatformResult(ErrorCode::ABORT_ERR, ml_strerror(ret_val));
+ }
+
+ return PlatformResult();
+}
+
+PlatformResult TrainerManager::ModelLoad(int id, const std::string& path,
+ ml_train_model_format_e format) {
+ ScopeLogger();
+
+ if (models_.find(id) == models_.end()) {
+ LoggerE("Could not find model with id: %d", id);
+ return PlatformResult(ErrorCode::ABORT_ERR, "Could not find model");
+ }
+
+ auto& model = models_[id];
+ bool available = model->instanceLock.try_lock();
+ if (!available) {
+ LoggerE("Model locked - probaly training in progress");
+ return PlatformResult(ErrorCode::NO_MODIFICATION_ALLOWED_ERR,
+ "Model training in progress - cannot save");
+ }
+
+ auto tmpString = path;
+ if (tmpString.substr(0, FILE_PATH_PREFIX.length()) == FILE_PATH_PREFIX) {
+ // remove 'file://' prefix from path before passing to native api
+ tmpString.erase(0, FILE_PATH_PREFIX.length());
+ }
+
+ LoggerI("Loading model from file: %s", tmpString.c_str());
+ int ret_val =
+ ml_train_model_load(model->getNative(), tmpString.c_str(), format);
+
+ model->instanceLock.unlock();
+
+ if (ret_val != ML_ERROR_NONE) {
+ LoggerE("Could not load model from file: %d (%s)", ret_val,
+ ml_strerror(ret_val));