2 * Copyright (c) 2017 TOYOTA MOTOR CORPORATION
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
27 static char ERROR_FLAG[6][20] = {"NONE", "ERROR", "WARNING", "NOTICE", "INFO", "DEBUG"};
29 void rectangle::fit(unsigned long to_width, unsigned long to_height)
31 // fit rect within (to_width x to_height)
33 if (to_width <= width()) {
35 set_bottom(top() + (static_cast<long>(to_width) * height() / width()) - 1);
36 set_right(left() + to_width - 1);
38 // scale to fit height
39 set_right(left() + (static_cast<long>(to_height) * width () / height()) - 1);
40 set_bottom(top() + to_height - 1);
44 void rectangle::center(unsigned long outer_w, unsigned long outer_h)
46 long inner_w = width();
47 long inner_h = height();
49 set_left((outer_w - inner_w) / 2);
50 set_right(left() + inner_w - 1);
51 set_top((outer_h - inner_h) / 2);
52 set_bottom(top() + inner_h - 1);
55 void rectangle::set_aspect(double ratio)
57 // aspect ratio is width:height (= width/height)
58 // e.g. Landscape of HD's ratio is 16:9 (= 1.777...)
59 // Portrait of HD's ratio is 9:16 (= 0.5625)
61 // width / height = ratio
62 // width * height = area
64 // width = sqrt(ratio * area)
65 // height = width / ratio
67 long orig_w = width();
68 long orig_h = height();
73 set_right(left() + orig_w - 1);
74 set_bottom(top() + static_cast<long>(orig_w / ratio + 0.5) - 1);
76 set_bottom(top() + orig_h - 1);
77 set_right(left() + static_cast<long>(orig_h * ratio + 0.5) - 1);
81 void _HMI_LOG(enum LOG_LEVEL level, const char* file, const char* func, const int line, const char* prefix, const char* log, ...)
83 const int log_level = (getenv("USE_HMI_DEBUG") == NULL)?LOG_LEVEL_ERROR:atoi(getenv("USE_HMI_DEBUG"));
93 clock_gettime(CLOCK_REALTIME, &tp);
94 time = (tp.tv_sec * 1000000L) + (tp.tv_nsec / 1000);
98 if (log == NULL || vasprintf(&message, log, args) < 0)
100 fprintf(stderr, "[%10.3f] [%s %s] [%s, %s(), Line:%d] >>> %s \n", time / 1000.0, prefix, ERROR_FLAG[level], file, func, line, message);
105 void _HMI_SEQ_LOG(enum LOG_LEVEL level, const char* file, const char* func, const int line, unsigned seq_num, const char* log, ...){
106 const int log_level = (getenv("USE_HMI_DEBUG") == NULL) ? LOG_LEVEL_ERROR:atoi(getenv("USE_HMI_DEBUG"));
107 if(log_level < level)
116 clock_gettime(CLOCK_REALTIME, &tp);
117 time = (tp.tv_sec * 1000000L) + (tp.tv_nsec / 1000);
121 if (log == NULL || vasprintf(&message, log, args) < 0)
123 fprintf(stderr, "[%10.3f] [wm %s] [%s, %s(), Line:%d] >>> req %d: %s \n", time / 1000.0, ERROR_FLAG[level], file, func, line, seq_num, message);
128 void _DUMP(enum LOG_LEVEL level, const char *log, ...)
130 const int log_level = (getenv("USE_HMI_DEBUG") == NULL) ? LOG_LEVEL_ERROR : atoi(getenv("USE_HMI_DEBUG"));
131 if (log_level < level)
138 if (log == NULL || vasprintf(&message, log, args) < 0)
140 fprintf(stderr, "%s \n", message);
145 std::vector<std::string> parseString(std::string str, char delimiter)
147 // Parse string by delimiter
148 std::vector<std::string> vct;
149 std::stringstream ss{str};
151 while (std::getline(ss, buf, delimiter))
155 // Delete space and push back to vector
156 vct.push_back(deleteSpace(buf));
162 std::string deleteSpace(std::string str)
164 std::string ret = str;
166 while ((pos = ret.find_first_of(" ")) != std::string::npos)
173 void ChangeAreaReq::dump()
175 DUMP("=== change request dump ===");
176 DUMP("request from : %s", this->appname.c_str());
177 DUMP("save : %s", this->save ? "true" : "false");
178 for(const auto& req : this->area_req)
180 DUMP("area change req : %s", req.first.c_str());
181 DUMP(" x:%d y:%d w:%d h:%d",req.second.x, req.second.y, req.second.w, req.second.h);
183 for(const auto& req : this->update_app2area)
185 DUMP("update change app : %s, area:%s", req.first.c_str(), req.second.c_str());
187 DUMP("======== dump end =========");