Main Page   Compound List   File List   Compound Members   File Members  

TclXPCOMInit.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 #include "nsXPCOM.h"
00042 #include "nsILocalFile.h"
00043 #include "nsIDirectoryService.h"
00044 #include "nsIThread.h"
00045 #include "nsString.h"
00046 
00047 
00048 nsIServiceManager       *servmanager;
00049 nsIInterfaceInfoManager *manager;    
00050 nsIComponentRegistrar   *registrar;  
00051 nsIMemory               *memmgr;     
00052 
00053 nsIID nsisupports_iid       = NS_ISUPPORTS_IID;
00054 nsIID nsiclassinfo_iid      = NS_ICLASSINFO_IID;
00055 nsIID nsiservicemanager_iid = NS_ISERVICEMANAGER_IID;
00056 
00057 nsIInterfaceInfo *nsisupports_info;
00058 nsIInterfaceInfo *nsiservicemanager_info;
00059 nsIInterfaceInfo *nsiclassinfo_info;
00060 
00061 Tcl_Encoding ascii_enc;
00062 
00063 static int TclXPCOMInitialized = 0;  
00064 
00065 
00073 int
00074 Tclxpcom_SafeInit(
00075     Tcl_Interp *interp 
00076 )
00077 {
00078     NS_PRECONDITION(interp, "null pointer");
00079 
00080     return Tclxpcom_Init(interp);
00081 }
00082 
00083 
00094 int
00095 Tclxpcom_Init(
00096     Tcl_Interp *interp 
00097 )
00098 {
00099     int rv;
00100     nsresult res;
00101     Tcl_Obj *mozhome;
00102     nsILocalFile *mozBinDirectory;
00103     nsIDirectoryServiceProvider *appFileLocProvider;
00104     nsIThread *mainthread;
00105 
00106     NS_PRECONDITION(interp, "null pointer");
00107 
00108     if (Tcl_InitStubs(interp, "8.3", 0) == NULL)
00109     {
00110         return TCL_ERROR;
00111     }
00112 
00113     rv = Tcl_PkgProvide(interp, "tclxpcom", "0.1");
00114     if (rv != TCL_OK)
00115     {
00116         return rv;
00117     }
00118 
00119     if (!TclXPCOMInitialized)
00120     {
00121         ascii_enc = Tcl_GetEncoding(interp, "ascii");
00122         if (!ascii_enc)
00123         {
00124             return TCL_ERROR;
00125         }
00126 
00127         res = nsIThread::GetMainThread(&mainthread);
00128         if (NS_FAILED(res))
00129         {
00130             mozhome = Tcl_GetVar2Ex(interp, TCLXPCOM_MOZHOMEVARNAME, NULL, TCL_GLOBAL_ONLY);
00131             if (mozhome)
00132             {
00133                 res = NS_NewLocalFile(nsString(Tcl_GetUnicode(mozhome), Tcl_GetCharLength(mozhome)), false, &mozBinDirectory);
00134                 if (NS_FAILED(res))
00135                 {
00136                     Tcl_ResetResult(interp);
00137                     Tcl_AppendResult(interp, "invalid path \"", Tcl_GetString(mozhome), "\" for mozilla home", NULL);
00138                     return TCL_ERROR;
00139                 }
00140             } else
00141             {
00142                 mozBinDirectory = nsnull;
00143             }
00144 
00145             appFileLocProvider = nsnull;
00146 
00147             NS_InitXPCOM2(nsnull, mozBinDirectory, appFileLocProvider);
00148 
00149             if (mozhome)
00150             {
00151                 NS_RELEASE(mozBinDirectory);
00152             }
00153         } else
00154         {
00155             NS_RELEASE(mainthread);
00156         }
00157 
00158         res = NS_GetServiceManager(&servmanager);
00159         if (NS_FAILED(res))
00160         {
00161             Tcl_ResetResult(interp);
00162             Tcl_AppendResult(interp, "unable to get service manager", NULL);
00163             return TCL_ERROR;
00164         }
00165 
00166         res = NS_GetComponentRegistrar(&registrar);
00167         if (NS_FAILED(res))
00168         {
00169             Tcl_ResetResult(interp);
00170             Tcl_AppendResult(interp, "unable to get component registrar", NULL);
00171             return TCL_ERROR;
00172         }
00173 
00174         res = NS_GetMemoryManager(&memmgr);
00175         if (NS_FAILED(res))
00176         {
00177             Tcl_ResetResult(interp);
00178             Tcl_AppendResult(interp, "unable to get memory manager", NULL);
00179             return TCL_ERROR;
00180         }
00181 
00182         manager = XPTI_GetInterfaceInfoManager();
00183         if (!manager)
00184         {
00185             Tcl_ResetResult(interp);
00186             Tcl_AppendResult(interp, "unable to get interfaceinfo manager", NULL);
00187             return TCL_ERROR;
00188         }
00189 
00190         res = manager->GetInfoForIID(&nsisupports_iid, &nsisupports_info);
00191         if (NS_FAILED(res))
00192         {
00193             Tcl_ResetResult(interp);
00194             Tcl_AppendResult(interp, "unable to get nsISupports interfaceinfo", NULL);
00195             return TCL_ERROR;
00196         }
00197 
00198         res = manager->GetInfoForIID(&nsiservicemanager_iid, &nsiservicemanager_info);
00199         if (NS_FAILED(res))
00200         {
00201             Tcl_ResetResult(interp);
00202             Tcl_AppendResult(interp, "unable to get nsIServiceManager interfaceinfo", NULL);
00203             return TCL_ERROR;
00204         }
00205 
00206         res = manager->GetInfoForIID(&nsiclassinfo_iid, &nsiclassinfo_info);
00207         if (NS_FAILED(res))
00208         {
00209             Tcl_ResetResult(interp);
00210             Tcl_AppendResult(interp, "unable to get nsIClassInfo interfaceinfo", NULL);
00211             return TCL_ERROR;
00212         }
00213 
00214         TclXPCOM_RegisterObjTypes();
00215         TclXPCOM_InitInterfaceInfo();
00216         TclXPCOM_InitClassInfo();
00217         TclXPCOM_InitInterfaceRef();
00218 
00219         TclXPCOMInitialized = 1;
00220     }
00221 
00222     TclXPCOM_RegisterCommands(interp);
00223 
00224     return TCL_OK;
00225 }

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