зеркало из 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.
|
* Reserved.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
/* The InterfaceInfo support public stuff. */
|
/* C++ wrappers for xpt_struct.h structures. */
|
||||||
|
|
||||||
#ifndef xpt_cpp_h___
|
#ifndef xpt_cpp_h___
|
||||||
#define xpt_cpp_h___
|
#define xpt_cpp_h___
|
||||||
|
|
|
@ -16,6 +16,8 @@
|
||||||
* Reserved.
|
* Reserved.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
/* XPTI_PUBLIC_API and XPTI_GetInterfaceInfoManager declarations. */
|
||||||
|
|
||||||
#ifndef xptiinfo_h___
|
#ifndef xptiinfo_h___
|
||||||
#define xptiinfo_h___
|
#define xptiinfo_h___
|
||||||
|
|
||||||
|
|
|
@ -16,6 +16,8 @@
|
||||||
* Reserved.
|
* Reserved.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
/* Implementation of nsIInterfaceInfoManager. */
|
||||||
|
|
||||||
#include "nscore.h"
|
#include "nscore.h"
|
||||||
|
|
||||||
#include "nsISupports.h"
|
#include "nsISupports.h"
|
||||||
|
@ -30,9 +32,9 @@
|
||||||
static NS_DEFINE_IID(kIInterfaceInfoIID, NS_IINTERFACEINFO_IID);
|
static NS_DEFINE_IID(kIInterfaceInfoIID, NS_IINTERFACEINFO_IID);
|
||||||
NS_IMPL_ISUPPORTS(nsInterfaceInfo, kIInterfaceInfoIID);
|
NS_IMPL_ISUPPORTS(nsInterfaceInfo, kIInterfaceInfoIID);
|
||||||
|
|
||||||
nsInterfaceInfo::nsInterfaceInfo(XPTInterfaceDirectoryEntry* entry,
|
nsInterfaceInfo::nsInterfaceInfo(nsInterfaceRecord *record,
|
||||||
nsInterfaceInfo *parent)
|
nsInterfaceInfo *parent)
|
||||||
: mEntry(entry),
|
: mInterfaceRecord(record),
|
||||||
mParent(parent)
|
mParent(parent)
|
||||||
{
|
{
|
||||||
NS_INIT_REFCNT();
|
NS_INIT_REFCNT();
|
||||||
|
@ -48,14 +50,20 @@ nsInterfaceInfo::nsInterfaceInfo(XPTInterfaceDirectoryEntry* entry,
|
||||||
mMethodBaseIndex = mConstantBaseIndex = 0;
|
mMethodBaseIndex = mConstantBaseIndex = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
mMethodCount = mEntry->interface_descriptor->num_methods;
|
mMethodCount =
|
||||||
mConstantCount = mEntry->interface_descriptor->num_constants;
|
mInterfaceRecord->entry->interface_descriptor->num_methods;
|
||||||
|
mConstantCount =
|
||||||
|
mInterfaceRecord->entry->interface_descriptor->num_constants;
|
||||||
}
|
}
|
||||||
|
|
||||||
nsInterfaceInfo::~nsInterfaceInfo()
|
nsInterfaceInfo::~nsInterfaceInfo()
|
||||||
{
|
{
|
||||||
if(mParent != NULL)
|
if (this->mParent != NULL)
|
||||||
NS_RELEASE(mParent);
|
NS_RELEASE(mParent);
|
||||||
|
|
||||||
|
// remove interface record's notion of my existence
|
||||||
|
if (this->mInterfaceRecord != NULL)
|
||||||
|
this->mInterfaceRecord->info = NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
NS_IMETHODIMP
|
NS_IMETHODIMP
|
||||||
|
@ -65,11 +73,11 @@ nsInterfaceInfo::GetName(char** name)
|
||||||
|
|
||||||
nsIAllocator* allocator;
|
nsIAllocator* allocator;
|
||||||
if(NULL != (allocator = nsInterfaceInfoManager::GetAllocator())) {
|
if(NULL != (allocator = nsInterfaceInfoManager::GetAllocator())) {
|
||||||
int len = strlen(mEntry->name)+1;
|
int len = strlen(mInterfaceRecord->entry->name)+1;
|
||||||
char* p = (char*)allocator->Alloc(len);
|
char* p = (char*)allocator->Alloc(len);
|
||||||
NS_RELEASE(allocator);
|
NS_RELEASE(allocator);
|
||||||
if(p) {
|
if(p) {
|
||||||
memcpy(p, mEntry->name, len);
|
memcpy(p, mInterfaceRecord->entry->name, len);
|
||||||
*name = p;
|
*name = p;
|
||||||
return NS_OK;
|
return NS_OK;
|
||||||
}
|
}
|
||||||
|
@ -89,7 +97,7 @@ nsInterfaceInfo::GetIID(nsIID** iid)
|
||||||
nsIID* p = (nsIID*)allocator->Alloc(sizeof(nsIID));
|
nsIID* p = (nsIID*)allocator->Alloc(sizeof(nsIID));
|
||||||
NS_RELEASE(allocator);
|
NS_RELEASE(allocator);
|
||||||
if(p) {
|
if(p) {
|
||||||
memcpy(p, &mEntry->iid, sizeof(nsIID));
|
memcpy(p, &(mInterfaceRecord->entry->iid), sizeof(nsIID));
|
||||||
*iid = p;
|
*iid = p;
|
||||||
return NS_OK;
|
return NS_OK;
|
||||||
}
|
}
|
||||||
|
@ -144,7 +152,7 @@ nsInterfaceInfo::GetMethodInfo(uint16 index, const nsXPTMethodInfo** info)
|
||||||
|
|
||||||
// else...
|
// else...
|
||||||
*info = NS_REINTERPRET_CAST(nsXPTMethodInfo*,
|
*info = NS_REINTERPRET_CAST(nsXPTMethodInfo*,
|
||||||
&mEntry->interface_descriptor->
|
&mInterfaceRecord->entry->interface_descriptor->
|
||||||
method_descriptors[index - mMethodBaseIndex]);
|
method_descriptors[index - mMethodBaseIndex]);
|
||||||
return NS_OK;
|
return NS_OK;
|
||||||
}
|
}
|
||||||
|
@ -163,9 +171,10 @@ nsInterfaceInfo::GetConstant(uint16 index, const nsXPTConstant** constant)
|
||||||
}
|
}
|
||||||
|
|
||||||
// else...
|
// else...
|
||||||
*constant = NS_REINTERPRET_CAST(nsXPTConstant*,
|
*constant =
|
||||||
&mEntry->interface_descriptor->
|
NS_REINTERPRET_CAST(nsXPTConstant*,
|
||||||
const_descriptors[index-mConstantBaseIndex]);
|
&mInterfaceRecord->entry->interface_descriptor->
|
||||||
|
const_descriptors[index-mConstantBaseIndex]);
|
||||||
return NS_OK;
|
return NS_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -175,12 +184,12 @@ void
|
||||||
nsInterfaceInfo::print(FILE *fd)
|
nsInterfaceInfo::print(FILE *fd)
|
||||||
{
|
{
|
||||||
fprintf(fd, "iid: %s name: %s name_space: %s\n",
|
fprintf(fd, "iid: %s name: %s name_space: %s\n",
|
||||||
mEntry->iid.ToString(),
|
this->mInterfaceRecord->entry->iid.ToString(),
|
||||||
mEntry->name,
|
this->mInterfaceRecord->entry->name,
|
||||||
mEntry->name_space);
|
this->mInterfaceRecord->entry->name_space);
|
||||||
if (mParent != NULL) {
|
if (mParent != NULL) {
|
||||||
fprintf(fd, "parent:\n\t");
|
fprintf(fd, "parent:\n\t");
|
||||||
mParent->print(fd);
|
this->mParent->print(fd);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -16,6 +16,8 @@
|
||||||
* Reserved.
|
* Reserved.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
/* Library-private header for nsInterfaceInfo implementation. */
|
||||||
|
|
||||||
#ifndef nsInterfaceInfo_h___
|
#ifndef nsInterfaceInfo_h___
|
||||||
#define nsInterfaceInfo_h___
|
#define nsInterfaceInfo_h___
|
||||||
|
|
||||||
|
@ -23,6 +25,8 @@
|
||||||
#include "xpt_struct.h"
|
#include "xpt_struct.h"
|
||||||
#include "xpt_cpp.h"
|
#include "xpt_cpp.h"
|
||||||
|
|
||||||
|
#include "nsInterfaceRecord.h"
|
||||||
|
|
||||||
#ifdef DEBUG
|
#ifdef DEBUG
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#endif
|
#endif
|
||||||
|
@ -47,8 +51,8 @@ class nsInterfaceInfo : public nsIInterfaceInfo
|
||||||
NS_IMETHOD GetConstant(uint16 index, const nsXPTConstant** constant);
|
NS_IMETHOD GetConstant(uint16 index, const nsXPTConstant** constant);
|
||||||
|
|
||||||
// why constructor public?
|
// why constructor public?
|
||||||
nsInterfaceInfo(XPTInterfaceDirectoryEntry* entry,
|
nsInterfaceInfo(nsInterfaceRecord *record,
|
||||||
nsInterfaceInfo *parent);
|
nsInterfaceInfo *parent);
|
||||||
public:
|
public:
|
||||||
virtual ~nsInterfaceInfo();
|
virtual ~nsInterfaceInfo();
|
||||||
|
|
||||||
|
@ -62,9 +66,9 @@ private:
|
||||||
friend const nsIID*
|
friend const nsIID*
|
||||||
nsXPTParamInfo::GetInterfaceIID(nsIInterfaceInfo *info) const;
|
nsXPTParamInfo::GetInterfaceIID(nsIInterfaceInfo *info) const;
|
||||||
|
|
||||||
XPTInterfaceDirectoryEntry *getIDE() { return mEntry; };
|
nsInterfaceRecord *getInterfaceRecord() { return mInterfaceRecord; };
|
||||||
|
nsInterfaceRecord *mInterfaceRecord;
|
||||||
XPTInterfaceDirectoryEntry* mEntry;
|
|
||||||
nsInterfaceInfo* mParent;
|
nsInterfaceInfo* mParent;
|
||||||
|
|
||||||
uint16 mMethodBaseIndex;
|
uint16 mMethodBaseIndex;
|
||||||
|
|
|
@ -16,6 +16,8 @@
|
||||||
* Reserved.
|
* Reserved.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
/* Implementation of nsIInterfaceInfo. */
|
||||||
|
|
||||||
#include <sys/stat.h>
|
#include <sys/stat.h>
|
||||||
#include "nscore.h"
|
#include "nscore.h"
|
||||||
|
|
||||||
|
@ -155,7 +157,6 @@ XPTHeader *getHeader(const char *filename) {
|
||||||
static void
|
static void
|
||||||
indexify_file(const char *filename,
|
indexify_file(const char *filename,
|
||||||
PLHashTable *interfaceTable,
|
PLHashTable *interfaceTable,
|
||||||
PLHashTable *typelibTable,
|
|
||||||
nsHashtable *IIDTable,
|
nsHashtable *IIDTable,
|
||||||
nsIAllocator *al)
|
nsIAllocator *al)
|
||||||
{
|
{
|
||||||
|
@ -163,26 +164,24 @@ indexify_file(const char *filename,
|
||||||
|
|
||||||
int limit = header->num_interfaces;
|
int limit = header->num_interfaces;
|
||||||
|
|
||||||
interface_record *value;
|
nsInterfaceRecord *value;
|
||||||
#ifdef DEBUG_mccabe
|
#ifdef DEBUG_mccabe
|
||||||
static int which = 0;
|
static int which = 0;
|
||||||
which++;
|
which++;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
for (int i = 0; i < limit; i++) {
|
for (int i = 0; i < limit; i++) {
|
||||||
XPTInterfaceDirectoryEntry *current = header->interface_directory + 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
|
#ifdef DEBUG_mccabe
|
||||||
fprintf(stderr, "%s", current->name);
|
fprintf(stderr, "%s", current->name);
|
||||||
#endif
|
#endif
|
||||||
// first try to look it up...
|
// first try to look it up...
|
||||||
value = (interface_record *)PL_HashTableLookup(interfaceTable,
|
value = (nsInterfaceRecord *)PL_HashTableLookup(interfaceTable,
|
||||||
current->name);
|
current->name);
|
||||||
// if none found, make a dummy record.
|
// if none found, make a dummy record.
|
||||||
if (value == NULL) {
|
if (value == NULL) {
|
||||||
value = new interface_record();
|
value = new nsInterfaceRecord();
|
||||||
value->which_header = NULL;
|
value->which_header = NULL;
|
||||||
value->resolved = PR_FALSE;
|
value->resolved = PR_FALSE;
|
||||||
value->which = -1;
|
value->which = -1;
|
||||||
|
@ -237,11 +236,6 @@ static PRIntn
|
||||||
check_enumerator(PLHashEntry *he, PRIntn index, void *arg);
|
check_enumerator(PLHashEntry *he, PRIntn index, void *arg);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
static PLHashNumber
|
|
||||||
hash_by_value(const void *key) {
|
|
||||||
return (uint32)key;
|
|
||||||
}
|
|
||||||
|
|
||||||
void nsInterfaceInfoManager::initInterfaceTables()
|
void nsInterfaceInfoManager::initInterfaceTables()
|
||||||
{
|
{
|
||||||
// make a hashtable to associate names with arbitrary info
|
// make a hashtable to associate names with arbitrary info
|
||||||
|
@ -250,14 +244,6 @@ void nsInterfaceInfoManager::initInterfaceTables()
|
||||||
PL_CompareStrings, // compare keys
|
PL_CompareStrings, // compare keys
|
||||||
PL_CompareValues, // comp values
|
PL_CompareValues, // comp values
|
||||||
NULL, NULL);
|
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
|
// make a hashtable to map iids to names
|
||||||
this->mIIDTable = new nsHashtable(XPT_HASHSIZE);
|
this->mIIDTable = new nsHashtable(XPT_HASHSIZE);
|
||||||
|
@ -313,7 +299,6 @@ void nsInterfaceInfoManager::initInterfaceTables()
|
||||||
#endif
|
#endif
|
||||||
indexify_file(fullname,
|
indexify_file(fullname,
|
||||||
this->mInterfaceTable,
|
this->mInterfaceTable,
|
||||||
this->mTypelibTable,
|
|
||||||
this->mIIDTable,
|
this->mIIDTable,
|
||||||
this->mAllocator);
|
this->mAllocator);
|
||||||
} else {
|
} else {
|
||||||
|
@ -333,7 +318,7 @@ void nsInterfaceInfoManager::initInterfaceTables()
|
||||||
#ifdef DEBUG
|
#ifdef DEBUG
|
||||||
PRIntn check_enumerator(PLHashEntry *he, PRIntn index, void *arg) {
|
PRIntn check_enumerator(PLHashEntry *he, PRIntn index, void *arg) {
|
||||||
char *key = (char *)he->key;
|
char *key = (char *)he->key;
|
||||||
interface_record *value = (interface_record *)he->value;
|
nsInterfaceRecord *value = (nsInterfaceRecord *)he->value;
|
||||||
nsHashtable *iidtable = (nsHashtable *)arg;
|
nsHashtable *iidtable = (nsHashtable *)arg;
|
||||||
|
|
||||||
|
|
||||||
|
@ -374,15 +359,15 @@ NS_IMETHODIMP
|
||||||
nsInterfaceInfoManager::GetInfoForName(const char* name,
|
nsInterfaceInfoManager::GetInfoForName(const char* name,
|
||||||
nsIInterfaceInfo** info)
|
nsIInterfaceInfo** info)
|
||||||
{
|
{
|
||||||
interface_record *record =
|
nsInterfaceRecord *record =
|
||||||
(interface_record *)PL_HashTableLookup(this->mInterfaceTable, name);
|
(nsInterfaceRecord *)PL_HashTableLookup(this->mInterfaceTable, name);
|
||||||
if (record == NULL || record->resolved == PR_FALSE) {
|
if (record == NULL || record->resolved == PR_FALSE) {
|
||||||
*info = NULL;
|
*info = NULL;
|
||||||
return NS_ERROR_FAILURE;
|
return NS_ERROR_FAILURE;
|
||||||
}
|
}
|
||||||
PR_ASSERT(record->entry != NULL);
|
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) {
|
if (record->info != NULL) {
|
||||||
// yay!
|
// yay!
|
||||||
*info = record->info;
|
*info = record->info;
|
||||||
|
@ -392,8 +377,7 @@ nsInterfaceInfoManager::GetInfoForName(const char* name,
|
||||||
|
|
||||||
// nope, better make one. first, find a parent for it.
|
// nope, better make one. first, find a parent for it.
|
||||||
nsIInterfaceInfo *parent;
|
nsIInterfaceInfo *parent;
|
||||||
XPTInterfaceDirectoryEntry *entry = record->entry;
|
uint16 parent_index = record->entry->interface_descriptor->parent_interface;
|
||||||
uint16 parent_index = entry->interface_descriptor->parent_interface;
|
|
||||||
// Does it _get_ a parent? (is it nsISupports?)
|
// Does it _get_ a parent? (is it nsISupports?)
|
||||||
if (parent_index == 0) {
|
if (parent_index == 0) {
|
||||||
// presumably this is only the case for nsISupports.
|
// 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
|
// got a parent for it, now build the object itself
|
||||||
nsInterfaceInfo *result =
|
nsInterfaceInfo *result =
|
||||||
new nsInterfaceInfo(entry, (nsInterfaceInfo *)parent);
|
new nsInterfaceInfo(record, (nsInterfaceInfo *)parent);
|
||||||
*info = result;
|
*info = result;
|
||||||
NS_ADDREF(*info);
|
NS_ADDREF(*info);
|
||||||
return NS_OK;
|
return NS_OK;
|
||||||
|
@ -424,8 +408,8 @@ nsInterfaceInfoManager::GetInfoForName(const char* name,
|
||||||
NS_IMETHODIMP
|
NS_IMETHODIMP
|
||||||
nsInterfaceInfoManager::GetIIDForName(const char* name, nsIID** iid)
|
nsInterfaceInfoManager::GetIIDForName(const char* name, nsIID** iid)
|
||||||
{
|
{
|
||||||
interface_record *record =
|
nsInterfaceRecord *record =
|
||||||
(interface_record *)PL_HashTableLookup(this->mInterfaceTable, name);
|
(nsInterfaceRecord *)PL_HashTableLookup(this->mInterfaceTable, name);
|
||||||
if (record == NULL || record->resolved == PR_FALSE) {
|
if (record == NULL || record->resolved == PR_FALSE) {
|
||||||
*iid = NULL;
|
*iid = NULL;
|
||||||
return NS_ERROR_FAILURE;
|
return NS_ERROR_FAILURE;
|
||||||
|
@ -472,43 +456,8 @@ nsInterfaceInfoManager::GetNameForIID(const nsIID* iid, char** name)
|
||||||
return NS_OK;
|
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_PUBLIC_API(nsIInterfaceInfoManager*)
|
||||||
XPTI_GetInterfaceInfoManager()
|
XPTI_GetInterfaceInfoManager()
|
||||||
{
|
{
|
||||||
return nsInterfaceInfoManager::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.
|
* Reserved.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
/* Library-private header for nsInterfaceInfoManager implementation. */
|
||||||
|
|
||||||
#ifndef nsInterfaceInfoManager_h___
|
#ifndef nsInterfaceInfoManager_h___
|
||||||
#define nsInterfaceInfoManager_h___
|
#define nsInterfaceInfoManager_h___
|
||||||
|
|
||||||
|
#include "plhash.h"
|
||||||
#include "nsIAllocator.h"
|
#include "nsIAllocator.h"
|
||||||
|
|
||||||
#include "xpt_struct.h"
|
|
||||||
|
|
||||||
#include "nsIInterfaceInfo.h"
|
#include "nsIInterfaceInfo.h"
|
||||||
#include "nsIInterfaceInfoManager.h"
|
#include "nsIInterfaceInfoManager.h"
|
||||||
|
|
||||||
#include "nsInterfaceInfo.h"
|
|
||||||
|
|
||||||
#include "nsHashtable.h"
|
#include "nsHashtable.h"
|
||||||
|
|
||||||
#include "plhash.h"
|
#include "xpt_struct.h"
|
||||||
|
#include "nsInterfaceInfo.h"
|
||||||
class hash_record;
|
#include "nsInterfaceRecord.h"
|
||||||
|
|
||||||
class nsInterfaceInfoManager : public nsIInterfaceInfoManager
|
class nsInterfaceInfoManager : public nsIInterfaceInfoManager
|
||||||
{
|
{
|
||||||
|
@ -64,9 +61,6 @@ private:
|
||||||
// mapping between names and records
|
// mapping between names and records
|
||||||
PLHashTable *mInterfaceTable;
|
PLHashTable *mInterfaceTable;
|
||||||
|
|
||||||
// mapping between entries and typelibs (for nsXPTParamInfo::GetInterface)
|
|
||||||
PLHashTable *mTypelibTable;
|
|
||||||
|
|
||||||
// mapping between iids and names
|
// mapping between iids and names
|
||||||
// (record handling is looked up by name; iids are translated there)
|
// (record handling is looked up by name; iids are translated there)
|
||||||
nsHashtable *mIIDTable;
|
nsHashtable *mIIDTable;
|
||||||
|
@ -74,19 +68,7 @@ private:
|
||||||
nsIAllocator* mAllocator;
|
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___ */
|
#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,
|
NS_PRECONDITION(GetType().TagPart() == nsXPTType::T_INTERFACE,
|
||||||
"not an interface");
|
"not an interface");
|
||||||
|
|
||||||
XPTInterfaceDirectoryEntry *entry = ((nsInterfaceInfo *)info)->getIDE();
|
nsInterfaceRecord *record =
|
||||||
|
((nsInterfaceInfo *)info)->getInterfaceRecord();
|
||||||
|
|
||||||
|
|
||||||
nsIInterfaceInfoManager* mgr;
|
nsIInterfaceInfoManager* mgr;
|
||||||
if(!(mgr = nsInterfaceInfoManager::GetInterfaceInfoManager()))
|
if(!(mgr = nsInterfaceInfoManager::GetInterfaceInfoManager()))
|
||||||
return NULL;
|
return NULL;
|
||||||
nsInterfaceInfoManager* mymgr = (nsInterfaceInfoManager *)mgr;
|
|
||||||
|
|
||||||
// what typelib did the entry come from?
|
// what typelib did the entry come from?
|
||||||
XPTHeader *which_header =
|
XPTHeader *which_header = record->which_header;
|
||||||
(XPTHeader *)PL_HashTableLookup(mymgr->mTypelibTable, entry);
|
NS_ASSERTION(which_header != NULL, "missing header info assoc'd with II");
|
||||||
NS_ASSERTION(which_header != NULL, "");
|
|
||||||
|
|
||||||
// can't use IID, because it could be null for this entry.
|
// can't use IID, because it could be null for this entry.
|
||||||
char *interface_name;
|
char *interface_name;
|
||||||
interface_name = which_header->interface_directory[type.type.interface].name;
|
interface_name = which_header->interface_directory[type.type.interface].name;
|
||||||
|
|
||||||
nsIInterfaceInfo *ii;
|
nsIInterfaceInfo *ii;
|
||||||
nsresult nsr = mymgr->GetInfoForName(interface_name, &ii);
|
nsresult nsr = mgr->GetInfoForName(interface_name, &ii);
|
||||||
if (NS_IS_ERROR(nsr)) {
|
if (NS_IS_ERROR(nsr)) {
|
||||||
NS_RELEASE(mgr);
|
NS_RELEASE(mgr);
|
||||||
return NULL;
|
return NULL;
|
||||||
|
@ -69,25 +69,23 @@ nsXPTParamInfo::GetInterfaceIID(nsIInterfaceInfo *info) const
|
||||||
NS_PRECONDITION(GetType().TagPart() == nsXPTType::T_INTERFACE,
|
NS_PRECONDITION(GetType().TagPart() == nsXPTType::T_INTERFACE,
|
||||||
"not an interface");
|
"not an interface");
|
||||||
|
|
||||||
XPTInterfaceDirectoryEntry *entry = ((nsInterfaceInfo *)info)->getIDE();
|
nsInterfaceRecord *record =
|
||||||
|
((nsInterfaceInfo *)info)->getInterfaceRecord();
|
||||||
|
|
||||||
nsIInterfaceInfoManager* mgr;
|
nsIInterfaceInfoManager* mgr;
|
||||||
if(!(mgr = nsInterfaceInfoManager::GetInterfaceInfoManager()))
|
if(!(mgr = nsInterfaceInfoManager::GetInterfaceInfoManager()))
|
||||||
return NULL;
|
return NULL;
|
||||||
nsInterfaceInfoManager* mymgr = (nsInterfaceInfoManager *)mgr;
|
|
||||||
|
|
||||||
// what typelib did the entry come from?
|
// what typelib did the entry come from?
|
||||||
XPTHeader *which_header =
|
XPTHeader *which_header = record->which_header;
|
||||||
(XPTHeader *)PL_HashTableLookup(mymgr->mTypelibTable, entry);
|
NS_ASSERTION(which_header != NULL, "header missing?");
|
||||||
NS_ASSERTION(which_header != NULL, "");
|
|
||||||
|
|
||||||
// can't use IID, because it could be null for this entry.
|
// can't use IID, because it could be null for this entry.
|
||||||
char *interface_name;
|
char *interface_name;
|
||||||
interface_name = which_header->interface_directory[type.type.interface].name;
|
interface_name = which_header->interface_directory[type.type.interface].name;
|
||||||
|
|
||||||
nsIID* iid;
|
nsIID* iid;
|
||||||
|
nsresult nsr = mgr->GetIIDForName(interface_name, &iid);
|
||||||
nsresult nsr = mymgr->GetIIDForName(interface_name, &iid);
|
|
||||||
if (NS_IS_ERROR(nsr)) {
|
if (NS_IS_ERROR(nsr)) {
|
||||||
NS_RELEASE(mgr);
|
NS_RELEASE(mgr);
|
||||||
return NULL;
|
return NULL;
|
||||||
|
|
|
@ -16,7 +16,7 @@
|
||||||
* Reserved.
|
* Reserved.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
/* The InterfaceInfo support public stuff. */
|
/* C++ wrappers for xpt_struct.h structures. */
|
||||||
|
|
||||||
#ifndef xpt_cpp_h___
|
#ifndef xpt_cpp_h___
|
||||||
#define xpt_cpp_h___
|
#define xpt_cpp_h___
|
||||||
|
|
|
@ -16,6 +16,8 @@
|
||||||
* Reserved.
|
* Reserved.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
/* XPTI_PUBLIC_API and XPTI_GetInterfaceInfoManager declarations. */
|
||||||
|
|
||||||
#ifndef xptiinfo_h___
|
#ifndef xptiinfo_h___
|
||||||
#define xptiinfo_h___
|
#define xptiinfo_h___
|
||||||
|
|
||||||
|
|
|
@ -16,6 +16,8 @@
|
||||||
* Reserved.
|
* Reserved.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
/* Implementation of nsIInterfaceInfoManager. */
|
||||||
|
|
||||||
#include "nscore.h"
|
#include "nscore.h"
|
||||||
|
|
||||||
#include "nsISupports.h"
|
#include "nsISupports.h"
|
||||||
|
@ -30,9 +32,9 @@
|
||||||
static NS_DEFINE_IID(kIInterfaceInfoIID, NS_IINTERFACEINFO_IID);
|
static NS_DEFINE_IID(kIInterfaceInfoIID, NS_IINTERFACEINFO_IID);
|
||||||
NS_IMPL_ISUPPORTS(nsInterfaceInfo, kIInterfaceInfoIID);
|
NS_IMPL_ISUPPORTS(nsInterfaceInfo, kIInterfaceInfoIID);
|
||||||
|
|
||||||
nsInterfaceInfo::nsInterfaceInfo(XPTInterfaceDirectoryEntry* entry,
|
nsInterfaceInfo::nsInterfaceInfo(nsInterfaceRecord *record,
|
||||||
nsInterfaceInfo *parent)
|
nsInterfaceInfo *parent)
|
||||||
: mEntry(entry),
|
: mInterfaceRecord(record),
|
||||||
mParent(parent)
|
mParent(parent)
|
||||||
{
|
{
|
||||||
NS_INIT_REFCNT();
|
NS_INIT_REFCNT();
|
||||||
|
@ -48,14 +50,20 @@ nsInterfaceInfo::nsInterfaceInfo(XPTInterfaceDirectoryEntry* entry,
|
||||||
mMethodBaseIndex = mConstantBaseIndex = 0;
|
mMethodBaseIndex = mConstantBaseIndex = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
mMethodCount = mEntry->interface_descriptor->num_methods;
|
mMethodCount =
|
||||||
mConstantCount = mEntry->interface_descriptor->num_constants;
|
mInterfaceRecord->entry->interface_descriptor->num_methods;
|
||||||
|
mConstantCount =
|
||||||
|
mInterfaceRecord->entry->interface_descriptor->num_constants;
|
||||||
}
|
}
|
||||||
|
|
||||||
nsInterfaceInfo::~nsInterfaceInfo()
|
nsInterfaceInfo::~nsInterfaceInfo()
|
||||||
{
|
{
|
||||||
if(mParent != NULL)
|
if (this->mParent != NULL)
|
||||||
NS_RELEASE(mParent);
|
NS_RELEASE(mParent);
|
||||||
|
|
||||||
|
// remove interface record's notion of my existence
|
||||||
|
if (this->mInterfaceRecord != NULL)
|
||||||
|
this->mInterfaceRecord->info = NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
NS_IMETHODIMP
|
NS_IMETHODIMP
|
||||||
|
@ -65,11 +73,11 @@ nsInterfaceInfo::GetName(char** name)
|
||||||
|
|
||||||
nsIAllocator* allocator;
|
nsIAllocator* allocator;
|
||||||
if(NULL != (allocator = nsInterfaceInfoManager::GetAllocator())) {
|
if(NULL != (allocator = nsInterfaceInfoManager::GetAllocator())) {
|
||||||
int len = strlen(mEntry->name)+1;
|
int len = strlen(mInterfaceRecord->entry->name)+1;
|
||||||
char* p = (char*)allocator->Alloc(len);
|
char* p = (char*)allocator->Alloc(len);
|
||||||
NS_RELEASE(allocator);
|
NS_RELEASE(allocator);
|
||||||
if(p) {
|
if(p) {
|
||||||
memcpy(p, mEntry->name, len);
|
memcpy(p, mInterfaceRecord->entry->name, len);
|
||||||
*name = p;
|
*name = p;
|
||||||
return NS_OK;
|
return NS_OK;
|
||||||
}
|
}
|
||||||
|
@ -89,7 +97,7 @@ nsInterfaceInfo::GetIID(nsIID** iid)
|
||||||
nsIID* p = (nsIID*)allocator->Alloc(sizeof(nsIID));
|
nsIID* p = (nsIID*)allocator->Alloc(sizeof(nsIID));
|
||||||
NS_RELEASE(allocator);
|
NS_RELEASE(allocator);
|
||||||
if(p) {
|
if(p) {
|
||||||
memcpy(p, &mEntry->iid, sizeof(nsIID));
|
memcpy(p, &(mInterfaceRecord->entry->iid), sizeof(nsIID));
|
||||||
*iid = p;
|
*iid = p;
|
||||||
return NS_OK;
|
return NS_OK;
|
||||||
}
|
}
|
||||||
|
@ -144,7 +152,7 @@ nsInterfaceInfo::GetMethodInfo(uint16 index, const nsXPTMethodInfo** info)
|
||||||
|
|
||||||
// else...
|
// else...
|
||||||
*info = NS_REINTERPRET_CAST(nsXPTMethodInfo*,
|
*info = NS_REINTERPRET_CAST(nsXPTMethodInfo*,
|
||||||
&mEntry->interface_descriptor->
|
&mInterfaceRecord->entry->interface_descriptor->
|
||||||
method_descriptors[index - mMethodBaseIndex]);
|
method_descriptors[index - mMethodBaseIndex]);
|
||||||
return NS_OK;
|
return NS_OK;
|
||||||
}
|
}
|
||||||
|
@ -163,9 +171,10 @@ nsInterfaceInfo::GetConstant(uint16 index, const nsXPTConstant** constant)
|
||||||
}
|
}
|
||||||
|
|
||||||
// else...
|
// else...
|
||||||
*constant = NS_REINTERPRET_CAST(nsXPTConstant*,
|
*constant =
|
||||||
&mEntry->interface_descriptor->
|
NS_REINTERPRET_CAST(nsXPTConstant*,
|
||||||
const_descriptors[index-mConstantBaseIndex]);
|
&mInterfaceRecord->entry->interface_descriptor->
|
||||||
|
const_descriptors[index-mConstantBaseIndex]);
|
||||||
return NS_OK;
|
return NS_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -175,12 +184,12 @@ void
|
||||||
nsInterfaceInfo::print(FILE *fd)
|
nsInterfaceInfo::print(FILE *fd)
|
||||||
{
|
{
|
||||||
fprintf(fd, "iid: %s name: %s name_space: %s\n",
|
fprintf(fd, "iid: %s name: %s name_space: %s\n",
|
||||||
mEntry->iid.ToString(),
|
this->mInterfaceRecord->entry->iid.ToString(),
|
||||||
mEntry->name,
|
this->mInterfaceRecord->entry->name,
|
||||||
mEntry->name_space);
|
this->mInterfaceRecord->entry->name_space);
|
||||||
if (mParent != NULL) {
|
if (mParent != NULL) {
|
||||||
fprintf(fd, "parent:\n\t");
|
fprintf(fd, "parent:\n\t");
|
||||||
mParent->print(fd);
|
this->mParent->print(fd);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -16,6 +16,8 @@
|
||||||
* Reserved.
|
* Reserved.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
/* Library-private header for nsInterfaceInfo implementation. */
|
||||||
|
|
||||||
#ifndef nsInterfaceInfo_h___
|
#ifndef nsInterfaceInfo_h___
|
||||||
#define nsInterfaceInfo_h___
|
#define nsInterfaceInfo_h___
|
||||||
|
|
||||||
|
@ -23,6 +25,8 @@
|
||||||
#include "xpt_struct.h"
|
#include "xpt_struct.h"
|
||||||
#include "xpt_cpp.h"
|
#include "xpt_cpp.h"
|
||||||
|
|
||||||
|
#include "nsInterfaceRecord.h"
|
||||||
|
|
||||||
#ifdef DEBUG
|
#ifdef DEBUG
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#endif
|
#endif
|
||||||
|
@ -47,8 +51,8 @@ class nsInterfaceInfo : public nsIInterfaceInfo
|
||||||
NS_IMETHOD GetConstant(uint16 index, const nsXPTConstant** constant);
|
NS_IMETHOD GetConstant(uint16 index, const nsXPTConstant** constant);
|
||||||
|
|
||||||
// why constructor public?
|
// why constructor public?
|
||||||
nsInterfaceInfo(XPTInterfaceDirectoryEntry* entry,
|
nsInterfaceInfo(nsInterfaceRecord *record,
|
||||||
nsInterfaceInfo *parent);
|
nsInterfaceInfo *parent);
|
||||||
public:
|
public:
|
||||||
virtual ~nsInterfaceInfo();
|
virtual ~nsInterfaceInfo();
|
||||||
|
|
||||||
|
@ -62,9 +66,9 @@ private:
|
||||||
friend const nsIID*
|
friend const nsIID*
|
||||||
nsXPTParamInfo::GetInterfaceIID(nsIInterfaceInfo *info) const;
|
nsXPTParamInfo::GetInterfaceIID(nsIInterfaceInfo *info) const;
|
||||||
|
|
||||||
XPTInterfaceDirectoryEntry *getIDE() { return mEntry; };
|
nsInterfaceRecord *getInterfaceRecord() { return mInterfaceRecord; };
|
||||||
|
nsInterfaceRecord *mInterfaceRecord;
|
||||||
XPTInterfaceDirectoryEntry* mEntry;
|
|
||||||
nsInterfaceInfo* mParent;
|
nsInterfaceInfo* mParent;
|
||||||
|
|
||||||
uint16 mMethodBaseIndex;
|
uint16 mMethodBaseIndex;
|
||||||
|
|
|
@ -16,6 +16,8 @@
|
||||||
* Reserved.
|
* Reserved.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
/* Implementation of nsIInterfaceInfo. */
|
||||||
|
|
||||||
#include <sys/stat.h>
|
#include <sys/stat.h>
|
||||||
#include "nscore.h"
|
#include "nscore.h"
|
||||||
|
|
||||||
|
@ -155,7 +157,6 @@ XPTHeader *getHeader(const char *filename) {
|
||||||
static void
|
static void
|
||||||
indexify_file(const char *filename,
|
indexify_file(const char *filename,
|
||||||
PLHashTable *interfaceTable,
|
PLHashTable *interfaceTable,
|
||||||
PLHashTable *typelibTable,
|
|
||||||
nsHashtable *IIDTable,
|
nsHashtable *IIDTable,
|
||||||
nsIAllocator *al)
|
nsIAllocator *al)
|
||||||
{
|
{
|
||||||
|
@ -163,26 +164,24 @@ indexify_file(const char *filename,
|
||||||
|
|
||||||
int limit = header->num_interfaces;
|
int limit = header->num_interfaces;
|
||||||
|
|
||||||
interface_record *value;
|
nsInterfaceRecord *value;
|
||||||
#ifdef DEBUG_mccabe
|
#ifdef DEBUG_mccabe
|
||||||
static int which = 0;
|
static int which = 0;
|
||||||
which++;
|
which++;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
for (int i = 0; i < limit; i++) {
|
for (int i = 0; i < limit; i++) {
|
||||||
XPTInterfaceDirectoryEntry *current = header->interface_directory + 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
|
#ifdef DEBUG_mccabe
|
||||||
fprintf(stderr, "%s", current->name);
|
fprintf(stderr, "%s", current->name);
|
||||||
#endif
|
#endif
|
||||||
// first try to look it up...
|
// first try to look it up...
|
||||||
value = (interface_record *)PL_HashTableLookup(interfaceTable,
|
value = (nsInterfaceRecord *)PL_HashTableLookup(interfaceTable,
|
||||||
current->name);
|
current->name);
|
||||||
// if none found, make a dummy record.
|
// if none found, make a dummy record.
|
||||||
if (value == NULL) {
|
if (value == NULL) {
|
||||||
value = new interface_record();
|
value = new nsInterfaceRecord();
|
||||||
value->which_header = NULL;
|
value->which_header = NULL;
|
||||||
value->resolved = PR_FALSE;
|
value->resolved = PR_FALSE;
|
||||||
value->which = -1;
|
value->which = -1;
|
||||||
|
@ -237,11 +236,6 @@ static PRIntn
|
||||||
check_enumerator(PLHashEntry *he, PRIntn index, void *arg);
|
check_enumerator(PLHashEntry *he, PRIntn index, void *arg);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
static PLHashNumber
|
|
||||||
hash_by_value(const void *key) {
|
|
||||||
return (uint32)key;
|
|
||||||
}
|
|
||||||
|
|
||||||
void nsInterfaceInfoManager::initInterfaceTables()
|
void nsInterfaceInfoManager::initInterfaceTables()
|
||||||
{
|
{
|
||||||
// make a hashtable to associate names with arbitrary info
|
// make a hashtable to associate names with arbitrary info
|
||||||
|
@ -250,14 +244,6 @@ void nsInterfaceInfoManager::initInterfaceTables()
|
||||||
PL_CompareStrings, // compare keys
|
PL_CompareStrings, // compare keys
|
||||||
PL_CompareValues, // comp values
|
PL_CompareValues, // comp values
|
||||||
NULL, NULL);
|
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
|
// make a hashtable to map iids to names
|
||||||
this->mIIDTable = new nsHashtable(XPT_HASHSIZE);
|
this->mIIDTable = new nsHashtable(XPT_HASHSIZE);
|
||||||
|
@ -313,7 +299,6 @@ void nsInterfaceInfoManager::initInterfaceTables()
|
||||||
#endif
|
#endif
|
||||||
indexify_file(fullname,
|
indexify_file(fullname,
|
||||||
this->mInterfaceTable,
|
this->mInterfaceTable,
|
||||||
this->mTypelibTable,
|
|
||||||
this->mIIDTable,
|
this->mIIDTable,
|
||||||
this->mAllocator);
|
this->mAllocator);
|
||||||
} else {
|
} else {
|
||||||
|
@ -333,7 +318,7 @@ void nsInterfaceInfoManager::initInterfaceTables()
|
||||||
#ifdef DEBUG
|
#ifdef DEBUG
|
||||||
PRIntn check_enumerator(PLHashEntry *he, PRIntn index, void *arg) {
|
PRIntn check_enumerator(PLHashEntry *he, PRIntn index, void *arg) {
|
||||||
char *key = (char *)he->key;
|
char *key = (char *)he->key;
|
||||||
interface_record *value = (interface_record *)he->value;
|
nsInterfaceRecord *value = (nsInterfaceRecord *)he->value;
|
||||||
nsHashtable *iidtable = (nsHashtable *)arg;
|
nsHashtable *iidtable = (nsHashtable *)arg;
|
||||||
|
|
||||||
|
|
||||||
|
@ -374,15 +359,15 @@ NS_IMETHODIMP
|
||||||
nsInterfaceInfoManager::GetInfoForName(const char* name,
|
nsInterfaceInfoManager::GetInfoForName(const char* name,
|
||||||
nsIInterfaceInfo** info)
|
nsIInterfaceInfo** info)
|
||||||
{
|
{
|
||||||
interface_record *record =
|
nsInterfaceRecord *record =
|
||||||
(interface_record *)PL_HashTableLookup(this->mInterfaceTable, name);
|
(nsInterfaceRecord *)PL_HashTableLookup(this->mInterfaceTable, name);
|
||||||
if (record == NULL || record->resolved == PR_FALSE) {
|
if (record == NULL || record->resolved == PR_FALSE) {
|
||||||
*info = NULL;
|
*info = NULL;
|
||||||
return NS_ERROR_FAILURE;
|
return NS_ERROR_FAILURE;
|
||||||
}
|
}
|
||||||
PR_ASSERT(record->entry != NULL);
|
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) {
|
if (record->info != NULL) {
|
||||||
// yay!
|
// yay!
|
||||||
*info = record->info;
|
*info = record->info;
|
||||||
|
@ -392,8 +377,7 @@ nsInterfaceInfoManager::GetInfoForName(const char* name,
|
||||||
|
|
||||||
// nope, better make one. first, find a parent for it.
|
// nope, better make one. first, find a parent for it.
|
||||||
nsIInterfaceInfo *parent;
|
nsIInterfaceInfo *parent;
|
||||||
XPTInterfaceDirectoryEntry *entry = record->entry;
|
uint16 parent_index = record->entry->interface_descriptor->parent_interface;
|
||||||
uint16 parent_index = entry->interface_descriptor->parent_interface;
|
|
||||||
// Does it _get_ a parent? (is it nsISupports?)
|
// Does it _get_ a parent? (is it nsISupports?)
|
||||||
if (parent_index == 0) {
|
if (parent_index == 0) {
|
||||||
// presumably this is only the case for nsISupports.
|
// 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
|
// got a parent for it, now build the object itself
|
||||||
nsInterfaceInfo *result =
|
nsInterfaceInfo *result =
|
||||||
new nsInterfaceInfo(entry, (nsInterfaceInfo *)parent);
|
new nsInterfaceInfo(record, (nsInterfaceInfo *)parent);
|
||||||
*info = result;
|
*info = result;
|
||||||
NS_ADDREF(*info);
|
NS_ADDREF(*info);
|
||||||
return NS_OK;
|
return NS_OK;
|
||||||
|
@ -424,8 +408,8 @@ nsInterfaceInfoManager::GetInfoForName(const char* name,
|
||||||
NS_IMETHODIMP
|
NS_IMETHODIMP
|
||||||
nsInterfaceInfoManager::GetIIDForName(const char* name, nsIID** iid)
|
nsInterfaceInfoManager::GetIIDForName(const char* name, nsIID** iid)
|
||||||
{
|
{
|
||||||
interface_record *record =
|
nsInterfaceRecord *record =
|
||||||
(interface_record *)PL_HashTableLookup(this->mInterfaceTable, name);
|
(nsInterfaceRecord *)PL_HashTableLookup(this->mInterfaceTable, name);
|
||||||
if (record == NULL || record->resolved == PR_FALSE) {
|
if (record == NULL || record->resolved == PR_FALSE) {
|
||||||
*iid = NULL;
|
*iid = NULL;
|
||||||
return NS_ERROR_FAILURE;
|
return NS_ERROR_FAILURE;
|
||||||
|
@ -472,43 +456,8 @@ nsInterfaceInfoManager::GetNameForIID(const nsIID* iid, char** name)
|
||||||
return NS_OK;
|
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_PUBLIC_API(nsIInterfaceInfoManager*)
|
||||||
XPTI_GetInterfaceInfoManager()
|
XPTI_GetInterfaceInfoManager()
|
||||||
{
|
{
|
||||||
return nsInterfaceInfoManager::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.
|
* Reserved.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
/* Library-private header for nsInterfaceInfoManager implementation. */
|
||||||
|
|
||||||
#ifndef nsInterfaceInfoManager_h___
|
#ifndef nsInterfaceInfoManager_h___
|
||||||
#define nsInterfaceInfoManager_h___
|
#define nsInterfaceInfoManager_h___
|
||||||
|
|
||||||
|
#include "plhash.h"
|
||||||
#include "nsIAllocator.h"
|
#include "nsIAllocator.h"
|
||||||
|
|
||||||
#include "xpt_struct.h"
|
|
||||||
|
|
||||||
#include "nsIInterfaceInfo.h"
|
#include "nsIInterfaceInfo.h"
|
||||||
#include "nsIInterfaceInfoManager.h"
|
#include "nsIInterfaceInfoManager.h"
|
||||||
|
|
||||||
#include "nsInterfaceInfo.h"
|
|
||||||
|
|
||||||
#include "nsHashtable.h"
|
#include "nsHashtable.h"
|
||||||
|
|
||||||
#include "plhash.h"
|
#include "xpt_struct.h"
|
||||||
|
#include "nsInterfaceInfo.h"
|
||||||
class hash_record;
|
#include "nsInterfaceRecord.h"
|
||||||
|
|
||||||
class nsInterfaceInfoManager : public nsIInterfaceInfoManager
|
class nsInterfaceInfoManager : public nsIInterfaceInfoManager
|
||||||
{
|
{
|
||||||
|
@ -64,9 +61,6 @@ private:
|
||||||
// mapping between names and records
|
// mapping between names and records
|
||||||
PLHashTable *mInterfaceTable;
|
PLHashTable *mInterfaceTable;
|
||||||
|
|
||||||
// mapping between entries and typelibs (for nsXPTParamInfo::GetInterface)
|
|
||||||
PLHashTable *mTypelibTable;
|
|
||||||
|
|
||||||
// mapping between iids and names
|
// mapping between iids and names
|
||||||
// (record handling is looked up by name; iids are translated there)
|
// (record handling is looked up by name; iids are translated there)
|
||||||
nsHashtable *mIIDTable;
|
nsHashtable *mIIDTable;
|
||||||
|
@ -74,19 +68,7 @@ private:
|
||||||
nsIAllocator* mAllocator;
|
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___ */
|
#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,
|
NS_PRECONDITION(GetType().TagPart() == nsXPTType::T_INTERFACE,
|
||||||
"not an interface");
|
"not an interface");
|
||||||
|
|
||||||
XPTInterfaceDirectoryEntry *entry = ((nsInterfaceInfo *)info)->getIDE();
|
nsInterfaceRecord *record =
|
||||||
|
((nsInterfaceInfo *)info)->getInterfaceRecord();
|
||||||
|
|
||||||
|
|
||||||
nsIInterfaceInfoManager* mgr;
|
nsIInterfaceInfoManager* mgr;
|
||||||
if(!(mgr = nsInterfaceInfoManager::GetInterfaceInfoManager()))
|
if(!(mgr = nsInterfaceInfoManager::GetInterfaceInfoManager()))
|
||||||
return NULL;
|
return NULL;
|
||||||
nsInterfaceInfoManager* mymgr = (nsInterfaceInfoManager *)mgr;
|
|
||||||
|
|
||||||
// what typelib did the entry come from?
|
// what typelib did the entry come from?
|
||||||
XPTHeader *which_header =
|
XPTHeader *which_header = record->which_header;
|
||||||
(XPTHeader *)PL_HashTableLookup(mymgr->mTypelibTable, entry);
|
NS_ASSERTION(which_header != NULL, "missing header info assoc'd with II");
|
||||||
NS_ASSERTION(which_header != NULL, "");
|
|
||||||
|
|
||||||
// can't use IID, because it could be null for this entry.
|
// can't use IID, because it could be null for this entry.
|
||||||
char *interface_name;
|
char *interface_name;
|
||||||
interface_name = which_header->interface_directory[type.type.interface].name;
|
interface_name = which_header->interface_directory[type.type.interface].name;
|
||||||
|
|
||||||
nsIInterfaceInfo *ii;
|
nsIInterfaceInfo *ii;
|
||||||
nsresult nsr = mymgr->GetInfoForName(interface_name, &ii);
|
nsresult nsr = mgr->GetInfoForName(interface_name, &ii);
|
||||||
if (NS_IS_ERROR(nsr)) {
|
if (NS_IS_ERROR(nsr)) {
|
||||||
NS_RELEASE(mgr);
|
NS_RELEASE(mgr);
|
||||||
return NULL;
|
return NULL;
|
||||||
|
@ -69,25 +69,23 @@ nsXPTParamInfo::GetInterfaceIID(nsIInterfaceInfo *info) const
|
||||||
NS_PRECONDITION(GetType().TagPart() == nsXPTType::T_INTERFACE,
|
NS_PRECONDITION(GetType().TagPart() == nsXPTType::T_INTERFACE,
|
||||||
"not an interface");
|
"not an interface");
|
||||||
|
|
||||||
XPTInterfaceDirectoryEntry *entry = ((nsInterfaceInfo *)info)->getIDE();
|
nsInterfaceRecord *record =
|
||||||
|
((nsInterfaceInfo *)info)->getInterfaceRecord();
|
||||||
|
|
||||||
nsIInterfaceInfoManager* mgr;
|
nsIInterfaceInfoManager* mgr;
|
||||||
if(!(mgr = nsInterfaceInfoManager::GetInterfaceInfoManager()))
|
if(!(mgr = nsInterfaceInfoManager::GetInterfaceInfoManager()))
|
||||||
return NULL;
|
return NULL;
|
||||||
nsInterfaceInfoManager* mymgr = (nsInterfaceInfoManager *)mgr;
|
|
||||||
|
|
||||||
// what typelib did the entry come from?
|
// what typelib did the entry come from?
|
||||||
XPTHeader *which_header =
|
XPTHeader *which_header = record->which_header;
|
||||||
(XPTHeader *)PL_HashTableLookup(mymgr->mTypelibTable, entry);
|
NS_ASSERTION(which_header != NULL, "header missing?");
|
||||||
NS_ASSERTION(which_header != NULL, "");
|
|
||||||
|
|
||||||
// can't use IID, because it could be null for this entry.
|
// can't use IID, because it could be null for this entry.
|
||||||
char *interface_name;
|
char *interface_name;
|
||||||
interface_name = which_header->interface_directory[type.type.interface].name;
|
interface_name = which_header->interface_directory[type.type.interface].name;
|
||||||
|
|
||||||
nsIID* iid;
|
nsIID* iid;
|
||||||
|
nsresult nsr = mgr->GetIIDForName(interface_name, &iid);
|
||||||
nsresult nsr = mymgr->GetIIDForName(interface_name, &iid);
|
|
||||||
if (NS_IS_ERROR(nsr)) {
|
if (NS_IS_ERROR(nsr)) {
|
||||||
NS_RELEASE(mgr);
|
NS_RELEASE(mgr);
|
||||||
return NULL;
|
return NULL;
|
||||||
|
|
Загрузка…
Ссылка в новой задаче