1 /*
2 * Copyright (c) 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 "normal_scene.h"
17
18 namespace OHOS {
19 namespace WuKong {
20 namespace {
21 const int MAXINPUTNUM = 2;
22 const int ONEHUNDRED = 100;
23 const int NEWPERCENT = 70;
24 const int OLDPERCENT = 20;
25 } // namespace
NormalScene()26 NormalScene::NormalScene()
27 {
28 }
29
~NormalScene()30 NormalScene::~NormalScene()
31 {
32 }
SetInputComponentList(std::vector<std::shared_ptr<ComponentTree>> & componentList)33 ErrCode NormalScene::SetInputComponentList(std::vector<std::shared_ptr<ComponentTree>> &componentList)
34 {
35 ErrCode result = OHOS::ERR_OK;
36 int randomNumber = rand() % ONEHUNDRED;
37 uint32_t count = 0;
38 DEBUG_LOG_STR("randomNumber: %d", randomNumber);
39 std::vector<uint32_t> indexList;
40 if (randomNumber < NEWPERCENT) {
41 for (auto it = componentList.begin(); it != componentList.end(); it++) {
42 DEBUG_LOG_STR("component inputcount: %d", (*it)->GetInputCount());
43 if ((*it)->GetInputCount() > MAXINPUTNUM) {
44 indexList.push_back((*it)->GetIndex());
45 TRACK_LOG_STR("index0: %d", distance(componentList.begin(), it));
46 }
47 }
48 } else if (randomNumber < (NEWPERCENT + OLDPERCENT)) {
49 for (auto it = componentList.begin(); it != componentList.end(); it++) {
50 DEBUG_LOG_STR("component inputcount: %d", (*it)->GetInputCount());
51 if ((*it)->GetInputCount() <= MAXINPUTNUM) {
52 count++;
53 TRACK_LOG_STR("inputed count: %d, componentList size: %d", count, componentList.size());
54 indexList.push_back((*it)->GetIndex());
55 TRACK_LOG_STR("index: %d", distance(componentList.begin(), it));
56 }
57 }
58 }
59 if (count >= componentList.size()) {
60 if ((componentList.size() == 0) || (randomNumber < ONEHUNDRED && randomNumber >= (NEWPERCENT + OLDPERCENT))) {
61 isBack_ = true;
62 }
63 indexList.clear();
64 return OHOS::ERR_OK;
65 }
66 TRACK_LOG_STR("componentList size: %d", componentList.size());
67 TRACK_LOG_STR("indexList size: %d", indexList.size());
68 for (auto index : indexList) {
69 for (auto it = componentList.begin(); it != componentList.end(); it++) {
70 if ((*it)->GetIndex() == index) {
71 componentList.erase(it);
72 it--;
73 }
74 }
75 }
76 if ((componentList.size() == 0) || (randomNumber < ONEHUNDRED && randomNumber >= (NEWPERCENT + OLDPERCENT))) {
77 isBack_ = true;
78 }
79 indexList.clear();
80 return result;
81 }
82
SetInputComponent(std::vector<std::shared_ptr<ComponentTree>> & componentList,std::shared_ptr<ComponentTree> & componentinfo)83 ErrCode NormalScene::SetInputComponent(std::vector<std::shared_ptr<ComponentTree>> &componentList,
84 std::shared_ptr<ComponentTree> &componentinfo)
85 {
86 ErrCode result = OHOS::ERR_OK;
87 if (!componentList.empty()) {
88 for (auto it : componentList) {
89 DEBUG_LOG_STR("component inputcount: %d, node id: %016llX", it->GetInputCount(), it->GetNodeId());
90 if (it->GetInputCount() < 1) {
91 componentinfo = it;
92 break;
93 }
94 }
95 }
96 if (componentinfo == nullptr) {
97 isBack_ = true;
98 }
99 return result;
100 }
101 } // namespace WuKong
102 } // namespace OHOS
103