summaryrefslogtreecommitdiff
path: root/src/qcam/message_handler.cpp
AgeCommit message (Collapse)Author
2020-12-01qcam: Make log less verbose by defaultLaurent Pinchart
The qcam log prints one message per frame, which is pretty verbose. This feature is useful for debugging, but not necessarily as a default option. Silence it by default, and add a -v/--verbose command line parameter to make the log verbose. While this could have been handled manually by checking a verbose flag when printing the message, the feature is instead integrated with the Qt log infrastructure to make it more flexible. Messages printed by qDebug() are now silenced by default and controlled by the -v/--verbose argument. Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com> Reviewed-by: Kieran Bingham <kieran.bingham@ideasonboard.com> Reviewed-by: Jacopo Mondi <jacopo@jmondi.org>
53'>53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193
/* SPDX-License-Identifier: LGPL-2.1-or-later */
/*
 * Copyright (C) 2020, Google Inc.
 *
 * flags.h - Type-safe enum-based bitfields
 */

#pragma once

#include <type_traits>

namespace libcamera {

template<typename E>
class Flags
{
public:
	static_assert(std::is_enum<E>::value,
		      "Flags<> template parameter must be an enum");

	using Type = std::underlying_type_t<E>;

	constexpr Flags()
		: value_(0)
	{
	}

	constexpr Flags(E flag)
		: value_(static_cast<Type>(flag))
	{
	}

	constexpr Flags &operator&=(E flag)
	{
		value_ &= static_cast<Type>(flag);
		return *this;
	}

	constexpr Flags &operator&=(Flags other)
	{
		value_ &= other.value_;
		return *this;
	}

	constexpr Flags &operator|=(E flag)
	{
		value_ |= static_cast<Type>(flag);
		return *this;
	}

	constexpr Flags &operator|=(Flags other)
	{
		value_ |= other.value_;
		return *this;
	}

	constexpr Flags &operator^=(E flag)
	{
		value_ ^= static_cast<Type>(flag);
		return *this;
	}

	constexpr Flags &operator^=(Flags other)
	{
		value_ ^= other.value_;
		return *this;
	}

	constexpr bool operator==(E flag)
	{
		return value_ == static_cast<Type>(flag);
	}

	constexpr bool operator==(Flags other)
	{
		return value_ == static_cast<Type>(other);
	}

	constexpr bool operator!=(E flag)
	{
		return value_ != static_cast<Type>(flag);
	}

	constexpr bool operator!=(Flags other)
	{
		return value_ != static_cast<Type>(other);
	}

	constexpr explicit operator Type() const
	{
		return value_;
	}

	constexpr explicit operator bool() const
	{
		return !!value_;
	}

	constexpr Flags operator&(E flag) const
	{
		return Flags(static_cast<E>(value_ & static_cast<Type>(flag)));
	}

	constexpr Flags operator&(Flags other) const
	{
		return Flags(static_cast<E>(value_ & other.value_));
	}

	constexpr Flags operator|(E flag) const
	{
		return Flags(static_cast<E>(value_ | static_cast<Type>(flag)));
	}

	constexpr Flags operator|(Flags other) const
	{
		return Flags(static_cast<E>(value_ | other.value_));
	}

	constexpr Flags operator^(E flag) const
	{
		return Flags(static_cast<E>(value_ ^ static_cast<Type>(flag)));
	}

	constexpr Flags operator^(Flags other) const
	{
		return Flags(static_cast<E>(value_ ^ other.value_));
	}

	constexpr Flags operator~() const
	{
		return Flags(static_cast<E>(~value_));
	}

	constexpr bool operator!() const
	{
		return !value_;
	}

private:
	Type value_;
};

#ifndef __DOXYGEN__
template<typename E>
struct flags_enable_operators {
	static const bool enable = false;
};

template<typename E>
typename std::enable_if_t<flags_enable_operators<E>::enable, Flags<E>>
operator|(E lhs, E rhs)
{
	using type = std::underlying_type_t<E>;
	return Flags<E>(static_cast<E>(static_cast<type>(lhs) | static_cast<type>(rhs)));
}

template<typename E>
typename std::enable_if_t<flags_enable_operators<E>::enable, Flags<E>>
operator&(E lhs, E rhs)
{
	using type = std::underlying_type_t<E>;
	return Flags<E>(static_cast<E>(static_cast<type>(lhs) & static_cast<type>(rhs)));
}

template<typename E>
typename std::enable_if_t<flags_enable_operators<E>::enable, Flags<E>>
operator^(E lhs, E rhs)
{
	using type = std::underlying_type_t<E>;
	return Flags<E>(static_cast<E>(static_cast<type>(lhs) ^ static_cast<type>(rhs)));
}

template<typename E>
typename std::enable_if_t<flags_enable_operators<E>::enable, Flags<E>>
operator~(E rhs)
{
	using type = std::underlying_type_t<E>;
	return Flags<E>(static_cast<E>(~static_cast<type>(rhs)));
}

#define LIBCAMERA_FLAGS_ENABLE_OPERATORS(_enum)				\
template<>								\
struct flags_enable_operators<_enum> {					\
	static const bool enable = true;				\
};

#else /* __DOXYGEN__ */

#define LIBCAMERA_FLAGS_ENABLE_OPERATORS(_enum)

#endif /* __DOXYGEN__ */

} /* namespace libcamera */