1 /*
2 * Copyright (c) 2021-2022 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
24 namespace {
25
26 constexpr int32_t GET_INSPECTOR_TREE_TIMES = 12;
27 constexpr int32_t GET_INSPECTOR_TREE_INTERVAL = 5000;
28 constexpr char FILE_NAME[] = "InspectorTree.txt";
29 constexpr char ACE_VERSION_2[] = "2.0";
30 constexpr char MAX_ARGS_COUNT = 2;
31
__anon20e2d9df0202(const void*, const size_t bufferSize, const int32_t width, const int32_t height) 32 auto&& renderCallback = [](const void*, const size_t bufferSize, const int32_t width, const int32_t height) -> bool {
33 return true;
34 };
35
36 } // namespace
37
main(int argc,const char * argv[])38 int main(int argc, const char* argv[])
39 {
40 #ifdef MAC_PLATFORM
41 std::string assetPathJs = "/Volumes/SSD2T/daily-test/preview/js/default";
42 std::string assetPathEts = "/Volumes/SSD2T/daily-test/preview/js/default_2.0";
43 #else
44 std::string assetPathJs = "D:\\Workspace\\preview\\js\\default";
45 std::string assetPathEts = "D:\\Workspace\\preview\\js\\default_2.0";
46 #endif
47 OHOS::Ace::Platform::AceRunArgs args = {
48 .assetPath = assetPathJs,
49 .deviceConfig.orientation = OHOS::Ace::DeviceOrientation::LANDSCAPE,
50 .deviceConfig.density = 1,
51 .deviceConfig.deviceType = OHOS::Ace::DeviceType::TV,
52 .windowTitle = "ACE TV",
53 .deviceWidth = 960,
54 .deviceHeight = 540,
55 .onRender = std::move(renderCallback),
56 };
57
58 if (argc == MAX_ARGS_COUNT && !std::strcmp(argv[1], ACE_VERSION_2)) {
59 args.assetPath = assetPathEts;
60 args.aceVersion = OHOS::Ace::Platform::AceVersion::ACE_2_0;
61 }
62
63 auto ability = OHOS::Ace::Platform::AceAbility::CreateInstance(args);
64 if (!ability) {
65 std::cerr << "Could not create AceAbility!" << std::endl;
66 return -1;
67 }
68
69 std::thread timer([&ability]() {
70 int32_t getJSONTreeTimes = GET_INSPECTOR_TREE_TIMES;
71 while (getJSONTreeTimes--) {
72 std::this_thread::sleep_for(std::chrono::milliseconds(GET_INSPECTOR_TREE_INTERVAL));
73 std::string jsonTreeStr = ability->GetJSONTree();
74 // clear all information
75 std::ofstream fileCleaner(FILE_NAME, std::ios_base::out);
76 std::ofstream fileWriter(FILE_NAME, std::ofstream::app);
77 fileWriter << jsonTreeStr;
78 fileWriter << std::endl;
79 fileWriter.close();
80 }
81 });
82 ability->InitEnv();
83 std::cout << "Ace initialize done. run loop now" << std::endl;
84 ability->Start();
85
86 return 0;
87 }
88