• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2021-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 <fstream>
17 #include <iostream>
18 #include <sstream>
19 #include <thread>
20 
21 #include "adapter/preview/entrance/ace_ability.h"
22 #include "adapter/preview/entrance/ace_run_args.h"
23 #include "adapter/preview/entrance/samples/key_input_handler.h"
24 #include "adapter/preview/entrance/samples/touch_event_handler.h"
25 
26 namespace {
27 
28 constexpr int32_t GET_INSPECTOR_TREE_TIMES = 12;
29 constexpr int32_t GET_INSPECTOR_TREE_INTERVAL = 5000;
30 constexpr char FILE_NAME[] = "InspectorTree.txt";
31 constexpr char ACE_VERSION_2[] = "2.0";
32 constexpr char MODEL_STAGE[] = "stage";
33 constexpr char MAX_ARGS_COUNT = 2;
34 
__anon6311ad5a0202(const void*, const size_t bufferSize, const int32_t width, const int32_t height) 35 auto&& renderCallback = [](const void*, const size_t bufferSize, const int32_t width, const int32_t height) -> bool {
36     return true;
37 };
38 
39 } // namespace
40 
main(int argc,const char * argv[])41 int main(int argc, const char* argv[])
42 {
43 #ifdef MAC_PLATFORM
44     std::string assetPathJs = "/Volumes/SSD2T/daily-test/preview/js/default";
45     std::string assetPathEts = "/Volumes/SSD2T/daily-test/preview/js/default_2.0";
46     std::string assetPathEtsStage = "/Volumes/SSD2T/daily-test/preview/js/default_stage/ets";
47     std::string appResourcesPath = "/Volumes/SSD2T/daily-test/preview/js/AppResources";
48     std::string appResourcesPathStage = "/Volumes/SSD2T/daily-test/preview/js/default_stage";
49     std::string systemResourcesPath = "/Volumes/SSD2T/daily-test/preview/js/SystemResources";
50 #elif WINDOWS_PLATFORM
51     std::string assetPathJs = "D:\\Workspace\\preview\\js\\default";
52     std::string assetPathEts = "D:\\Workspace\\preview\\js\\default_2.0";
53     std::string assetPathEtsStage = "D:\\Workspace\\preview\\js\\default_stage\\ets";
54     std::string appResourcesPath = "D:\\Workspace\\preview\\js\\AppResources\\assets\\entry";
55     std::string appResourcesPathStage = "D:\\Workspace\\preview\\js\\default_stage";
56     std::string systemResourcesPath = "D:\\Workspace\\preview\\js\\SystemResources\\assets\\entry";
57 #else
58     std::string assetPathJs = "/home/ubuntu/demo/preview/js/default";
59     std::string assetPathEts = "/home/ubuntu/demo/preview/js/default_2.0";
60     std::string assetPathEtsStage = "/home/ubuntu/demo/preview/js/default_stage/ets";
61     std::string appResourcesPath = "/home/ubuntu/demo/preview/js/AppResources";
62     std::string appResourcesPathStage = "/home/ubuntu/demo/preview/js/default_stage";
63     std::string systemResourcesPath = "/home/ubuntu/demo/preview/js/SystemResources";
64 #endif
65     OHOS::Ace::Platform::AceRunArgs args = {
66         .assetPath = assetPathJs,
67         .systemResourcesPath = systemResourcesPath,
68         .appResourcesPath = appResourcesPath,
69         .deviceConfig.orientation = OHOS::Ace::DeviceOrientation::LANDSCAPE,
70         .deviceConfig.density = 1,
71         .deviceConfig.deviceType = OHOS::Ace::DeviceType::CAR,
72         .windowTitle = "ACE Car",
73         .deviceWidth = 1280,
74         .deviceHeight = 800,
75         .onRender = std::move(renderCallback),
76     };
77 
78     if (argc == MAX_ARGS_COUNT) {
79         if (!std::strcmp(argv[1], ACE_VERSION_2)) {
80             args.assetPath = assetPathEts;
81             args.aceVersion = OHOS::Ace::Platform::AceVersion::ACE_2_0;
82         } else if (!std::strcmp(argv[1], MODEL_STAGE)) {
83             args.assetPath = assetPathEtsStage;
84             args.aceVersion = OHOS::Ace::Platform::AceVersion::ACE_2_0;
85             args.appResourcesPath = appResourcesPathStage;
86             args.projectModel = OHOS::Ace::Platform::ProjectModel::STAGE;
87         }
88     }
89 
90     auto ability = OHOS::Ace::Platform::AceAbility::CreateInstance(args);
91     if (!ability) {
92         std::cerr << "Could not create AceAbility!" << std::endl;
93         return -1;
94     }
95     OHOS::Ace::Platform::KeyInputHandler::InitialTextInputCallback(ability->GetGlfwWindowController());
96     OHOS::Ace::Platform::TouchEventHandler::InitialTouchEventCallback(ability->GetGlfwWindowController());
97 
98     std::thread timer([&ability]() {
99         int32_t getJSONTreeTimes = GET_INSPECTOR_TREE_TIMES;
100         while (getJSONTreeTimes--) {
101             std::this_thread::sleep_for(std::chrono::milliseconds(GET_INSPECTOR_TREE_INTERVAL));
102             std::string jsonTreeStr = ability->GetJSONTree();
103             // clear all information
104             std::ofstream fileCleaner(FILE_NAME, std::ios_base::out);
105             std::ofstream fileWriter(FILE_NAME, std::ofstream::app);
106             fileWriter << jsonTreeStr;
107             fileWriter << std::endl;
108             fileWriter.close();
109         }
110     });
111     ability->InitEnv();
112     std::cout << "Ace initialize done. run loop now" << std::endl;
113     ability->Start();
114 
115     return 0;
116 }
117