Fri, 16 Jan 2015 18:13:44 +0100
Integrate suggestion from review to improve consistency with existing code.
michael@0 | 1 | /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ |
michael@0 | 2 | /* This Source Code Form is subject to the terms of the Mozilla Public |
michael@0 | 3 | * License, v. 2.0. If a copy of the MPL was not distributed with this |
michael@0 | 4 | * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ |
michael@0 | 5 | |
michael@0 | 6 | #include "mozilla/ModuleUtils.h" |
michael@0 | 7 | #include "nsIClassInfoImpl.h" |
michael@0 | 8 | |
michael@0 | 9 | #include "nsSample.h" |
michael@0 | 10 | |
michael@0 | 11 | //////////////////////////////////////////////////////////////////////// |
michael@0 | 12 | // With the below sample, you can define an implementation glue |
michael@0 | 13 | // that talks with xpcom for creation of component nsSampleImpl |
michael@0 | 14 | // that implement the interface nsISample. This can be extended for |
michael@0 | 15 | // any number of components. |
michael@0 | 16 | //////////////////////////////////////////////////////////////////////// |
michael@0 | 17 | |
michael@0 | 18 | //////////////////////////////////////////////////////////////////////// |
michael@0 | 19 | // Define the contructor function for the object nsSampleImpl |
michael@0 | 20 | // |
michael@0 | 21 | // What this does is defines a function nsSampleImplConstructor which we |
michael@0 | 22 | // will specific in the nsModuleComponentInfo table. This function will |
michael@0 | 23 | // be used by the generic factory to create an instance of nsSampleImpl. |
michael@0 | 24 | // |
michael@0 | 25 | // NOTE: This creates an instance of nsSampleImpl by using the default |
michael@0 | 26 | // constructor nsSampleImpl::nsSampleImpl() |
michael@0 | 27 | // |
michael@0 | 28 | NS_GENERIC_FACTORY_CONSTRUCTOR(nsSampleImpl) |
michael@0 | 29 | |
michael@0 | 30 | // The following line defines a kNS_SAMPLE_CID CID variable. |
michael@0 | 31 | NS_DEFINE_NAMED_CID(NS_SAMPLE_CID); |
michael@0 | 32 | |
michael@0 | 33 | // Build a table of ClassIDs (CIDs) which are implemented by this module. CIDs |
michael@0 | 34 | // should be completely unique UUIDs. |
michael@0 | 35 | // each entry has the form { CID, service, factoryproc, constructorproc } |
michael@0 | 36 | // where factoryproc is usually nullptr. |
michael@0 | 37 | static const mozilla::Module::CIDEntry kSampleCIDs[] = { |
michael@0 | 38 | { &kNS_SAMPLE_CID, false, nullptr, nsSampleImplConstructor }, |
michael@0 | 39 | { nullptr } |
michael@0 | 40 | }; |
michael@0 | 41 | |
michael@0 | 42 | // Build a table which maps contract IDs to CIDs. |
michael@0 | 43 | // A contract is a string which identifies a particular set of functionality. In some |
michael@0 | 44 | // cases an extension component may override the contract ID of a builtin gecko component |
michael@0 | 45 | // to modify or extend functionality. |
michael@0 | 46 | static const mozilla::Module::ContractIDEntry kSampleContracts[] = { |
michael@0 | 47 | { NS_SAMPLE_CONTRACTID, &kNS_SAMPLE_CID }, |
michael@0 | 48 | { nullptr } |
michael@0 | 49 | }; |
michael@0 | 50 | |
michael@0 | 51 | // Category entries are category/key/value triples which can be used |
michael@0 | 52 | // to register contract ID as content handlers or to observe certain |
michael@0 | 53 | // notifications. Most modules do not need to register any category |
michael@0 | 54 | // entries: this is just a sample of how you'd do it. |
michael@0 | 55 | // @see nsICategoryManager for information on retrieving category data. |
michael@0 | 56 | static const mozilla::Module::CategoryEntry kSampleCategories[] = { |
michael@0 | 57 | { "my-category", "my-key", NS_SAMPLE_CONTRACTID }, |
michael@0 | 58 | { nullptr } |
michael@0 | 59 | }; |
michael@0 | 60 | |
michael@0 | 61 | static const mozilla::Module kSampleModule = { |
michael@0 | 62 | mozilla::Module::kVersion, |
michael@0 | 63 | kSampleCIDs, |
michael@0 | 64 | kSampleContracts, |
michael@0 | 65 | kSampleCategories |
michael@0 | 66 | }; |
michael@0 | 67 | |
michael@0 | 68 | // The following line implements the one-and-only "NSModule" symbol exported from this |
michael@0 | 69 | // shared library. |
michael@0 | 70 | NSMODULE_DEFN(nsSampleModule) = &kSampleModule; |
michael@0 | 71 | |
michael@0 | 72 | // The following line implements the one-and-only "NSGetModule" symbol |
michael@0 | 73 | // for compatibility with mozilla 1.9.2. You should only use this |
michael@0 | 74 | // if you need a binary which is backwards-compatible and if you use |
michael@0 | 75 | // interfaces carefully across multiple versions. |
michael@0 | 76 | NS_IMPL_MOZILLA192_NSGETMODULE(&kSampleModule) |