Back to index

lightning-sunbird  0.9+nobinonly
nsSampleModule.cpp
Go to the documentation of this file.
00001 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
00002 /* ***** BEGIN LICENSE BLOCK *****
00003  * Version: MPL 1.1/GPL 2.0/LGPL 2.1
00004  *
00005  * The contents of this file are subject to the Mozilla Public License Version
00006  * 1.1 (the "License"); you may not use this file except in compliance with
00007  * the License. You may obtain a copy of the License at
00008  * http://www.mozilla.org/MPL/
00009  *
00010  * Software distributed under the License is distributed on an "AS IS" basis,
00011  * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
00012  * for the specific language governing rights and limitations under the
00013  * License.
00014  *
00015  * The Original Code is mozilla.org code.
00016  *
00017  * The Initial Developer of the Original Code is
00018  * Netscape Communications Corporation.
00019  * Portions created by the Initial Developer are Copyright (C) 1998
00020  * the Initial Developer. All Rights Reserved.
00021  *
00022  * Contributor(s):
00023  *   Suresh Duddu <dp@netscape.com>
00024  *
00025  * Alternatively, the contents of this file may be used under the terms of
00026  * either of the GNU General Public License Version 2 or later (the "GPL"),
00027  * or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
00028  * in which case the provisions of the GPL or the LGPL are applicable instead
00029  * of those above. If you wish to allow use of your version of this file only
00030  * under the terms of either the GPL or the LGPL, and not to allow others to
00031  * use your version of this file under the terms of the MPL, indicate your
00032  * decision by deleting the provisions above and replace them with the notice
00033  * and other provisions required by the GPL or the LGPL. If you do not delete
00034  * the provisions above, a recipient may use your version of this file under
00035  * the terms of any one of the MPL, the GPL or the LGPL.
00036  *
00037  * ***** END LICENSE BLOCK ***** */
00038 #include "nsIGenericFactory.h"
00039 
00040 #include "nsSample.h"
00041 
00043 // NOTE this file supercedes nsSampleFactory.cpp.  nsSampleFactory has
00044 // extensive comments, but it has been CVS removed to reduce clutter
00045 // in this sample.  It's available to the interested via CVS history:
00046 // cvs up nsSampleFactory.cpp -r 1.10
00048 
00050 // With the below sample, you can define an implementation glue
00051 // that talks with xpcom for creation of component nsSampleImpl
00052 // that implement the interface nsISample. This can be extended for
00053 // any number of components.
00055 
00057 // Define the contructor function for the object nsSampleImpl
00058 //
00059 // What this does is defines a function nsSampleImplConstructor which we
00060 // will specific in the nsModuleComponentInfo table. This function will
00061 // be used by the generic factory to create an instance of nsSampleImpl.
00062 //
00063 // NOTE: This creates an instance of nsSampleImpl by using the default
00064 //             constructor nsSampleImpl::nsSampleImpl()
00065 //
00066 NS_GENERIC_FACTORY_CONSTRUCTOR(nsSampleImpl)
00067 
00068 
00069 // Define a table of CIDs implemented by this module along with other
00070 // information like the function to create an instance, contractid, and
00071 // class name.
00072 //
00073 // The Registration and Unregistration proc are optional in the structure.
00074 //
00075 static NS_METHOD nsSampleRegistrationProc(nsIComponentManager *aCompMgr,
00076                                           nsIFile *aPath,
00077                                           const char *registryLocation,
00078                                           const char *componentType,
00079                                           const nsModuleComponentInfo *info)
00080 {
00081     // Do any registration specific activity like adding yourself to a
00082     // category. The Generic Module will take care of registering your
00083     // component with xpcom. You dont need to do that. Only any component
00084     // specific additional activity needs to be done here.
00085 
00086     // This functions is optional. If you dont need it, dont add it to the structure.
00087 
00088     return NS_OK;
00089 }
00090 
00091 static NS_METHOD nsSampleUnregistrationProc(nsIComponentManager *aCompMgr,
00092                                             nsIFile *aPath,
00093                                             const char *registryLocation,
00094                                             const nsModuleComponentInfo *info)
00095 {
00096     // Undo any component specific registration like adding yourself to a
00097     // category here. The Generic Module will take care of unregistering your
00098     // component from xpcom. You dont need to do that. Only any component
00099     // specific additional activity needs to be done here.
00100 
00101     // This functions is optional. If you dont need it, dont add it to the structure.
00102 
00103     // Return value is not used from this function.
00104     return NS_OK;
00105 }
00106 
00107 // For each class that wishes to support nsIClassInfo, add a line like this
00108 NS_DECL_CLASSINFO(nsSampleImpl)
00109 
00110 static const nsModuleComponentInfo components[] =
00111 {
00112   { "Sample Component", NS_SAMPLE_CID, NS_SAMPLE_CONTRACTID, nsSampleImplConstructor,
00113     nsSampleRegistrationProc /* NULL if you dont need one */,
00114     nsSampleUnregistrationProc /* NULL if you dont need one */,
00115     NULL /* no factory destructor */,
00116     NS_CI_INTERFACE_GETTER_NAME(nsSampleImpl),
00117     NULL /* no language helper */,
00118     &NS_CLASSINFO_NAME(nsSampleImpl)
00119   }
00120 };
00121 
00123 // Implement the NSGetModule() exported function for your module
00124 // and the entire implementation of the module object.
00125 //
00126 // NOTE: If you want to use the module shutdown to release any
00127 //            module specific resources, use the macro
00128 //            NS_IMPL_NSGETMODULE_WITH_DTOR() instead of the vanilla
00129 //            NS_IMPL_NSGETMODULE()
00130 //
00131 NS_IMPL_NSGETMODULE(nsSampleModule, components)