Back to index

lightning-sunbird  0.9+nobinonly
Public Member Functions | Public Attributes | Protected Member Functions | Static Protected Member Functions | Private Attributes
nsAbRDFDataSource Class Reference

The addressbook data source. More...

#include <nsAbRDFDataSource.h>

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

List of all members.

Public Member Functions

NS_DECL_ISUPPORTS
NS_DECL_NSIRDFDATASOURCE 
nsAbRDFDataSource ()
virtual ~nsAbRDFDataSource ()
nsIRDFResource GetSource (in nsIRDFResource aProperty, in nsIRDFNode aTarget, in boolean aTruthValue)
 Find an RDF resource that points to a given node over the specified arc & truth value.
nsISimpleEnumerator GetSources (in nsIRDFResource aProperty, in nsIRDFNode aTarget, in boolean aTruthValue)
 Find all RDF resources that point to a given node over the specified arc & truth value.
nsIRDFNode GetTarget (in nsIRDFResource aSource, in nsIRDFResource aProperty, in boolean aTruthValue)
 Find a child of that is related to the source by the given arc arc and truth value.
nsISimpleEnumerator GetTargets (in nsIRDFResource aSource, in nsIRDFResource aProperty, in boolean aTruthValue)
 Find all children of that are related to the source by the given arc arc and truth value.
void Assert (in nsIRDFResource aSource, in nsIRDFResource aProperty, in nsIRDFNode aTarget, in boolean aTruthValue)
 Add an assertion to the graph.
void Unassert (in nsIRDFResource aSource, in nsIRDFResource aProperty, in nsIRDFNode aTarget)
 Remove an assertion from the graph.
void Change (in nsIRDFResource aSource, in nsIRDFResource aProperty, in nsIRDFNode aOldTarget, in nsIRDFNode aNewTarget)
 Change an assertion from.
void Move (in nsIRDFResource aOldSource, in nsIRDFResource aNewSource, in nsIRDFResource aProperty, in nsIRDFNode aTarget)
 'Move' an assertion from
boolean HasAssertion (in nsIRDFResource aSource, in nsIRDFResource aProperty, in nsIRDFNode aTarget, in boolean aTruthValue)
 Query whether an assertion exists in this graph.
void AddObserver (in nsIRDFObserver aObserver)
 Add an observer to this data source.
void RemoveObserver (in nsIRDFObserver aObserver)
 Remove an observer from this data source.
nsISimpleEnumerator ArcLabelsIn (in nsIRDFNode aNode)
 Get a cursor to iterate over all the arcs that point into a node.
nsISimpleEnumerator ArcLabelsOut (in nsIRDFResource aSource)
 Get a cursor to iterate over all the arcs that originate in a resource.
nsISimpleEnumerator GetAllResources ()
 Retrieve all of the resources that the data source currently refers to.
boolean IsCommandEnabled (in nsISupportsArray aSources, in nsIRDFResource aCommand, in nsISupportsArray aArguments)
 Returns whether a given command is enabled for a set of sources.
void DoCommand (in nsISupportsArray aSources, in nsIRDFResource aCommand, in nsISupportsArray aArguments)
 Perform the specified command on set of sources.
nsISimpleEnumerator GetAllCmds (in nsIRDFResource aSource)
 Returns the set of all commands defined for a given source.
boolean hasArcIn (in nsIRDFNode aNode, in nsIRDFResource aArc)
 Returns true if the specified node is pointed to by the specified arc.
boolean hasArcOut (in nsIRDFResource aSource, in nsIRDFResource aArc)
 Returns true if the specified node has the specified outward arc.
void beginUpdateBatch ()
 Notify observers that the datasource is about to send several notifications at once.
void endUpdateBatch ()
 Notify observers that the datasource has completed issuing a notification group.

Public Attributes

readonly attribute string URI
 The "URI" of the data source.

Protected Member Functions

nsresult createNode (const PRUnichar *str, nsIRDFNode **node)
nsresult createBlobNode (PRUint8 *value, PRUint32 &length, nsIRDFNode **node, nsIRDFService *rdfService)
nsresult NotifyPropertyChanged (nsIRDFResource *resource, nsIRDFResource *propertyResource, const PRUnichar *oldValue, const PRUnichar *newValue)
nsresult NotifyObservers (nsIRDFResource *subject, nsIRDFResource *property, nsIRDFNode *object, PRBool assert, PRBool change)
nsresult CreateProxyObservers ()
nsresult CreateProxyObserver (nsIRDFObserver *observer, nsIRDFObserver **proxyObserver)

Static Protected Member Functions

static PRBool assertEnumFunc (nsISupports *aElement, void *aData)
static PRBool unassertEnumFunc (nsISupports *aElement, void *aData)
static PRBool changeEnumFunc (nsISupports *aElement, void *aData)

Private Attributes

nsCOMPtr< nsISupportsArraymObservers
nsCOMPtr< nsISupportsArraymProxyObservers
PRLockmLock

Detailed Description

The addressbook data source.

Definition at line 51 of file nsAbRDFDataSource.h.


Constructor & Destructor Documentation

Definition at line 301 of file nsAbRDFDataSource.cpp.

Here is the call graph for this function:

Definition at line 309 of file nsAbRDFDataSource.cpp.

Here is the call graph for this function:


Member Function Documentation

Add an observer to this data source.

If the datasource supports observers, the datasource source should hold a strong reference to the observer.

Here is the caller graph for this function:

Get a cursor to iterate over all the arcs that point into a node.

Returns:
NS_OK unless a catastrophic error occurs. If the method returns NS_OK, you may assume that labels points to a valid (but possible empty) nsISimpleEnumerator object.

Here is the caller graph for this function:

Get a cursor to iterate over all the arcs that originate in a resource.

Returns:
NS_OK unless a catastrophic error occurs. If the method returns NS_OK, you may assume that labels points to a valid (but possible empty) nsISimpleEnumerator object.

Here is the caller graph for this function:

void nsIRDFDataSource::Assert ( in nsIRDFResource  aSource,
in nsIRDFResource  aProperty,
in nsIRDFNode  aTarget,
in boolean  aTruthValue 
) [inherited]

Add an assertion to the graph.

Here is the caller graph for this function:

PRBool nsAbRDFDataSource::assertEnumFunc ( nsISupports *  aElement,
void aData 
) [static, protected]

Definition at line 108 of file nsAbRDFDataSource.cpp.

{
  nsAbRDFNotification *note = (nsAbRDFNotification *)aData;
  nsIRDFObserver* observer = (nsIRDFObserver *)aElement;
  
  observer->OnAssert(note->datasource,
                     note->subject,
                     note->property,
                     note->object);
  return PR_TRUE;
}

Here is the caller graph for this function:

Notify observers that the datasource is about to send several notifications at once.

This must be followed by calling endUpdateBatch(), otherwise viewers will get out of sync.

void nsIRDFDataSource::Change ( in nsIRDFResource  aSource,
in nsIRDFResource  aProperty,
in nsIRDFNode  aOldTarget,
in nsIRDFNode  aNewTarget 
) [inherited]

Change an assertion from.

[aSource]--[aProperty]-->[aOldTarget]

to

[aSource]--[aProperty]-->[aNewTarget]

Here is the caller graph for this function:

PRBool nsAbRDFDataSource::changeEnumFunc ( nsISupports *  aElement,
void aData 
) [static, protected]

Definition at line 96 of file nsAbRDFDataSource.cpp.

{
  nsAbRDFNotification* note = (nsAbRDFNotification *)aData;
  nsIRDFObserver* observer = (nsIRDFObserver *)aElement;

  observer->OnChange(note->datasource,
                     note->subject,
                     note->property,
                     nsnull, note->object);
  return PR_TRUE;
}

Here is the caller graph for this function:

nsresult nsAbRDFDataSource::createBlobNode ( PRUint8 value,
PRUint32 length,
nsIRDFNode **  node,
nsIRDFService rdfService 
) [protected]

Definition at line 83 of file nsAbRDFDataSource.cpp.

{
  NS_ENSURE_ARG_POINTER(node);
  NS_ENSURE_ARG_POINTER(rdfService);

  *node = nsnull;
  nsCOMPtr<nsIRDFBlob> blob;
  nsresult rv = rdfService->GetBlobLiteral(value, length, getter_AddRefs(blob));
  NS_ENSURE_SUCCESS(rv,rv);
  NS_IF_ADDREF(*node = blob);
  return rv;
}

Here is the call graph for this function:

Here is the caller graph for this function:

nsresult nsAbRDFDataSource::createNode ( const PRUnichar str,
nsIRDFNode **  node 
) [protected]

Definition at line 68 of file nsAbRDFDataSource.cpp.

{
       *node = nsnull;
       nsresult rv; 
    nsCOMPtr<nsIRDFService> rdf(do_GetService("@mozilla.org/rdf/rdf-service;1", &rv)); 
       NS_ENSURE_SUCCESS(rv, rv); // always check this before proceeding 
       nsCOMPtr<nsIRDFLiteral> value;
       rv = rdf->GetLiteral(str, getter_AddRefs(value));
       if (NS_SUCCEEDED(rv)) 
       {
              NS_IF_ADDREF(*node = value);
       }
       return rv;
}

Here is the call graph for this function:

Here is the caller graph for this function:

nsresult nsAbRDFDataSource::CreateProxyObserver ( nsIRDFObserver observer,
nsIRDFObserver **  proxyObserver 
) [protected]

Definition at line 132 of file nsAbRDFDataSource.cpp.

{
       nsresult rv;

       nsCOMPtr<nsIEventQueueService> eventQSvc = do_GetService (NS_EVENTQUEUESERVICE_CONTRACTID, &rv);
       NS_ENSURE_SUCCESS(rv, rv);

       // Get the UI event queue
       nsCOMPtr<nsIEventQueue> uiQueue;
       rv = eventQSvc->GetSpecialEventQueue (
                     nsIEventQueueService::UI_THREAD_EVENT_QUEUE,
                     getter_AddRefs (uiQueue));
       NS_ENSURE_SUCCESS(rv, rv);

       nsCOMPtr<nsIProxyObjectManager> proxyMgr = 
              do_GetService(NS_XPCOMPROXY_CONTRACTID, &rv);
       NS_ENSURE_SUCCESS(rv, rv);

       // Proxy the observer on the UI queue
       /*
        * TODO
        * Currenly using PROXY_ASYNC, however
        * this can flood the event queue if
        * rate of events on the observer is
        * greater that the time to process the
        * events.
        * This causes the UI to pause.
        */
       rv = proxyMgr->GetProxyForObject (uiQueue,
              NS_GET_IID(nsIRDFObserver),
              observer,
              PROXY_ASYNC | PROXY_ALWAYS,
              (void** )proxyObserver);

       return rv;
}

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 170 of file nsAbRDFDataSource.cpp.

{
       nsresult rv = NS_OK;

       PRUint32 nObservers;
       mObservers->Count (&nObservers);

       if (!mProxyObservers)
       {
              rv = NS_NewISupportsArray(getter_AddRefs(mProxyObservers));
              NS_ENSURE_SUCCESS(rv, rv);
       }

       PRUint32 nProxyObservers;
       mProxyObservers->Count (&nProxyObservers);

       /*
        * For all the outstanding observers that
        * have not been proxied
        */
       for (PRUint32 i = nProxyObservers; i < nObservers; i++)
       {
              nsCOMPtr<nsISupports> supports;
              rv = mObservers->GetElementAt (i, getter_AddRefs (supports));
              NS_ENSURE_SUCCESS(rv, rv);

              nsCOMPtr<nsIRDFObserver> observer (do_QueryInterface (supports, &rv));
              NS_ENSURE_SUCCESS(rv, rv);
              
              // Create the proxy
              nsCOMPtr<nsIRDFObserver> proxyObserver;
              rv = CreateProxyObserver (observer, getter_AddRefs (proxyObserver));
              NS_ENSURE_SUCCESS(rv, rv);

              mProxyObservers->AppendElement(proxyObserver);
       }

       return rv;
}

Here is the call graph for this function:

Here is the caller graph for this function:

void nsIRDFDataSource::DoCommand ( in nsISupportsArray  aSources,
in nsIRDFResource  aCommand,
in nsISupportsArray  aArguments 
) [inherited]

Perform the specified command on set of sources.

Here is the caller graph for this function:

Notify observers that the datasource has completed issuing a notification group.

Returns the set of all commands defined for a given source.

Here is the caller graph for this function:

Retrieve all of the resources that the data source currently refers to.

Here is the caller graph for this function:

nsIRDFResource nsIRDFDataSource::GetSource ( in nsIRDFResource  aProperty,
in nsIRDFNode  aTarget,
in boolean  aTruthValue 
) [inherited]

Find an RDF resource that points to a given node over the specified arc & truth value.

Returns:
NS_RDF_NO_VALUE if there is no source that leads to the target with the specified property.

Here is the caller graph for this function:

nsISimpleEnumerator nsIRDFDataSource::GetSources ( in nsIRDFResource  aProperty,
in nsIRDFNode  aTarget,
in boolean  aTruthValue 
) [inherited]

Find all RDF resources that point to a given node over the specified arc & truth value.

Returns:
NS_OK unless a catastrophic error occurs. If the method returns NS_OK, you may assume that nsISimpleEnumerator points to a valid (but possibly empty) cursor.

Here is the caller graph for this function:

nsIRDFNode nsIRDFDataSource::GetTarget ( in nsIRDFResource  aSource,
in nsIRDFResource  aProperty,
in boolean  aTruthValue 
) [inherited]

Find a child of that is related to the source by the given arc arc and truth value.

Returns:
NS_RDF_NO_VALUE if there is no target accessable from the source via the specified property.

Here is the caller graph for this function:

nsISimpleEnumerator nsIRDFDataSource::GetTargets ( in nsIRDFResource  aSource,
in nsIRDFResource  aProperty,
in boolean  aTruthValue 
) [inherited]

Find all children of that are related to the source by the given arc arc and truth value.

Returns:
NS_OK unless a catastrophic error occurs. If the method returns NS_OK, you may assume that nsISimpleEnumerator points to a valid (but possibly empty) cursor.

Here is the caller graph for this function:

boolean nsIRDFDataSource::hasArcIn ( in nsIRDFNode  aNode,
in nsIRDFResource  aArc 
) [inherited]

Returns true if the specified node is pointed to by the specified arc.

Equivalent to enumerating ArcLabelsIn and comparing for the specified arc.

Returns true if the specified node has the specified outward arc.

Equivalent to enumerating ArcLabelsOut and comparing for the specified arc.

boolean nsIRDFDataSource::HasAssertion ( in nsIRDFResource  aSource,
in nsIRDFResource  aProperty,
in nsIRDFNode  aTarget,
in boolean  aTruthValue 
) [inherited]

Query whether an assertion exists in this graph.

Here is the caller graph for this function:

boolean nsIRDFDataSource::IsCommandEnabled ( in nsISupportsArray  aSources,
in nsIRDFResource  aCommand,
in nsISupportsArray  aArguments 
) [inherited]

Returns whether a given command is enabled for a set of sources.

Here is the caller graph for this function:

void nsIRDFDataSource::Move ( in nsIRDFResource  aOldSource,
in nsIRDFResource  aNewSource,
in nsIRDFResource  aProperty,
in nsIRDFNode  aTarget 
) [inherited]

'Move' an assertion from

[aOldSource]--[aProperty]-->[aTarget]

to

[aNewSource]--[aProperty]-->[aTarget]

Here is the caller graph for this function:

nsresult nsAbRDFDataSource::NotifyObservers ( nsIRDFResource subject,
nsIRDFResource property,
nsIRDFNode object,
PRBool  assert,
PRBool  change 
) [protected]

Definition at line 210 of file nsAbRDFDataSource.cpp.

{
       NS_ASSERTION(!(change && assert),
                 "Can't change and assert at the same time!\n");

       if(!mLock)
       {
              NS_ERROR("Error in AutoLock resource in nsAbRDFDataSource::NotifyObservers()");
              return NS_ERROR_OUT_OF_MEMORY;
       }

       nsresult rv;

       nsAutoLock lockGuard (mLock);

       if (!mObservers)
              return NS_OK;


       // Get the current thread
       nsCOMPtr<nsIThread> currentThread;
       rv = nsIThread::GetCurrent (getter_AddRefs(currentThread));
       NS_ENSURE_SUCCESS (rv, rv);

       // Get the main thread, which is the UI thread
       /*
        * TODO
        * Is the main thread always guaranteed to be
        * the UI thread?
        *
        * Note that this also binds the data source
        * to the UI which is supposedly the only
        * place where it is used, but what about
        * RDF datasources that are not UI specific
        * but are used in the UI?
        */
       nsCOMPtr<nsIThread> uiThread;
       rv = nsIThread::GetMainThread (getter_AddRefs(uiThread));
       NS_ENSURE_SUCCESS (rv, rv);

       nsCOMPtr<nsISupportsArray> observers;
       if (currentThread == uiThread)
       {
              /*
               * Since this is the UI Thread use the
               * observers list directly for performance
               */
              observers = mObservers;
       }
       else
       {
              /*
               * This is a different thread to the UI
               * thread need to use proxies to the
               * observers
               *
               * Create the proxies
               */
              rv = CreateProxyObservers ();
              NS_ENSURE_SUCCESS (rv, rv);

              observers = mProxyObservers;
       }

       nsAbRDFNotification note = { this, subject, property, object };
       if (change)
              observers->EnumerateForwards(changeEnumFunc, &note);
       else if (assert)
              observers->EnumerateForwards(assertEnumFunc, &note);
       else
              observers->EnumerateForwards(unassertEnumFunc, &note);

       return NS_OK;
}

Here is the call graph for this function:

Here is the caller graph for this function:

nsresult nsAbRDFDataSource::NotifyPropertyChanged ( nsIRDFResource resource,
nsIRDFResource propertyResource,
const PRUnichar oldValue,
const PRUnichar newValue 
) [protected]

Definition at line 289 of file nsAbRDFDataSource.cpp.

{
       nsCOMPtr<nsIRDFNode> newValueNode;
       createNode(newValue, getter_AddRefs(newValueNode));
       NotifyObservers(resource, propertyResource, newValueNode, PR_FALSE, PR_TRUE);
       return NS_OK;
}

Here is the call graph for this function:

Remove an observer from this data source.

Here is the caller graph for this function:

void nsIRDFDataSource::Unassert ( in nsIRDFResource  aSource,
in nsIRDFResource  aProperty,
in nsIRDFNode  aTarget 
) [inherited]

Remove an assertion from the graph.

Here is the caller graph for this function:

PRBool nsAbRDFDataSource::unassertEnumFunc ( nsISupports *  aElement,
void aData 
) [static, protected]

Definition at line 120 of file nsAbRDFDataSource.cpp.

{
  nsAbRDFNotification* note = (nsAbRDFNotification *)aData;
  nsIRDFObserver* observer = (nsIRDFObserver *)aElement;

  observer->OnUnassert(note->datasource,
                       note->subject,
                       note->property,
                       note->object);
  return PR_TRUE;
}

Here is the caller graph for this function:


Member Data Documentation

Definition at line 92 of file nsAbRDFDataSource.h.

Definition at line 89 of file nsAbRDFDataSource.h.

Definition at line 90 of file nsAbRDFDataSource.h.

readonly attribute string nsIRDFDataSource::URI [inherited]

The "URI" of the data source.

This used by the RDF service's |GetDataSource()| method to cache datasources.

Definition at line 56 of file nsIRDFDataSource.idl.


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