xpcom/components/Module.h

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/xpcom/components/Module.h	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,128 @@
     1.4 +/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
     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 +#ifndef mozilla_Module_h
    1.10 +#define mozilla_Module_h
    1.11 +
    1.12 +#include "nscore.h"
    1.13 +#include "nsID.h"
    1.14 +#include "nsIFactory.h"
    1.15 +#include "nsCOMPtr.h" // for already_AddRefed
    1.16 +
    1.17 +namespace mozilla {
    1.18 +
    1.19 +/**
    1.20 + * A module implements one or more XPCOM components. This structure is used
    1.21 + * for both binary and script modules, but the registration members
    1.22 + * (cids/contractids/categoryentries) are unused for modules which are loaded
    1.23 + * via a module loader.
    1.24 + */
    1.25 +struct Module
    1.26 +{
    1.27 +  static const unsigned int kVersion = 31;
    1.28 +
    1.29 +  struct CIDEntry;
    1.30 +
    1.31 +  typedef already_AddRefed<nsIFactory> (*GetFactoryProcPtr)
    1.32 +    (const Module& module, const CIDEntry& entry);
    1.33 +
    1.34 +  typedef nsresult (*ConstructorProcPtr)(nsISupports* aOuter,
    1.35 +                                         const nsIID& aIID,
    1.36 +                                         void** aResult);
    1.37 +
    1.38 +  typedef nsresult (*LoadFuncPtr)();
    1.39 +  typedef void (*UnloadFuncPtr)();
    1.40 +
    1.41 +  /**
    1.42 +   * This selector allows CIDEntrys to be marked so that they're only loaded
    1.43 +   * into certain kinds of processes.
    1.44 +   */
    1.45 +  enum ProcessSelector
    1.46 +  {
    1.47 +    ANY_PROCESS = 0,
    1.48 +    MAIN_PROCESS_ONLY,
    1.49 +    CONTENT_PROCESS_ONLY
    1.50 +  };
    1.51 +
    1.52 +  /**
    1.53 +   * The constructor callback is an implementation detail of the default binary
    1.54 +   * loader and may be null.
    1.55 +   */
    1.56 +  struct CIDEntry
    1.57 +  {
    1.58 +    const nsCID* cid;
    1.59 +    bool service;
    1.60 +    GetFactoryProcPtr getFactoryProc;
    1.61 +    ConstructorProcPtr constructorProc;
    1.62 +    ProcessSelector processSelector;
    1.63 +  };
    1.64 +
    1.65 +  struct ContractIDEntry
    1.66 +  {
    1.67 +    const char* contractid;
    1.68 +    nsID const * cid;
    1.69 +    ProcessSelector processSelector;
    1.70 +  };
    1.71 +
    1.72 +  struct CategoryEntry
    1.73 +  {
    1.74 +    const char* category;
    1.75 +    const char* entry;
    1.76 +    const char* value;
    1.77 +  };
    1.78 +
    1.79 +  /**
    1.80 +   * Binary compatibility check, should be kModuleVersion.
    1.81 +   */
    1.82 +  unsigned int mVersion;
    1.83 +
    1.84 +  /**
    1.85 +   * An array of CIDs (class IDs) implemented by this module. The final entry
    1.86 +   * should be { nullptr }.
    1.87 +   */
    1.88 +  const CIDEntry* mCIDs;
    1.89 +
    1.90 +  /**
    1.91 +   * An array of mappings from contractid to CID. The final entry should
    1.92 +   * be { nullptr }.
    1.93 +   */
    1.94 +  const ContractIDEntry* mContractIDs;
    1.95 +
    1.96 +  /**
    1.97 +   * An array of category manager entries. The final entry should be
    1.98 +   * { nullptr }.
    1.99 +   */
   1.100 +  const CategoryEntry* mCategoryEntries;
   1.101 +
   1.102 +  /**
   1.103 +   * When the component manager tries to get the factory for a CID, it first
   1.104 +   * checks for this module-level getfactory callback. If this function is
   1.105 +   * not implemented, it checks the CIDEntry getfactory callback. If that is
   1.106 +   * also nullptr, a generic factory is generated using the CIDEntry
   1.107 +   * constructor callback which must be non-nullptr.
   1.108 +   */
   1.109 +  GetFactoryProcPtr getFactoryProc;
   1.110 +
   1.111 +  /**
   1.112 +   * Optional Function which are called when this module is loaded and
   1.113 +   * at shutdown. These are not C++ constructor/destructors to avoid
   1.114 +   * calling them too early in startup or too late in shutdown.
   1.115 +   */
   1.116 +  LoadFuncPtr loadProc;
   1.117 +  UnloadFuncPtr unloadProc;
   1.118 +};
   1.119 +
   1.120 +} // namespace
   1.121 +
   1.122 +#if defined(MOZILLA_INTERNAL_API)
   1.123 +#  define NSMODULE_NAME(_name) _name##_NSModule
   1.124 +#  define NSMODULE_DECL(_name) extern mozilla::Module const *const NSMODULE_NAME(_name)
   1.125 +#  define NSMODULE_DEFN(_name) NSMODULE_DECL(_name)
   1.126 +#else
   1.127 +#  define NSMODULE_NAME(_name) NSModule
   1.128 +#  define NSMODULE_DEFN(_name) extern "C" NS_EXPORT mozilla::Module const *const NSModule
   1.129 +#endif
   1.130 +
   1.131 +#endif // mozilla_Module_h

mercurial