xpcom/sample/nsSampleModule.cpp

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/xpcom/sample/nsSampleModule.cpp	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,76 @@
     1.4 +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
     1.5 +/* This Source Code Form is subject to the terms of the Mozilla Public
     1.6 + * License, v. 2.0. If a copy of the MPL was not distributed with this
     1.7 + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
     1.8 +
     1.9 +#include "mozilla/ModuleUtils.h"
    1.10 +#include "nsIClassInfoImpl.h"
    1.11 +
    1.12 +#include "nsSample.h"
    1.13 +
    1.14 +////////////////////////////////////////////////////////////////////////
    1.15 +// With the below sample, you can define an implementation glue
    1.16 +// that talks with xpcom for creation of component nsSampleImpl
    1.17 +// that implement the interface nsISample. This can be extended for
    1.18 +// any number of components.
    1.19 +////////////////////////////////////////////////////////////////////////
    1.20 +
    1.21 +////////////////////////////////////////////////////////////////////////
    1.22 +// Define the contructor function for the object nsSampleImpl
    1.23 +//
    1.24 +// What this does is defines a function nsSampleImplConstructor which we
    1.25 +// will specific in the nsModuleComponentInfo table. This function will
    1.26 +// be used by the generic factory to create an instance of nsSampleImpl.
    1.27 +//
    1.28 +// NOTE: This creates an instance of nsSampleImpl by using the default
    1.29 +//		 constructor nsSampleImpl::nsSampleImpl()
    1.30 +//
    1.31 +NS_GENERIC_FACTORY_CONSTRUCTOR(nsSampleImpl)
    1.32 +
    1.33 +// The following line defines a kNS_SAMPLE_CID CID variable.
    1.34 +NS_DEFINE_NAMED_CID(NS_SAMPLE_CID);
    1.35 +
    1.36 +// Build a table of ClassIDs (CIDs) which are implemented by this module. CIDs
    1.37 +// should be completely unique UUIDs.
    1.38 +// each entry has the form { CID, service, factoryproc, constructorproc }
    1.39 +// where factoryproc is usually nullptr.
    1.40 +static const mozilla::Module::CIDEntry kSampleCIDs[] = {
    1.41 +    { &kNS_SAMPLE_CID, false, nullptr, nsSampleImplConstructor },
    1.42 +    { nullptr }
    1.43 +};
    1.44 +
    1.45 +// Build a table which maps contract IDs to CIDs.
    1.46 +// A contract is a string which identifies a particular set of functionality. In some
    1.47 +// cases an extension component may override the contract ID of a builtin gecko component
    1.48 +// to modify or extend functionality.
    1.49 +static const mozilla::Module::ContractIDEntry kSampleContracts[] = {
    1.50 +    { NS_SAMPLE_CONTRACTID, &kNS_SAMPLE_CID },
    1.51 +    { nullptr }
    1.52 +};
    1.53 +
    1.54 +// Category entries are category/key/value triples which can be used
    1.55 +// to register contract ID as content handlers or to observe certain
    1.56 +// notifications. Most modules do not need to register any category
    1.57 +// entries: this is just a sample of how you'd do it.
    1.58 +// @see nsICategoryManager for information on retrieving category data.
    1.59 +static const mozilla::Module::CategoryEntry kSampleCategories[] = {
    1.60 +    { "my-category", "my-key", NS_SAMPLE_CONTRACTID },
    1.61 +    { nullptr }
    1.62 +};
    1.63 +
    1.64 +static const mozilla::Module kSampleModule = {
    1.65 +    mozilla::Module::kVersion,
    1.66 +    kSampleCIDs,
    1.67 +    kSampleContracts,
    1.68 +    kSampleCategories
    1.69 +};
    1.70 +
    1.71 +// The following line implements the one-and-only "NSModule" symbol exported from this
    1.72 +// shared library.
    1.73 +NSMODULE_DEFN(nsSampleModule) = &kSampleModule;
    1.74 +
    1.75 +// The following line implements the one-and-only "NSGetModule" symbol
    1.76 +// for compatibility with mozilla 1.9.2. You should only use this
    1.77 +// if you need a binary which is backwards-compatible and if you use
    1.78 +// interfaces carefully across multiple versions.
    1.79 +NS_IMPL_MOZILLA192_NSGETMODULE(&kSampleModule)

mercurial