mirror of
https://github.com/openharmony/tools_previewer.git
synced 2026-07-19 22:33:34 -04:00
@@ -25,6 +25,7 @@
|
||||
#include "ModelManager.h"
|
||||
#include "PreviewerEngineLog.h"
|
||||
#include "VirtualScreen.h"
|
||||
#include "CommandParser.h"
|
||||
|
||||
using namespace std;
|
||||
|
||||
@@ -135,6 +136,9 @@ void CommandLineInterface::ProcessCommandMessage(std::string message) const
|
||||
}
|
||||
|
||||
string command = jsonData["command"].asString();
|
||||
if (CommandParser::GetInstance().IsStaticCard() && IsStaticIgnoreCmd(command)) {
|
||||
return;
|
||||
}
|
||||
std::unique_ptr<CommandLine> commandLine =
|
||||
CommandLineFactory::CreateCommandLine(command, type, jsonData["args"], *socket);
|
||||
if (commandLine == nullptr) {
|
||||
@@ -266,3 +270,13 @@ void CommandLineInterface::CreatCommandToSendData(const string commandName,
|
||||
}
|
||||
commandLine->RunAndSendResultToManager();
|
||||
}
|
||||
|
||||
bool CommandLineInterface::IsStaticIgnoreCmd(const string cmd) const
|
||||
{
|
||||
auto it = std::find(staticIgnoreCmd.begin(), staticIgnoreCmd.end(), cmd);
|
||||
if (it != staticIgnoreCmd.end()) {
|
||||
return false;
|
||||
} else {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -17,6 +17,7 @@
|
||||
#define COMMANDLINEINTERFACE_H
|
||||
|
||||
#include <memory>
|
||||
#include <vector>
|
||||
|
||||
#include "CommandLine.h"
|
||||
#include "LocalSocket.h"
|
||||
@@ -51,6 +52,8 @@ private:
|
||||
const static uint32_t MAX_COMMAND_LENGTH = 128;
|
||||
static bool isFirstWsSend;
|
||||
static bool isPipeConnected;
|
||||
std::vector<std::string> staticIgnoreCmd = { "ResolutionSwitch" };
|
||||
bool IsStaticIgnoreCmd(const std::string cmd) const;
|
||||
};
|
||||
|
||||
#endif // COMMANDLINEINTERFACE_H
|
||||
|
||||
@@ -34,6 +34,7 @@ bool VirtualScreen::isWebSocketListening = false;
|
||||
std::string VirtualScreen::webSocketPort = "";
|
||||
|
||||
std::chrono::system_clock::time_point VirtualScreen::startTime = std::chrono::system_clock::now();
|
||||
std::chrono::system_clock::time_point VirtualScreen::staticCardStartTime = std::chrono::system_clock::now();
|
||||
bool VirtualScreen::isStartCount = true;
|
||||
bool VirtualScreen::isOutOfSeconds = false;
|
||||
|
||||
@@ -272,6 +273,24 @@ bool VirtualScreen::JudgeStaticImage(const int duration)
|
||||
return true;
|
||||
}
|
||||
|
||||
bool VirtualScreen::StopSendStaticCardImage(const int duration)
|
||||
{
|
||||
if (CommandParser::GetInstance().IsStaticCard()) {
|
||||
static bool first = true;
|
||||
if (first) {
|
||||
first = false;
|
||||
VirtualScreen::staticCardStartTime = std::chrono::system_clock::now();
|
||||
}
|
||||
auto endTime = std::chrono::system_clock::now();
|
||||
int64_t timePassed = chrono::duration_cast<chrono::milliseconds>(endTime -
|
||||
VirtualScreen::staticCardStartTime).count();
|
||||
if (timePassed > duration) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
void VirtualScreen::RgbToJpg(unsigned char* data, const int32_t width, const int32_t height)
|
||||
{
|
||||
if (width < 1 || height < 1) {
|
||||
|
||||
@@ -86,6 +86,7 @@ public:
|
||||
bool JudgeAndDropFrame();
|
||||
void SetDropFrameFrequency(const int32_t& value);
|
||||
static bool JudgeStaticImage(const int duration);
|
||||
static bool StopSendStaticCardImage(const int duration);
|
||||
void RgbToJpg(unsigned char* data, const int32_t width, const int32_t height);
|
||||
static uint32_t inputKeyCountPerMinute;
|
||||
static uint32_t inputMethodCountPerMinute;
|
||||
@@ -121,6 +122,7 @@ protected:
|
||||
int bluePos = 2;
|
||||
|
||||
static std::chrono::system_clock::time_point startTime;
|
||||
static std::chrono::system_clock::time_point staticCardStartTime;
|
||||
VirtualScreen::LoadDocType startLoadDoc = VirtualScreen::LoadDocType::INIT;
|
||||
std::chrono::system_clock::time_point startDropFrameTime; // record start drop frame time
|
||||
int dropFrameFrequency = 0; // save drop frame frequency
|
||||
|
||||
@@ -103,6 +103,9 @@ bool VirtualScreenImpl::LoadDocCallback(const void* data,
|
||||
bool VirtualScreenImpl::CallBack(const void* data, const size_t length,
|
||||
const int32_t width, const int32_t height)
|
||||
{
|
||||
if (VirtualScreenImpl::GetInstance().StopSendStaticCardImage(STOP_SEND_CARD_DURATION_MS)) {
|
||||
return false;
|
||||
}
|
||||
if (VirtualScreenImpl::GetInstance().GetLoadDocFlag() < VirtualScreen::LoadDocType::FINISHED) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -55,6 +55,7 @@ private:
|
||||
uint64_t bufferSize;
|
||||
unsigned long long currentPos;
|
||||
static constexpr int SEND_IMG_DURATION_MS = 300;
|
||||
static constexpr int STOP_SEND_CARD_DURATION_MS = 10000;
|
||||
|
||||
uint8_t* loadDocTempBuffer;
|
||||
uint8_t* loadDocCopyBuffer;
|
||||
|
||||
+26
-2
@@ -45,7 +45,8 @@ CommandParser::CommandParser()
|
||||
pages("main_pages"),
|
||||
containerSdkPath(""),
|
||||
isComponentMode(false),
|
||||
abilityPath("")
|
||||
abilityPath(""),
|
||||
staticCard(false)
|
||||
{
|
||||
Register("-j", 1, "Launch the js app in <directory>.");
|
||||
Register("-n", 1, "Set the js app name show on <window title>.");
|
||||
@@ -81,6 +82,7 @@ CommandParser::CommandParser()
|
||||
Register("-hsp", 1, "Set container sdk path.");
|
||||
Register("-cpm", 1, "Set previewer start mode.");
|
||||
Register("-abp", 1, "Set abilityPath for debug.");
|
||||
Register("-staticCard", 1, "Set card mode.");
|
||||
}
|
||||
|
||||
CommandParser& CommandParser::GetInstance()
|
||||
@@ -118,7 +120,7 @@ bool CommandParser::IsCommandValid()
|
||||
partRet = partRet && IsColorModeValid() && IsOrientationValid() && IsWebSocketPortValid() && IsAceVersionValid();
|
||||
partRet = partRet && IsScreenModeValid() && IsAppResourcePathValid();
|
||||
partRet = partRet && IsProjectModelValid() && IsPagesValid() && IsContainerSdkPathValid();
|
||||
partRet = partRet && IsComponentModeValid() && IsAbilityPathValid();
|
||||
partRet = partRet && IsComponentModeValid() && IsAbilityPathValid() && IsStaticCardValid();
|
||||
if (partRet) {
|
||||
return true;
|
||||
}
|
||||
@@ -273,6 +275,11 @@ string CommandParser::GetAbilityPath() const
|
||||
return abilityPath;
|
||||
}
|
||||
|
||||
bool CommandParser::IsStaticCard() const
|
||||
{
|
||||
return staticCard;
|
||||
}
|
||||
|
||||
bool CommandParser::IsDebugPortValid()
|
||||
{
|
||||
if (IsSet("p")) {
|
||||
@@ -824,4 +831,21 @@ bool CommandParser::IsAbilityPathValid()
|
||||
}
|
||||
abilityPath = path;
|
||||
return true;
|
||||
}
|
||||
|
||||
bool CommandParser::IsStaticCardValid()
|
||||
{
|
||||
if (!IsSet("staticCard")) {
|
||||
return true;
|
||||
}
|
||||
string val = Value("staticCard");
|
||||
if (val != "true" && val != "false") {
|
||||
errorInfo = string("The staticCard argument unsupported.");
|
||||
ELOG("Launch -staticCard parameters abnormal!");
|
||||
return false;
|
||||
}
|
||||
if (val == "true") {
|
||||
staticCard = true;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
@@ -57,6 +57,7 @@ public:
|
||||
bool CheckParamInvalidity(std::string param, bool isNum);
|
||||
bool IsComponentMode() const;
|
||||
std::string GetAbilityPath() const;
|
||||
bool IsStaticCard() const;
|
||||
|
||||
private:
|
||||
CommandParser();
|
||||
@@ -110,6 +111,7 @@ private:
|
||||
std::string regex4Str = "^(?:[a-zA-Z0-9-_./\\s]+)$";
|
||||
bool isComponentMode;
|
||||
std::string abilityPath;
|
||||
bool staticCard;
|
||||
|
||||
bool IsDebugPortValid();
|
||||
bool IsAppPathValid();
|
||||
@@ -142,6 +144,7 @@ private:
|
||||
bool IsContainerSdkPathValid();
|
||||
bool IsComponentModeValid();
|
||||
bool IsAbilityPathValid();
|
||||
bool IsStaticCardValid();
|
||||
std::string HelpText();
|
||||
void ProcessingCommand(const std::vector<std::string>& strs);
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user