Main Page   Compound List   File List   Compound Members   File Members  

TclXPCOMError.cpp

Go to the documentation of this file.
00001 /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*-
00002  *
00003  * The contents of this file are subject to the Mozilla Public License Version
00004  * 1.1 (the "License"); you may not use this file except in compliance with
00005  * the License. You may obtain a copy of the License at
00006  * http://www.mozilla.org/MPL/
00007  *
00008  * Software distributed under the License is distributed on an "AS IS" basis,
00009  * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
00010  * for the specific language governing rights and limitations under the
00011  * License.
00012  *
00013  * The Original Code is TclXPCOM.
00014  * 
00015  * The Initial Developer of the Original Code is Mark Follett.
00016  * Portions created by Mark Follett are Copyright (C) 2001-2002
00017  * Mark Follett.  All Rights Reserved.
00018  * 
00019  * Contributor(s):
00020  *     Mark Follett <mef123@myrealbox.com> (Original Author)
00021  *
00022  * Alternatively, the contents of this file may be used under the terms of
00023  * either the GNU General Public License Version 2 or later (the "GPL"), or
00024  * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
00025  * in which case the provisions of the GPL or the LGPL are applicable instead
00026  * of those above. If you wish to allow use of your version of this file only
00027  * under the terms of either the GPL or the LGPL, and not to allow others to
00028  * use your version of this file under the terms of the MPL, indicate your
00029  * decision by deleting the provisions above and replace them with the notice
00030  * and other provisions required by the GPL or the LGPL. If you do not delete
00031  * the provisions above, a recipient may use your version of this file under
00032  * the terms of any one of the MPL, the GPL or the LGPL.
00033  */
00034 
00040 #include "TclXPCOMPrivate.h"
00041 
00042 
00049 void
00050 TclXPCOM_SetErrorCode(
00051     Tcl_Interp *interp, 
00052     nsresult    res     
00053 )
00054 {
00055     Tcl_Obj *errorCode;
00056 
00057     NS_PRECONDITION(interp, "null pointer");
00058 
00059     errorCode = Tcl_NewListObj(0, NULL);
00060     Tcl_ListObjAppendElement(NULL, errorCode, Tcl_NewStringObj("XPCOM", -1));
00061     Tcl_ListObjAppendElement(NULL, errorCode, Tcl_NewLongObj((long)res));
00062     Tcl_SetObjErrorCode(interp, errorCode);
00063 }
00064 
00065 
00073 int
00074 TclXPCOM_GetErrorCode(
00075     Tcl_Interp *interp, 
00076     nsresult   *res     
00077 
00078 )
00079 {
00080     Tcl_Obj *errorCode;
00081     int     objc;
00082     Tcl_Obj **objv;
00083     long     longVal;
00084 
00085     NS_PRECONDITION(interp, "null pointer");
00086     NS_PRECONDITION(res, "null pointer");
00087 
00088     errorCode = Tcl_GetVar2Ex(interp, "errorCode", NULL, TCL_GLOBAL_ONLY);
00089 
00090     if (errorCode && (Tcl_ListObjGetElements(NULL, errorCode, &objc, &objv) == TCL_OK))
00091     {
00092         if ((objc == 2) && (!strcmp("XPCOM", Tcl_GetString(objv[0]))))
00093         {
00094             if (Tcl_GetLongFromObj(NULL, objv[1], &longVal) == TCL_OK)
00095             {
00096                 *res = (nsresult)longVal;
00097                 return 1;
00098             }
00099         }
00100     }
00101     
00102     return 0;
00103 }
00104 
00105 
00110 void
00111 TclXPCOM_SetErrorMessage(
00112     Tcl_Interp *interp, 
00113     nsresult    res     
00114 )
00115 {
00116     int rv;
00117     Tcl_CmdInfo cmdinfo;
00118     Tcl_Obj *script;
00119 
00120     NS_PRECONDITION(interp, "null pointer");
00121 
00122     if (Tcl_GetCommandInfo(interp, TCLXPCOM_ERRORMSGPROC, &cmdinfo))
00123     {
00124         script = Tcl_NewListObj(0, NULL);
00125         Tcl_IncrRefCount(script);
00126         Tcl_ListObjAppendElement(interp, script, Tcl_NewStringObj(TCLXPCOM_ERRORMSGPROC, -1));
00127         Tcl_ListObjAppendElement(interp, script, Tcl_NewLongObj((long)res));
00128 
00129         rv = Tcl_EvalObjEx(interp, script, TCL_EVAL_DIRECT | TCL_EVAL_GLOBAL);
00130 
00131         Tcl_DecrRefCount(script);
00132 
00133         if (rv != TCL_OK)
00134         {
00135             Tcl_AddObjErrorInfo(interp, "\nwhile executing error message procedure", -1);
00136         }
00137 
00138     } else
00139     {
00140         Tcl_ResetResult(interp);
00141         Tcl_AppendResult(interp, "xpcom error: unknown (no error message procedure defined)", NULL);
00142     }
00143 }
00144 
00145 
00150 void
00151 TclXPCOM_SetError(
00152     Tcl_Interp *interp, 
00153     nsresult    res     
00154 )
00155 {
00156     NS_PRECONDITION(interp, "null pointer");
00157 
00158     TclXPCOM_SetErrorMessage(interp, res);
00159     TclXPCOM_SetErrorCode   (interp, res);
00160 }
00161 
00162 
00174 void
00175 TclXPCOM_BackgroundError(
00176     Tcl_Interp *interp  
00177 )
00178 {
00179     int rv;
00180     Tcl_CmdInfo cmdinfo;
00181     Tcl_Obj *script;
00182 
00183     NS_PRECONDITION(interp, "null pointer");
00184 
00185     if (Tcl_GetCommandInfo(interp, TCLXPCOM_BGERRORPROC, &cmdinfo))
00186     {
00187         script = Tcl_NewListObj(0, NULL);
00188         Tcl_IncrRefCount(script);
00189         Tcl_ListObjAppendElement(interp, script, Tcl_NewStringObj(TCLXPCOM_BGERRORPROC, -1));
00190         Tcl_ListObjAppendElement(interp, script, Tcl_GetObjResult(interp));
00191 
00192         rv = Tcl_EvalObjEx(interp, script, TCL_EVAL_DIRECT | TCL_EVAL_GLOBAL);
00193 
00194         Tcl_DecrRefCount(script);
00195 
00196         if (rv != TCL_OK)
00197         {
00198             Tcl_BackgroundError(interp);
00199         }
00200 
00201     } else
00202     {
00203         Tcl_BackgroundError(interp);
00204     }
00205 }

Generated on Fri Jun 14 23:25:50 2002 for TclXPCOM by doxygen1.2.14 written by Dimitri van Heesch, © 1997-2002