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