x_error_count, etc

This commit is contained in:
David Rose 2010-05-04 19:33:27 +00:00
parent 42a456b2db
commit 24c91f85f3
3 changed files with 66 additions and 0 deletions

View File

@ -70,3 +70,49 @@ get_hidden_cursor() {
}
return _hidden_cursor;
}
////////////////////////////////////////////////////////////////////
// Function: x11GraphicsPipe::disable_x_error_messages
// Access: Public, Static
// Description: Globally disables the printing of error messages that
// are raised by the X11 system, for instance in order
// to test whether a particular X11 operation will
// succeed. Reenable error messages with a later call
// to enable_x_error_messages().
//
// The return value is the current value of
// get_x_error_count().
////////////////////////////////////////////////////////////////////
INLINE int x11GraphicsPipe::
disable_x_error_messages() {
_x_error_messages_enabled = false;
return _x_error_count;
}
////////////////////////////////////////////////////////////////////
// Function: x11GraphicsPipe::enable_x_error_messages
// Access: Public, Static
// Description: Reenables the printing of error messages after a
// previous call to disable_x_error_messages().
//
// The return value is the current value of
// get_x_error_count().
////////////////////////////////////////////////////////////////////
INLINE int x11GraphicsPipe::
enable_x_error_messages() {
_x_error_messages_enabled = true;
return _x_error_count;
}
////////////////////////////////////////////////////////////////////
// Function: x11GraphicsPipe::get_x_error_count
// Access: Public, Static
// Description: Returns the number of times an error indication has
// been raised by the X11 system since application
// start, including errors raised while error messages
// were disabled.
////////////////////////////////////////////////////////////////////
INLINE int x11GraphicsPipe::
get_x_error_count() {
return _x_error_count;
}

View File

@ -30,6 +30,8 @@ TypeHandle x11GraphicsPipe::_type_handle;
bool x11GraphicsPipe::_error_handlers_installed = false;
x11GraphicsPipe::ErrorHandlerFunc *x11GraphicsPipe::_prev_error_handler;
x11GraphicsPipe::IOErrorHandlerFunc *x11GraphicsPipe::_prev_io_error_handler;
bool x11GraphicsPipe::_x_error_messages_enabled = true;
int x11GraphicsPipe::_x_error_count = 0;
LightReMutex x11GraphicsPipe::_x_mutex;
@ -257,9 +259,20 @@ install_error_handlers() {
////////////////////////////////////////////////////////////////////
int x11GraphicsPipe::
error_handler(Display *display, XErrorEvent *error) {
++_x_error_count;
static const int msg_len = 80;
char msg[msg_len];
XGetErrorText(display, error->error_code, msg, msg_len);
if (!_x_error_messages_enabled) {
if (x11display_cat.is_debug()) {
x11display_cat.debug()
<< msg << "\n";
}
return 0;
}
x11display_cat.error()
<< msg << "\n";

View File

@ -44,6 +44,10 @@ public:
INLINE Cursor get_hidden_cursor();
static INLINE int disable_x_error_messages();
static INLINE int enable_x_error_messages();
static INLINE int get_x_error_count();
public:
virtual PreferredWindowThread get_preferred_window_thread() const;
@ -81,6 +85,9 @@ private:
static bool _error_handlers_installed;
static ErrorHandlerFunc *_prev_error_handler;
static IOErrorHandlerFunc *_prev_io_error_handler;
static bool _x_error_messages_enabled;
static int _x_error_count;
public:
// This Mutex protects any X library calls, which all have to be