Skip to content

Commit

Permalink
[OV JS] Expose core.query_model to Node.js Api
Browse files Browse the repository at this point in the history
Changes as part of this commit include:
* Add a CoreWrap::query_model function:
  Calls the underlying core.query_model function
* Update the addon.ts with the queryModel method

Signed-off-by: Nashez Zubair <[email protected]>
  • Loading branch information
nashez committed Aug 23, 2024
1 parent 6a87630 commit 8eebf29
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 0 deletions.
2 changes: 2 additions & 0 deletions src/bindings/js/node/include/core_wrap.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,8 @@ class CoreWrap : public Napi::ObjectWrap<CoreWrap> {
Napi::Value set_property(const Napi::CallbackInfo& info);
Napi::Value get_property(const Napi::CallbackInfo& info);

Napi::Value query_model(const Napi::CallbackInfo& info);

void add_extension(const Napi::CallbackInfo& info);
protected:
Napi::Value compile_model_sync(const Napi::CallbackInfo& info,
Expand Down
7 changes: 7 additions & 0 deletions src/bindings/js/node/lib/addon.ts
Original file line number Diff line number Diff line change
Expand Up @@ -205,6 +205,13 @@ interface Core {
deviceName: string,
properties: { [key: string]: string | number | boolean },
): void;
/**
* It queries the model passed for the requested property.
* @param model The passed model to query the property.
* @param deviceName The name of a device.
* @param properties An object with the property name - property value pairs.
*/
queryModel(model: Model, deviceName: string, properties?: {[key: string]: string | number | boolean}): {[key: string]: string | number | boolean};
}
interface CoreConstructor {
new(): Core;
Expand Down
27 changes: 27 additions & 0 deletions src/bindings/js/node/src/core_wrap.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ Napi::Function CoreWrap::get_class(Napi::Env env) {
InstanceMethod("getVersions", &CoreWrap::get_versions),
InstanceMethod("setProperty", &CoreWrap::set_property),
InstanceMethod("getProperty", &CoreWrap::get_property),
InstanceMethod("queryModel", &CoreWrap::query_model),
InstanceMethod("addExtension", &CoreWrap::add_extension)});
}

Expand Down Expand Up @@ -463,3 +464,29 @@ void CoreWrap::add_extension(const Napi::CallbackInfo& info) {
reportError(info.Env(), err.what());
}
}

Napi::Value CoreWrap::query_model(const Napi::CallbackInfo& info) {
std::vector<std::string> allowed_signatures;
try {
if (ov::js::validate<ModelWrap, Napi::String>(info, allowed_signatures) ||
ov::js::validate<ModelWrap, Napi::String, Napi::Object>(info, allowed_signatures)) {
ov::AnyMap properties;
auto model = Napi::ObjectWrap<ModelWrap>::Unwrap(info[0].ToObject())->get_model();
auto device_name = info[1].ToString();
if (info.Length() == 3) {
properties = to_anyMap(info.Env(), info[2]);
}
auto query_result = _core.query_model(model, device_name, properties);
Napi::Object result = Napi::Object::New(info.Env());
for (const auto& elem: query_result) {
result.Set(elem.first, elem.second);
}
return result;
} else {
OPENVINO_THROW("'queryModel'", ov::js::get_parameters_error_msg(info, allowed_signatures));
}
} catch (std::exception& err) {
reportError(info.Env(), err.what());
return info.Env().Undefined();
}
}

0 comments on commit 8eebf29

Please sign in to comment.