michael@0: /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ michael@0: /* vim: set ts=4 et sw=4 tw=80: */ michael@0: /* This Source Code Form is subject to the terms of the Mozilla Public michael@0: * License, v. 2.0. If a copy of the MPL was not distributed with this michael@0: * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ michael@0: michael@0: #ifndef mozilla_XPTInterfaceInfoManager_h_ michael@0: #define mozilla_XPTInterfaceInfoManager_h_ michael@0: michael@0: #include "nsIInterfaceInfoManager.h" michael@0: #include "nsIMemoryReporter.h" michael@0: michael@0: #include "mozilla/MemoryReporting.h" michael@0: #include "mozilla/Mutex.h" michael@0: #include "mozilla/ReentrantMonitor.h" michael@0: #include "nsDataHashtable.h" michael@0: michael@0: template class nsCOMArray; michael@0: class nsIMemoryReporter; michael@0: class XPTHeader; michael@0: class XPTInterfaceDirectoryEntry; michael@0: class xptiInterfaceEntry; michael@0: class xptiInterfaceInfo; michael@0: class xptiTypelibGuts; michael@0: michael@0: namespace mozilla { michael@0: michael@0: class XPTInterfaceInfoManager MOZ_FINAL michael@0: : public nsIInterfaceInfoManager michael@0: , public nsIMemoryReporter michael@0: { michael@0: NS_DECL_THREADSAFE_ISUPPORTS michael@0: NS_DECL_NSIINTERFACEINFOMANAGER michael@0: NS_DECL_NSIMEMORYREPORTER michael@0: michael@0: public: michael@0: // GetSingleton() is infallible michael@0: static XPTInterfaceInfoManager* GetSingleton(); michael@0: static void FreeInterfaceInfoManager(); michael@0: michael@0: void GetScriptableInterfaces(nsCOMArray& aInterfaces); michael@0: michael@0: void RegisterBuffer(char *buf, uint32_t length); michael@0: michael@0: static Mutex& GetResolveLock() michael@0: { michael@0: return GetSingleton()->mResolveLock; michael@0: } michael@0: michael@0: xptiInterfaceEntry* GetInterfaceEntryForIID(const nsIID *iid); michael@0: michael@0: size_t SizeOfIncludingThis(mozilla::MallocSizeOf aMallocSizeOf); michael@0: michael@0: private: michael@0: XPTInterfaceInfoManager(); michael@0: ~XPTInterfaceInfoManager(); michael@0: michael@0: void InitMemoryReporter(); michael@0: michael@0: void RegisterXPTHeader(XPTHeader* aHeader); michael@0: michael@0: // idx is the index of this interface in the XPTHeader michael@0: void VerifyAndAddEntryIfNew(XPTInterfaceDirectoryEntry* iface, michael@0: uint16_t idx, michael@0: xptiTypelibGuts* typelib); michael@0: michael@0: private: michael@0: michael@0: class xptiWorkingSet michael@0: { michael@0: public: michael@0: xptiWorkingSet(); michael@0: ~xptiWorkingSet(); michael@0: michael@0: bool IsValid() const; michael@0: michael@0: void InvalidateInterfaceInfos(); michael@0: void ClearHashTables(); michael@0: michael@0: // utility methods... michael@0: michael@0: enum {NOT_FOUND = 0xffffffff}; michael@0: michael@0: // Directory stuff... michael@0: michael@0: uint32_t GetDirectoryCount(); michael@0: nsresult GetCloneOfDirectoryAt(uint32_t i, nsIFile** dir); michael@0: nsresult GetDirectoryAt(uint32_t i, nsIFile** dir); michael@0: bool FindDirectory(nsIFile* dir, uint32_t* index); michael@0: bool FindDirectoryOfFile(nsIFile* file, uint32_t* index); michael@0: bool DirectoryAtMatchesPersistentDescriptor(uint32_t i, const char* desc); michael@0: michael@0: private: michael@0: uint32_t mFileCount; michael@0: uint32_t mMaxFileCount; michael@0: michael@0: public: michael@0: // XXX make these private with accessors michael@0: // mTableMonitor must be held across: michael@0: // * any read from or write to mIIDTable or mNameTable michael@0: // * any writing to the links between an xptiInterfaceEntry michael@0: // and its xptiInterfaceInfo (mEntry/mInfo) michael@0: mozilla::ReentrantMonitor mTableReentrantMonitor; michael@0: nsDataHashtable mIIDTable; michael@0: nsDataHashtable mNameTable; michael@0: }; michael@0: michael@0: // XXX xptiInterfaceInfo want's to poke at the working set itself michael@0: friend class ::xptiInterfaceInfo; michael@0: friend class ::xptiInterfaceEntry; michael@0: friend class ::xptiTypelibGuts; michael@0: michael@0: xptiWorkingSet mWorkingSet; michael@0: Mutex mResolveLock; michael@0: }; michael@0: michael@0: } michael@0: michael@0: #endif