blob: 3d544c1d5fb76ebfd17bb3c8c49f2008da860057 [file] [log] [blame]
/* Copyright 2016 The Chromium OS Authors. All rights reserved.
* Use of this source code is governed by a BSD-style license that can be
* found in the LICENSE file.
*/
#ifndef CAMERA_INCLUDE_CROS_CAMERA_COMMON_H_
#define CAMERA_INCLUDE_CROS_CAMERA_COMMON_H_
#include <fcntl.h>
#include <string>
#include <base/files/scoped_file.h>
#include <base/logging.h>
#include <base/posix/eintr_wrapper.h>
#include <base/strings/stringprintf.h>
#include <base/threading/thread.h>
#define LOGF(level) LOG(level) << __FUNCTION__ << "(): "
#define LOGFID(level, id) LOG(level) << __FUNCTION__ << "(): id: " << id << ": "
#define LOGF_IF(level, res) LOG_IF(level, res) << __FUNCTION__ << "(): "
#define PLOGF(level) PLOG(level) << __FUNCTION__ << "(): "
#define PLOGFID(level, id) \
PLOG(level) << __FUNCTION__ << "(): id: " << id << ": "
#define PLOGF_IF(level, res) PLOG_IF(level, res) << __FUNCTION__ << "(): "
#define VLOGF(level) VLOG(level) << __FUNCTION__ << "(): "
#define VLOGFID(level, id) \
VLOG(level) << __FUNCTION__ << "(): id: " << id << ": "
#define VLOGF_ENTER() VLOGF(1) << "enter"
#define VLOGF_EXIT() VLOGF(1) << "exit"
// To keep compatibility with the existing code paths enabled by NDEBUG or
// DCHECK_ALWAYS_ON, we still enable the DVLOGF*() macros when DCHECK_IS_ON().
// The ENABLE_VERBOSE_DEBUG_LOGS is for when the image is built without NDEBUG
// (i.e. without the cros-debug USE flag). We can still turn on the debug logs
// by recompiling the binaries with ENABLE_VERBOSE_DEBUG_LOGS defined in
// //camera/build/BUILD.gn without breaking ABI compatibility with the libchrome
// in the image.
#if DCHECK_IS_ON() || ENABLE_VERBOSE_DEBUG_LOGS
#define DVLOGF(level) VLOG(level) << __FUNCTION__ << "(): "
#define DVLOGFID(level, id) \
VLOG(level) << __FUNCTION__ << "(): id: " << id << ": "
#else
#define DVLOGF(level) EAT_STREAM_PARAMETERS
#define DVLOGFID(level, id) EAT_STREAM_PARAMETERS
#endif // DCHECK_IS_ON() || ENABLE_VERBOSE_DEBUG_LOGS
inline std::string FormatToString(int32_t format) {
return std::string(reinterpret_cast<char*>(&format), 4);
}
// Duplicate the file descriptor |fd| with O_CLOEXEC flag set.
inline base::ScopedFD DupWithCloExec(int fd) {
if (fd < 0) {
return base::ScopedFD();
}
return base::ScopedFD(HANDLE_EINTR(fcntl(fd, F_DUPFD_CLOEXEC)));
}
#endif // CAMERA_INCLUDE_CROS_CAMERA_COMMON_H_