2 * Copyright (c) 2017 TOYOTA MOTOR CORPORATION
3 * Copyright (c) 2018 Konsulko Group
5 * Licensed under the Apache License, Version 2.0 (the "License");
6 * you may not use this file except in compliance with the License.
7 * You may obtain a copy of the License at
9 * http://www.apache.org/licenses/LICENSE-2.0
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 * See the License for the specific language governing permissions and
15 * limitations under the License.
28 #define CONCAT_(X, Y) X##Y
29 #define CONCAT(X, Y) CONCAT_(X, Y)
32 #define ATTR_FORMAT(stringindex, firsttocheck) \
33 __attribute__((format(printf, stringindex, firsttocheck)))
34 #define ATTR_NORETURN __attribute__((noreturn))
36 #define ATTR_FORMAT(stringindex, firsttocheck)
40 #ifdef AFB_BINDING_VERSION
41 #define lognotice(...) AFB_NOTICE(__VA_ARGS__)
42 #define logerror(...) AFB_ERROR(__VA_ARGS__)
46 AFB_ERROR(__VA_ARGS__); \
50 #define lognotice(...)
60 #ifdef AFB_BINDING_VERSION
61 #define logdebug(...) AFB_DEBUG(__VA_ARGS__)
74 ScopeTrace __attribute__((unused)) CONCAT(trace_scope_, __LINE__)(__func__)
76 ScopeTrace __attribute__((unused)) CONCAT(named_trace_scope_, __LINE__)(#N)
80 thread_local static int indent;
82 explicit ScopeTrace(char const *func);
93 unique_fd() = default;
94 explicit unique_fd(int f) : fd{f} {}
95 operator int() const { return fd; }
97 unique_fd(unique_fd const &) = delete;
98 unique_fd &operator=(unique_fd const &) = delete;
99 unique_fd(unique_fd &&o) : fd(o.fd) { o.fd = -1; }
100 unique_fd &operator=(unique_fd &&o)
102 std::swap(this->fd, o.fd);
110 explicit rectangle(long wd, long ht) : _right(wd - 1), _bottom(ht - 1) {};
112 void set_left(long l) {
115 long left() const { return _left; };
117 void set_right(long r) {
120 long right() const { return _right; };
122 void set_top(long t) {
125 long top() const { return _top; };
127 void set_bottom(long b) {
130 long bottom() const { return _bottom; }
136 return _right - _left + 1;
139 long height() const {
143 return _bottom - _top + 1;
146 void set_aspect(double ratio);
147 void fit(unsigned long to_width, unsigned long to_height);
148 void center(unsigned long outer_w, unsigned long outer_h);
151 bool is_valid() const {
152 return (_top > _bottom || _left > _right);
161 // Configuration file path helper
162 std::string get_file_path(const char *file_name, const char *log_category = "wm");
164 #endif // !WM_UTIL_HPP