Analysis-Utilities
26.9.9
C++/ROOT utilities for nuclear measurement data analysis
Toggle main menu visibility
Loading...
Searching...
No Matches
InteractiveEditorX11Guard.hpp
Go to the documentation of this file.
1
#ifndef INTERACTIVEEDITORX11GUARD_H
2
#define INTERACTIVEEDITORX11GUARD_H
3
4
#include <Rtypes.h>
5
#include <dlfcn.h>
6
28
31
typedef
int (*
AUXErrorHandler
)(
void
*display,
void
*event);
32
34
typedef
AUXErrorHandler
(*
AUXSetErrorHandlerFn
)(
AUXErrorHandler
);
35
38
inline
int
AUIgnoreXError
(
void
*,
void
*) {
return
0; }
39
45
struct
AUXErrorHandlerSave
{
47
AUXSetErrorHandlerFn
set_fn
;
49
AUXErrorHandler
prev
;
50
};
51
70
inline
AUXErrorHandlerSave
AUInstallTolerantXErrorHandler
() {
71
AUXErrorHandlerSave
s;
72
s.
set_fn
= (
AUXSetErrorHandlerFn
)dlsym(RTLD_DEFAULT,
"XSetErrorHandler"
);
73
if
(!s.
set_fn
) {
74
// libX11 may have been brought in with local scope; promote and retry.
75
void
*h = dlopen(
"libX11.so.6"
, RTLD_NOW | RTLD_GLOBAL | RTLD_NOLOAD);
76
if
(h) {
77
s.
set_fn
= (
AUXSetErrorHandlerFn
)dlsym(h,
"XSetErrorHandler"
);
78
}
79
}
80
s.
prev
= s.
set_fn
? s.
set_fn
(
AUIgnoreXError
) : (
AUXErrorHandler
)0;
81
return
s;
82
}
83
90
inline
void
AURestoreXErrorHandler
(
AUXErrorHandlerSave
s) {
91
if
(s.
set_fn
) {
92
s.
set_fn
(s.
prev
);
93
}
94
}
95
96
#endif
AUXSetErrorHandlerFn
AUXErrorHandler(* AUXSetErrorHandlerFn)(AUXErrorHandler)
Signature of XSetErrorHandler itself, resolved via dlsym.
Definition
InteractiveEditorX11Guard.hpp:34
AUInstallTolerantXErrorHandler
AUXErrorHandlerSave AUInstallTolerantXErrorHandler()
Install the tolerant X error handler for the duration of an event loop.
Definition
InteractiveEditorX11Guard.hpp:70
AUIgnoreXError
int AUIgnoreXError(void *, void *)
The tolerant handler: ignores the error and reports success.
Definition
InteractiveEditorX11Guard.hpp:38
AUXErrorHandler
int(* AUXErrorHandler)(void *display, void *event)
Xlib error handler signature, with opaque pointers so that no libX11 headers are needed here.
Definition
InteractiveEditorX11Guard.hpp:31
AURestoreXErrorHandler
void AURestoreXErrorHandler(AUXErrorHandlerSave s)
Put back the handler that was in place before the tolerant one.
Definition
InteractiveEditorX11Guard.hpp:90
AUXErrorHandlerSave
What AUInstallTolerantXErrorHandler() needs in order to undo itself.
Definition
InteractiveEditorX11Guard.hpp:45
AUXErrorHandlerSave::prev
AUXErrorHandler prev
Handler that was installed before, to be put back on restore.
Definition
InteractiveEditorX11Guard.hpp:49
AUXErrorHandlerSave::set_fn
AUXSetErrorHandlerFn set_fn
Resolved XSetErrorHandler, or null if it could not be found.
Definition
InteractiveEditorX11Guard.hpp:47
include
InteractiveEditorX11Guard.hpp
Generated by
1.17.0