Back to index

lightning-sunbird  0.9+nobinonly
Public Member Functions | Protected Member Functions | Protected Attributes
tmQueue Class Reference

This class isn't so much a queue as it is storage for transactions. More...

#include <tmQueue.h>

Collaboration diagram for tmQueue:
Collaboration graph
[legend]

List of all members.

Public Member Functions

 tmQueue ()
 Set the internal state to default values.
virtual ~tmQueue ()
 Reclaim the memory allocated in Init().
PRInt32 Init (const char *aName, PRUint32 aID, tmTransactionManager *aTM)
 Initialize internal storage vectors and set the name of the queue and the pointer to the TM container.
PRInt32 AttachClient (PRUint32 aClientID)
 Adds the clientID to the list of queue listeners.
PRInt32 DetachClient (PRUint32 aClientID)
 Removes the client from the list of queue listeners.
void FlushQueue (PRUint32 aClientID)
 Removes all the transactions being held in the queue.
PRInt32 PostTransaction (tmTransaction *aTrans)
 Places the transaction passed in on the queue.
PRUint32 GetID () const
const char * GetName () const

Protected Member Functions

PRBool IsAttached (PRUint32 aClientID)
 Helper method to determine if the client has already attached.

Protected Attributes

tmVector mTransactions
tmVector mListeners
PRUint32 mID
char * mName
tmTransactionManagermTM

Detailed Description

This class isn't so much a queue as it is storage for transactions.

It is set up to recieve and store transactions in a growing collection (using tmVectors). Different messages can be recieved from the Transaction Manager(TM) the queue belongs to which can add and remove listeners, empty the queue (flush), and add messages to the queue.

See the documentation in tmTransactionService.h for details on the messages you can send to and recieve from the queues in the TM

Definition at line 58 of file tmQueue.h.


Constructor & Destructor Documentation

tmQueue::tmQueue ( ) [inline]

Set the internal state to default values.

Init() must be called after construction to allocate the storage and set the name and ID.

Definition at line 70 of file tmQueue.h.

: mID(0), mName(nsnull), mTM(nsnull) { }
tmQueue::~tmQueue ( ) [virtual]

Reclaim the memory allocated in Init().

Destroys the transactions in the transaction storage and the ids in the listener storage

Definition at line 47 of file tmQueue.cpp.

                  {

  // empty the vectors
  PRUint32 index = 0;
  PRUint32 size = mTransactions.Size();
  for ( ; index < size ; index++) {
    if (mTransactions[index])
      delete (tmTransaction *)mTransactions[index];
  }

  // don't need to delete the mListeners because 
  // we just insert PRUint32s, no allocation

  mTM = nsnull;
  mID = 0;
  if (mName)
    PL_strfree(mName);
}

Here is the call graph for this function:


Member Function Documentation

Adds the clientID to the list of queue listeners.

A reply is created and sent to the client. The reply contains both the name of the queue and the id, so the client can match the id to the name and then use the id in all further communications to the queue. All current transactions in the queue are then sent to the client.

If the client was already attached the reply is sent, but not the outstanding transactions, the assumption being made that all transactions have already been sent to the client.

The reply is sent for all cases, with the return value in the status field.

Returns:
>= 0 if the client was attached successfully
-1 if the client was not attached
-2 if the client was already attached

Definition at line 84 of file tmQueue.cpp.

                                        {

  PRInt32 status = NS_OK;                 // success of adding client

  if (!IsAttached(aClientID)) {
    // add the client to the listener list -- null safe call
    status = mListeners.Append((void*) aClientID);
  }
  else
    status = -2;

  // create & init a reply transaction
  tmTransaction trans;
  if (NS_SUCCEEDED(trans.Init(aClientID,        // owner's ipc ID
                              mID,              // client gets our ID
                              TM_ATTACH_REPLY,  // action
                              status,           // success of the add
                              (PRUint8*)mName,  // client matches name to ID
                              PL_strlen(mName)+1))) {
    // send the reply
    mTM->SendTransaction(aClientID, &trans);
  }

  // if we successfully added the client - send all current transactions
  if (status >= 0) { // append returns the index of the added element
    
    PRUint32 size = mTransactions.Size();
    for (PRUint32 index = 0; index < size; index++) {
      if (mTransactions[index])
        mTM->SendTransaction(aClientID, (tmTransaction*) mTransactions[index]);
    }
  }
  return status;
}

Here is the call graph for this function:

Here is the caller graph for this function:

Removes the client from the list of queue listeners.

A reply is created and sent to the client to indicate the success of the removal.

The reply is sent for all cases, with the status field set to either -1 or NS_OK.

Returns:
NS_OK on success
-1 if client is not attached to this queue
TM_SUCCESS_DELETE_QUEUE if there are no more listeners, instructing the Transaction Mangaer to delete the queue.

Definition at line 120 of file tmQueue.cpp.

                                        {

  PRUint32 size = mListeners.Size();
  PRUint32 id = 0;
  PRInt32 status = -1;

  for (PRUint32 index = 0; index < size; index++) {
    id = (PRUint32)NS_PTR_TO_INT32(mListeners[index]);
    if(id == aClientID) {
      mListeners.RemoveAt(index);
      status = NS_OK;
      break;
    }
  }

  tmTransaction trans;
  if (NS_SUCCEEDED(trans.Init(aClientID,
                               mID,
                               TM_DETACH_REPLY,
                               status,
                               nsnull,
                               0))) {
    // send the reply
    mTM->SendTransaction(aClientID, &trans);
  }

  // if we've removed all the listeners, remove the queue.
  if (mListeners.Size() == 0)
    return TM_SUCCESS_DELETE_QUEUE;
  return status;
}

Here is the call graph for this function:

Here is the caller graph for this function:

Removes all the transactions being held in the queue.

A reply is created and sent to the client to indicate the completion of the operation.

Definition at line 153 of file tmQueue.cpp.

                                      {

  if(!IsAttached(aClientID))
    return;

  PRUint32 size = mTransactions.Size();
  for (PRUint32 index = 0; index < size; index++)
    if (mTransactions[index])
      delete (tmTransaction*)mTransactions[index];

  mTransactions.Clear();

  tmTransaction trans;
  if (NS_SUCCEEDED(trans.Init(aClientID,
                               mID, 
                               TM_FLUSH_REPLY, 
                               NS_OK,
                               nsnull,
                               0))) {
    mTM->SendTransaction(aClientID, &trans);
  }
}

Here is the call graph for this function:

Here is the caller graph for this function:

PRUint32 tmQueue::GetID ( ) const [inline]
Returns:
the ID of the queue

Definition at line 155 of file tmQueue.h.

{ return mID; }
const char* tmQueue::GetName ( ) const [inline]
Returns:
the name of the queue

Definition at line 160 of file tmQueue.h.

{ return mName; }

Here is the caller graph for this function:

PRInt32 tmQueue::Init ( const char *  aName,
PRUint32  aID,
tmTransactionManager aTM 
)

Initialize internal storage vectors and set the name of the queue and the pointer to the TM container.

Returns:
NS_OK if everything succeeds
-1 if initialization fails

Definition at line 70 of file tmQueue.cpp.

                                                                        {
  PR_ASSERT(mTM == nsnull);

  if (NS_SUCCEEDED(mTransactions.Init()) &&
      NS_SUCCEEDED(mListeners.Init()) &&
      ((mName = PL_strdup(aName)) != nsnull) ) {
    mTM = aTM;
    mID = aID;
    return NS_OK;
  }
  return -1;
}

Here is the call graph for this function:

Here is the caller graph for this function:

PRBool tmQueue::IsAttached ( PRUint32  aClientID) [protected]

Helper method to determine if the client has already attached.

Returns:
PR_TRUE if the client is attached to the queue.
PR_FALSE if the client is not attached to the queue.

Definition at line 214 of file tmQueue.cpp.

                                      {
  // XXX could be an issue if the aClientID is 0 and there
  // is a "hole" in the mListeners vector. - may NEED to store PRUint32*s
  PRUint32 size = mListeners.Size();
  for (PRUint32 index = 0; index < size; index++) {
    if (aClientID == (PRUint32)NS_PTR_TO_INT32(mListeners[index]))
      return PR_TRUE;
  }
  return PR_FALSE;
}

Here is the call graph for this function:

Here is the caller graph for this function:

Places the transaction passed in on the queue.

Takes ownership of the transaction, deletes it in the destructor. A reply is created and sent to the client to indicate the success of the posting of the transaction.

The reply is sent for all cases, with the status field containing the return value.

Returns:
>= 0 if the message was posted properly.
-1 if the client posting is not attached to this queue, if the transaction has been posted to the wrong queue or if an error occured when trying to add the post to the internal storage.

Definition at line 177 of file tmQueue.cpp.

                                              {

  PRInt32 status = -1;
  PRUint32 ownerID = aTrans->GetOwnerID();

  // if we are attached, have the right queue and have successfully
  //    appended the transaction to the queue, send the transaction
  //    to all the listeners.

  if (IsAttached(ownerID) && aTrans->GetQueueID() == mID)
    status = mTransactions.Append(aTrans);

  if (status >= 0) {
    // send the transaction to all members of mListeners except the owner
    PRUint32 size = mListeners.Size();
    PRUint32 id = 0;
    for (PRUint32 index = 0; index < size; index++) {
      id = (PRUint32)NS_PTR_TO_INT32(mListeners[index]);
      if (ownerID != id)
        mTM->SendTransaction(id, aTrans);
    }
  }

  tmTransaction trans;
  if (NS_SUCCEEDED(trans.Init(ownerID,
                              mID,
                              TM_POST_REPLY,
                              status,
                              nsnull,
                              0))) {
    // send the reply
    mTM->SendTransaction(ownerID, &trans);
  }
  return status;
}

Here is the call graph for this function:

Here is the caller graph for this function:


Member Data Documentation

PRUint32 tmQueue::mID [protected]

Definition at line 180 of file tmQueue.h.

Definition at line 177 of file tmQueue.h.

char* tmQueue::mName [protected]

Definition at line 181 of file tmQueue.h.

Definition at line 182 of file tmQueue.h.

Definition at line 176 of file tmQueue.h.


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