17c804472Sopenharmony_ci/*
27c804472Sopenharmony_ci * Copyright (c) 2023 Huawei Device Co., Ltd.
37c804472Sopenharmony_ci * Licensed under the Apache License, Version 2.0 (the "License");
47c804472Sopenharmony_ci * you may not use this file except in compliance with the License.
57c804472Sopenharmony_ci * You may obtain a copy of the License at
67c804472Sopenharmony_ci *
77c804472Sopenharmony_ci *     http://www.apache.org/licenses/LICENSE-2.0
87c804472Sopenharmony_ci *
97c804472Sopenharmony_ci * Unless required by applicable law or agreed to in writing, software
107c804472Sopenharmony_ci * distributed under the License is distributed on an "AS IS" BASIS,
117c804472Sopenharmony_ci * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
127c804472Sopenharmony_ci * See the License for the specific language governing permissions and
137c804472Sopenharmony_ci * limitations under the License.
147c804472Sopenharmony_ci */
157c804472Sopenharmony_ci
167c804472Sopenharmony_ci#ifndef JSAPP_H
177c804472Sopenharmony_ci#define JSAPP_H
187c804472Sopenharmony_ci
197c804472Sopenharmony_ci#include <atomic>
207c804472Sopenharmony_ci#include <string>
217c804472Sopenharmony_ci#include <thread>
227c804472Sopenharmony_ci#include <vector>
237c804472Sopenharmony_ci#include "JsonReader.h"
247c804472Sopenharmony_ci
257c804472Sopenharmony_cistruct ResolutionParam {
267c804472Sopenharmony_ci    ResolutionParam(int32_t orignalWidth, int32_t orignalHeight,
277c804472Sopenharmony_ci        int32_t compressionWidth, int32_t compressionHeight)
287c804472Sopenharmony_ci    {
297c804472Sopenharmony_ci        this->orignalWidth = orignalWidth;
307c804472Sopenharmony_ci        this->orignalHeight = orignalHeight;
317c804472Sopenharmony_ci        this->compressionWidth = compressionWidth;
327c804472Sopenharmony_ci        this->compressionHeight = compressionHeight;
337c804472Sopenharmony_ci    }
347c804472Sopenharmony_ci    int32_t orignalWidth;
357c804472Sopenharmony_ci    int32_t orignalHeight;
367c804472Sopenharmony_ci    int32_t compressionWidth;
377c804472Sopenharmony_ci    int32_t compressionHeight;
387c804472Sopenharmony_ci};
397c804472Sopenharmony_ci
407c804472Sopenharmony_cistruct AvoidRect {
417c804472Sopenharmony_ci    int32_t posX;
427c804472Sopenharmony_ci    int32_t posY;
437c804472Sopenharmony_ci    uint32_t width;
447c804472Sopenharmony_ci    uint32_t height;
457c804472Sopenharmony_ci
467c804472Sopenharmony_ci    AvoidRect() : posX(0), posY(0), width(0), height(0) {}
477c804472Sopenharmony_ci
487c804472Sopenharmony_ci    AvoidRect(int32_t x, int32_t y, uint32_t w, uint32_t h) : posX(x), posY(y), width(w), height(h) {}
497c804472Sopenharmony_ci
507c804472Sopenharmony_ci    AvoidRect(const AvoidRect& other) : posX(other.posX), posY(other.posY),
517c804472Sopenharmony_ci        width(other.width), height(other.height) {}
527c804472Sopenharmony_ci
537c804472Sopenharmony_ci    bool operator==(const AvoidRect& a) const
547c804472Sopenharmony_ci    {
557c804472Sopenharmony_ci        return (posX == a.posX && posY == a.posY && width == a.width && height == a.height);
567c804472Sopenharmony_ci    }
577c804472Sopenharmony_ci
587c804472Sopenharmony_ci    AvoidRect& operator=(const AvoidRect& other)
597c804472Sopenharmony_ci    {
607c804472Sopenharmony_ci        if (this != &other) {
617c804472Sopenharmony_ci            this->posX = other.posX;
627c804472Sopenharmony_ci            this->posY = other.posY;
637c804472Sopenharmony_ci            this->width = other.width;
647c804472Sopenharmony_ci            this->height = other.height;
657c804472Sopenharmony_ci        }
667c804472Sopenharmony_ci        return *this;
677c804472Sopenharmony_ci    }
687c804472Sopenharmony_ci};
697c804472Sopenharmony_ci
707c804472Sopenharmony_cistruct AvoidAreas {
717c804472Sopenharmony_ci    AvoidRect topRect { 0, 0, 0, 0 };
727c804472Sopenharmony_ci    AvoidRect leftRect { 0, 0, 0, 0 };
737c804472Sopenharmony_ci    AvoidRect rightRect { 0, 0, 0, 0 };
747c804472Sopenharmony_ci    AvoidRect bottomRect { 0, 0, 0, 0 };
757c804472Sopenharmony_ci
767c804472Sopenharmony_ci    AvoidAreas() : topRect(0, 0, 0, 0), leftRect(0, 0, 0, 0), rightRect(0, 0, 0, 0), bottomRect(0, 0, 0, 0) {}
777c804472Sopenharmony_ci
787c804472Sopenharmony_ci    AvoidAreas(AvoidRect top, AvoidRect left, AvoidRect right, AvoidRect bottom) : topRect(top),
797c804472Sopenharmony_ci        leftRect(left), rightRect(right), bottomRect(bottom) {}
807c804472Sopenharmony_ci
817c804472Sopenharmony_ci    AvoidAreas(const AvoidAreas& other) : topRect(other.topRect), leftRect(other.leftRect),
827c804472Sopenharmony_ci                                          rightRect(other.rightRect), bottomRect(other.bottomRect) {}
837c804472Sopenharmony_ci
847c804472Sopenharmony_ci    bool operator==(const AvoidAreas& a) const
857c804472Sopenharmony_ci    {
867c804472Sopenharmony_ci        return (topRect == a.topRect && leftRect == a.leftRect &&
877c804472Sopenharmony_ci            rightRect == a.rightRect && bottomRect == a.bottomRect);
887c804472Sopenharmony_ci    }
897c804472Sopenharmony_ci
907c804472Sopenharmony_ci    AvoidAreas& operator=(const AvoidAreas& other)
917c804472Sopenharmony_ci    {
927c804472Sopenharmony_ci        if (this != &other) {
937c804472Sopenharmony_ci            this->topRect = other.topRect;
947c804472Sopenharmony_ci            this->leftRect = other.leftRect;
957c804472Sopenharmony_ci            this->rightRect = other.rightRect;
967c804472Sopenharmony_ci            this->bottomRect = other.bottomRect;
977c804472Sopenharmony_ci        }
987c804472Sopenharmony_ci        return *this;
997c804472Sopenharmony_ci    }
1007c804472Sopenharmony_ci};
1017c804472Sopenharmony_ci
1027c804472Sopenharmony_ciclass JsApp {
1037c804472Sopenharmony_cipublic:
1047c804472Sopenharmony_ci    JsApp& operator=(const JsApp&) = delete;
1057c804472Sopenharmony_ci    JsApp(const JsApp&) = delete;
1067c804472Sopenharmony_ci    virtual void Start() = 0;
1077c804472Sopenharmony_ci    virtual void Restart() = 0;
1087c804472Sopenharmony_ci    virtual void Interrupt() = 0;
1097c804472Sopenharmony_ci    virtual void Stop();
1107c804472Sopenharmony_ci    void SetJsAppPath(const std::string& value);
1117c804472Sopenharmony_ci    void SetUrlPath(const std::string& value);
1127c804472Sopenharmony_ci    void SetPipeName(const std::string& name);
1137c804472Sopenharmony_ci    void SetPipePort(const std::string& port);
1147c804472Sopenharmony_ci    void SetBundleName(const std::string& name);
1157c804472Sopenharmony_ci    void SetRunning(bool flag);
1167c804472Sopenharmony_ci    bool GetRunning();
1177c804472Sopenharmony_ci    void SetIsDebug(bool value);
1187c804472Sopenharmony_ci    void SetDebugServerPort(uint16_t value);
1197c804472Sopenharmony_ci    void SetJSHeapSize(uint32_t size);
1207c804472Sopenharmony_ci    virtual std::string GetJSONTree();
1217c804472Sopenharmony_ci    virtual std::string GetDefaultJSONTree();
1227c804472Sopenharmony_ci    virtual void OrientationChanged(std::string commandOrientation);
1237c804472Sopenharmony_ci    virtual void ResolutionChanged(ResolutionParam&, int32_t, std::string);
1247c804472Sopenharmony_ci    virtual void SetArgsColorMode(const std::string& value);
1257c804472Sopenharmony_ci    virtual void SetArgsAceVersion(const std::string& value);
1267c804472Sopenharmony_ci    virtual std::string GetOrientation() const;
1277c804472Sopenharmony_ci    virtual std::string GetColorMode() const;
1287c804472Sopenharmony_ci    virtual void ColorModeChanged(const std::string commandColorMode);
1297c804472Sopenharmony_ci    static bool IsLiteDevice(std::string deviceType);
1307c804472Sopenharmony_ci    virtual void ReloadRuntimePage(const std::string);
1317c804472Sopenharmony_ci    virtual void SetScreenDensity(const std::string value);
1327c804472Sopenharmony_ci    virtual void SetConfigChanges(const std::string value);
1337c804472Sopenharmony_ci    virtual bool MemoryRefresh(const std::string) const;
1347c804472Sopenharmony_ci    virtual void LoadDocument(const std::string, const std::string, const Json2::Value&);
1357c804472Sopenharmony_ci    virtual void FoldStatusChanged(const std::string commandFoldStatus,
1367c804472Sopenharmony_ci        int32_t currentWidth, int32_t currentHeight);
1377c804472Sopenharmony_ci    virtual void SetAvoidArea(const AvoidAreas& areas);
1387c804472Sopenharmony_ci    virtual const AvoidAreas GetCurrentAvoidArea() const;
1397c804472Sopenharmony_ci    virtual void InitJsApp();
1407c804472Sopenharmony_ciprotected:
1417c804472Sopenharmony_ci    JsApp();
1427c804472Sopenharmony_ci    virtual ~JsApp() {};
1437c804472Sopenharmony_ci    std::string pipeName;
1447c804472Sopenharmony_ci    std::string pipePort;
1457c804472Sopenharmony_ci    std::string jsAppPath;
1467c804472Sopenharmony_ci    std::string bundleName;
1477c804472Sopenharmony_ci    std::string urlPath;
1487c804472Sopenharmony_ci    std::atomic<bool> isFinished;
1497c804472Sopenharmony_ci    std::atomic<bool> isRunning;
1507c804472Sopenharmony_ci    bool isDebug;
1517c804472Sopenharmony_ci    uint16_t debugServerPort;
1527c804472Sopenharmony_ci    uint32_t jsHeapSize;
1537c804472Sopenharmony_ci    std::string colorMode;
1547c804472Sopenharmony_ci    std::string orientation;
1557c804472Sopenharmony_ci    std::string aceVersion;
1567c804472Sopenharmony_ci    std::string screenDensity;
1577c804472Sopenharmony_ci    std::string configChanges;
1587c804472Sopenharmony_ci};
1597c804472Sopenharmony_ci
1607c804472Sopenharmony_ci#endif // JSAPP_H
161