These are supported by gcc and clang, and I don't think MSVC works well with our code anyway, so let's keep things simple and use these directly.pull/1574/head
#ifndef __RDR_EXCEPTION_H__ | #ifndef __RDR_EXCEPTION_H__ | ||||
#define __RDR_EXCEPTION_H__ | #define __RDR_EXCEPTION_H__ | ||||
#ifdef __GNUC__ | |||||
# define __printf_attr(a, b) __attribute__((__format__ (__printf__, a, b))) | |||||
#else | |||||
# define __printf_attr(a, b) | |||||
#endif // __GNUC__ | |||||
namespace rdr { | namespace rdr { | ||||
struct Exception { | struct Exception { | ||||
enum { len = 256 }; | enum { len = 256 }; | ||||
char str_[len]; | char str_[len]; | ||||
Exception(const char *format = 0, ...) __printf_attr(2, 3); | |||||
Exception(const char *format = 0, ...) | |||||
__attribute__((__format__ (__printf__, 2, 3))); | |||||
virtual ~Exception() {} | virtual ~Exception() {} | ||||
virtual const char* str() const { return str_; } | virtual const char* str() const { return str_; } | ||||
}; | }; |
#include <rfb/Logger.h> | #include <rfb/Logger.h> | ||||
#include <rfb/Configuration.h> | #include <rfb/Configuration.h> | ||||
#ifdef __GNUC__ | |||||
# define __printf_attr(a, b) __attribute__((__format__ (__printf__, a, b))) | |||||
#else | |||||
# define __printf_attr(a, b) | |||||
#endif // __GNUC__ | |||||
// Each log writer instance has a unique textual name, | // Each log writer instance has a unique textual name, | ||||
// and is attached to a particular Log instance and | // and is attached to a particular Log instance and | ||||
// is assigned a particular log level. | // is assigned a particular log level. | ||||
#define DEF_LOGFUNCTION(name, level) \ | #define DEF_LOGFUNCTION(name, level) \ | ||||
inline void v##name(const char* fmt, va_list ap) __printf_attr(2, 0) { \ | |||||
inline void v##name(const char* fmt, va_list ap) \ | |||||
__attribute__((__format__ (__printf__, 2, 0))) \ | |||||
{ \ | |||||
if (m_log && (level <= m_level)) \ | if (m_log && (level <= m_level)) \ | ||||
m_log->write(level, m_name, fmt, ap); \ | m_log->write(level, m_name, fmt, ap); \ | ||||
} \ | } \ | ||||
inline void name(const char* fmt, ...) __printf_attr(2, 3) { \ | |||||
inline void name(const char* fmt, ...) \ | |||||
__attribute__((__format__ (__printf__, 2, 3))) \ | |||||
{ \ | |||||
if (m_log && (level <= m_level)) { \ | if (m_log && (level <= m_level)) { \ | ||||
va_list ap; va_start(ap, fmt); \ | va_list ap; va_start(ap, fmt); \ | ||||
m_log->write(level, m_name, fmt, ap);\ | m_log->write(level, m_name, fmt, ap);\ | ||||
void setLevel(int level); | void setLevel(int level); | ||||
int getLevel(void) { return m_level; } | int getLevel(void) { return m_level; } | ||||
inline void write(int level, const char* format, ...) __printf_attr(3, 4) { | |||||
inline void write(int level, const char* format, ...) | |||||
__attribute__((__format__ (__printf__, 3, 4))) | |||||
{ | |||||
if (m_log && (level <= m_level)) { | if (m_log && (level <= m_level)) { | ||||
va_list ap; | va_list ap; | ||||
va_start(ap, format); | va_start(ap, format); |
// and is attached to a particular Logger instance and | // and is attached to a particular Logger instance and | ||||
// is assigned a particular log level. | // is assigned a particular log level. | ||||
#ifdef __GNUC__ | |||||
# define __printf_attr(a, b) __attribute__((__format__ (__printf__, a, b))) | |||||
#else | |||||
# define __printf_attr(a, b) | |||||
#endif // __GNUC__ | |||||
namespace rfb { | namespace rfb { | ||||
class Logger { | class Logger { | ||||
// -=- Write data to a log | // -=- Write data to a log | ||||
virtual void write(int level, const char *logname, const char *text) = 0; | virtual void write(int level, const char *logname, const char *text) = 0; | ||||
void write(int level, const char *logname, const char* format, va_list ap) __printf_attr(4, 0); | |||||
void write(int level, const char *logname, const char* format, va_list ap) | |||||
__attribute__((__format__ (__printf__, 4, 0))); | |||||
// -=- Register a logger | // -=- Register a logger | ||||
// throwConnFailedException() prints a message to the log, sends a conn | // throwConnFailedException() prints a message to the log, sends a conn | ||||
// failed message to the client (if possible) and throws a | // failed message to the client (if possible) and throws a | ||||
// ConnFailedException. | // ConnFailedException. | ||||
void throwConnFailedException(const char* format, ...) __printf_attr(2, 3); | |||||
void throwConnFailedException(const char* format, ...) | |||||
__attribute__((__format__ (__printf__, 2, 3))); | |||||
void setState(stateEnum s) { state_ = s; } | void setState(stateEnum s) { state_ = s; } | ||||
struct timeval; | struct timeval; | ||||
#ifdef __GNUC__ | |||||
# define __printf_attr(a, b) __attribute__((__format__ (__printf__, a, b))) | |||||
#else | |||||
# define __printf_attr(a, b) | |||||
#endif // __GNUC__ | |||||
namespace rfb { | namespace rfb { | ||||
// -=- Class to handle cleanup of arrays of characters | // -=- Class to handle cleanup of arrays of characters | ||||
~CharArray() { | ~CharArray() { | ||||
delete [] buf; | delete [] buf; | ||||
} | } | ||||
void format(const char *fmt, ...) __printf_attr(2, 3); | |||||
void format(const char *fmt, ...) | |||||
__attribute__((__format__ (__printf__, 2, 3))); | |||||
// Get the buffer pointer & clear it (i.e. caller takes ownership) | // Get the buffer pointer & clear it (i.e. caller takes ownership) | ||||
char* takeBuf() {char* tmp = buf; buf = 0; return tmp;} | char* takeBuf() {char* tmp = buf; buf = 0; return tmp;} | ||||
void replaceBuf(char* b) {delete [] buf; buf = b;} | void replaceBuf(char* b) {delete [] buf; buf = b;} |
void vncInitRFB(void); | void vncInitRFB(void); | ||||
#ifdef __GNUC__ | |||||
# define __printf_attr(a, b) __attribute__((__format__ (__printf__, a, b))) | |||||
#else | |||||
# define __printf_attr(a, b) | |||||
#endif // __GNUC__ | |||||
void vncLogError(const char *name, const char *format, ...) __printf_attr(2, 3); | |||||
void vncLogStatus(const char *name, const char *format, ...) __printf_attr(2, 3); | |||||
void vncLogInfo(const char *name, const char *format, ...) __printf_attr(2, 3); | |||||
void vncLogDebug(const char *name, const char *format, ...) __printf_attr(2, 3); | |||||
void vncLogError(const char *name, const char *format, ...) | |||||
__attribute__((__format__ (__printf__, 2, 3))); | |||||
void vncLogStatus(const char *name, const char *format, ...) | |||||
__attribute__((__format__ (__printf__, 2, 3))); | |||||
void vncLogInfo(const char *name, const char *format, ...) | |||||
__attribute__((__format__ (__printf__, 2, 3))); | |||||
void vncLogDebug(const char *name, const char *format, ...) | |||||
__attribute__((__format__ (__printf__, 2, 3))); | |||||
int vncSetParam(const char *name, const char *value); | int vncSetParam(const char *name, const char *value); | ||||
int vncSetParamSimple(const char *nameAndValue); | int vncSetParamSimple(const char *nameAndValue); |
extern "C" { | extern "C" { | ||||
#endif | #endif | ||||
#ifdef __GNUC__ | |||||
# define __printf_attr(a, b) __attribute__((__format__ (__printf__, a, b))) | |||||
# define __noreturn_attr __attribute__((noreturn)) | |||||
#else | |||||
# define __printf_attr(a, b) | |||||
# define __noreturn_attr | |||||
#endif // __GNUC__ | |||||
const char *vncGetDisplay(void); | const char *vncGetDisplay(void); | ||||
unsigned long vncGetServerGeneration(void); | unsigned long vncGetServerGeneration(void); | ||||
void vncFatalError(const char *format, ...) __printf_attr(1, 2) __noreturn_attr; | |||||
void vncFatalError(const char *format, ...) | |||||
__attribute__((__format__ (__printf__, 1, 2))) | |||||
__attribute__((noreturn)); | |||||
int vncGetScreenCount(void); | int vncGetScreenCount(void); | ||||
class Fl_Scrollbar; | class Fl_Scrollbar; | ||||
#ifdef __GNUC__ | |||||
# define __printf_attr(a, b) __attribute__((__format__ (__printf__, a, b))) | |||||
#else | |||||
# define __printf_attr(a, b) | |||||
#endif // __GNUC__ | |||||
class DesktopWindow : public Fl_Window { | class DesktopWindow : public Fl_Window { | ||||
public: | public: | ||||
private: | private: | ||||
static void menuOverlay(void *data); | static void menuOverlay(void *data); | ||||
void setOverlay(const char *text, ...) __printf_attr(2, 3); | |||||
void setOverlay(const char *text, ...) | |||||
__attribute__((__format__ (__printf__, 2, 3))); | |||||
static void updateOverlay(void *data); | static void updateOverlay(void *data); | ||||
static int fltkDispatch(int event, Fl_Window *win); | static int fltkDispatch(int event, Fl_Window *win); |
#define VNCSERVERNAMELEN 256 | #define VNCSERVERNAMELEN 256 | ||||
#ifdef __GNUC__ | |||||
# define __printf_attr(a, b) __attribute__((__format__ (__printf__, a, b))) | |||||
#else | |||||
# define __printf_attr(a, b) | |||||
#endif // __GNUC__ | |||||
namespace rdr { | namespace rdr { | ||||
struct Exception; | struct Exception; | ||||
}; | }; | ||||
void abort_vncviewer(const char *error, ...) __printf_attr(1, 2); | |||||
void abort_connection(const char *error, ...) __printf_attr(1, 2); | |||||
void abort_vncviewer(const char *error, ...) | |||||
__attribute__((__format__ (__printf__, 1, 2))); | |||||
void abort_connection(const char *error, ...) | |||||
__attribute__((__format__ (__printf__, 1, 2))); | |||||
void abort_connection_with_unexpected_error(const rdr::Exception &); | void abort_connection_with_unexpected_error(const rdr::Exception &); | ||||
void disconnect(); | void disconnect(); |