mirror of
https://github.com/openharmony/ability_ability_runtime.git
synced 2026-08-24 12:43:16 -04:00
revert idl
Signed-off-by: wendel <yuwenze1@huawei.com> Co-Authored-By: wendel Change-Id: Ibdcf416d56748278f5326e13b657c0c33a86d5db
This commit is contained in:
+1
-1
@@ -25,9 +25,9 @@
|
||||
|
||||
namespace OHOS {
|
||||
namespace CliTool {
|
||||
class CliSessionInfo;
|
||||
class CliToolEvent;
|
||||
class ExecOptions;
|
||||
struct CliSessionInfo;
|
||||
|
||||
/**
|
||||
* @brief Unwrap a string map from JavaScript object.
|
||||
|
||||
@@ -19,9 +19,9 @@
|
||||
|
||||
#include "cli_error_code.h"
|
||||
#include "cli_manager_error_utils.h"
|
||||
#include "cli_session_info.h"
|
||||
#include "cli_tool_mgr_client.h"
|
||||
#include "hilog_tag_wrapper.h"
|
||||
#include "icli_tool_data.h"
|
||||
#include "js_cli_manager_utils.h"
|
||||
#include "js_error_utils.h"
|
||||
#include "napi_common_util.h"
|
||||
|
||||
+12
-11
@@ -17,6 +17,7 @@
|
||||
|
||||
#include <nlohmann/json.hpp>
|
||||
|
||||
#include "cli_session_info.h"
|
||||
#include "cli_tool_event.h"
|
||||
#include "exec_options.h"
|
||||
#include "hilog_tag_wrapper.h"
|
||||
@@ -223,33 +224,33 @@ napi_value CreateJsCliSessionInfo(napi_env env, const CliSessionInfo &session)
|
||||
napi_set_named_property(env, jsObj, "status", AppExecFwk::WrapStringToJS(env, session.status));
|
||||
|
||||
// Set result if present
|
||||
if (session.status != "running") {
|
||||
if (session.status != "running" && session.result != nullptr) {
|
||||
napi_value jsResult = nullptr;
|
||||
status = napi_create_object(env, &jsResult);
|
||||
if (status != napi_ok) {
|
||||
TAG_LOGE(AAFwkTag::CLI_TOOL, "Failed to create JS ExecResult");
|
||||
return nullptr;
|
||||
}
|
||||
if (!session.result.timedOut) {
|
||||
napi_value jsExitCode = AppExecFwk::WrapInt32ToJS(env, session.result.exitCode);
|
||||
if (!session.result->timedOut) {
|
||||
napi_value jsExitCode = AppExecFwk::WrapInt32ToJS(env, session.result->exitCode);
|
||||
napi_set_named_property(env, jsResult, "exitCode", jsExitCode);
|
||||
}
|
||||
if (!session.result.outputText.empty()) {
|
||||
napi_value jsOutputText = AppExecFwk::WrapStringToJS(env, session.result.outputText);
|
||||
if (!session.result->outputText.empty()) {
|
||||
napi_value jsOutputText = AppExecFwk::WrapStringToJS(env, session.result->outputText);
|
||||
napi_set_named_property(env, jsResult, "outputText", jsOutputText);
|
||||
}
|
||||
if (!session.result.errorText.empty()) {
|
||||
napi_value jsErrorText = AppExecFwk::WrapStringToJS(env, session.result.errorText);
|
||||
if (!session.result->errorText.empty()) {
|
||||
napi_value jsErrorText = AppExecFwk::WrapStringToJS(env, session.result->errorText);
|
||||
napi_set_named_property(env, jsResult, "errorText", jsErrorText);
|
||||
}
|
||||
if (session.result.signalNumber != 0) {
|
||||
napi_value jsSignalNumber = AppExecFwk::WrapInt32ToJS(env, session.result.signalNumber);
|
||||
if (session.result->signalNumber != 0) {
|
||||
napi_value jsSignalNumber = AppExecFwk::WrapInt32ToJS(env, session.result->signalNumber);
|
||||
napi_set_named_property(env, jsResult, "signalNumber", jsSignalNumber);
|
||||
}
|
||||
// Set timedOut
|
||||
napi_set_named_property(env, jsResult, "timedOut", AppExecFwk::WrapBoolToJS(env, session.result.timedOut));
|
||||
napi_set_named_property(env, jsResult, "timedOut", AppExecFwk::WrapBoolToJS(env, session.result->timedOut));
|
||||
// Set executionTime
|
||||
napi_value jsExecutionTime = AppExecFwk::WrapInt64ToJS(env, session.result.executionTime);
|
||||
napi_value jsExecutionTime = AppExecFwk::WrapInt64ToJS(env, session.result->executionTime);
|
||||
napi_set_named_property(env, jsResult, "executionTime", jsExecutionTime);
|
||||
napi_set_named_property(env, jsObj, "result", jsResult);
|
||||
}
|
||||
|
||||
@@ -52,11 +52,13 @@ ohos_shared_library("cli_tool_client") {
|
||||
sources = [
|
||||
"src/cli_mgr_load_callback.cpp",
|
||||
"src/cli_event_reply_manager.cpp",
|
||||
"src/cli_session_info.cpp",
|
||||
"src/cli_session_subscription_manager.cpp",
|
||||
"src/cli_tool_event.cpp",
|
||||
"src/cli_tool_mgr_client.cpp",
|
||||
"src/cli_tool_mgr_scheduler_recipient.cpp",
|
||||
"src/exec_options.cpp",
|
||||
"src/exec_result.cpp",
|
||||
"src/exec_tool_param.cpp",
|
||||
"src/sub_command_info.cpp",
|
||||
"src/tool_info.cpp",
|
||||
|
||||
@@ -27,21 +27,3 @@ struct CommandPermission
|
||||
List<String> permissions;
|
||||
int queryRet;
|
||||
};
|
||||
|
||||
struct ExecResult
|
||||
{
|
||||
int exitCode;
|
||||
String outputText;
|
||||
String errorText;
|
||||
int signalNumber;
|
||||
boolean timedOut;
|
||||
long executionTime;
|
||||
};
|
||||
|
||||
struct CliSessionInfo
|
||||
{
|
||||
String sessionId;
|
||||
String toolName;
|
||||
String status;
|
||||
ExecResult result;
|
||||
};
|
||||
|
||||
@@ -17,6 +17,7 @@ package OHOS.CliTool;
|
||||
|
||||
import ICliToolData;
|
||||
import ICliToolManagerScheduler;
|
||||
sequenceable CliSessionInfo..OHOS.CliTool.CliSessionInfo;
|
||||
sequenceable ExecToolParam..OHOS.CliTool.ExecToolParam;
|
||||
sequenceable OHOS.CliTool.ToolSummary;
|
||||
sequenceable ToolInfo..OHOS.CliTool.ToolInfo;
|
||||
|
||||
@@ -15,7 +15,7 @@
|
||||
|
||||
package OHOS.CliTool;
|
||||
|
||||
import ICliToolData;
|
||||
sequenceable CliSessionInfo..OHOS.CliTool.CliSessionInfo;
|
||||
sequenceable CliToolEvent..OHOS.CliTool.CliToolEvent;
|
||||
|
||||
interface ICliToolManagerScheduler {
|
||||
|
||||
@@ -24,7 +24,7 @@
|
||||
#include <vector>
|
||||
#include <optional>
|
||||
|
||||
#include "icli_tool_data.h"
|
||||
#include "cli_session_info.h"
|
||||
|
||||
namespace OHOS {
|
||||
namespace CliTool {
|
||||
|
||||
@@ -0,0 +1,44 @@
|
||||
/*
|
||||
* Copyright (c) 2026 Huawei Device Co., Ltd.
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#ifndef OHOS_ABILITY_RUNTIME_CLI_SESSION_INFO_H
|
||||
#define OHOS_ABILITY_RUNTIME_CLI_SESSION_INFO_H
|
||||
|
||||
#include <string>
|
||||
|
||||
#include "exec_result.h"
|
||||
#include "parcel.h"
|
||||
|
||||
namespace OHOS {
|
||||
namespace CliTool {
|
||||
/**
|
||||
* @struct CliSessionInfo
|
||||
* @brief Information about a CLI tool execution session.
|
||||
*/
|
||||
class CliSessionInfo : public Parcelable {
|
||||
public:
|
||||
std::string sessionId;
|
||||
std::string toolName;
|
||||
std::string status; // "running", "completed", "failed"
|
||||
std::shared_ptr<ExecResult> result = nullptr; // optional, only when status="completed" and status="failed"
|
||||
|
||||
CliSessionInfo() = default;
|
||||
|
||||
bool Marshalling(Parcel &parcel) const;
|
||||
static CliSessionInfo *Unmarshalling(Parcel &parcel);
|
||||
};
|
||||
} // namespace CliTool
|
||||
} // namespace OHOS
|
||||
#endif // OHOS_ABILITY_RUNTIME_CLI_SESSION_INFO_H
|
||||
@@ -20,9 +20,9 @@
|
||||
#include <functional>
|
||||
#include <mutex>
|
||||
|
||||
#include "cli_session_info.h"
|
||||
#include "cli_tool_event.h"
|
||||
#include "exec_options.h"
|
||||
#include "icli_tool_data.h"
|
||||
#include "icli_tool_manager.h"
|
||||
#include "iremote_object.h"
|
||||
|
||||
|
||||
@@ -0,0 +1,42 @@
|
||||
/*
|
||||
* Copyright (c) 2026 Huawei Device Co., Ltd.
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#ifndef OHOS_ABILITY_RUNTIME_EXEC_RESULT_H
|
||||
#define OHOS_ABILITY_RUNTIME_EXEC_RESULT_H
|
||||
|
||||
#include <string>
|
||||
|
||||
#include "parcel.h"
|
||||
|
||||
namespace OHOS {
|
||||
namespace CliTool {
|
||||
/**
|
||||
* @brief Tool execution result
|
||||
*/
|
||||
class ExecResult : public Parcelable {
|
||||
public:
|
||||
int32_t exitCode = 1;
|
||||
std::string outputText = "";
|
||||
std::string errorText = "";
|
||||
int32_t signalNumber = 0;
|
||||
bool timedOut = false;
|
||||
int64_t executionTime = 0;
|
||||
|
||||
bool Marshalling(Parcel &parcel) const;
|
||||
static ExecResult *Unmarshalling(Parcel &parcel);
|
||||
};
|
||||
} // namespace CliTool
|
||||
} // namespace OHOS
|
||||
#endif // OHOS_ABILITY_RUNTIME_EXEC_RESULT_H
|
||||
@@ -0,0 +1,77 @@
|
||||
/*
|
||||
* Copyright (c) 2026 Huawei Device Co., Ltd.
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#include "cli_session_info.h"
|
||||
|
||||
#include "hilog_tag_wrapper.h"
|
||||
|
||||
namespace OHOS {
|
||||
namespace CliTool {
|
||||
bool CliSessionInfo::Marshalling(Parcel &parcel) const
|
||||
{
|
||||
if (!parcel.WriteString(sessionId)) {
|
||||
return false;
|
||||
}
|
||||
if (!parcel.WriteString(toolName)) {
|
||||
return false;
|
||||
}
|
||||
if (!parcel.WriteString(status)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
bool hasResult = (result != nullptr);
|
||||
if (!parcel.WriteBool(hasResult)) {
|
||||
return false;
|
||||
}
|
||||
if (hasResult && !parcel.WriteParcelable(result.get())) {
|
||||
TAG_LOGE(AAFwkTag::CLI_TOOL, "Write result failed.");
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
CliSessionInfo *CliSessionInfo::Unmarshalling(Parcel &parcel)
|
||||
{
|
||||
auto *info = new (std::nothrow) CliSessionInfo();
|
||||
if (info && !parcel.ReadString(info->sessionId)) {
|
||||
delete info;
|
||||
return nullptr;
|
||||
}
|
||||
if (!parcel.ReadString(info->toolName)) {
|
||||
delete info;
|
||||
return nullptr;
|
||||
}
|
||||
if (!parcel.ReadString(info->status)) {
|
||||
delete info;
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
bool hasResult = false;
|
||||
if (!parcel.ReadBool(hasResult)) {
|
||||
delete info;
|
||||
return nullptr;
|
||||
}
|
||||
if (hasResult) {
|
||||
std::shared_ptr<ExecResult> execResult(parcel.ReadParcelable<ExecResult>());
|
||||
if (execResult == nullptr) {
|
||||
delete info;
|
||||
return nullptr;
|
||||
}
|
||||
info->result = execResult;
|
||||
}
|
||||
return info;
|
||||
}
|
||||
} // namespace CliTool
|
||||
} // namespace OHOS
|
||||
@@ -0,0 +1,73 @@
|
||||
/*
|
||||
* Copyright (c) 2026 Huawei Device Co., Ltd.
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#include "exec_result.h"
|
||||
|
||||
namespace OHOS {
|
||||
namespace CliTool {
|
||||
bool ExecResult::Marshalling(Parcel &parcel) const
|
||||
{
|
||||
if (!parcel.WriteInt32(exitCode)) {
|
||||
return false;
|
||||
}
|
||||
if (!parcel.WriteString(outputText)) {
|
||||
return false;
|
||||
}
|
||||
if (!parcel.WriteString(errorText)) {
|
||||
return false;
|
||||
}
|
||||
if (!parcel.WriteInt32(signalNumber)) {
|
||||
return false;
|
||||
}
|
||||
if (!parcel.WriteBool(timedOut)) {
|
||||
return false;
|
||||
}
|
||||
if (!parcel.WriteInt64(executionTime)) {
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
ExecResult *ExecResult::Unmarshalling(Parcel &parcel)
|
||||
{
|
||||
auto *result = new (std::nothrow) ExecResult();
|
||||
if (result && !parcel.ReadInt32(result->exitCode)) {
|
||||
delete result;
|
||||
return nullptr;
|
||||
}
|
||||
if (!parcel.ReadString(result->outputText)) {
|
||||
delete result;
|
||||
return nullptr;
|
||||
}
|
||||
if (!parcel.ReadString(result->errorText)) {
|
||||
delete result;
|
||||
return nullptr;
|
||||
}
|
||||
if (!parcel.ReadInt32(result->signalNumber)) {
|
||||
delete result;
|
||||
return nullptr;
|
||||
}
|
||||
if (!parcel.ReadBool(result->timedOut)) {
|
||||
delete result;
|
||||
return nullptr;
|
||||
}
|
||||
if (!parcel.ReadInt64(result->executionTime)) {
|
||||
delete result;
|
||||
return nullptr;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
} // namespace CliTool
|
||||
} // namespace OHOS
|
||||
@@ -25,7 +25,7 @@
|
||||
#include <sys/wait.h>
|
||||
#include <condition_variable>
|
||||
|
||||
#include "icli_tool_data.h"
|
||||
#include "cli_session_info.h"
|
||||
|
||||
namespace OHOS {
|
||||
namespace CliTool {
|
||||
@@ -84,7 +84,7 @@ public:
|
||||
private:
|
||||
void TrimBufferedOutput(std::string &buffer);
|
||||
|
||||
ExecResult &BuildExecResult() const;
|
||||
std::shared_ptr<ExecResult> BuildExecResult() const;
|
||||
|
||||
private:
|
||||
std::atomic<SessionState> state_ {SessionState::SPAWNING};
|
||||
|
||||
@@ -124,7 +124,8 @@ void SessionRecord::BuildSessionInfo(CliSessionInfo &session) const
|
||||
session.status = "running";
|
||||
} else {
|
||||
session.result = BuildExecResult();
|
||||
session.status = (session.result.timedOut || session.result.exitCode != 0) ? "failed" : "completed";
|
||||
session.status =
|
||||
(!session.result || session.result->timedOut || session.result->exitCode != 0) ? "failed" : "completed";
|
||||
}
|
||||
}
|
||||
|
||||
@@ -136,20 +137,20 @@ void SessionRecord::TrimBufferedOutput(std::string &buffer)
|
||||
buffer.erase(0, buffer.size() - MAX_BUFFERED_OUTPUT_BYTES);
|
||||
}
|
||||
|
||||
ExecResult &SessionRecord::BuildExecResult() const
|
||||
std::shared_ptr<ExecResult> SessionRecord::BuildExecResult() const
|
||||
{
|
||||
ExecResult result;
|
||||
auto result = std::make_shared<ExecResult>();
|
||||
std::lock_guard<std::mutex> lock(resultMutex_);
|
||||
if (timedOut_) {
|
||||
result.executionTime = timeoutMs;
|
||||
result->executionTime = timeoutMs;
|
||||
} else {
|
||||
result.exitCode = terminalStatus_;
|
||||
result.executionTime = (endTimeMs_ > startTime) ? (endTimeMs_ - startTime) : 0;
|
||||
result->exitCode = terminalStatus_;
|
||||
result->executionTime = (endTimeMs_ > startTime) ? (endTimeMs_ - startTime) : 0;
|
||||
}
|
||||
result.outputText = stdoutText_;
|
||||
result.errorText = stderrText_;
|
||||
result.signalNumber = signalNumber_;
|
||||
result.timedOut = timedOut_;
|
||||
result->outputText = stdoutText_;
|
||||
result->errorText = stderrText_;
|
||||
result->signalNumber = signalNumber_;
|
||||
result->timedOut = timedOut_;
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user