Back to index

lightning-sunbird  0.9+nobinonly
Public Member Functions | Public Attributes | Private Member Functions | Private Attributes
nsSubscribableServer Class Reference

#include <nsSubscribableServer.h>

Inheritance diagram for nsSubscribableServer:
Inheritance graph
[legend]
Collaboration diagram for nsSubscribableServer:
Collaboration graph
[legend]

List of all members.

Public Member Functions

 nsSubscribableServer ()
virtual ~nsSubscribableServer ()
nsresult Init ()
void startPopulating (in nsIMsgWindow aMsgWindow, in boolean forceToServer)
void startPopulatingWithUri (in nsIMsgWindow aMsgWindow, in boolean forceToServer, in string uri)
void stopPopulating (in nsIMsgWindow aMsgWindow)
boolean setState (in AUTF8String path, in boolean state)
void subscribeCleanup ()
void subscribe (in wstring name)
void unsubscribe (in wstring name)
void commitSubscribeChanges ()
void setIncomingServer (in nsIMsgIncomingServer server)
void addTo (in AUTF8String aName, in boolean addAsSubscribed, in boolean aSubscribable, in boolean aChangeIfExists)
void setAsSubscribed (in AUTF8String path)
void updateSubscribed ()
void setShowFullName (in boolean showFullName)
boolean hasChildren (in AUTF8String path)
boolean isSubscribed (in AUTF8String path)
boolean isSubscribable (in AUTF8String path)
AString getLeafName (in AUTF8String path)
void getChildren (in AUTF8String path, in nsISupportsArray array)
AUTF8String getFirstChildURI (in AUTF8String path)
void setSearchValue (in AString searchValue)

Public Attributes

attribute nsISubscribeListener subscribeListener
attribute char delimiter
readonly attribute boolean supportsSubscribeSearch

Private Member Functions

nsresult ConvertNameToUnichar (const char *inStr, PRUnichar **outStr)
nsresult FreeSubtree (SubscribeTreeNode *node)
nsresult CreateNode (SubscribeTreeNode *parent, const char *name, SubscribeTreeNode **result)
nsresult AddChildNode (SubscribeTreeNode *parent, const char *name, SubscribeTreeNode **child)
nsresult FindAndCreateNode (const nsACString &aPath, SubscribeTreeNode **aResult)
nsresult NotifyAssert (SubscribeTreeNode *subjectNode, nsIRDFResource *property, SubscribeTreeNode *objectNode)
nsresult NotifyChange (SubscribeTreeNode *subjectNode, nsIRDFResource *property, PRBool value)
nsresult Notify (nsIRDFResource *subject, nsIRDFResource *property, nsIRDFNode *object, PRBool isAssert, PRBool isChange)
void BuildURIFromNode (SubscribeTreeNode *node, nsACString &uri)
nsresult EnsureSubscribeDS ()
nsresult EnsureRDFService ()

Private Attributes

nsCOMPtr< nsISubscribeListenermSubscribeListener
nsCOMPtr< nsIMsgIncomingServermIncomingServer
nsCOMPtr< nsISubscribeDataSourcemSubscribeDS
char mDelimiter
PRBool mShowFullName
PRBool mStopped
nsCOMPtr< nsIRDFResourcekNC_Child
nsCOMPtr< nsIRDFResourcekNC_Subscribed
nsCOMPtr< nsIRDFLiteralkTrueLiteral
nsCOMPtr< nsIRDFLiteralkFalseLiteral
nsCOMPtr< nsIRDFServicemRDFService
SubscribeTreeNodemTreeRoot

Detailed Description

Definition at line 72 of file nsSubscribableServer.h.


Constructor & Destructor Documentation

Definition at line 63 of file nsSubscribableServer.cpp.

Definition at line 95 of file nsSubscribableServer.cpp.

{
    nsresult rv = NS_OK;
#ifdef DEBUG_seth
    printf("free subscribe tree\n");
#endif
    rv = FreeSubtree(mTreeRoot);
    NS_ASSERTION(NS_SUCCEEDED(rv),"failed to free tree");
}

Here is the call graph for this function:


Member Function Documentation

nsresult nsSubscribableServer::AddChildNode ( SubscribeTreeNode parent,
const char *  name,
SubscribeTreeNode **  child 
) [private]

Definition at line 516 of file nsSubscribableServer.cpp.

{
    nsresult rv = NS_OK;
    NS_ASSERTION(parent && child && name, "parent, child or name is null");
    if (!parent || !child || !name) return NS_ERROR_NULL_POINTER;

    if (!parent->firstChild) {
        // CreateNode will set the parent->cachedChild
        rv = CreateNode(parent, name, child);
        NS_ENSURE_SUCCESS(rv,rv);

        parent->firstChild = *child;
        parent->lastChild = *child;

        rv = NotifyAssert(parent, kNC_Child, *child);
        NS_ENSURE_SUCCESS(rv,rv);   

        return NS_OK;
    }
    else {
        if (parent->cachedChild) {
            if (nsCRT::strcmp(parent->cachedChild->name,name) == 0) {
                *child = parent->cachedChild;
                return NS_OK;
            }
        }

        SubscribeTreeNode *current = parent->firstChild;

        /*
         * insert in reverse alphabetical order
         * this will reduce the # of strcmps
         * since this is faster assuming:
         *  1) the hostinfo.dat feeds us the groups in alphabetical order
         *     since we control the hostinfo.dat file, we can guarantee this.
         *  2) the server gives us the groups in alphabetical order
         *     we can't guarantee this, but it seems to be a common thing
         *
         * because we have firstChild, lastChild, nextSibling, prevSibling
         * we can efficiently reverse the order when dumping to hostinfo.dat
         * or to GetTargets()
         */
        PRInt32 compare = nsCRT::strcmp(current->name, name);

        while (current && (compare != 0)) {
            if (compare < 0) {
                // CreateNode will set the parent->cachedChild
                rv = CreateNode(parent, name, child);
                NS_ENSURE_SUCCESS(rv,rv);

                (*child)->nextSibling = current;
                (*child)->prevSibling = current->prevSibling;
                current->prevSibling = (*child);
                if (!(*child)->prevSibling) {
                    parent->firstChild = (*child);
                }
                else {
                    (*child)->prevSibling->nextSibling = (*child);
                }

                rv = NotifyAssert(parent, kNC_Child, *child);
                NS_ENSURE_SUCCESS(rv,rv);
                return NS_OK;
            }
            current = current->nextSibling;
            if (current) {
                NS_ASSERTION(current->name, "no name!");
                compare = nsCRT::strcmp(current->name,name);
            }
            else {
                compare = -1; // anything but 0, since that would be a match
            }
        }

        if (compare == 0) {
            // already exists;
            *child = current;

            // set the cachedChild
            parent->cachedChild = *child;
            return NS_OK;
        }

        // CreateNode will set the parent->cachedChild
        rv = CreateNode(parent, name, child);
        NS_ENSURE_SUCCESS(rv,rv);

        (*child)->prevSibling = parent->lastChild;
        (*child)->nextSibling = nsnull;
        parent->lastChild->nextSibling = *child;
        parent->lastChild = *child;

        rv = NotifyAssert(parent, kNC_Child, *child);
        NS_ENSURE_SUCCESS(rv,rv);
        return NS_OK;
    }
    return NS_OK;
}

Here is the call graph for this function:

Here is the caller graph for this function:

void nsISubscribableServer::addTo ( in AUTF8String  aName,
in boolean  addAsSubscribed,
in boolean  aSubscribable,
in boolean  aChangeIfExists 
) [inherited]
void nsSubscribableServer::BuildURIFromNode ( SubscribeTreeNode node,
nsACString &  uri 
) [private]

Definition at line 221 of file nsSubscribableServer.cpp.

{
    if (node->parent) {
        BuildURIFromNode(node->parent, uri);
        if (node->parent == mTreeRoot) {
            uri += "/";
        }
        else {
            uri += mDelimiter;
        }
    }

    uri += node->name;
    return;
}

Here is the caller graph for this function:

nsresult nsSubscribableServer::ConvertNameToUnichar ( const char *  inStr,
PRUnichar **  outStr 
) [private]
nsresult nsSubscribableServer::CreateNode ( SubscribeTreeNode parent,
const char *  name,
SubscribeTreeNode **  result 
) [private]

Definition at line 482 of file nsSubscribableServer.cpp.

{
    NS_ASSERTION(result && name, "result or name is null");
    if (!result || !name) return NS_ERROR_NULL_POINTER;

    *result = (SubscribeTreeNode *) PR_Malloc(sizeof(SubscribeTreeNode));
    if (!*result) return NS_ERROR_OUT_OF_MEMORY;

    (*result)->name = nsCRT::strdup(name);
    if (!(*result)->name) return NS_ERROR_OUT_OF_MEMORY;

    (*result)->parent = parent;
    (*result)->prevSibling = nsnull;
    (*result)->nextSibling = nsnull;
    (*result)->firstChild = nsnull;
    (*result)->lastChild = nsnull;
    (*result)->isSubscribed = PR_FALSE;
    (*result)->isSubscribable = PR_FALSE;
#ifdef HAVE_SUBSCRIBE_DESCRIPTION
    (*result)->description = nsnull;
#endif
#ifdef HAVE_SUBSCRIBE_MESSAGES
    (*result)->messages = 0;
#endif
    (*result)->cachedChild = nsnull;

    if (parent) {
        parent->cachedChild = *result;
    }

    return NS_OK;
}

Here is the caller graph for this function:

Definition at line 277 of file nsSubscribableServer.cpp.

{
    nsresult rv;

    if (!mRDFService) {
        mRDFService = do_GetService(kRDFServiceCID, &rv);
        NS_ASSERTION(NS_SUCCEEDED(rv) && mRDFService, "failed to get rdf service");
        NS_ENSURE_SUCCESS(rv,rv);
        if (!mRDFService) return NS_ERROR_FAILURE;
    }
    return NS_OK;
}

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 327 of file nsSubscribableServer.cpp.

{
    nsresult rv = NS_OK;

    if (!mSubscribeDS) {
        nsCOMPtr<nsIRDFDataSource> ds;

        rv = EnsureRDFService();
        NS_ENSURE_SUCCESS(rv,rv);

        rv = mRDFService->GetDataSource("rdf:subscribe", getter_AddRefs(ds));
        NS_ENSURE_SUCCESS(rv,rv);
        if (!ds) return NS_ERROR_FAILURE;

        mSubscribeDS = do_QueryInterface(ds, &rv);
        NS_ENSURE_SUCCESS(rv,rv);
        if (!mSubscribeDS) return NS_ERROR_FAILURE;
    }
    return NS_OK;
}

Here is the call graph for this function:

Here is the caller graph for this function:

nsresult nsSubscribableServer::FindAndCreateNode ( const nsACString &  aPath,
SubscribeTreeNode **  aResult 
) [private]

Definition at line 616 of file nsSubscribableServer.cpp.

{
    nsresult rv = NS_OK;
    NS_ASSERTION(aResult, "no result");
    if (!aResult) return NS_ERROR_NULL_POINTER;

    if (!mTreeRoot) {
        nsXPIDLCString serverUri;
        rv = mIncomingServer->GetServerURI(getter_Copies(serverUri));
        NS_ENSURE_SUCCESS(rv,rv);
        // the root has no parent, and its name is server uri
        rv = CreateNode(nsnull, (const char *)serverUri, &mTreeRoot);
        NS_ENSURE_SUCCESS(rv,rv);
    }

    if (aPath.IsEmpty()) {
        *aResult = mTreeRoot;
        return NS_OK;
    }

    char *pathStr = nsCRT::strdup(PromiseFlatCString(aPath).get());
    char *token = nsnull;
    char *rest = pathStr;
    
    // todo do this only once
    char delimstr[2];
    delimstr[0] = mDelimiter;
    delimstr[1] = '\0';
    
    *aResult = nsnull;

    SubscribeTreeNode *parent = mTreeRoot;
    SubscribeTreeNode *child = nsnull;

    token = nsCRT::strtok(rest, delimstr, &rest);
    while (token && *token) {
        rv = AddChildNode(parent, token, &child);
        if (NS_FAILED(rv)) {
            CRTFREEIF(pathStr);
            return rv;
        }
        token = nsCRT::strtok(rest, delimstr, &rest);
        parent = child;
    }   
    CRTFREEIF(pathStr);

    // the last child we add is the result
    *aResult = child;
    return rv;
}

Here is the call graph for this function:

Definition at line 443 of file nsSubscribableServer.cpp.

{
    nsresult rv = NS_OK;

    if (node) {
        // recursively free the children
        if (node->firstChild) {
            // will free node->firstChild      
            rv = FreeSubtree(node->firstChild);
            NS_ENSURE_SUCCESS(rv,rv);
            node->firstChild = nsnull;
        }

        // recursively free the siblings
        if (node->nextSibling) {
            // will free node->nextSibling
            rv = FreeSubtree(node->nextSibling);
            NS_ENSURE_SUCCESS(rv,rv);
            node->nextSibling = nsnull;
        }

#ifdef HAVE_SUBSCRIBE_DESCRIPTION
        NS_ASSERTION(node->description == nsnull, "you need to free the description");
#endif
        CRTFREEIF(node->name);
#if 0 
        node->name = nsnull;
        node->parent = nsnull;
        node->lastChild = nsnull;
        node->cachedChild = nsnull;
#endif

        PR_Free(node);  
    }

    return NS_OK;
}

Here is the caller graph for this function:

void nsISubscribableServer::getChildren ( in AUTF8String  path,
in nsISupportsArray  array 
) [inherited]
AUTF8String nsISubscribableServer::getFirstChildURI ( in AUTF8String  path) [inherited]
AString nsISubscribableServer::getLeafName ( in AUTF8String  path) [inherited]
boolean nsISubscribableServer::hasChildren ( in AUTF8String  path) [inherited]

Definition at line 72 of file nsSubscribableServer.cpp.

Here is the call graph for this function:

boolean nsISubscribableServer::isSubscribable ( in AUTF8String  path) [inherited]
boolean nsISubscribableServer::isSubscribed ( in AUTF8String  path) [inherited]
nsresult nsSubscribableServer::Notify ( nsIRDFResource subject,
nsIRDFResource property,
nsIRDFNode object,
PRBool  isAssert,
PRBool  isChange 
) [private]

Definition at line 349 of file nsSubscribableServer.cpp.

{
    nsresult rv = NS_OK;

    rv = EnsureSubscribeDS();
    NS_ENSURE_SUCCESS(rv,rv);

    rv = mSubscribeDS->NotifyObservers(subject, property, object, isAssert, isChange);
    NS_ENSURE_SUCCESS(rv,rv);
    return rv;
}

Here is the call graph for this function:

Here is the caller graph for this function:

nsresult nsSubscribableServer::NotifyAssert ( SubscribeTreeNode subjectNode,
nsIRDFResource property,
SubscribeTreeNode objectNode 
) [private]

Definition at line 238 of file nsSubscribableServer.cpp.

{
    nsresult rv;

    PRBool hasObservers = PR_TRUE;
    rv = EnsureSubscribeDS();
    NS_ENSURE_SUCCESS(rv,rv);
    rv = mSubscribeDS->GetHasObservers(&hasObservers);
    NS_ENSURE_SUCCESS(rv,rv);
    // no need to do all this work, there are no observers
    if (!hasObservers) {
        return NS_OK;
    }
    
    nsCAutoString subjectUri;
    BuildURIFromNode(subjectNode, subjectUri);

    // we could optimize this, since we know that objectUri == subjectUri + mDelimiter + object->name
    // is it worth it?
    nsCAutoString objectUri;
    BuildURIFromNode(objectNode, objectUri);

    nsCOMPtr <nsIRDFResource> subject;
    nsCOMPtr <nsIRDFResource> object;

    rv = EnsureRDFService();
    NS_ENSURE_SUCCESS(rv,rv);

    rv = mRDFService->GetResource(subjectUri, getter_AddRefs(subject));
    NS_ENSURE_SUCCESS(rv,rv);
    rv = mRDFService->GetResource(objectUri, getter_AddRefs(object));
    NS_ENSURE_SUCCESS(rv,rv);

    rv = Notify(subject, property, object, PR_TRUE, PR_FALSE);
    NS_ENSURE_SUCCESS(rv,rv);
    return NS_OK;
}

Here is the call graph for this function:

Here is the caller graph for this function:

nsresult nsSubscribableServer::NotifyChange ( SubscribeTreeNode subjectNode,
nsIRDFResource property,
PRBool  value 
) [private]

Definition at line 291 of file nsSubscribableServer.cpp.

{
    nsresult rv;
    nsCOMPtr <nsIRDFResource> subject;

    PRBool hasObservers = PR_TRUE;
    rv = EnsureSubscribeDS();
    NS_ENSURE_SUCCESS(rv,rv);
    rv = mSubscribeDS->GetHasObservers(&hasObservers);
    NS_ENSURE_SUCCESS(rv,rv);
    // no need to do all this work, there are no observers
    if (!hasObservers) {
        return NS_OK;
    }

    nsCAutoString subjectUri;
    BuildURIFromNode(subjectNode, subjectUri);

    rv = EnsureRDFService();
    NS_ENSURE_SUCCESS(rv,rv);

    rv = mRDFService->GetResource(subjectUri, getter_AddRefs(subject));
    NS_ENSURE_SUCCESS(rv,rv);

    if (value) {
        rv = Notify(subject,property,kTrueLiteral,PR_FALSE,PR_TRUE);
    }
    else {
        rv = Notify(subject,property,kFalseLiteral,PR_FALSE,PR_TRUE);
    }

    NS_ENSURE_SUCCESS(rv,rv);
    return NS_OK;
}

Here is the call graph for this function:

void nsISubscribableServer::setAsSubscribed ( in AUTF8String  path) [inherited]
void nsISubscribableServer::setSearchValue ( in AString  searchValue) [inherited]
void nsISubscribableServer::setShowFullName ( in boolean  showFullName) [inherited]
boolean nsISubscribableServer::setState ( in AUTF8String  path,
in boolean  state 
) [inherited]
void nsISubscribableServer::startPopulating ( in nsIMsgWindow  aMsgWindow,
in boolean  forceToServer 
) [inherited]
void nsISubscribableServer::startPopulatingWithUri ( in nsIMsgWindow  aMsgWindow,
in boolean  forceToServer,
in string  uri 
) [inherited]
void nsISubscribableServer::subscribe ( in wstring  name) [inherited]
void nsISubscribableServer::unsubscribe ( in wstring  name) [inherited]

Member Data Documentation

Definition at line 61 of file nsISubscribableServer.idl.

Definition at line 95 of file nsSubscribableServer.h.

Definition at line 92 of file nsSubscribableServer.h.

Definition at line 93 of file nsSubscribableServer.h.

Definition at line 94 of file nsSubscribableServer.h.

Definition at line 88 of file nsSubscribableServer.h.

Definition at line 86 of file nsSubscribableServer.h.

Definition at line 97 of file nsSubscribableServer.h.

Definition at line 89 of file nsSubscribableServer.h.

Definition at line 90 of file nsSubscribableServer.h.

Definition at line 87 of file nsSubscribableServer.h.

Definition at line 85 of file nsSubscribableServer.h.

Definition at line 99 of file nsSubscribableServer.h.

Definition at line 60 of file nsISubscribableServer.idl.

Definition at line 100 of file nsISubscribableServer.idl.


The documentation for this class was generated from the following files: