зеркало из https://github.com/mozilla/gecko-dev.git
Not yet part of the Monkey.
- Added magic comments to make the LXR browsing experience more pleasant. - introduced the nsInterfaceRecord class (formerly less formally interface_record). - changed the XPTInterfaceDirectoryEntry pointer in InterfaceInfoes into nsInterfaceRecord pointers, removing the need for a hash just to go from entries to records to support nsXPTParamInfo::GetInterface. - made the destructor for InterfaceInfo objects remove null the pointer in the corresponding reference.
This commit is contained in:
Родитель
c3220b48e7
Коммит
1a1a2d5d23
|
@ -16,7 +16,7 @@
|
|||
* Reserved.
|
||||
*/
|
||||
|
||||
/* The InterfaceInfo support public stuff. */
|
||||
/* C++ wrappers for xpt_struct.h structures. */
|
||||
|
||||
#ifndef xpt_cpp_h___
|
||||
#define xpt_cpp_h___
|
||||
|
|
|
@ -16,6 +16,8 @@
|
|||
* Reserved.
|
||||
*/
|
||||
|
||||
/* XPTI_PUBLIC_API and XPTI_GetInterfaceInfoManager declarations. */
|
||||
|
||||
#ifndef xptiinfo_h___
|
||||
#define xptiinfo_h___
|
||||
|
||||
|
|
|
@ -16,6 +16,8 @@
|
|||
* Reserved.
|
||||
*/
|
||||
|
||||
/* Implementation of nsIInterfaceInfoManager. */
|
||||
|
||||
#include "nscore.h"
|
||||
|
||||
#include "nsISupports.h"
|
||||
|
@ -30,9 +32,9 @@
|
|||
static NS_DEFINE_IID(kIInterfaceInfoIID, NS_IINTERFACEINFO_IID);
|
||||
NS_IMPL_ISUPPORTS(nsInterfaceInfo, kIInterfaceInfoIID);
|
||||
|
||||
nsInterfaceInfo::nsInterfaceInfo(XPTInterfaceDirectoryEntry* entry,
|
||||
nsInterfaceInfo::nsInterfaceInfo(nsInterfaceRecord *record,
|
||||
nsInterfaceInfo *parent)
|
||||
: mEntry(entry),
|
||||
: mInterfaceRecord(record),
|
||||
mParent(parent)
|
||||
{
|
||||
NS_INIT_REFCNT();
|
||||
|
@ -48,14 +50,20 @@ nsInterfaceInfo::nsInterfaceInfo(XPTInterfaceDirectoryEntry* entry,
|
|||
mMethodBaseIndex = mConstantBaseIndex = 0;
|
||||
}
|
||||
|
||||
mMethodCount = mEntry->interface_descriptor->num_methods;
|
||||
mConstantCount = mEntry->interface_descriptor->num_constants;
|
||||
mMethodCount =
|
||||
mInterfaceRecord->entry->interface_descriptor->num_methods;
|
||||
mConstantCount =
|
||||
mInterfaceRecord->entry->interface_descriptor->num_constants;
|
||||
}
|
||||
|
||||
nsInterfaceInfo::~nsInterfaceInfo()
|
||||
{
|
||||
if(mParent != NULL)
|
||||
if (this->mParent != NULL)
|
||||
NS_RELEASE(mParent);
|
||||
|
||||
// remove interface record's notion of my existence
|
||||
if (this->mInterfaceRecord != NULL)
|
||||
this->mInterfaceRecord->info = NULL;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
|
@ -65,11 +73,11 @@ nsInterfaceInfo::GetName(char** name)
|
|||
|
||||
nsIAllocator* allocator;
|
||||
if(NULL != (allocator = nsInterfaceInfoManager::GetAllocator())) {
|
||||
int len = strlen(mEntry->name)+1;
|
||||
int len = strlen(mInterfaceRecord->entry->name)+1;
|
||||
char* p = (char*)allocator->Alloc(len);
|
||||
NS_RELEASE(allocator);
|
||||
if(p) {
|
||||
memcpy(p, mEntry->name, len);
|
||||
memcpy(p, mInterfaceRecord->entry->name, len);
|
||||
*name = p;
|
||||
return NS_OK;
|
||||
}
|
||||
|
@ -89,7 +97,7 @@ nsInterfaceInfo::GetIID(nsIID** iid)
|
|||
nsIID* p = (nsIID*)allocator->Alloc(sizeof(nsIID));
|
||||
NS_RELEASE(allocator);
|
||||
if(p) {
|
||||
memcpy(p, &mEntry->iid, sizeof(nsIID));
|
||||
memcpy(p, &(mInterfaceRecord->entry->iid), sizeof(nsIID));
|
||||
*iid = p;
|
||||
return NS_OK;
|
||||
}
|
||||
|
@ -144,7 +152,7 @@ nsInterfaceInfo::GetMethodInfo(uint16 index, const nsXPTMethodInfo** info)
|
|||
|
||||
// else...
|
||||
*info = NS_REINTERPRET_CAST(nsXPTMethodInfo*,
|
||||
&mEntry->interface_descriptor->
|
||||
&mInterfaceRecord->entry->interface_descriptor->
|
||||
method_descriptors[index - mMethodBaseIndex]);
|
||||
return NS_OK;
|
||||
}
|
||||
|
@ -163,9 +171,10 @@ nsInterfaceInfo::GetConstant(uint16 index, const nsXPTConstant** constant)
|
|||
}
|
||||
|
||||
// else...
|
||||
*constant = NS_REINTERPRET_CAST(nsXPTConstant*,
|
||||
&mEntry->interface_descriptor->
|
||||
const_descriptors[index-mConstantBaseIndex]);
|
||||
*constant =
|
||||
NS_REINTERPRET_CAST(nsXPTConstant*,
|
||||
&mInterfaceRecord->entry->interface_descriptor->
|
||||
const_descriptors[index-mConstantBaseIndex]);
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
|
@ -175,12 +184,12 @@ void
|
|||
nsInterfaceInfo::print(FILE *fd)
|
||||
{
|
||||
fprintf(fd, "iid: %s name: %s name_space: %s\n",
|
||||
mEntry->iid.ToString(),
|
||||
mEntry->name,
|
||||
mEntry->name_space);
|
||||
this->mInterfaceRecord->entry->iid.ToString(),
|
||||
this->mInterfaceRecord->entry->name,
|
||||
this->mInterfaceRecord->entry->name_space);
|
||||
if (mParent != NULL) {
|
||||
fprintf(fd, "parent:\n\t");
|
||||
mParent->print(fd);
|
||||
this->mParent->print(fd);
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
|
|
@ -16,6 +16,8 @@
|
|||
* Reserved.
|
||||
*/
|
||||
|
||||
/* Library-private header for nsInterfaceInfo implementation. */
|
||||
|
||||
#ifndef nsInterfaceInfo_h___
|
||||
#define nsInterfaceInfo_h___
|
||||
|
||||
|
@ -23,6 +25,8 @@
|
|||
#include "xpt_struct.h"
|
||||
#include "xpt_cpp.h"
|
||||
|
||||
#include "nsInterfaceRecord.h"
|
||||
|
||||
#ifdef DEBUG
|
||||
#include <stdio.h>
|
||||
#endif
|
||||
|
@ -47,8 +51,8 @@ class nsInterfaceInfo : public nsIInterfaceInfo
|
|||
NS_IMETHOD GetConstant(uint16 index, const nsXPTConstant** constant);
|
||||
|
||||
// why constructor public?
|
||||
nsInterfaceInfo(XPTInterfaceDirectoryEntry* entry,
|
||||
nsInterfaceInfo *parent);
|
||||
nsInterfaceInfo(nsInterfaceRecord *record,
|
||||
nsInterfaceInfo *parent);
|
||||
public:
|
||||
virtual ~nsInterfaceInfo();
|
||||
|
||||
|
@ -62,9 +66,9 @@ private:
|
|||
friend const nsIID*
|
||||
nsXPTParamInfo::GetInterfaceIID(nsIInterfaceInfo *info) const;
|
||||
|
||||
XPTInterfaceDirectoryEntry *getIDE() { return mEntry; };
|
||||
|
||||
XPTInterfaceDirectoryEntry* mEntry;
|
||||
nsInterfaceRecord *getInterfaceRecord() { return mInterfaceRecord; };
|
||||
nsInterfaceRecord *mInterfaceRecord;
|
||||
|
||||
nsInterfaceInfo* mParent;
|
||||
|
||||
uint16 mMethodBaseIndex;
|
||||
|
|
|
@ -16,6 +16,8 @@
|
|||
* Reserved.
|
||||
*/
|
||||
|
||||
/* Implementation of nsIInterfaceInfo. */
|
||||
|
||||
#include <sys/stat.h>
|
||||
#include "nscore.h"
|
||||
|
||||
|
@ -155,7 +157,6 @@ XPTHeader *getHeader(const char *filename) {
|
|||
static void
|
||||
indexify_file(const char *filename,
|
||||
PLHashTable *interfaceTable,
|
||||
PLHashTable *typelibTable,
|
||||
nsHashtable *IIDTable,
|
||||
nsIAllocator *al)
|
||||
{
|
||||
|
@ -163,26 +164,24 @@ indexify_file(const char *filename,
|
|||
|
||||
int limit = header->num_interfaces;
|
||||
|
||||
interface_record *value;
|
||||
nsInterfaceRecord *value;
|
||||
#ifdef DEBUG_mccabe
|
||||
static int which = 0;
|
||||
which++;
|
||||
#endif
|
||||
|
||||
for (int i = 0; i < limit; i++) {
|
||||
XPTInterfaceDirectoryEntry *current = header->interface_directory + i;
|
||||
|
||||
// associate the current entry with the header it came from.
|
||||
PL_HashTableAdd(typelibTable, current, header);
|
||||
|
||||
#ifdef DEBUG_mccabe
|
||||
fprintf(stderr, "%s", current->name);
|
||||
#endif
|
||||
// first try to look it up...
|
||||
value = (interface_record *)PL_HashTableLookup(interfaceTable,
|
||||
value = (nsInterfaceRecord *)PL_HashTableLookup(interfaceTable,
|
||||
current->name);
|
||||
// if none found, make a dummy record.
|
||||
if (value == NULL) {
|
||||
value = new interface_record();
|
||||
value = new nsInterfaceRecord();
|
||||
value->which_header = NULL;
|
||||
value->resolved = PR_FALSE;
|
||||
value->which = -1;
|
||||
|
@ -237,11 +236,6 @@ static PRIntn
|
|||
check_enumerator(PLHashEntry *he, PRIntn index, void *arg);
|
||||
#endif
|
||||
|
||||
static PLHashNumber
|
||||
hash_by_value(const void *key) {
|
||||
return (uint32)key;
|
||||
}
|
||||
|
||||
void nsInterfaceInfoManager::initInterfaceTables()
|
||||
{
|
||||
// make a hashtable to associate names with arbitrary info
|
||||
|
@ -250,14 +244,6 @@ void nsInterfaceInfoManager::initInterfaceTables()
|
|||
PL_CompareStrings, // compare keys
|
||||
PL_CompareValues, // comp values
|
||||
NULL, NULL);
|
||||
|
||||
// make a hashtable to associate InterfaceDirectoryEntry values
|
||||
// with XPTHeaders. (for nsXPTParamInfo::GetInterface)
|
||||
this->mTypelibTable = PL_NewHashTable(XPT_HASHSIZE,
|
||||
hash_by_value,
|
||||
PL_CompareValues,
|
||||
PL_CompareValues,
|
||||
NULL, NULL);
|
||||
|
||||
// make a hashtable to map iids to names
|
||||
this->mIIDTable = new nsHashtable(XPT_HASHSIZE);
|
||||
|
@ -313,7 +299,6 @@ void nsInterfaceInfoManager::initInterfaceTables()
|
|||
#endif
|
||||
indexify_file(fullname,
|
||||
this->mInterfaceTable,
|
||||
this->mTypelibTable,
|
||||
this->mIIDTable,
|
||||
this->mAllocator);
|
||||
} else {
|
||||
|
@ -333,7 +318,7 @@ void nsInterfaceInfoManager::initInterfaceTables()
|
|||
#ifdef DEBUG
|
||||
PRIntn check_enumerator(PLHashEntry *he, PRIntn index, void *arg) {
|
||||
char *key = (char *)he->key;
|
||||
interface_record *value = (interface_record *)he->value;
|
||||
nsInterfaceRecord *value = (nsInterfaceRecord *)he->value;
|
||||
nsHashtable *iidtable = (nsHashtable *)arg;
|
||||
|
||||
|
||||
|
@ -374,15 +359,15 @@ NS_IMETHODIMP
|
|||
nsInterfaceInfoManager::GetInfoForName(const char* name,
|
||||
nsIInterfaceInfo** info)
|
||||
{
|
||||
interface_record *record =
|
||||
(interface_record *)PL_HashTableLookup(this->mInterfaceTable, name);
|
||||
nsInterfaceRecord *record =
|
||||
(nsInterfaceRecord *)PL_HashTableLookup(this->mInterfaceTable, name);
|
||||
if (record == NULL || record->resolved == PR_FALSE) {
|
||||
*info = NULL;
|
||||
return NS_ERROR_FAILURE;
|
||||
}
|
||||
PR_ASSERT(record->entry != NULL);
|
||||
|
||||
// Is there already an II obj associated with the interface_record?
|
||||
// Is there already an II obj associated with the nsInterfaceRecord?
|
||||
if (record->info != NULL) {
|
||||
// yay!
|
||||
*info = record->info;
|
||||
|
@ -392,8 +377,7 @@ nsInterfaceInfoManager::GetInfoForName(const char* name,
|
|||
|
||||
// nope, better make one. first, find a parent for it.
|
||||
nsIInterfaceInfo *parent;
|
||||
XPTInterfaceDirectoryEntry *entry = record->entry;
|
||||
uint16 parent_index = entry->interface_descriptor->parent_interface;
|
||||
uint16 parent_index = record->entry->interface_descriptor->parent_interface;
|
||||
// Does it _get_ a parent? (is it nsISupports?)
|
||||
if (parent_index == 0) {
|
||||
// presumably this is only the case for nsISupports.
|
||||
|
@ -415,7 +399,7 @@ nsInterfaceInfoManager::GetInfoForName(const char* name,
|
|||
|
||||
// got a parent for it, now build the object itself
|
||||
nsInterfaceInfo *result =
|
||||
new nsInterfaceInfo(entry, (nsInterfaceInfo *)parent);
|
||||
new nsInterfaceInfo(record, (nsInterfaceInfo *)parent);
|
||||
*info = result;
|
||||
NS_ADDREF(*info);
|
||||
return NS_OK;
|
||||
|
@ -424,8 +408,8 @@ nsInterfaceInfoManager::GetInfoForName(const char* name,
|
|||
NS_IMETHODIMP
|
||||
nsInterfaceInfoManager::GetIIDForName(const char* name, nsIID** iid)
|
||||
{
|
||||
interface_record *record =
|
||||
(interface_record *)PL_HashTableLookup(this->mInterfaceTable, name);
|
||||
nsInterfaceRecord *record =
|
||||
(nsInterfaceRecord *)PL_HashTableLookup(this->mInterfaceTable, name);
|
||||
if (record == NULL || record->resolved == PR_FALSE) {
|
||||
*iid = NULL;
|
||||
return NS_ERROR_FAILURE;
|
||||
|
@ -472,43 +456,8 @@ nsInterfaceInfoManager::GetNameForIID(const nsIID* iid, char** name)
|
|||
return NS_OK;
|
||||
}
|
||||
|
||||
// XXX this goes away; IIM should be a service.
|
||||
// ... where does decl for this go?
|
||||
// Even if this is a service, it is cool to provide a direct accessor
|
||||
XPTI_PUBLIC_API(nsIInterfaceInfoManager*)
|
||||
XPTI_GetInterfaceInfoManager()
|
||||
{
|
||||
return nsInterfaceInfoManager::GetInterfaceInfoManager();
|
||||
}
|
||||
|
||||
#if 0
|
||||
struct XPTInterfaceDirectoryEntry {
|
||||
nsID iid;
|
||||
char *name;
|
||||
char *name_space;
|
||||
XPTInterfaceDescriptor *interface_descriptor;
|
||||
#if 0 /* not yet */
|
||||
/* not stored on disk */
|
||||
uint32 offset; /* the offset for an ID still to be read */
|
||||
#endif
|
||||
};
|
||||
|
||||
struct XPTInterfaceDescriptor {
|
||||
uint16 parent_interface;
|
||||
uint16 num_methods;
|
||||
XPTMethodDescriptor *method_descriptors;
|
||||
uint16 num_constants;
|
||||
XPTConstDescriptor *const_descriptors;
|
||||
};
|
||||
|
||||
struct XPTHeader {
|
||||
char magic[16];
|
||||
uint8 major_version;
|
||||
uint8 minor_version;
|
||||
uint16 num_interfaces;
|
||||
uint32 file_length;
|
||||
XPTInterfaceDirectoryEntry *interface_directory;
|
||||
uint32 data_pool;
|
||||
XPTAnnotation *annotations;
|
||||
};
|
||||
#endif
|
||||
|
|
|
@ -16,23 +16,20 @@
|
|||
* Reserved.
|
||||
*/
|
||||
|
||||
/* Library-private header for nsInterfaceInfoManager implementation. */
|
||||
|
||||
#ifndef nsInterfaceInfoManager_h___
|
||||
#define nsInterfaceInfoManager_h___
|
||||
|
||||
#include "plhash.h"
|
||||
#include "nsIAllocator.h"
|
||||
|
||||
#include "xpt_struct.h"
|
||||
|
||||
#include "nsIInterfaceInfo.h"
|
||||
#include "nsIInterfaceInfoManager.h"
|
||||
|
||||
#include "nsInterfaceInfo.h"
|
||||
|
||||
#include "nsHashtable.h"
|
||||
|
||||
#include "plhash.h"
|
||||
|
||||
class hash_record;
|
||||
#include "xpt_struct.h"
|
||||
#include "nsInterfaceInfo.h"
|
||||
#include "nsInterfaceRecord.h"
|
||||
|
||||
class nsInterfaceInfoManager : public nsIInterfaceInfoManager
|
||||
{
|
||||
|
@ -64,9 +61,6 @@ private:
|
|||
// mapping between names and records
|
||||
PLHashTable *mInterfaceTable;
|
||||
|
||||
// mapping between entries and typelibs (for nsXPTParamInfo::GetInterface)
|
||||
PLHashTable *mTypelibTable;
|
||||
|
||||
// mapping between iids and names
|
||||
// (record handling is looked up by name; iids are translated there)
|
||||
nsHashtable *mIIDTable;
|
||||
|
@ -74,19 +68,7 @@ private:
|
|||
nsIAllocator* mAllocator;
|
||||
};
|
||||
|
||||
// For references in the mInterfaceTable hashtable.
|
||||
class interface_record {
|
||||
public:
|
||||
XPTHeader *which_header;
|
||||
PRBool resolved;
|
||||
XPTInterfaceDirectoryEntry *entry;
|
||||
nsInterfaceInfo *info;
|
||||
#ifdef DEBUG
|
||||
// which (counting from 1) typelib was it loaded from?
|
||||
int which;
|
||||
#endif
|
||||
};
|
||||
|
||||
|
||||
|
||||
#endif /* nsInterfaceInfoManager_h___ */
|
||||
|
||||
|
||||
|
||||
|
|
|
@ -0,0 +1,43 @@
|
|||
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
|
||||
/*
|
||||
* The contents of this file are subject to the Netscape Public License
|
||||
* Version 1.0 (the "NPL"); you may not use this file except in
|
||||
* compliance with the NPL. You may obtain a copy of the NPL at
|
||||
* http://www.mozilla.org/NPL/
|
||||
*
|
||||
* Software distributed under the NPL is distributed on an "AS IS" basis,
|
||||
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
|
||||
* for the specific language governing rights and limitations under the
|
||||
* NPL.
|
||||
*
|
||||
* The Initial Developer of this code under the NPL is Netscape
|
||||
* Communications Corporation. Portions created by Netscape are
|
||||
* Copyright (C) 1999 Netscape Communications Corporation. All Rights
|
||||
* Reserved.
|
||||
*/
|
||||
|
||||
/* For keeping track of interface directory entries. */
|
||||
|
||||
#ifndef nsInterfaceRecord_h___
|
||||
#define nsInterfaceRecord_h___
|
||||
|
||||
#include "xpt_struct.h"
|
||||
#include "nsInterfaceInfo.h"
|
||||
|
||||
// resolve circular ref...
|
||||
class nsInterfaceInfo;
|
||||
|
||||
// For references in the mInterfaceTable hashtable.
|
||||
class nsInterfaceRecord {
|
||||
public:
|
||||
XPTHeader *which_header;
|
||||
PRBool resolved;
|
||||
XPTInterfaceDirectoryEntry *entry;
|
||||
nsInterfaceInfo *info;
|
||||
#ifdef DEBUG
|
||||
// which (counting from 1) typelib was it loaded from?
|
||||
int which;
|
||||
#endif
|
||||
};
|
||||
|
||||
#endif /* nsInterfaceRecord_h___ */
|
|
@ -38,24 +38,24 @@ nsXPTParamInfo::GetInterface(nsIInterfaceInfo *info) const
|
|||
NS_PRECONDITION(GetType().TagPart() == nsXPTType::T_INTERFACE,
|
||||
"not an interface");
|
||||
|
||||
XPTInterfaceDirectoryEntry *entry = ((nsInterfaceInfo *)info)->getIDE();
|
||||
nsInterfaceRecord *record =
|
||||
((nsInterfaceInfo *)info)->getInterfaceRecord();
|
||||
|
||||
|
||||
nsIInterfaceInfoManager* mgr;
|
||||
if(!(mgr = nsInterfaceInfoManager::GetInterfaceInfoManager()))
|
||||
return NULL;
|
||||
nsInterfaceInfoManager* mymgr = (nsInterfaceInfoManager *)mgr;
|
||||
|
||||
// what typelib did the entry come from?
|
||||
XPTHeader *which_header =
|
||||
(XPTHeader *)PL_HashTableLookup(mymgr->mTypelibTable, entry);
|
||||
NS_ASSERTION(which_header != NULL, "");
|
||||
XPTHeader *which_header = record->which_header;
|
||||
NS_ASSERTION(which_header != NULL, "missing header info assoc'd with II");
|
||||
|
||||
// can't use IID, because it could be null for this entry.
|
||||
char *interface_name;
|
||||
interface_name = which_header->interface_directory[type.type.interface].name;
|
||||
|
||||
nsIInterfaceInfo *ii;
|
||||
nsresult nsr = mymgr->GetInfoForName(interface_name, &ii);
|
||||
nsresult nsr = mgr->GetInfoForName(interface_name, &ii);
|
||||
if (NS_IS_ERROR(nsr)) {
|
||||
NS_RELEASE(mgr);
|
||||
return NULL;
|
||||
|
@ -69,25 +69,23 @@ nsXPTParamInfo::GetInterfaceIID(nsIInterfaceInfo *info) const
|
|||
NS_PRECONDITION(GetType().TagPart() == nsXPTType::T_INTERFACE,
|
||||
"not an interface");
|
||||
|
||||
XPTInterfaceDirectoryEntry *entry = ((nsInterfaceInfo *)info)->getIDE();
|
||||
nsInterfaceRecord *record =
|
||||
((nsInterfaceInfo *)info)->getInterfaceRecord();
|
||||
|
||||
nsIInterfaceInfoManager* mgr;
|
||||
if(!(mgr = nsInterfaceInfoManager::GetInterfaceInfoManager()))
|
||||
return NULL;
|
||||
nsInterfaceInfoManager* mymgr = (nsInterfaceInfoManager *)mgr;
|
||||
|
||||
// what typelib did the entry come from?
|
||||
XPTHeader *which_header =
|
||||
(XPTHeader *)PL_HashTableLookup(mymgr->mTypelibTable, entry);
|
||||
NS_ASSERTION(which_header != NULL, "");
|
||||
XPTHeader *which_header = record->which_header;
|
||||
NS_ASSERTION(which_header != NULL, "header missing?");
|
||||
|
||||
// can't use IID, because it could be null for this entry.
|
||||
char *interface_name;
|
||||
interface_name = which_header->interface_directory[type.type.interface].name;
|
||||
|
||||
nsIID* iid;
|
||||
|
||||
nsresult nsr = mymgr->GetIIDForName(interface_name, &iid);
|
||||
nsresult nsr = mgr->GetIIDForName(interface_name, &iid);
|
||||
if (NS_IS_ERROR(nsr)) {
|
||||
NS_RELEASE(mgr);
|
||||
return NULL;
|
||||
|
|
|
@ -16,7 +16,7 @@
|
|||
* Reserved.
|
||||
*/
|
||||
|
||||
/* The InterfaceInfo support public stuff. */
|
||||
/* C++ wrappers for xpt_struct.h structures. */
|
||||
|
||||
#ifndef xpt_cpp_h___
|
||||
#define xpt_cpp_h___
|
||||
|
|
|
@ -16,6 +16,8 @@
|
|||
* Reserved.
|
||||
*/
|
||||
|
||||
/* XPTI_PUBLIC_API and XPTI_GetInterfaceInfoManager declarations. */
|
||||
|
||||
#ifndef xptiinfo_h___
|
||||
#define xptiinfo_h___
|
||||
|
||||
|
|
|
@ -16,6 +16,8 @@
|
|||
* Reserved.
|
||||
*/
|
||||
|
||||
/* Implementation of nsIInterfaceInfoManager. */
|
||||
|
||||
#include "nscore.h"
|
||||
|
||||
#include "nsISupports.h"
|
||||
|
@ -30,9 +32,9 @@
|
|||
static NS_DEFINE_IID(kIInterfaceInfoIID, NS_IINTERFACEINFO_IID);
|
||||
NS_IMPL_ISUPPORTS(nsInterfaceInfo, kIInterfaceInfoIID);
|
||||
|
||||
nsInterfaceInfo::nsInterfaceInfo(XPTInterfaceDirectoryEntry* entry,
|
||||
nsInterfaceInfo::nsInterfaceInfo(nsInterfaceRecord *record,
|
||||
nsInterfaceInfo *parent)
|
||||
: mEntry(entry),
|
||||
: mInterfaceRecord(record),
|
||||
mParent(parent)
|
||||
{
|
||||
NS_INIT_REFCNT();
|
||||
|
@ -48,14 +50,20 @@ nsInterfaceInfo::nsInterfaceInfo(XPTInterfaceDirectoryEntry* entry,
|
|||
mMethodBaseIndex = mConstantBaseIndex = 0;
|
||||
}
|
||||
|
||||
mMethodCount = mEntry->interface_descriptor->num_methods;
|
||||
mConstantCount = mEntry->interface_descriptor->num_constants;
|
||||
mMethodCount =
|
||||
mInterfaceRecord->entry->interface_descriptor->num_methods;
|
||||
mConstantCount =
|
||||
mInterfaceRecord->entry->interface_descriptor->num_constants;
|
||||
}
|
||||
|
||||
nsInterfaceInfo::~nsInterfaceInfo()
|
||||
{
|
||||
if(mParent != NULL)
|
||||
if (this->mParent != NULL)
|
||||
NS_RELEASE(mParent);
|
||||
|
||||
// remove interface record's notion of my existence
|
||||
if (this->mInterfaceRecord != NULL)
|
||||
this->mInterfaceRecord->info = NULL;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
|
@ -65,11 +73,11 @@ nsInterfaceInfo::GetName(char** name)
|
|||
|
||||
nsIAllocator* allocator;
|
||||
if(NULL != (allocator = nsInterfaceInfoManager::GetAllocator())) {
|
||||
int len = strlen(mEntry->name)+1;
|
||||
int len = strlen(mInterfaceRecord->entry->name)+1;
|
||||
char* p = (char*)allocator->Alloc(len);
|
||||
NS_RELEASE(allocator);
|
||||
if(p) {
|
||||
memcpy(p, mEntry->name, len);
|
||||
memcpy(p, mInterfaceRecord->entry->name, len);
|
||||
*name = p;
|
||||
return NS_OK;
|
||||
}
|
||||
|
@ -89,7 +97,7 @@ nsInterfaceInfo::GetIID(nsIID** iid)
|
|||
nsIID* p = (nsIID*)allocator->Alloc(sizeof(nsIID));
|
||||
NS_RELEASE(allocator);
|
||||
if(p) {
|
||||
memcpy(p, &mEntry->iid, sizeof(nsIID));
|
||||
memcpy(p, &(mInterfaceRecord->entry->iid), sizeof(nsIID));
|
||||
*iid = p;
|
||||
return NS_OK;
|
||||
}
|
||||
|
@ -144,7 +152,7 @@ nsInterfaceInfo::GetMethodInfo(uint16 index, const nsXPTMethodInfo** info)
|
|||
|
||||
// else...
|
||||
*info = NS_REINTERPRET_CAST(nsXPTMethodInfo*,
|
||||
&mEntry->interface_descriptor->
|
||||
&mInterfaceRecord->entry->interface_descriptor->
|
||||
method_descriptors[index - mMethodBaseIndex]);
|
||||
return NS_OK;
|
||||
}
|
||||
|
@ -163,9 +171,10 @@ nsInterfaceInfo::GetConstant(uint16 index, const nsXPTConstant** constant)
|
|||
}
|
||||
|
||||
// else...
|
||||
*constant = NS_REINTERPRET_CAST(nsXPTConstant*,
|
||||
&mEntry->interface_descriptor->
|
||||
const_descriptors[index-mConstantBaseIndex]);
|
||||
*constant =
|
||||
NS_REINTERPRET_CAST(nsXPTConstant*,
|
||||
&mInterfaceRecord->entry->interface_descriptor->
|
||||
const_descriptors[index-mConstantBaseIndex]);
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
|
@ -175,12 +184,12 @@ void
|
|||
nsInterfaceInfo::print(FILE *fd)
|
||||
{
|
||||
fprintf(fd, "iid: %s name: %s name_space: %s\n",
|
||||
mEntry->iid.ToString(),
|
||||
mEntry->name,
|
||||
mEntry->name_space);
|
||||
this->mInterfaceRecord->entry->iid.ToString(),
|
||||
this->mInterfaceRecord->entry->name,
|
||||
this->mInterfaceRecord->entry->name_space);
|
||||
if (mParent != NULL) {
|
||||
fprintf(fd, "parent:\n\t");
|
||||
mParent->print(fd);
|
||||
this->mParent->print(fd);
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
|
|
@ -16,6 +16,8 @@
|
|||
* Reserved.
|
||||
*/
|
||||
|
||||
/* Library-private header for nsInterfaceInfo implementation. */
|
||||
|
||||
#ifndef nsInterfaceInfo_h___
|
||||
#define nsInterfaceInfo_h___
|
||||
|
||||
|
@ -23,6 +25,8 @@
|
|||
#include "xpt_struct.h"
|
||||
#include "xpt_cpp.h"
|
||||
|
||||
#include "nsInterfaceRecord.h"
|
||||
|
||||
#ifdef DEBUG
|
||||
#include <stdio.h>
|
||||
#endif
|
||||
|
@ -47,8 +51,8 @@ class nsInterfaceInfo : public nsIInterfaceInfo
|
|||
NS_IMETHOD GetConstant(uint16 index, const nsXPTConstant** constant);
|
||||
|
||||
// why constructor public?
|
||||
nsInterfaceInfo(XPTInterfaceDirectoryEntry* entry,
|
||||
nsInterfaceInfo *parent);
|
||||
nsInterfaceInfo(nsInterfaceRecord *record,
|
||||
nsInterfaceInfo *parent);
|
||||
public:
|
||||
virtual ~nsInterfaceInfo();
|
||||
|
||||
|
@ -62,9 +66,9 @@ private:
|
|||
friend const nsIID*
|
||||
nsXPTParamInfo::GetInterfaceIID(nsIInterfaceInfo *info) const;
|
||||
|
||||
XPTInterfaceDirectoryEntry *getIDE() { return mEntry; };
|
||||
|
||||
XPTInterfaceDirectoryEntry* mEntry;
|
||||
nsInterfaceRecord *getInterfaceRecord() { return mInterfaceRecord; };
|
||||
nsInterfaceRecord *mInterfaceRecord;
|
||||
|
||||
nsInterfaceInfo* mParent;
|
||||
|
||||
uint16 mMethodBaseIndex;
|
||||
|
|
|
@ -16,6 +16,8 @@
|
|||
* Reserved.
|
||||
*/
|
||||
|
||||
/* Implementation of nsIInterfaceInfo. */
|
||||
|
||||
#include <sys/stat.h>
|
||||
#include "nscore.h"
|
||||
|
||||
|
@ -155,7 +157,6 @@ XPTHeader *getHeader(const char *filename) {
|
|||
static void
|
||||
indexify_file(const char *filename,
|
||||
PLHashTable *interfaceTable,
|
||||
PLHashTable *typelibTable,
|
||||
nsHashtable *IIDTable,
|
||||
nsIAllocator *al)
|
||||
{
|
||||
|
@ -163,26 +164,24 @@ indexify_file(const char *filename,
|
|||
|
||||
int limit = header->num_interfaces;
|
||||
|
||||
interface_record *value;
|
||||
nsInterfaceRecord *value;
|
||||
#ifdef DEBUG_mccabe
|
||||
static int which = 0;
|
||||
which++;
|
||||
#endif
|
||||
|
||||
for (int i = 0; i < limit; i++) {
|
||||
XPTInterfaceDirectoryEntry *current = header->interface_directory + i;
|
||||
|
||||
// associate the current entry with the header it came from.
|
||||
PL_HashTableAdd(typelibTable, current, header);
|
||||
|
||||
#ifdef DEBUG_mccabe
|
||||
fprintf(stderr, "%s", current->name);
|
||||
#endif
|
||||
// first try to look it up...
|
||||
value = (interface_record *)PL_HashTableLookup(interfaceTable,
|
||||
value = (nsInterfaceRecord *)PL_HashTableLookup(interfaceTable,
|
||||
current->name);
|
||||
// if none found, make a dummy record.
|
||||
if (value == NULL) {
|
||||
value = new interface_record();
|
||||
value = new nsInterfaceRecord();
|
||||
value->which_header = NULL;
|
||||
value->resolved = PR_FALSE;
|
||||
value->which = -1;
|
||||
|
@ -237,11 +236,6 @@ static PRIntn
|
|||
check_enumerator(PLHashEntry *he, PRIntn index, void *arg);
|
||||
#endif
|
||||
|
||||
static PLHashNumber
|
||||
hash_by_value(const void *key) {
|
||||
return (uint32)key;
|
||||
}
|
||||
|
||||
void nsInterfaceInfoManager::initInterfaceTables()
|
||||
{
|
||||
// make a hashtable to associate names with arbitrary info
|
||||
|
@ -250,14 +244,6 @@ void nsInterfaceInfoManager::initInterfaceTables()
|
|||
PL_CompareStrings, // compare keys
|
||||
PL_CompareValues, // comp values
|
||||
NULL, NULL);
|
||||
|
||||
// make a hashtable to associate InterfaceDirectoryEntry values
|
||||
// with XPTHeaders. (for nsXPTParamInfo::GetInterface)
|
||||
this->mTypelibTable = PL_NewHashTable(XPT_HASHSIZE,
|
||||
hash_by_value,
|
||||
PL_CompareValues,
|
||||
PL_CompareValues,
|
||||
NULL, NULL);
|
||||
|
||||
// make a hashtable to map iids to names
|
||||
this->mIIDTable = new nsHashtable(XPT_HASHSIZE);
|
||||
|
@ -313,7 +299,6 @@ void nsInterfaceInfoManager::initInterfaceTables()
|
|||
#endif
|
||||
indexify_file(fullname,
|
||||
this->mInterfaceTable,
|
||||
this->mTypelibTable,
|
||||
this->mIIDTable,
|
||||
this->mAllocator);
|
||||
} else {
|
||||
|
@ -333,7 +318,7 @@ void nsInterfaceInfoManager::initInterfaceTables()
|
|||
#ifdef DEBUG
|
||||
PRIntn check_enumerator(PLHashEntry *he, PRIntn index, void *arg) {
|
||||
char *key = (char *)he->key;
|
||||
interface_record *value = (interface_record *)he->value;
|
||||
nsInterfaceRecord *value = (nsInterfaceRecord *)he->value;
|
||||
nsHashtable *iidtable = (nsHashtable *)arg;
|
||||
|
||||
|
||||
|
@ -374,15 +359,15 @@ NS_IMETHODIMP
|
|||
nsInterfaceInfoManager::GetInfoForName(const char* name,
|
||||
nsIInterfaceInfo** info)
|
||||
{
|
||||
interface_record *record =
|
||||
(interface_record *)PL_HashTableLookup(this->mInterfaceTable, name);
|
||||
nsInterfaceRecord *record =
|
||||
(nsInterfaceRecord *)PL_HashTableLookup(this->mInterfaceTable, name);
|
||||
if (record == NULL || record->resolved == PR_FALSE) {
|
||||
*info = NULL;
|
||||
return NS_ERROR_FAILURE;
|
||||
}
|
||||
PR_ASSERT(record->entry != NULL);
|
||||
|
||||
// Is there already an II obj associated with the interface_record?
|
||||
// Is there already an II obj associated with the nsInterfaceRecord?
|
||||
if (record->info != NULL) {
|
||||
// yay!
|
||||
*info = record->info;
|
||||
|
@ -392,8 +377,7 @@ nsInterfaceInfoManager::GetInfoForName(const char* name,
|
|||
|
||||
// nope, better make one. first, find a parent for it.
|
||||
nsIInterfaceInfo *parent;
|
||||
XPTInterfaceDirectoryEntry *entry = record->entry;
|
||||
uint16 parent_index = entry->interface_descriptor->parent_interface;
|
||||
uint16 parent_index = record->entry->interface_descriptor->parent_interface;
|
||||
// Does it _get_ a parent? (is it nsISupports?)
|
||||
if (parent_index == 0) {
|
||||
// presumably this is only the case for nsISupports.
|
||||
|
@ -415,7 +399,7 @@ nsInterfaceInfoManager::GetInfoForName(const char* name,
|
|||
|
||||
// got a parent for it, now build the object itself
|
||||
nsInterfaceInfo *result =
|
||||
new nsInterfaceInfo(entry, (nsInterfaceInfo *)parent);
|
||||
new nsInterfaceInfo(record, (nsInterfaceInfo *)parent);
|
||||
*info = result;
|
||||
NS_ADDREF(*info);
|
||||
return NS_OK;
|
||||
|
@ -424,8 +408,8 @@ nsInterfaceInfoManager::GetInfoForName(const char* name,
|
|||
NS_IMETHODIMP
|
||||
nsInterfaceInfoManager::GetIIDForName(const char* name, nsIID** iid)
|
||||
{
|
||||
interface_record *record =
|
||||
(interface_record *)PL_HashTableLookup(this->mInterfaceTable, name);
|
||||
nsInterfaceRecord *record =
|
||||
(nsInterfaceRecord *)PL_HashTableLookup(this->mInterfaceTable, name);
|
||||
if (record == NULL || record->resolved == PR_FALSE) {
|
||||
*iid = NULL;
|
||||
return NS_ERROR_FAILURE;
|
||||
|
@ -472,43 +456,8 @@ nsInterfaceInfoManager::GetNameForIID(const nsIID* iid, char** name)
|
|||
return NS_OK;
|
||||
}
|
||||
|
||||
// XXX this goes away; IIM should be a service.
|
||||
// ... where does decl for this go?
|
||||
// Even if this is a service, it is cool to provide a direct accessor
|
||||
XPTI_PUBLIC_API(nsIInterfaceInfoManager*)
|
||||
XPTI_GetInterfaceInfoManager()
|
||||
{
|
||||
return nsInterfaceInfoManager::GetInterfaceInfoManager();
|
||||
}
|
||||
|
||||
#if 0
|
||||
struct XPTInterfaceDirectoryEntry {
|
||||
nsID iid;
|
||||
char *name;
|
||||
char *name_space;
|
||||
XPTInterfaceDescriptor *interface_descriptor;
|
||||
#if 0 /* not yet */
|
||||
/* not stored on disk */
|
||||
uint32 offset; /* the offset for an ID still to be read */
|
||||
#endif
|
||||
};
|
||||
|
||||
struct XPTInterfaceDescriptor {
|
||||
uint16 parent_interface;
|
||||
uint16 num_methods;
|
||||
XPTMethodDescriptor *method_descriptors;
|
||||
uint16 num_constants;
|
||||
XPTConstDescriptor *const_descriptors;
|
||||
};
|
||||
|
||||
struct XPTHeader {
|
||||
char magic[16];
|
||||
uint8 major_version;
|
||||
uint8 minor_version;
|
||||
uint16 num_interfaces;
|
||||
uint32 file_length;
|
||||
XPTInterfaceDirectoryEntry *interface_directory;
|
||||
uint32 data_pool;
|
||||
XPTAnnotation *annotations;
|
||||
};
|
||||
#endif
|
||||
|
|
|
@ -16,23 +16,20 @@
|
|||
* Reserved.
|
||||
*/
|
||||
|
||||
/* Library-private header for nsInterfaceInfoManager implementation. */
|
||||
|
||||
#ifndef nsInterfaceInfoManager_h___
|
||||
#define nsInterfaceInfoManager_h___
|
||||
|
||||
#include "plhash.h"
|
||||
#include "nsIAllocator.h"
|
||||
|
||||
#include "xpt_struct.h"
|
||||
|
||||
#include "nsIInterfaceInfo.h"
|
||||
#include "nsIInterfaceInfoManager.h"
|
||||
|
||||
#include "nsInterfaceInfo.h"
|
||||
|
||||
#include "nsHashtable.h"
|
||||
|
||||
#include "plhash.h"
|
||||
|
||||
class hash_record;
|
||||
#include "xpt_struct.h"
|
||||
#include "nsInterfaceInfo.h"
|
||||
#include "nsInterfaceRecord.h"
|
||||
|
||||
class nsInterfaceInfoManager : public nsIInterfaceInfoManager
|
||||
{
|
||||
|
@ -64,9 +61,6 @@ private:
|
|||
// mapping between names and records
|
||||
PLHashTable *mInterfaceTable;
|
||||
|
||||
// mapping between entries and typelibs (for nsXPTParamInfo::GetInterface)
|
||||
PLHashTable *mTypelibTable;
|
||||
|
||||
// mapping between iids and names
|
||||
// (record handling is looked up by name; iids are translated there)
|
||||
nsHashtable *mIIDTable;
|
||||
|
@ -74,19 +68,7 @@ private:
|
|||
nsIAllocator* mAllocator;
|
||||
};
|
||||
|
||||
// For references in the mInterfaceTable hashtable.
|
||||
class interface_record {
|
||||
public:
|
||||
XPTHeader *which_header;
|
||||
PRBool resolved;
|
||||
XPTInterfaceDirectoryEntry *entry;
|
||||
nsInterfaceInfo *info;
|
||||
#ifdef DEBUG
|
||||
// which (counting from 1) typelib was it loaded from?
|
||||
int which;
|
||||
#endif
|
||||
};
|
||||
|
||||
|
||||
|
||||
#endif /* nsInterfaceInfoManager_h___ */
|
||||
|
||||
|
||||
|
||||
|
|
|
@ -0,0 +1,43 @@
|
|||
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
|
||||
/*
|
||||
* The contents of this file are subject to the Netscape Public License
|
||||
* Version 1.0 (the "NPL"); you may not use this file except in
|
||||
* compliance with the NPL. You may obtain a copy of the NPL at
|
||||
* http://www.mozilla.org/NPL/
|
||||
*
|
||||
* Software distributed under the NPL is distributed on an "AS IS" basis,
|
||||
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
|
||||
* for the specific language governing rights and limitations under the
|
||||
* NPL.
|
||||
*
|
||||
* The Initial Developer of this code under the NPL is Netscape
|
||||
* Communications Corporation. Portions created by Netscape are
|
||||
* Copyright (C) 1999 Netscape Communications Corporation. All Rights
|
||||
* Reserved.
|
||||
*/
|
||||
|
||||
/* For keeping track of interface directory entries. */
|
||||
|
||||
#ifndef nsInterfaceRecord_h___
|
||||
#define nsInterfaceRecord_h___
|
||||
|
||||
#include "xpt_struct.h"
|
||||
#include "nsInterfaceInfo.h"
|
||||
|
||||
// resolve circular ref...
|
||||
class nsInterfaceInfo;
|
||||
|
||||
// For references in the mInterfaceTable hashtable.
|
||||
class nsInterfaceRecord {
|
||||
public:
|
||||
XPTHeader *which_header;
|
||||
PRBool resolved;
|
||||
XPTInterfaceDirectoryEntry *entry;
|
||||
nsInterfaceInfo *info;
|
||||
#ifdef DEBUG
|
||||
// which (counting from 1) typelib was it loaded from?
|
||||
int which;
|
||||
#endif
|
||||
};
|
||||
|
||||
#endif /* nsInterfaceRecord_h___ */
|
|
@ -38,24 +38,24 @@ nsXPTParamInfo::GetInterface(nsIInterfaceInfo *info) const
|
|||
NS_PRECONDITION(GetType().TagPart() == nsXPTType::T_INTERFACE,
|
||||
"not an interface");
|
||||
|
||||
XPTInterfaceDirectoryEntry *entry = ((nsInterfaceInfo *)info)->getIDE();
|
||||
nsInterfaceRecord *record =
|
||||
((nsInterfaceInfo *)info)->getInterfaceRecord();
|
||||
|
||||
|
||||
nsIInterfaceInfoManager* mgr;
|
||||
if(!(mgr = nsInterfaceInfoManager::GetInterfaceInfoManager()))
|
||||
return NULL;
|
||||
nsInterfaceInfoManager* mymgr = (nsInterfaceInfoManager *)mgr;
|
||||
|
||||
// what typelib did the entry come from?
|
||||
XPTHeader *which_header =
|
||||
(XPTHeader *)PL_HashTableLookup(mymgr->mTypelibTable, entry);
|
||||
NS_ASSERTION(which_header != NULL, "");
|
||||
XPTHeader *which_header = record->which_header;
|
||||
NS_ASSERTION(which_header != NULL, "missing header info assoc'd with II");
|
||||
|
||||
// can't use IID, because it could be null for this entry.
|
||||
char *interface_name;
|
||||
interface_name = which_header->interface_directory[type.type.interface].name;
|
||||
|
||||
nsIInterfaceInfo *ii;
|
||||
nsresult nsr = mymgr->GetInfoForName(interface_name, &ii);
|
||||
nsresult nsr = mgr->GetInfoForName(interface_name, &ii);
|
||||
if (NS_IS_ERROR(nsr)) {
|
||||
NS_RELEASE(mgr);
|
||||
return NULL;
|
||||
|
@ -69,25 +69,23 @@ nsXPTParamInfo::GetInterfaceIID(nsIInterfaceInfo *info) const
|
|||
NS_PRECONDITION(GetType().TagPart() == nsXPTType::T_INTERFACE,
|
||||
"not an interface");
|
||||
|
||||
XPTInterfaceDirectoryEntry *entry = ((nsInterfaceInfo *)info)->getIDE();
|
||||
nsInterfaceRecord *record =
|
||||
((nsInterfaceInfo *)info)->getInterfaceRecord();
|
||||
|
||||
nsIInterfaceInfoManager* mgr;
|
||||
if(!(mgr = nsInterfaceInfoManager::GetInterfaceInfoManager()))
|
||||
return NULL;
|
||||
nsInterfaceInfoManager* mymgr = (nsInterfaceInfoManager *)mgr;
|
||||
|
||||
// what typelib did the entry come from?
|
||||
XPTHeader *which_header =
|
||||
(XPTHeader *)PL_HashTableLookup(mymgr->mTypelibTable, entry);
|
||||
NS_ASSERTION(which_header != NULL, "");
|
||||
XPTHeader *which_header = record->which_header;
|
||||
NS_ASSERTION(which_header != NULL, "header missing?");
|
||||
|
||||
// can't use IID, because it could be null for this entry.
|
||||
char *interface_name;
|
||||
interface_name = which_header->interface_directory[type.type.interface].name;
|
||||
|
||||
nsIID* iid;
|
||||
|
||||
nsresult nsr = mymgr->GetIIDForName(interface_name, &iid);
|
||||
nsresult nsr = mgr->GetIIDForName(interface_name, &iid);
|
||||
if (NS_IS_ERROR(nsr)) {
|
||||
NS_RELEASE(mgr);
|
||||
return NULL;
|
||||
|
|
Загрузка…
Ссылка в новой задаче