• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 #ifndef UPDATER_UI_TRAITS_H
17 #define UPDATER_UI_TRAITS_H
18 
19 #include "component/component_factory.h"
20 #include "json_visitor.h"
21 #include "macros_updater.h"
22 #include "traits_util.h"
23 
24 namespace Updater {
25 // define struct for load ui strategy in ui config file
26 DEFINE_STRUCT_TRAIT(ComInfo, "com",
27     (std::string, pageId),
28     (std::string, comId)
29 );
30 
31 DEFINE_STRUCT_TRAIT(ProgressPage, "",
32     (std::string, progressPageId),
33     (std::string, progressComId),
34     (std::string, progressType),
35     (std::string, logoComId),
36     (std::string, logoType),
37     (std::string, warningComId)
38 );
39 
40 DEFINE_STRUCT_TRAIT(ResPage, "",
41     (std::string, successPageId),
42     (std::string, failPageId)
43 );
44 
45 DEFINE_STRUCT_TRAIT(UiStrategyCfg, "strategy",
46     (std::string, confirmPageId),
47     (ComInfo, labelLogId),
48     (ComInfo, labelLogResId),
49     (ComInfo, labelUpdId),
50     (ProgressPage, progressPage),
51     (ResPage, resPage)
52 );
53 
54 // define struct for load pages' components from page json config, such as menu.json, update.json
55 DEFINE_TRAIT(UxViewCommonInfo, "Common",
56     (int, x),
57     (int, y),
58     (int, w),
59     (int, h),
60     (std::string, id),
61     (std::string, type),
62     (bool, visible)
63 );
64 
65 DEFINE_TRAIT(UxBoxProgressInfo, BoxProgressAdapter::COMPONENT_TYPE,
66     (uint32_t, defaultValue),
67     (std::string, fgColor),
68     (std::string, bgColor),
69     (std::string, endPoint),
70     (bool, hasEp)
71 );
72 
73 DEFINE_TRAIT(UxLabelInfo, TextLabelAdapter::COMPONENT_TYPE,
74     (uint8_t, fontSize),
75     (std::string, text),
76     (std::string, align),
77     (std::string, fontColor),
78     (std::string, bgColor),
79     (std::string, style)
80 );
81 
82 DEFINE_TRAIT(UxImageInfo, ImgViewAdapter::COMPONENT_TYPE,
83     (std::string, resPath),
84     (std::string, filePrefix),
85     (uint32_t, imgCnt),
86     (uint32_t, updInterval)
87 );
88 
89 DEFINE_TRAIT(UxLabelBtnInfo, LabelBtnAdapter::COMPONENT_TYPE,
90     (uint8_t, fontSize),
91     (std::string, text),
92     (std::string, txtColor),
93     (std::string, bgColor),
94     (std::string, focusedTxtColor),
95     (std::string, focusedBgColor),
96     (bool, focusable)
97 );
98 
99 DEFINE_STRUCT_TRAIT(UxSubPageInfo, "subpages",
100     (std::string, id),
101     (std::string, bgColor),
102     (std::vector<std::string>, coms)
103 );
104 
105 DEFINE_STRUCT_TRAIT(PagePath, "",
106     (std::string, dir),
107     (std::string, entry),
108     (std::vector<std::string>, pages)
109 );
110 
111 struct UxPageInfo {
112     std::string id {};
113     std::string bgColor {};
114     std::vector<UxViewInfo> viewInfos {};
115     std::vector<UxSubPageInfo> subpages {};
116 };
117 
118 /**
119  * only define trait for uxpageinfo, because viewInfos_ is a variant,
120  * can't be parsed by Visit<SETVAL>(...), so it's manually parsed in
121  * LayoutParser
122  */
123 DEFINE_TRAIT(UxPageInfo, "",
124     (std::string, id),
125     (std::string, bgColor),
126     (std::vector<UxSubPageInfo>, subpages)
127 );
128 
129 // define struct for load language resources in ui config file
130 DEFINE_STRUCT_TRAIT(Res, "Res",
131     (std::string, path),
132     (int, level)
133 );
134 
135 DEFINE_STRUCT_TRAIT(LangResource, "",
136     (std::string, localeFile),
137     (std::vector<Res>, res)
138 );
139 
140 // define struct for load callback configuration in ui config file
141 DEFINE_STRUCT_TRAIT(CallbackCfg, "",
142     (std::string, pageId),
143     (std::string, comId),
144     (std::string, type),
145     (std::string, func)
146 );
147 
148 inline std::ostream &operator<<(std::ostream &os, const ComInfo &com)
149 {
150     os << "pageId: " << com.pageId << " comId: " << com.comId;
151     return os;
152 }
153 }
154 #endif
155