• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 using namespace std;
24 
25 static std::vector<std::string> liteDevice = {"liteWearable", "smartVision"};
26 
JsApp()27 JsApp::JsApp()
28     : pipeName(""),
29       pipePort(""),
30       jsAppPath(""),
31       bundleName("undefined"),
32       urlPath(""),
33       isFinished(true),
34       isRunning(true),
35       isDebug(false),
36       debugServerPort(0),
37       jsHeapSize(0),
38       colorMode(""),
39       orientation(""),
40       aceVersion(""),
41       screenDensity(""),
42       configChanges("")
43 {
44 }
45 
Stop()46 void JsApp::Stop()
47 {
48     ILOG("JsApp::Stop start stop js app.");
49     auto start = std::chrono::system_clock::now();
50     while (!isFinished) {
51         Interrupt();
52         this_thread::sleep_for(chrono::milliseconds(1));
53         auto end = std::chrono::system_clock::now();
54         auto passedSecond = chrono::duration_cast<chrono::seconds>(end - start).count();
55         if (passedSecond > 10) { // The restart timeout interval is 10 seconds.
56             ILOG("Restart js app time out!");
57             return;
58         }
59     }
60     ILOG("JsApp::Stop js app stop finished.");
61 }
62 
Interrupt()63 void JsApp::Interrupt() {}
64 
IsLiteDevice(std::string deviceType)65 bool JsApp::IsLiteDevice(std::string deviceType)
66 {
67     auto iter = find(liteDevice.begin(), liteDevice.end(), deviceType);
68     if (iter == liteDevice.end()) {
69         return false;
70     }
71     return true;
72 }
73 
SetPipeName(const std::string & name)74 void JsApp::SetPipeName(const std::string& name)
75 {
76     pipeName = name;
77 }
78 
SetPipePort(const std::string & port)79 void JsApp::SetPipePort(const std::string& port)
80 {
81     pipePort = port;
82 }
83 
SetJsAppPath(const string & value)84 void JsApp::SetJsAppPath(const string& value)
85 {
86     jsAppPath = value;
87 }
88 
SetScreenDensity(const std::string value)89 void JsApp::SetScreenDensity(const std::string value)
90 {
91     screenDensity = value;
92 }
93 
SetConfigChanges(const std::string value)94 void JsApp::SetConfigChanges(const std::string value)
95 {
96     configChanges = value;
97 }
98 
SetUrlPath(const string & value)99 void JsApp::SetUrlPath(const string& value)
100 {
101     urlPath = value;
102 }
103 
SetBundleName(const string & name)104 void JsApp::SetBundleName(const string& name)
105 {
106     bundleName = name;
107     FileSystem::SetBundleName(name);
108     FileSystem::MakeVirtualFileSystemPath();
109 }
110 
SetRunning(bool flag)111 void JsApp::SetRunning(bool flag)
112 {
113     isRunning = flag;
114 }
115 
GetRunning()116 bool JsApp::GetRunning()
117 {
118     return isRunning;
119 }
120 
SetIsDebug(bool value)121 void JsApp::SetIsDebug(bool value)
122 {
123     isDebug = value;
124 }
125 
SetDebugServerPort(uint16_t value)126 void JsApp::SetDebugServerPort(uint16_t value)
127 {
128     debugServerPort = value;
129 }
130 
SetJSHeapSize(uint32_t size)131 void JsApp::SetJSHeapSize(uint32_t size)
132 {
133     jsHeapSize = size;
134 }
135 
GetJSONTree()136 string JsApp::GetJSONTree()
137 {
138     return "";
139 }
140 
GetDefaultJSONTree()141 string JsApp::GetDefaultJSONTree()
142 {
143     return "";
144 }
145 
SetArgsColorMode(const string & value)146 void JsApp::SetArgsColorMode(const string& value)
147 {
148     colorMode = value;
149 }
150 
SetArgsAceVersion(const string & value)151 void JsApp::SetArgsAceVersion(const string& value)
152 {
153     aceVersion = value;
154 }
155 
ColorModeChanged(const std::string commandColorMode)156 void JsApp::ColorModeChanged(const std::string commandColorMode)
157 {
158     colorMode = commandColorMode;
159 }
160 
GetColorMode() const161 std::string JsApp::GetColorMode() const
162 {
163     return colorMode;
164 }
165 
GetOrientation() const166 std::string JsApp::GetOrientation() const
167 {
168     return orientation;
169 }
170 
OrientationChanged(std::string commandOrientation)171 void JsApp::OrientationChanged(std::string commandOrientation)
172 {
173     orientation = commandOrientation;
174 }
175 
ResolutionChanged(ResolutionParam &,int32_t,std::string)176 void JsApp::ResolutionChanged(ResolutionParam&, int32_t, std::string) {}
177 
ReloadRuntimePage(const std::string)178 void JsApp::ReloadRuntimePage(const std::string) {}
179 
MemoryRefresh(const std::string) const180 bool JsApp::MemoryRefresh(const std::string) const
181 {
182     return false;
183 }
184 
LoadDocument(const std::string,const std::string,const Json2::Value &)185 void JsApp::LoadDocument(const std::string, const std::string, const Json2::Value&) {}
186 
FoldStatusChanged(const std::string commandFoldStatus,int32_t currentWidth,int32_t currentHeight)187 void JsApp::FoldStatusChanged(const std::string commandFoldStatus,
188     int32_t currentWidth, int32_t currentHeight) {}
189 
SetAvoidArea(const AvoidAreas & areas)190 void JsApp::SetAvoidArea(const AvoidAreas& areas) {}
191 
GetCurrentAvoidArea() const192 const AvoidAreas JsApp::GetCurrentAvoidArea() const
193 {
194     AvoidAreas areas;
195     return areas;
196 }
197 
InitJsApp()198 void JsApp::InitJsApp() {}