1 | /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
|
---|
2 | /* ***** BEGIN LICENSE BLOCK *****
|
---|
3 | * Version: MPL 1.1/GPL 2.0/LGPL 2.1
|
---|
4 | *
|
---|
5 | * The contents of this file are subject to the Mozilla Public License Version
|
---|
6 | * 1.1 (the "License"); you may not use this file except in compliance with
|
---|
7 | * the License. You may obtain a copy of the License at
|
---|
8 | * http://www.mozilla.org/MPL/
|
---|
9 | *
|
---|
10 | * Software distributed under the License is distributed on an "AS IS" basis,
|
---|
11 | * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
|
---|
12 | * for the specific language governing rights and limitations under the
|
---|
13 | * License.
|
---|
14 | *
|
---|
15 | * The Original Code is mozilla.org code.
|
---|
16 | *
|
---|
17 | * The Initial Developer of the Original Code is
|
---|
18 | * Netscape Communications Corporation.
|
---|
19 | * Portions created by the Initial Developer are Copyright (C) 1998
|
---|
20 | * the Initial Developer. All Rights Reserved.
|
---|
21 | *
|
---|
22 | * Contributor(s):
|
---|
23 | * Suresh Duddu <[email protected]>
|
---|
24 | *
|
---|
25 | * Alternatively, the contents of this file may be used under the terms of
|
---|
26 | * either of the GNU General Public License Version 2 or later (the "GPL"),
|
---|
27 | * or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
|
---|
28 | * in which case the provisions of the GPL or the LGPL are applicable instead
|
---|
29 | * of those above. If you wish to allow use of your version of this file only
|
---|
30 | * under the terms of either the GPL or the LGPL, and not to allow others to
|
---|
31 | * use your version of this file under the terms of the MPL, indicate your
|
---|
32 | * decision by deleting the provisions above and replace them with the notice
|
---|
33 | * and other provisions required by the GPL or the LGPL. If you do not delete
|
---|
34 | * the provisions above, a recipient may use your version of this file under
|
---|
35 | * the terms of any one of the MPL, the GPL or the LGPL.
|
---|
36 | *
|
---|
37 | * ***** END LICENSE BLOCK ***** */
|
---|
38 | #include "nsIGenericFactory.h"
|
---|
39 |
|
---|
40 | #include "nsSample.h"
|
---|
41 |
|
---|
42 | ////////////////////////////////////////////////////////////////////////
|
---|
43 | // NOTE this file supercedes nsSampleFactory.cpp. nsSampleFactory has
|
---|
44 | // extensive comments, but it has been CVS removed to reduce clutter
|
---|
45 | // in this sample. It's available to the interested via CVS history:
|
---|
46 | // cvs up nsSampleFactory.cpp -r 1.10
|
---|
47 | ////////////////////////////////////////////////////////////////////////
|
---|
48 |
|
---|
49 | ////////////////////////////////////////////////////////////////////////
|
---|
50 | // With the below sample, you can define an implementation glue
|
---|
51 | // that talks with xpcom for creation of component nsSampleImpl
|
---|
52 | // that implement the interface nsISample. This can be extended for
|
---|
53 | // any number of components.
|
---|
54 | ////////////////////////////////////////////////////////////////////////
|
---|
55 |
|
---|
56 | ////////////////////////////////////////////////////////////////////////
|
---|
57 | // Define the contructor function for the object nsSampleImpl
|
---|
58 | //
|
---|
59 | // What this does is defines a function nsSampleImplConstructor which we
|
---|
60 | // will specific in the nsModuleComponentInfo table. This function will
|
---|
61 | // be used by the generic factory to create an instance of nsSampleImpl.
|
---|
62 | //
|
---|
63 | // NOTE: This creates an instance of nsSampleImpl by using the default
|
---|
64 | // constructor nsSampleImpl::nsSampleImpl()
|
---|
65 | //
|
---|
66 | NS_GENERIC_FACTORY_CONSTRUCTOR(nsSampleImpl)
|
---|
67 |
|
---|
68 | ////////////////////////////////////////////////////////////////////////
|
---|
69 | // Define a table of CIDs implemented by this module along with other
|
---|
70 | // information like the function to create an instance, contractid, and
|
---|
71 | // class name.
|
---|
72 | //
|
---|
73 | // The Registration and Unregistration proc are optional in the structure.
|
---|
74 | //
|
---|
75 | static NS_METHOD nsSampleRegistrationProc(nsIComponentManager *aCompMgr,
|
---|
76 | nsIFile *aPath,
|
---|
77 | const char *registryLocation,
|
---|
78 | const char *componentType,
|
---|
79 | const nsModuleComponentInfo *info)
|
---|
80 | {
|
---|
81 | // Do any registration specific activity like adding yourself to a
|
---|
82 | // category. The Generic Module will take care of registering your
|
---|
83 | // component with xpcom. You dont need to do that. Only any component
|
---|
84 | // specific additional activity needs to be done here.
|
---|
85 |
|
---|
86 | // This functions is optional. If you dont need it, dont add it to the structure.
|
---|
87 |
|
---|
88 | return NS_OK;
|
---|
89 | }
|
---|
90 |
|
---|
91 | static NS_METHOD nsSampleUnregistrationProc(nsIComponentManager *aCompMgr,
|
---|
92 | nsIFile *aPath,
|
---|
93 | const char *registryLocation,
|
---|
94 | const nsModuleComponentInfo *info)
|
---|
95 | {
|
---|
96 | // Undo any component specific registration like adding yourself to a
|
---|
97 | // category here. The Generic Module will take care of unregistering your
|
---|
98 | // component from xpcom. You dont need to do that. Only any component
|
---|
99 | // specific additional activity needs to be done here.
|
---|
100 |
|
---|
101 | // This functions is optional. If you dont need it, dont add it to the structure.
|
---|
102 |
|
---|
103 | // Return value is not used from this function.
|
---|
104 | return NS_OK;
|
---|
105 | }
|
---|
106 |
|
---|
107 | // For each class that wishes to support nsIClassInfo, add a line like this
|
---|
108 | NS_DECL_CLASSINFO(nsSampleImpl)
|
---|
109 |
|
---|
110 | static const nsModuleComponentInfo components[] =
|
---|
111 | {
|
---|
112 | { "Sample Component", NS_SAMPLE_CID, NS_SAMPLE_CONTRACTID, nsSampleImplConstructor,
|
---|
113 | nsSampleRegistrationProc /* NULL if you dont need one */,
|
---|
114 | nsSampleUnregistrationProc /* NULL if you dont need one */,
|
---|
115 | NULL /* no factory destructor */,
|
---|
116 | NS_CI_INTERFACE_GETTER_NAME(nsSampleImpl),
|
---|
117 | NULL /* no language helper */,
|
---|
118 | &NS_CLASSINFO_NAME(nsSampleImpl)
|
---|
119 | }
|
---|
120 | };
|
---|
121 |
|
---|
122 | ////////////////////////////////////////////////////////////////////////
|
---|
123 | // Implement the NSGetModule() exported function for your module
|
---|
124 | // and the entire implementation of the module object.
|
---|
125 | //
|
---|
126 | // NOTE: If you want to use the module shutdown to release any
|
---|
127 | // module specific resources, use the macro
|
---|
128 | // NS_IMPL_NSGETMODULE_WITH_DTOR() instead of the vanilla
|
---|
129 | // NS_IMPL_NSGETMODULE()
|
---|
130 | //
|
---|
131 | NS_IMPL_NSGETMODULE(nsSampleModule, components)
|
---|