2 * Copyright (C) 2017 Mentor Graphics Development (Deutschland) GmbH
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.
26 #include <afb/afb-binding.h>
30 #define ATTR_FORMAT(stringindex, firsttocheck) \
31 __attribute__((format(printf, stringindex, firsttocheck)))
32 #define ATTR_NORETURN __attribute__((noreturn))
34 #define ATTR_FORMAT(stringindex, firsttocheck)
38 #define lognotice(...) AFB_NOTICE(__VA_ARGS__)
39 #define logerror(...) AFB_ERROR(__VA_ARGS__)
42 AFB_ERROR(__VA_ARGS__); \
47 #define logdebug(...) AFB_DEBUG(__VA_ARGS__)
55 std::ostringstream o; \
56 o << __FILE__ << ":" << __LINE__ << ":" << __func__ << ": " << expr; \
57 logdebug("%s", o.str().c_str()); \
64 // ___| |_ _ __ _ _ ___| |_ _ _ _ __ (_) __ _ _ _ ___ / _| __| |
65 // / __| __| '__| | | |/ __| __| | | | | '_ \| |/ _` | | | |/ _ \ | |_ / _` |
66 // \__ \ |_| | | |_| | (__| |_ | |_| | | | | | (_| | |_| | __/ | _| (_| |
67 // |___/\__|_| \__,_|\___|\__| \__,_|_| |_|_|\__, |\__,_|\___|___|_| \__,_|
71 unique_fd() = default;
72 explicit unique_fd(int f) : fd{f} {}
73 operator int() const { return fd; }
75 unique_fd(unique_fd const &) = delete;
76 unique_fd &operator=(unique_fd const &) = delete;
77 unique_fd(unique_fd &&o) : fd(o.fd) { o.fd = -1; }
78 unique_fd &operator=(unique_fd &&o) {
79 std::swap(this->fd, o.fd);
85 // ___| |_ _ __ _ _ ___| |_ | _ \ ___ | | | ___ _ __
86 // / __| __| '__| | | |/ __| __| | |_) / _ \| | |/ _ \ '__|
87 // \__ \ |_| | | |_| | (__| |_ | __/ (_) | | | __/ |
88 // |___/\__|_| \__,_|\___|\__| |_| \___/|_|_|\___|_|
91 std::vector<std::function<int(int)>> handlers;
92 std::vector<struct pollfd> pfds;
95 void add_fd(int fd, std::function<int(int)> handler);
99 #endif // !WM_UTIL_HPP