mirror of
https://github.com/openharmony/ability_ability_runtime.git
synced 2026-08-24 12:43:16 -04:00
aa queryall
Co-Authored-By:Agent Signed-off-by: unknown <sijunjie@huawei.com>
This commit is contained in:
@@ -64,6 +64,24 @@ public:
|
||||
*/
|
||||
static napi_value GetToolInfoByName(napi_env env, napi_callback_info info);
|
||||
|
||||
/**
|
||||
* @brief Native method for querying all tool summaries.
|
||||
*
|
||||
* @param env The N-API environment.
|
||||
* @param info The N-API callback info.
|
||||
* @return Returns the N-API value.
|
||||
*/
|
||||
static napi_value QueryToolSummaries(napi_env env, napi_callback_info info);
|
||||
|
||||
/**
|
||||
* @brief Native method for querying all tools.
|
||||
*
|
||||
* @param env The N-API environment.
|
||||
* @param info The N-API callback info.
|
||||
* @return Returns the N-API value.
|
||||
*/
|
||||
static napi_value QueryTools(napi_env env, napi_callback_info info);
|
||||
|
||||
private:
|
||||
/**
|
||||
* @brief Implementation for executing a CLI tool.
|
||||
@@ -84,6 +102,26 @@ private:
|
||||
* @return Returns the N-API value.
|
||||
*/
|
||||
napi_value OnGetToolInfoByName(napi_env env, size_t argc, napi_value *argv);
|
||||
|
||||
/**
|
||||
* @brief Implementation for querying all tool summaries.
|
||||
*
|
||||
* @param env The N-API environment.
|
||||
* @param argc The argument count.
|
||||
* @param argv The argument values.
|
||||
* @return Returns the N-API value.
|
||||
*/
|
||||
napi_value OnQueryToolSummaries(napi_env env, size_t argc, napi_value *argv);
|
||||
|
||||
/**
|
||||
* @brief Implementation for querying all tools.
|
||||
*
|
||||
* @param env The N-API environment.
|
||||
* @param argc The argument count.
|
||||
* @param argv The argument values.
|
||||
* @return Returns the N-API value.
|
||||
*/
|
||||
napi_value OnQueryTools(napi_env env, size_t argc, napi_value *argv);
|
||||
};
|
||||
|
||||
/**
|
||||
|
||||
@@ -25,6 +25,7 @@
|
||||
#include "exec_result.h"
|
||||
#include "native_engine/native_engine.h"
|
||||
#include "tool_info.h"
|
||||
#include "tool_summary.h"
|
||||
|
||||
namespace OHOS {
|
||||
namespace CliTool {
|
||||
@@ -88,6 +89,14 @@ napi_value CreateJsSubCommandInfo(napi_env env, const SubCommandInfo &subcmd);
|
||||
*/
|
||||
napi_value CreateJsToolInfo(napi_env env, const ToolInfo &tool);
|
||||
|
||||
/**
|
||||
* @brief Create JavaScript ToolSummary object.
|
||||
* @param env The N-API environment.
|
||||
* @param summary The ToolSummary structure.
|
||||
* @return Returns the JavaScript object.
|
||||
*/
|
||||
napi_value CreateJsToolSummary(napi_env env, const ToolSummary &summary);
|
||||
|
||||
} // namespace CliTool
|
||||
} // namespace OHOS
|
||||
|
||||
|
||||
@@ -54,6 +54,16 @@ napi_value JSCliManager::GetToolInfoByName(napi_env env, napi_callback_info info
|
||||
GET_CB_INFO_AND_CALL(env, info, JSCliManager, OnGetToolInfoByName);
|
||||
}
|
||||
|
||||
napi_value JSCliManager::QueryToolSummaries(napi_env env, napi_callback_info info)
|
||||
{
|
||||
GET_CB_INFO_AND_CALL(env, info, JSCliManager, OnQueryToolSummaries);
|
||||
}
|
||||
|
||||
napi_value JSCliManager::QueryTools(napi_env env, napi_callback_info info)
|
||||
{
|
||||
GET_CB_INFO_AND_CALL(env, info, JSCliManager, OnQueryTools);
|
||||
}
|
||||
|
||||
napi_value JSCliManager::OnExecTool(napi_env env, size_t argc, napi_value *argv)
|
||||
{
|
||||
TAG_LOGD(AAFwkTag::CLI_TOOL, "JSCliManager::OnExecTool called");
|
||||
@@ -165,6 +175,82 @@ napi_value JSCliManager::OnGetToolInfoByName(napi_env env, size_t argc, napi_val
|
||||
return handleEscape.Escape(asyncResult);
|
||||
}
|
||||
|
||||
napi_value JSCliManager::OnQueryToolSummaries(napi_env env, size_t argc, napi_value *argv)
|
||||
{
|
||||
TAG_LOGD(AAFwkTag::CLI_TOOL, "JSCliManager::OnQueryToolSummaries called");
|
||||
HandleEscape handleEscape(env);
|
||||
|
||||
auto innerErrCode = std::make_shared<int32_t>(ERR_OK);
|
||||
auto summaries = std::make_shared<std::vector<ToolSummary>>();
|
||||
|
||||
NapiAsyncTask::ExecuteCallback execute = [innerErrCode, summaries]() {
|
||||
*innerErrCode = CliToolMGRClient::GetInstance().GetAllToolSummaries(*summaries);
|
||||
};
|
||||
|
||||
NapiAsyncTask::CompleteCallback complete = [innerErrCode, summaries](
|
||||
napi_env env, NapiAsyncTask &task, int32_t status) {
|
||||
HandleScope handleScope(env);
|
||||
if (*innerErrCode != ERR_OK) {
|
||||
TAG_LOGE(AAFwkTag::CLI_TOOL, "QueryToolSummaries error: %{public}d", *innerErrCode);
|
||||
task.Reject(env, CreateCliJsErrorByNativeErr(env, *innerErrCode));
|
||||
return;
|
||||
}
|
||||
|
||||
napi_value jsArray = nullptr;
|
||||
napi_create_array(env, &jsArray);
|
||||
for (size_t i = 0; i < summaries->size(); i++) {
|
||||
napi_value jsSummary = CreateJsToolSummary(env, (*summaries)[i]);
|
||||
if (jsSummary != nullptr) {
|
||||
napi_set_element(env, jsArray, i, jsSummary);
|
||||
}
|
||||
}
|
||||
task.ResolveWithNoError(env, jsArray);
|
||||
};
|
||||
|
||||
napi_value asyncResult = nullptr;
|
||||
NapiAsyncTask::Schedule("JsCliManager::OnQueryToolSummaries", env,
|
||||
CreateAsyncTaskWithLastParam(env, nullptr, std::move(execute), std::move(complete), &asyncResult));
|
||||
return handleEscape.Escape(asyncResult);
|
||||
}
|
||||
|
||||
napi_value JSCliManager::OnQueryTools(napi_env env, size_t argc, napi_value *argv)
|
||||
{
|
||||
TAG_LOGD(AAFwkTag::CLI_TOOL, "JSCliManager::OnQueryTools called");
|
||||
HandleEscape handleEscape(env);
|
||||
|
||||
auto innerErrCode = std::make_shared<int32_t>(ERR_OK);
|
||||
auto tools = std::make_shared<std::vector<ToolInfo>>();
|
||||
|
||||
NapiAsyncTask::ExecuteCallback execute = [innerErrCode, tools]() {
|
||||
*innerErrCode = CliToolMGRClient::GetInstance().GetAllToolInfos(*tools);
|
||||
};
|
||||
|
||||
NapiAsyncTask::CompleteCallback complete = [innerErrCode, tools](
|
||||
napi_env env, NapiAsyncTask &task, int32_t status) {
|
||||
HandleScope handleScope(env);
|
||||
if (*innerErrCode != ERR_OK) {
|
||||
TAG_LOGE(AAFwkTag::CLI_TOOL, "QueryTools error: %{public}d", *innerErrCode);
|
||||
task.Reject(env, CreateCliJsErrorByNativeErr(env, *innerErrCode));
|
||||
return;
|
||||
}
|
||||
|
||||
napi_value jsArray = nullptr;
|
||||
napi_create_array(env, &jsArray);
|
||||
for (size_t i = 0; i < tools->size(); i++) {
|
||||
napi_value jsTool = CreateJsToolInfo(env, (*tools)[i]);
|
||||
if (jsTool != nullptr) {
|
||||
napi_set_element(env, jsArray, i, jsTool);
|
||||
}
|
||||
}
|
||||
task.ResolveWithNoError(env, jsArray);
|
||||
};
|
||||
|
||||
napi_value asyncResult = nullptr;
|
||||
NapiAsyncTask::Schedule("JsCliManager::OnQueryTools", env,
|
||||
CreateAsyncTaskWithLastParam(env, nullptr, std::move(execute), std::move(complete), &asyncResult));
|
||||
return handleEscape.Escape(asyncResult);
|
||||
}
|
||||
|
||||
napi_value JSCliManagerInit(napi_env env, napi_value exportObj)
|
||||
{
|
||||
TAG_LOGD(AAFwkTag::CLI_TOOL, "Init JSCliManager");
|
||||
@@ -180,6 +266,8 @@ napi_value JSCliManagerInit(napi_env env, napi_value exportObj)
|
||||
const char *moduleName = "CliManager";
|
||||
BindNativeFunction(env, exportObj, "execTool", moduleName, JSCliManager::ExecTool);
|
||||
BindNativeFunction(env, exportObj, "getToolInfoByName", moduleName, JSCliManager::GetToolInfoByName);
|
||||
BindNativeFunction(env, exportObj, "queryToolSummaries", moduleName, JSCliManager::QueryToolSummaries);
|
||||
BindNativeFunction(env, exportObj, "queryTools", moduleName, JSCliManager::QueryTools);
|
||||
|
||||
TAG_LOGD(AAFwkTag::CLI_TOOL, "JSCliManagerInit end");
|
||||
return CreateJsUndefined(env);
|
||||
|
||||
@@ -484,5 +484,29 @@ napi_value CreateJsToolInfo(napi_env env, const ToolInfo &tool)
|
||||
return jsObj;
|
||||
}
|
||||
|
||||
napi_value CreateJsToolSummary(napi_env env, const ToolSummary &summary)
|
||||
{
|
||||
napi_value jsObj = nullptr;
|
||||
napi_status status = napi_create_object(env, &jsObj);
|
||||
if (status != napi_ok) {
|
||||
TAG_LOGE(AAFwkTag::CLI_TOOL, "Failed to create JS object");
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
// Set name
|
||||
napi_value jsName = AppExecFwk::WrapStringToJS(env, summary.name);
|
||||
napi_set_named_property(env, jsObj, "name", jsName);
|
||||
|
||||
// Set version
|
||||
napi_value jsVersion = AppExecFwk::WrapStringToJS(env, summary.version);
|
||||
napi_set_named_property(env, jsObj, "version", jsVersion);
|
||||
|
||||
// Set description
|
||||
napi_value jsDescription = AppExecFwk::WrapStringToJS(env, summary.description);
|
||||
napi_set_named_property(env, jsObj, "description", jsDescription);
|
||||
|
||||
return jsObj;
|
||||
}
|
||||
|
||||
} // namespace CliTool
|
||||
} // namespace OHOS
|
||||
|
||||
Reference in New Issue
Block a user