1 /*
2 * Copyright (c) 2023 Huawei Device Co., Ltd.
3 * Licensed under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License.
5 * You may obtain a copy of the License at
6 *
7 * http://www.apache.org/licenses/LICENSE-2.0
8 *
9 * Unless required by applicable law or agreed to in writing, software
10 * distributed under the License is distributed on an "AS IS" BASIS,
11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 * See the License for the specific language governing permissions and
13 * limitations under the License.
14 */
15
16 #include "JsApp.h"
17 #include <algorithm>
18 #include <sstream>
19 #include <cstdio>
20 #include "FileSystem.h"
21 #include "PreviewerEngineLog.h"
22
23 static std::vector<std::string> liteDevice = {"liteWearable", "smartVision"};
24
JsApp()25 JsApp::JsApp()
26 : pipeName(""),
27 pipePort(""),
28 jsAppPath(""),
29 bundleName("undefined"),
30 urlPath(""),
31 isFinished(true),
32 isRunning(true),
33 isDebug(false),
34 debugServerPort(0),
35 jsHeapSize(0),
36 colorMode(""),
37 orientation(""),
38 aceVersion(""),
39 screenDensity(""),
40 configChanges("")
41 {
42 }
43
Stop()44 void JsApp::Stop()
45 {
46 ILOG("JsApp::Stop start stop js app.");
47 auto start = std::chrono::system_clock::now();
48 while (!isFinished) {
49 Interrupt();
50 std::this_thread::sleep_for(std::chrono::milliseconds(1));
51 auto end = std::chrono::system_clock::now();
52 auto passedSecond = std::chrono::duration_cast<std::chrono::seconds>(end - start).count();
53 if (passedSecond > 10) { // The restart timeout interval is 10 seconds.
54 ILOG("Restart js app time out!");
55 return;
56 }
57 }
58 ILOG("JsApp::Stop js app stop finished.");
59 }
60
Interrupt()61 void JsApp::Interrupt() {}
62
IsLiteDevice(std::string deviceType)63 bool JsApp::IsLiteDevice(std::string deviceType)
64 {
65 auto iter = find(liteDevice.begin(), liteDevice.end(), deviceType);
66 if (iter == liteDevice.end()) {
67 return false;
68 }
69 return true;
70 }
71
SetPipeName(const std::string & name)72 void JsApp::SetPipeName(const std::string& name)
73 {
74 pipeName = name;
75 }
76
SetPipePort(const std::string & port)77 void JsApp::SetPipePort(const std::string& port)
78 {
79 pipePort = port;
80 }
81
SetJsAppPath(const std::string & value)82 void JsApp::SetJsAppPath(const std::string& value)
83 {
84 jsAppPath = value;
85 }
86
SetScreenDensity(const std::string value)87 void JsApp::SetScreenDensity(const std::string value)
88 {
89 screenDensity = value;
90 }
91
SetConfigChanges(const std::string value)92 void JsApp::SetConfigChanges(const std::string value)
93 {
94 configChanges = value;
95 }
96
SetUrlPath(const std::string & value)97 void JsApp::SetUrlPath(const std::string& value)
98 {
99 urlPath = value;
100 }
101
SetBundleName(const std::string & name)102 void JsApp::SetBundleName(const std::string& name)
103 {
104 bundleName = name;
105 FileSystem::SetBundleName(name);
106 FileSystem::MakeVirtualFileSystemPath();
107 }
108
SetRunning(bool flag)109 void JsApp::SetRunning(bool flag)
110 {
111 isRunning = flag;
112 }
113
GetRunning()114 bool JsApp::GetRunning()
115 {
116 return isRunning;
117 }
118
SetIsDebug(bool value)119 void JsApp::SetIsDebug(bool value)
120 {
121 isDebug = value;
122 }
123
SetDebugServerPort(uint16_t value)124 void JsApp::SetDebugServerPort(uint16_t value)
125 {
126 debugServerPort = value;
127 }
128
SetJSHeapSize(uint32_t size)129 void JsApp::SetJSHeapSize(uint32_t size)
130 {
131 jsHeapSize = size;
132 }
133
GetJSONTree()134 std::string JsApp::GetJSONTree()
135 {
136 return "";
137 }
138
GetDefaultJSONTree()139 std::string JsApp::GetDefaultJSONTree()
140 {
141 return "";
142 }
143
SetArgsColorMode(const std::string & value)144 void JsApp::SetArgsColorMode(const std::string& value)
145 {
146 colorMode = value;
147 }
148
SetArgsAceVersion(const std::string & value)149 void JsApp::SetArgsAceVersion(const std::string& value)
150 {
151 aceVersion = value;
152 }
153
ColorModeChanged(const std::string commandColorMode)154 void JsApp::ColorModeChanged(const std::string commandColorMode)
155 {
156 colorMode = commandColorMode;
157 }
158
GetColorMode() const159 std::string JsApp::GetColorMode() const
160 {
161 return colorMode;
162 }
163
GetOrientation() const164 std::string JsApp::GetOrientation() const
165 {
166 return orientation;
167 }
168
OrientationChanged(std::string commandOrientation)169 void JsApp::OrientationChanged(std::string commandOrientation)
170 {
171 orientation = commandOrientation;
172 }
173
ResolutionChanged(ResolutionParam &,int32_t,std::string)174 void JsApp::ResolutionChanged(ResolutionParam&, int32_t, std::string) {}
175
ReloadRuntimePage(const std::string)176 void JsApp::ReloadRuntimePage(const std::string) {}
177
MemoryRefresh(const std::string) const178 bool JsApp::MemoryRefresh(const std::string) const
179 {
180 return false;
181 }
182
LoadDocument(const std::string,const std::string,const Json2::Value &)183 void JsApp::LoadDocument(const std::string, const std::string, const Json2::Value&) {}
184
FoldStatusChanged(const std::string commandFoldStatus,int32_t currentWidth,int32_t currentHeight)185 void JsApp::FoldStatusChanged(const std::string commandFoldStatus,
186 int32_t currentWidth, int32_t currentHeight) {}
187
SetAvoidArea(const AvoidAreas & areas)188 void JsApp::SetAvoidArea(const AvoidAreas& areas) {}
189
GetCurrentAvoidArea() const190 const AvoidAreas JsApp::GetCurrentAvoidArea() const
191 {
192 AvoidAreas areas;
193 return areas;
194 }
195
InitJsApp()196 void JsApp::InitJsApp() {}