src/solaris/classes/sun/awt/X11/XErrorHandlerUtil.java

Print this page


   1 /*
   2  * Copyright (c) 2013, Oracle and/or its affiliates. All rights reserved.
   3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   4  *
   5  * This code is free software; you can redistribute it and/or modify it
   6  * under the terms of the GNU General Public License version 2 only, as
   7  * published by the Free Software Foundation.  Oracle designates this
   8  * particular file as subject to the "Classpath" exception as provided
   9  * by Oracle in the LICENSE file that accompanied this code.
  10  *
  11  * This code is distributed in the hope that it will be useful, but WITHOUT
  12  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  13  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  14  * version 2 for more details (a copy is included in the LICENSE file that
  15  * accompanied this code).
  16  *
  17  * You should have received a copy of the GNU General Public License version
  18  * 2 along with this work; if not, write to the Free Software Foundation,
  19  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  20  *
  21  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  22  * or visit www.oracle.com if you need additional information or have any


  80      * @param display the connection to X11 server which should be stored
  81      */
  82     private static void init(long display) {
  83         SunToolkit.awtLock();
  84         try {
  85             if (!initPassed) {
  86                 XErrorHandlerUtil.display = display;
  87                 saved_error_handler = XlibWrapper.SetToolkitErrorHandler();
  88                 initPassed = true;
  89             }
  90         } finally {
  91             SunToolkit.awtUnlock();
  92         }
  93     }
  94 
  95     /**
  96      * Sets a synthetic error handler. Must be called with the acquired AWT lock.
  97      * @param handler the synthetic error handler to set
  98      */
  99     public static void WITH_XERROR_HANDLER(XErrorHandler handler) {

 100         saved_error = null;
 101         current_error_handler = handler;
 102     }
 103 
 104     /**
 105      * Unsets a current synthetic error handler. Must be called with the acquired AWT lock.
 106      */
 107     public static void RESTORE_XERROR_HANDLER() {
 108         RESTORE_XERROR_HANDLER(true);
 109     }
 110 
 111     private static void RESTORE_XERROR_HANDLER(boolean doXSync) {
 112         if (doXSync) {
 113             // Wait until all requests are processed by the X server
 114             // and only then uninstall the error handler.
 115             XSync();
 116         }
 117         current_error_handler = null;
 118     }
 119 
 120     /**
 121      * Should be called under LOCK.
 122      */
 123     public static int SAVED_XERROR_HANDLER(long display, XErrorEvent error) {
 124         if (saved_error_handler != 0) {
 125             // Default XErrorHandler may just terminate the process. Don't call it.
 126             // return XlibWrapper.CallErrorHandler(saved_error_handler, display, error.pData);
 127         }
 128         if (log.isLoggable(PlatformLogger.Level.FINE)) {
 129             log.fine("Unhandled XErrorEvent: " +
 130                 "id=" + error.get_resourceid() + ", " +
 131                 "serial=" + error.get_serial() + ", " +
 132                 "ec=" + error.get_error_code() + ", " +
 133                 "rc=" + error.get_request_code() + ", " +
 134                 "mc=" + error.get_minor_code());
 135         }
 136         return 0;


   1 /*
   2  * Copyright (c) 2014, Oracle and/or its affiliates. All rights reserved.
   3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   4  *
   5  * This code is free software; you can redistribute it and/or modify it
   6  * under the terms of the GNU General Public License version 2 only, as
   7  * published by the Free Software Foundation.  Oracle designates this
   8  * particular file as subject to the "Classpath" exception as provided
   9  * by Oracle in the LICENSE file that accompanied this code.
  10  *
  11  * This code is distributed in the hope that it will be useful, but WITHOUT
  12  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  13  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  14  * version 2 for more details (a copy is included in the LICENSE file that
  15  * accompanied this code).
  16  *
  17  * You should have received a copy of the GNU General Public License version
  18  * 2 along with this work; if not, write to the Free Software Foundation,
  19  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  20  *
  21  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  22  * or visit www.oracle.com if you need additional information or have any


  80      * @param display the connection to X11 server which should be stored
  81      */
  82     private static void init(long display) {
  83         SunToolkit.awtLock();
  84         try {
  85             if (!initPassed) {
  86                 XErrorHandlerUtil.display = display;
  87                 saved_error_handler = XlibWrapper.SetToolkitErrorHandler();
  88                 initPassed = true;
  89             }
  90         } finally {
  91             SunToolkit.awtUnlock();
  92         }
  93     }
  94 
  95     /**
  96      * Sets a synthetic error handler. Must be called with the acquired AWT lock.
  97      * @param handler the synthetic error handler to set
  98      */
  99     public static void WITH_XERROR_HANDLER(XErrorHandler handler) {
 100         XSync();
 101         saved_error = null;
 102         current_error_handler = handler;
 103     }
 104 
 105     /**
 106      * Unsets a current synthetic error handler. Must be called with the acquired AWT lock.
 107      */
 108     public static void RESTORE_XERROR_HANDLER() {





 109         // Wait until all requests are processed by the X server
 110         // and only then uninstall the error handler.
 111         XSync();

 112         current_error_handler = null;
 113     }
 114 
 115     /**
 116      * Should be called under LOCK.
 117      */
 118     public static int SAVED_XERROR_HANDLER(long display, XErrorEvent error) {
 119         if (saved_error_handler != 0) {
 120             // Default XErrorHandler may just terminate the process. Don't call it.
 121             // return XlibWrapper.CallErrorHandler(saved_error_handler, display, error.pData);
 122         }
 123         if (log.isLoggable(PlatformLogger.Level.FINE)) {
 124             log.fine("Unhandled XErrorEvent: " +
 125                 "id=" + error.get_resourceid() + ", " +
 126                 "serial=" + error.get_serial() + ", " +
 127                 "ec=" + error.get_error_code() + ", " +
 128                 "rc=" + error.get_request_code() + ", " +
 129                 "mc=" + error.get_minor_code());
 130         }
 131         return 0;