Back to index

lightning-sunbird  0.9+nobinonly
Classes | Defines | Functions
xptiInterfaceInfoManager.cpp File Reference
#include "xptiprivate.h"
#include "nsDependentString.h"
#include "nsString.h"

Go to the source code of this file.

Classes

struct  SortData
struct  TwoWorkingSets
struct  ArrayAndPrefix
class  xptiAdditionalManagersEnumerator

Defines

#define NS_ZIPLOADER_CONTRACTID   NS_XPTLOADER_CONTRACTID_PREFIX "zip"

Functions

 NS_IMPL_THREADSAFE_ISUPPORTS2 (xptiInterfaceInfoManager, nsIInterfaceInfoManager, nsIInterfaceInfoSuperManager) static xptiInterfaceInfoManager *gInterfaceInfoManager
static nsresult GetDirectoryFromDirService (const char *codename, nsILocalFile **aDir)
static PRBool AppendFromDirServiceList (const char *codename, nsISupportsArray *aPath)
static int IndexOfFileWithName (const char *aName, const xptiWorkingSet *aWorkingSet)
static int IndexOfDirectoryOfFile (nsISupportsArray *aSearchPath, nsILocalFile *aFile)
 xptiSortFileList (const void *p1, const void *p2, void *closure)
 xpti_Merger (PLDHashTable *table, PLDHashEntryHdr *hdr, PRUint32 number, void *arg)
 xpti_ResolvedFileNameLogger (PLDHashTable *table, PLDHashEntryHdr *hdr, PRUint32 number, void *arg)
static nsresult EntryToInfo (xptiInterfaceEntry *entry, nsIInterfaceInfo **_retval)
 xpti_ArrayAppender (PLDHashTable *table, PLDHashEntryHdr *hdr, PRUint32 number, void *arg)
 xpti_ArrayPrefixAppender (PLDHashTable *table, PLDHashEntryHdr *hdr, PRUint32 number, void *arg)
 XPTI_GetInterfaceInfoManager ()
 XPTI_FreeInterfaceInfoManager ()

Class Documentation

struct SortData

Definition at line 636 of file xptiInterfaceInfoManager.cpp.

Collaboration diagram for SortData:
Class Members
nsISupportsArray * mSearchPath
xptiWorkingSet * mWorkingSet
struct ArrayAndPrefix

Definition at line 1830 of file xptiInterfaceInfoManager.cpp.

Collaboration diagram for ArrayAndPrefix:
Class Members
nsISupportsArray * array
PRUint32 length
const char * prefix

Define Documentation

Definition at line 46 of file xptiInterfaceInfoManager.cpp.


Function Documentation

static PRBool AppendFromDirServiceList ( const char *  codename,
nsISupportsArray aPath 
) [static]

Definition at line 197 of file xptiInterfaceInfoManager.cpp.

{
    NS_ASSERTION(codename,"loser!");
    NS_ASSERTION(aPath,"loser!");
    
    nsCOMPtr<nsIProperties> dirService = 
        do_GetService(NS_DIRECTORY_SERVICE_CONTRACTID);
    if(!dirService)
        return PR_FALSE;

    nsCOMPtr<nsISimpleEnumerator> fileList;
    dirService->Get(codename, NS_GET_IID(nsISimpleEnumerator), 
                    getter_AddRefs(fileList));
    if(!fileList)
        return PR_FALSE;
    
    PRBool more;
    while(NS_SUCCEEDED(fileList->HasMoreElements(&more)) && more)
    {
        nsCOMPtr<nsILocalFile> dir;
        fileList->GetNext(getter_AddRefs(dir));
        if(!dir || !aPath->AppendElement(dir))
            return PR_FALSE;
    }

    return PR_TRUE;
}        

Here is the call graph for this function:

Here is the caller graph for this function:

static nsresult EntryToInfo ( xptiInterfaceEntry entry,
nsIInterfaceInfo **  _retval 
) [static]

Definition at line 1707 of file xptiInterfaceInfoManager.cpp.

{
    xptiInterfaceInfo* info;
    nsresult rv;

    if(!entry)
    {
        *_retval = nsnull;
        return NS_ERROR_FAILURE;    
    }

    rv = entry->GetInterfaceInfo(&info);
    if(NS_FAILED(rv))
        return rv;

    // Transfer the AddRef done by GetInterfaceInfo.
    *_retval = NS_STATIC_CAST(nsIInterfaceInfo*, info);
    return NS_OK;    
}

Here is the call graph for this function:

Here is the caller graph for this function:

static nsresult GetDirectoryFromDirService ( const char *  codename,
nsILocalFile **  aDir 
) [static]

Definition at line 183 of file xptiInterfaceInfoManager.cpp.

{
    NS_ASSERTION(codename,"loser!");
    NS_ASSERTION(aDir,"loser!");
    
    nsresult rv;
    nsCOMPtr<nsIProperties> dirService =
        do_GetService(NS_DIRECTORY_SERVICE_CONTRACTID, &rv);
    if (NS_FAILED(rv)) return rv;

    return dirService->Get(codename, NS_GET_IID(nsILocalFile), (void**) aDir);
}

Here is the call graph for this function:

Here is the caller graph for this function:

static int IndexOfDirectoryOfFile ( nsISupportsArray aSearchPath,
nsILocalFile aFile 
) [static]

Definition at line 612 of file xptiInterfaceInfoManager.cpp.

{
    nsCOMPtr<nsIFile> parent;
    aFile->GetParent(getter_AddRefs(parent));
    if(parent)
    {
        PRUint32 count = 0;
        aSearchPath->Count(&count);
        NS_ASSERTION(count, "broken search path! bad count");
        for(PRUint32 i = 0; i < count; i++)
        {
            nsCOMPtr<nsIFile> current;
            aSearchPath->QueryElementAt(i, NS_GET_IID(nsIFile), 
                                        getter_AddRefs(current));
            NS_ASSERTION(current, "broken search path! bad element");
            PRBool same;
            if(NS_SUCCEEDED(parent->Equals(current, &same)) && same)
                return (int) i;
        }
    }
    NS_ERROR("file not in search directory!");
    return -1;
}        

Here is the call graph for this function:

Here is the caller graph for this function:

static int IndexOfFileWithName ( const char *  aName,
const xptiWorkingSet aWorkingSet 
) [static]

Definition at line 599 of file xptiInterfaceInfoManager.cpp.

{
    NS_ASSERTION(aName, "loser!");

    for(PRUint32 i = 0; i < aWorkingSet->GetFileCount(); ++i)
    {
        if(0 == PL_strcmp(aName, aWorkingSet->GetFileAt(i).GetName()))
            return i;     
    }
    return -1;        
}        

Here is the call graph for this function:

Here is the caller graph for this function:

xpti_ArrayAppender ( PLDHashTable table,
PLDHashEntryHdr hdr,
PRUint32  number,
void arg 
)

Definition at line 1800 of file xptiInterfaceInfoManager.cpp.

Here is the call graph for this function:

xpti_ArrayPrefixAppender ( PLDHashTable table,
PLDHashEntryHdr hdr,
PRUint32  number,
void arg 
)

Definition at line 1838 of file xptiInterfaceInfoManager.cpp.

{
    xptiInterfaceEntry* entry = ((xptiHashEntry*)hdr)->value;
    ArrayAndPrefix* args = (ArrayAndPrefix*) arg;

    const char* name = entry->GetTheName();
    if(name != PL_strnstr(name, args->prefix, args->length))
        return PL_DHASH_NEXT;

    nsCOMPtr<nsIInterfaceInfo> ii;
    if(NS_SUCCEEDED(EntryToInfo(entry, getter_AddRefs(ii))))
        args->array->AppendElement(ii);
    return PL_DHASH_NEXT;
}

Here is the call graph for this function:

Definition at line 2122 of file xptiInterfaceInfoManager.cpp.

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 2113 of file xptiInterfaceInfoManager.cpp.

Here is the call graph for this function:

xpti_Merger ( PLDHashTable table,
PLDHashEntryHdr hdr,
PRUint32  number,
void arg 
)

Definition at line 1352 of file xptiInterfaceInfoManager.cpp.

{
    xptiInterfaceEntry* srcEntry = ((xptiHashEntry*)hdr)->value;
    xptiWorkingSet* aSrcWorkingSet = ((TwoWorkingSets*)arg)->aSrcWorkingSet;
    xptiWorkingSet* aDestWorkingSet = ((TwoWorkingSets*)arg)->aDestWorkingSet;

    xptiHashEntry* hashEntry = (xptiHashEntry*)
        PL_DHashTableOperate(aDestWorkingSet->mIIDTable, 
                             srcEntry->GetTheIID(), PL_DHASH_LOOKUP);

    xptiInterfaceEntry* destEntry = 
        PL_DHASH_ENTRY_IS_FREE(hashEntry) ? nsnull : hashEntry->value;
    
    if(destEntry)
    {
        // Let's see if this is referring to the same exact typelib
         
        const char* destFilename = 
            aDestWorkingSet->GetTypelibFileName(destEntry->GetTypelibRecord());
        
        const char* srcFilename = 
            aSrcWorkingSet->GetTypelibFileName(srcEntry->GetTypelibRecord());
    
        if(0 == PL_strcmp(destFilename, srcFilename) && 
           (destEntry->GetTypelibRecord().GetZipItemIndex() ==
            srcEntry->GetTypelibRecord().GetZipItemIndex()))
        {
            // This is the same item.
            // But... Let's make sure they didn't change the interface name.
            // There are wacky developers that do stuff like that!
            if(0 == PL_strcmp(destEntry->GetTheName(), srcEntry->GetTheName()))
                return PL_DHASH_NEXT;
        }
    }
    
    // Clone the xptiInterfaceEntry into our destination WorkingSet.

    xptiTypelib typelibRecord;

    uint16 fileIndex = srcEntry->GetTypelibRecord().GetFileIndex();
    uint16 zipItemIndex = srcEntry->GetTypelibRecord().GetZipItemIndex();
    
    fileIndex += aDestWorkingSet->mFileMergeOffsetMap[fileIndex];
    
    // If it is not a zipItem, then the original index is fine.
    if(srcEntry->GetTypelibRecord().IsZip())
        zipItemIndex += aDestWorkingSet->mZipItemMergeOffsetMap[zipItemIndex];

    typelibRecord.Init(fileIndex, zipItemIndex);
                
    destEntry = xptiInterfaceEntry::NewEntry(*srcEntry, typelibRecord, 
                                             aDestWorkingSet);
    if(!destEntry)
    {
        // XXX bad! should log
        return PL_DHASH_NEXT;
    }


    // Add our entry to the iid hashtable.

    hashEntry = (xptiHashEntry*)
        PL_DHashTableOperate(aDestWorkingSet->mNameTable, 
                             destEntry->GetTheName(), PL_DHASH_ADD);
    if(hashEntry)
        hashEntry->value = destEntry;
    
    // Add our entry to the name hashtable.

    hashEntry = (xptiHashEntry*)
        PL_DHashTableOperate(aDestWorkingSet->mIIDTable, 
                             destEntry->GetTheIID(), PL_DHASH_ADD);
    if(hashEntry)
        hashEntry->value = destEntry;

    return PL_DHASH_NEXT;
}       

Here is the call graph for this function:

Here is the caller graph for this function:

xpti_ResolvedFileNameLogger ( PLDHashTable table,
PLDHashEntryHdr hdr,
PRUint32  number,
void arg 
)

Definition at line 1626 of file xptiInterfaceInfoManager.cpp.

{
    xptiInterfaceEntry* entry = ((xptiHashEntry*)hdr)->value;
    xptiInterfaceInfoManager* mgr = (xptiInterfaceInfoManager*) arg;

    if(entry->IsFullyResolved())
    {
        xptiWorkingSet*  aWorkingSet = mgr->GetWorkingSet();
        PRFileDesc* fd = mgr->GetOpenLogFile();

        const xptiTypelib& typelib = entry->GetTypelibRecord();
        const char* filename = 
                aWorkingSet->GetFileAt(typelib.GetFileIndex()).GetName();
        
        if(typelib.IsZip())
        {
            const char* zipItemName = 
                aWorkingSet->GetZipItemAt(typelib.GetZipItemIndex()).GetName();
            PR_fprintf(fd, "xpti used interface: %s from %s::%s\n", 
                       entry->GetTheName(), filename, zipItemName);
        }    
        else
        {
            PR_fprintf(fd, "xpti used interface: %s from %s\n", 
                       entry->GetTheName(), filename);
        }
    }
    return PL_DHASH_NEXT;
}

Here is the call graph for this function:

Here is the caller graph for this function:

xptiSortFileList ( const void p1,
const void p2,
void closure 
)

Definition at line 643 of file xptiInterfaceInfoManager.cpp.

{
    nsILocalFile* pFile1 = *((nsILocalFile**) p1);
    nsILocalFile* pFile2 = *((nsILocalFile**) p2);
    SortData* data = (SortData*) closure;
    
    nsCAutoString name1;
    nsCAutoString name2;
        
    if(NS_FAILED(pFile1->GetNativeLeafName(name1)))
    {
        NS_ERROR("way bad, with no happy out!");
        return 0;    
    }    
    if(NS_FAILED(pFile2->GetNativeLeafName(name2)))
    {
        NS_ERROR("way bad, with no happy out!");
        return 0;    
    }    

    int index1 = IndexOfFileWithName(name1.get(), data->mWorkingSet); 
    int index2 = IndexOfFileWithName(name2.get(), data->mWorkingSet); 
   
    // Get these now in case we need them later.
    PRBool isXPT1 = xptiFileType::IsXPT(name1.get());
    PRBool isXPT2 = xptiFileType::IsXPT(name2.get());
    int nameOrder = Compare(name1, name2);
    
    // both in workingSet, preserve old order
    if(index1 != -1 && index2 != -1)
        return index1 - index2;

    if(index1 != -1)
        return 1;

    if(index2 != -1)
        return -1;

    // neither is in workingset

    // check how they compare in search path order
    
    int dirIndex1 = IndexOfDirectoryOfFile(data->mSearchPath, pFile1);
    int dirIndex2 = IndexOfDirectoryOfFile(data->mSearchPath, pFile2);

    if(dirIndex1 != dirIndex2)
        return dirIndex1 - dirIndex2;

    // .xpt files come before archives (.zip, .jar, etc)
    if(isXPT1 &&!isXPT2)
        return -1;
        
    if(!isXPT1 && isXPT2)
        return 1;
    
    // neither element is in the workingSet and both are same type and in 
    // the same directory, sort by size

    PRInt64 size1;
    PRInt64 size2;

    if(NS_FAILED(pFile1->GetFileSize(&size1)))
    {
        NS_ERROR("way bad, with no happy out!");
        return 0;    
    }    
    if(NS_FAILED(pFile2->GetFileSize(&size2)))
    {
        NS_ERROR("way bad, with no happy out!");
        return 0;    
    }    

    // by size with largest first, or by name if size is the same
    int sizeDiff = int(PRInt32(nsInt64(size2) - nsInt64(size1)));
    return sizeDiff != 0  ? sizeDiff : nameOrder;
}        

Here is the call graph for this function:

Here is the caller graph for this function: