// SingleShot::invoke()
-// SingleShot::getValue()
+var GetSetValueValidExceptions = [
+ 'AbortError',
+ 'InvalidValuesError',
+ 'NotSupportedError'
+];
+
+SingleShot.prototype.getValue = function() {
+ var args = validator_.validateArgs(arguments, [
+ {
+ name: 'name',
+ type: types_.STRING
+ }
+ ]);
+
+ if (!args.has.name) {
+ throw new WebAPIException(
+ WebAPIException.INVALID_VALUES_ERR,
+ 'Invalid parameter: name is undefined'
+ );
+ }
-// SingleShot::setValue()
+ var callArgs = {
+ id: this._id,
+ name: args.name
+ };
+
+ var result = native_.callSync('MLSingleShotGetValue', callArgs);
+ if (native_.isFailure(result)) {
+ throw native_.getErrorObjectAndValidate(
+ result,
+ GetSetValueValidExceptions,
+ AbortError
+ );
+ }
+ return native_.getResultObject(result);
+};
+
+SingleShot.prototype.setValue = function() {
+ var args = validator_.validateArgs(arguments, [
+ {
+ name: 'name',
+ type: types_.STRING
+ },
+ {
+ name: 'value',
+ type: types_.STRING
+ }
+ ]);
+
+ if (!args.has.name || !args.has.value) {
+ throw new WebAPIException(
+ WebAPIException.INVALID_VALUES_ERR,
+ 'Invalid parameter: ' + (args.has.name ? 'value' : 'name') + ' is undefined'
+ );
+ }
+
+ var callArgs = {
+ id: this._id,
+ name: args.name,
+ value: args.value
+ };
+
+ var result = native_.callSync('MLSingleShotSetValue', callArgs);
+
+ if (native_.isFailure(result)) {
+ throw native_.getErrorObjectAndValidate(
+ result,
+ GetSetValueValidExceptions,
+ AbortError
+ );
+ }
+};
// SingleShot::setTimeout()
// SingleShot::close()
REGISTER_METHOD(MLSingleShotGetTensorsInfo);
REGISTER_METHOD(MLSingleShotSetInputInfo);
// SingleShot::invoke()
- // SingleShot::getValue()
- // SingleShot::setValue()
+ REGISTER_METHOD(MLSingleShotGetValue);
+ REGISTER_METHOD(MLSingleShotSetValue);
// SingleShot::setTimeout()
// SingleShot::close()
const std::string kFwType = "fwType";
const std::string kHwType = "hwType";
const std::string kIsDynamicMode = "isDynamicMode";
+const std::string kValue = "value";
const int kNoId = -1;
} // namespace
+
void MlInstance::MLSingleManagerOpenModel(const picojson::value& args, picojson::object& out) {
ScopeLogger("args: %s", args.serialize().c_str());
CHECK_ARGS(args, kModelPath, std::string, out);
// SingleShot::invoke()
-// SingleShot::getValue()
+void MlInstance::MLSingleShotGetValue(const picojson::value& args, picojson::object& out) {
+ ScopeLogger("args: %s", args.serialize().c_str());
+ CHECK_ARGS(args, kId, double, out);
+ CHECK_ARGS(args, kName, std::string, out);
+
+ auto id = static_cast<int>(args.get(kId).get<double>());
+ const auto& name = args.get(kName).get<std::string>();
+ std::string value;
+ auto ret = single_manager_.GetValue(id, name, value);
+ if (!ret) {
+ ReportError(ret, &out);
+ return;
+ }
+
+ picojson::value val = picojson::value{value};
+ ReportSuccess(val, out);
+}
+
+void MlInstance::MLSingleShotSetValue(const picojson::value& args, picojson::object& out) {
+ ScopeLogger("args: %s", args.serialize().c_str());
+ CHECK_ARGS(args, kId, double, out);
+ CHECK_ARGS(args, kName, std::string, out);
+ CHECK_ARGS(args, kValue, std::string, out);
+
+ auto id = static_cast<int>(args.get(kId).get<double>());
+ const auto& name = args.get(kName).get<std::string>();
+ const auto& value = args.get(kValue).get<std::string>();
+
+ auto ret = single_manager_.SetValue(id, name, value);
+ if (!ret) {
+ ReportError(ret, &out);
+ return;
+ }
-// SingleShot::setValue()
+ ReportSuccess(out);
+}
// SingleShot::setTimeout()
void MLSingleShotGetTensorsInfo(const picojson::value& args, picojson::object& out);
void MLSingleShotSetInputInfo(const picojson::value& args, picojson::object& out);
// SingleShot::invoke()
- // SingleShot::getValue()
- // SingleShot::setValue()
+ void MLSingleShotGetValue(const picojson::value& args, picojson::object& out);
+ void MLSingleShotSetValue(const picojson::value& args, picojson::object& out);
// SingleShot::setTimeout()
// SingleShot::close()
// Single API end
}
// SingleShot::invoke()
-// SingleShot::getValue()
-// SingleShot::setValue()
+PlatformResult SingleManager::GetValue(int id, const std::string& name, std::string& value) {
+ ScopeLogger();
+
+ SingleShot* single = GetSingleShot(id);
+ if (!single) {
+ LoggerE("Could not find SingleShot handle");
+ return PlatformResult(ErrorCode::ABORT_ERR, "Internal SingleShot error");
+ }
+
+ return single->GetValue(name, value);
+}
+
+PlatformResult SingleManager::SetValue(int id, const std::string& name, const std::string& value) {
+ ScopeLogger();
+
+ SingleShot* single = GetSingleShot(id);
+ if (!single) {
+ LoggerE("Could not find SingleShot handle");
+ return PlatformResult(ErrorCode::ABORT_ERR, "Internal SingleShot error");
+ }
+
+ return single->SetValue(name, value);
+}
+
// SingleShot::setTimeout()
// SingleShot::close()
PlatformResult GetNativeTensorsInfo(int id, bool get_input_mode, int* res_id);
PlatformResult SetNativeInputInfo(int id, TensorsInfo* inTensorsInfo);
// SingleShot::invoke()
- // SingleShot::getValue()
- // SingleShot::setValue()
+ PlatformResult GetValue(int id, const std::string& name, std::string& value);
+ PlatformResult SetValue(int id, const std::string& name, const std::string& value);
// SingleShot::setTimeout()
// SingleShot::close()
* See the License for the specific language governing permissions and
* limitations under the License.
*/
+#include <glib.h>
#include <tizen.h>
#include "common/logger.h"
// SingleShot::invoke()
-// SingleShot::getValue()
+PlatformResult SingleShot::GetValue(const std::string& name, std::string& value) {
+ ScopeLogger();
+
+ gchar* out_value = nullptr;
+ int ret = ml_single_get_property(handle_, name.c_str(), &out_value);
+ if (ML_ERROR_NONE != ret) {
+ LoggerE("ml_single_get_property failed: %d (%s)", ret, get_error_message(ret));
+ return util::ToPlatformResult(ret, "Failed to get value");
+ }
+
+ if (nullptr == out_value) {
+ LoggerW("ml_single_get_property returned nullptr, returning empty string instead");
+ // set value to an empty string as ml_single_get_property returned ML_ERROR_NONE
+ value = std::string{};
+ } else {
+ value = std::string{out_value};
+ g_free(out_value);
+ }
+
+ return PlatformResult{};
+}
+
+PlatformResult SingleShot::SetValue(const std::string& name, const std::string& value) {
+ ScopeLogger();
+ int ret = ml_single_set_property(handle_, name.c_str(), value.c_str());
+ if (ML_ERROR_NONE != ret) {
+ LoggerE("ml_single_set_property failed: %d (%s)", ret, get_error_message(ret));
+ return util::ToPlatformResult(ret, "Failed to set value");
+ }
-// SingleShot::setValue()
+ return PlatformResult{};
+}
// SingleShot::setTimeout()
PlatformResult SetInputInfo(ml_tensors_info_h in_info);
// SingleShot::invoke()
- // SingleShot::getValue()
-
- // SingleShot::setValue()
+ PlatformResult GetValue(const std::string& name, std::string& value);
+ PlatformResult SetValue(const std::string& name, const std::string& value);
// SingleShot::setTimeout()