h804tun/common.h

47 lines
1.0 KiB
C
Raw Permalink Normal View History

2018-10-17 03:11:21 +00:00
#pragma once
#include <iostream>
#include <string>
#ifdef H804_SYSTEMD_ENABLE
#include <systemd/sd-daemon.h>
#endif
namespace h804 {
enum class LogLevel : size_t { DEBUG, INFO, NOTICE, WARN, ERROR, _SIZE };
void daemon_notify_ready();
2018-10-17 17:01:46 +00:00
void daemon_notify(const std::string& args);
2018-10-17 03:11:21 +00:00
void _log(const LogLevel, const std::string&);
void _log(const LogLevel, const char*);
class _Logger {
LogLevel level;
public:
_Logger(LogLevel level);
void operator<<(const std::string&) const;
void operator<<(const char*) const;
};
const _Logger debug(LogLevel::DEBUG);
const _Logger info(LogLevel::INFO);
const _Logger notice(LogLevel::NOTICE);
const _Logger warn(LogLevel::WARN);
const _Logger error(LogLevel::ERROR);
class errno_exception : public std::exception {
const std::string _what;
public:
2018-10-17 17:01:46 +00:00
const int saved_errno;
2018-10-17 03:11:21 +00:00
errno_exception() noexcept;
errno_exception(const char* msg) noexcept;
const char* what() const noexcept;
};
void check(long x);
void check(long x, const char* msg);
} // namespace h804