• 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 #ifndef JSAPP_H
17 #define JSAPP_H
18 
19 #include <atomic>
20 #include <string>
21 #include <thread>
22 #include <vector>
23 #include "JsonReader.h"
24 
25 struct ResolutionParam {
ResolutionParamResolutionParam26     ResolutionParam(int32_t orignalWidth, int32_t orignalHeight,
27         int32_t compressionWidth, int32_t compressionHeight)
28     {
29         this->orignalWidth = orignalWidth;
30         this->orignalHeight = orignalHeight;
31         this->compressionWidth = compressionWidth;
32         this->compressionHeight = compressionHeight;
33     }
34     int32_t orignalWidth;
35     int32_t orignalHeight;
36     int32_t compressionWidth;
37     int32_t compressionHeight;
38 };
39 
40 struct AvoidRect {
41     int32_t posX;
42     int32_t posY;
43     uint32_t width;
44     uint32_t height;
45 
AvoidRectAvoidRect46     AvoidRect() : posX(0), posY(0), width(0), height(0) {}
47 
AvoidRectAvoidRect48     AvoidRect(int32_t x, int32_t y, uint32_t w, uint32_t h) : posX(x), posY(y), width(w), height(h) {}
49 
AvoidRectAvoidRect50     AvoidRect(const AvoidRect& other) : posX(other.posX), posY(other.posY),
51         width(other.width), height(other.height) {}
52 
53     bool operator==(const AvoidRect& a) const
54     {
55         return (posX == a.posX && posY == a.posY && width == a.width && height == a.height);
56     }
57 
58     AvoidRect& operator=(const AvoidRect& other)
59     {
60         if (this != &other) {
61             this->posX = other.posX;
62             this->posY = other.posY;
63             this->width = other.width;
64             this->height = other.height;
65         }
66         return *this;
67     }
68 };
69 
70 struct AvoidAreas {
71     AvoidRect topRect { 0, 0, 0, 0 };
72     AvoidRect leftRect { 0, 0, 0, 0 };
73     AvoidRect rightRect { 0, 0, 0, 0 };
74     AvoidRect bottomRect { 0, 0, 0, 0 };
75 
AvoidAreasAvoidAreas76     AvoidAreas() : topRect(0, 0, 0, 0), leftRect(0, 0, 0, 0), rightRect(0, 0, 0, 0), bottomRect(0, 0, 0, 0) {}
77 
AvoidAreasAvoidAreas78     AvoidAreas(AvoidRect top, AvoidRect left, AvoidRect right, AvoidRect bottom) : topRect(top),
79         leftRect(left), rightRect(right), bottomRect(bottom) {}
80 
AvoidAreasAvoidAreas81     AvoidAreas(const AvoidAreas& other) : topRect(other.topRect), leftRect(other.leftRect),
82                                           rightRect(other.rightRect), bottomRect(other.bottomRect) {}
83 
84     bool operator==(const AvoidAreas& a) const
85     {
86         return (topRect == a.topRect && leftRect == a.leftRect &&
87             rightRect == a.rightRect && bottomRect == a.bottomRect);
88     }
89 
90     AvoidAreas& operator=(const AvoidAreas& other)
91     {
92         if (this != &other) {
93             this->topRect = other.topRect;
94             this->leftRect = other.leftRect;
95             this->rightRect = other.rightRect;
96             this->bottomRect = other.bottomRect;
97         }
98         return *this;
99     }
100 };
101 
102 class JsApp {
103 public:
104     JsApp& operator=(const JsApp&) = delete;
105     JsApp(const JsApp&) = delete;
106     virtual void Start() = 0;
107     virtual void Restart() = 0;
108     virtual void Interrupt() = 0;
109     virtual void Stop();
110     void SetJsAppPath(const std::string& value);
111     void SetUrlPath(const std::string& value);
112     void SetPipeName(const std::string& name);
113     void SetPipePort(const std::string& port);
114     void SetBundleName(const std::string& name);
115     void SetRunning(bool flag);
116     bool GetRunning();
117     void SetIsDebug(bool value);
118     void SetDebugServerPort(uint16_t value);
119     void SetJSHeapSize(uint32_t size);
120     virtual std::string GetJSONTree();
121     virtual std::string GetDefaultJSONTree();
122     virtual void OrientationChanged(std::string commandOrientation);
123     virtual void ResolutionChanged(ResolutionParam&, int32_t, std::string);
124     virtual void SetArgsColorMode(const std::string& value);
125     virtual void SetArgsAceVersion(const std::string& value);
126     virtual std::string GetOrientation() const;
127     virtual std::string GetColorMode() const;
128     virtual void ColorModeChanged(const std::string commandColorMode);
129     static bool IsLiteDevice(std::string deviceType);
130     virtual void ReloadRuntimePage(const std::string);
131     virtual void SetScreenDensity(const std::string value);
132     virtual void SetConfigChanges(const std::string value);
133     virtual bool MemoryRefresh(const std::string) const;
134     virtual void LoadDocument(const std::string, const std::string, const Json2::Value&);
135     virtual void FoldStatusChanged(const std::string commandFoldStatus,
136         int32_t currentWidth, int32_t currentHeight);
137     virtual void SetAvoidArea(const AvoidAreas& areas);
138     virtual const AvoidAreas GetCurrentAvoidArea() const;
139     virtual void InitJsApp();
140 protected:
141     JsApp();
~JsApp()142     virtual ~JsApp() {};
143     std::string pipeName;
144     std::string pipePort;
145     std::string jsAppPath;
146     std::string bundleName;
147     std::string urlPath;
148     std::atomic<bool> isFinished;
149     std::atomic<bool> isRunning;
150     bool isDebug;
151     uint16_t debugServerPort;
152     uint32_t jsHeapSize;
153     std::string colorMode;
154     std::string orientation;
155     std::string aceVersion;
156     std::string screenDensity;
157     std::string configChanges;
158 };
159 
160 #endif // JSAPP_H
161