reSIProcate/DialogUsageManager  9694
Public Member Functions | Protected Member Functions | Private Types | Private Attributes
resip::InMemoryRegistrationDatabase Class Reference

Trivial implementation of a persistence manager. More...

#include <InMemoryRegistrationDatabase.hxx>

Inheritance diagram for resip::InMemoryRegistrationDatabase:
Inheritance graph
[legend]
Collaboration diagram for resip::InMemoryRegistrationDatabase:
Collaboration graph
[legend]

List of all members.

Public Member Functions

 InMemoryRegistrationDatabase (bool checkExpiry=false)
virtual ~InMemoryRegistrationDatabase ()
virtual void addAor (const Uri &aor, const ContactList &contacts)
virtual void removeAor (const Uri &aor)
virtual bool aorIsRegistered (const Uri &aor)
virtual void lockRecord (const Uri &aor)
virtual void unlockRecord (const Uri &aor)
virtual update_status_t updateContact (const resip::Uri &aor, const ContactInstanceRecord &rec)
virtual void removeContact (const Uri &aor, const ContactInstanceRecord &rec)
virtual void getContacts (const Uri &aor, ContactList &container)
virtual void getAors (UriList &container)
 return all the AOR in the DB

Protected Member Functions

database_map_t::iterator findNotExpired (const Uri &aor)
 Find aor in mDatabase Before returning the iterator pointing to aor, delete all expired contacts.

Private Types

typedef std::map< Uri,
ContactList * > 
database_map_t

Private Attributes

database_map_t mDatabase
Mutex mDatabaseMutex
std::set< UrimLockedRecords
Mutex mLockedRecordsMutex
Condition mRecordUnlocked
bool mCheckExpiry

Detailed Description

Trivial implementation of a persistence manager.

This class keeps all registrations in memory, and has no schemes for disk storage or replication of any kind. It's good for testing, but probably inappropriate for any commercially deployable products.

Definition at line 21 of file InMemoryRegistrationDatabase.hxx.


Member Typedef Documentation

typedef std::map<Uri,ContactList *> resip::InMemoryRegistrationDatabase::database_map_t [private]

Definition at line 51 of file InMemoryRegistrationDatabase.hxx.


Constructor & Destructor Documentation

InMemoryRegistrationDatabase::InMemoryRegistrationDatabase ( bool  checkExpiry = false)
Parameters:
checkExpiryif set, then the methods aorIsRegistered() and getContacts() will check that contacts are not expired before returning an answer.

Definition at line 12 of file InMemoryRegistrationDatabase.cxx.

                                                                           :
   mCheckExpiry(checkExpiry)
{
}
InMemoryRegistrationDatabase::~InMemoryRegistrationDatabase ( ) [virtual]

Definition at line 17 of file InMemoryRegistrationDatabase.cxx.

References mDatabase.

{
   for( database_map_t::const_iterator it = mDatabase.begin();
        it != mDatabase.end(); it++)
   {
      delete it->second;
   }
   mDatabase.clear();
}

Member Function Documentation

void InMemoryRegistrationDatabase::addAor ( const Uri aor,
const ContactList &  contacts 
) [virtual]

Implements resip::RegistrationPersistenceManager.

Definition at line 28 of file InMemoryRegistrationDatabase.cxx.

References mDatabase, and mDatabaseMutex.

{
  Lock g(mDatabaseMutex);
  mDatabase[aor] = new ContactList(contacts);
}
bool InMemoryRegistrationDatabase::aorIsRegistered ( const Uri aor) [virtual]

Implements resip::RegistrationPersistenceManager.

Definition at line 68 of file InMemoryRegistrationDatabase.cxx.

References findNotExpired(), mDatabase, and mDatabaseMutex.

{
  Lock g(mDatabaseMutex);
  database_map_t::iterator i = findNotExpired(aor);
  if (i == mDatabase.end() || i->second == 0)
  {
    return false;
  }
  return true;
}

Here is the call graph for this function:

InMemoryRegistrationDatabase::database_map_t::iterator InMemoryRegistrationDatabase::findNotExpired ( const Uri aor) [protected]

Find aor in mDatabase Before returning the iterator pointing to aor, delete all expired contacts.

Definition at line 242 of file InMemoryRegistrationDatabase.cxx.

References expired(), mCheckExpiry, and mDatabase.

Referenced by aorIsRegistered(), and getContacts().

{
   database_map_t::iterator i;
   i = mDatabase.find(aor);
   if (i == mDatabase.end() || i->second == 0) 
   {
      return i;
   }
   if(mCheckExpiry)
   {
      ContactList *contacts = i->second;
#ifdef __SUNPRO_CC
      contacts->remove_if(expired);
#else
      contacts->remove_if(RemoveIfExpired());
#endif
   }
   return i;
}

Here is the call graph for this function:

void InMemoryRegistrationDatabase::getAors ( InMemoryRegistrationDatabase::UriList container) [virtual]

return all the AOR in the DB

Implements resip::RegistrationPersistenceManager.

Definition at line 56 of file InMemoryRegistrationDatabase.cxx.

References mDatabase, and mDatabaseMutex.

{
   container.clear();
   Lock g(mDatabaseMutex);
   for( database_map_t::const_iterator it = mDatabase.begin();
        it != mDatabase.end(); it++)
   {
      container.push_back(it->first);
   }
}
void InMemoryRegistrationDatabase::getContacts ( const Uri aor,
ContactList &  container 
) [virtual]

Implements resip::RegistrationPersistenceManager.

Definition at line 199 of file InMemoryRegistrationDatabase.cxx.

References findNotExpired(), mDatabase, and mDatabaseMutex.

{
  Lock g(mDatabaseMutex);
  database_map_t::iterator i = findNotExpired(aor);
  if (i == mDatabase.end() || i->second == 0)
  {
      container.clear();
      return;
  }
   container = *(i->second);
}

Here is the call graph for this function:

void InMemoryRegistrationDatabase::lockRecord ( const Uri aor) [virtual]

Implements resip::RegistrationPersistenceManager.

Definition at line 80 of file InMemoryRegistrationDatabase.cxx.

References mDatabase, mDatabaseMutex, mLockedRecords, mLockedRecordsMutex, mRecordUnlocked, and resip::Condition::wait().

{
  Lock g2(mLockedRecordsMutex);

  {
    Lock g1(mDatabaseMutex);
    // This forces insertion if the record does not yet exist.
    mDatabase[aor];
  }

  while (mLockedRecords.count(aor))
  {
    mRecordUnlocked.wait(mLockedRecordsMutex);
  }

  mLockedRecords.insert(aor);
}

Here is the call graph for this function:

void InMemoryRegistrationDatabase::removeAor ( const Uri aor) [virtual]

Implements resip::RegistrationPersistenceManager.

Definition at line 36 of file InMemoryRegistrationDatabase.cxx.

References DebugLog, mDatabase, and mDatabaseMutex.

Referenced by removeContact().

{
  database_map_t::iterator i;

  Lock g(mDatabaseMutex);
  i = mDatabase.find(aor);
  //DebugLog (<< "Removing registration bindings " << aor);
  if (i != mDatabase.end())
  {
     if (i->second)
     {
        DebugLog (<< "Removed " << i->second->size() << " entries");
        delete i->second;
        // Setting this to 0 causes it to be removed when we unlock the AOR.
        i->second = 0;
     }
  }
}
void InMemoryRegistrationDatabase::removeContact ( const Uri aor,
const ContactInstanceRecord rec 
) [virtual]

Implements resip::RegistrationPersistenceManager.

Definition at line 164 of file InMemoryRegistrationDatabase.cxx.

References mDatabase, mDatabaseMutex, and removeAor().

{
  ContactList *contactList = 0;

  {
    Lock g(mDatabaseMutex);

    database_map_t::iterator i;
    i = mDatabase.find(aor);
    if (i == mDatabase.end() || i->second == 0)
    {
      return;
    }
    contactList = i->second;
  }

  ContactList::iterator j;

  // See if the contact is present. We use URI matching rules here.
  for (j = contactList->begin(); j != contactList->end(); j++)
  {
    if (*j == rec)
    {
      contactList->erase(j);
      if (contactList->empty())
      {
        removeAor(aor);
      }
      return;
    }
  }
}

Here is the call graph for this function:

void InMemoryRegistrationDatabase::unlockRecord ( const Uri aor) [virtual]

Implements resip::RegistrationPersistenceManager.

Definition at line 99 of file InMemoryRegistrationDatabase.cxx.

References resip::Condition::broadcast(), mDatabase, mDatabaseMutex, mLockedRecords, mLockedRecordsMutex, and mRecordUnlocked.

{
  Lock g2(mLockedRecordsMutex);

  {
    Lock g1(mDatabaseMutex);
    // If the pointer is null, we remove the record from the map.
    database_map_t::iterator i = mDatabase.find(aor);

    // The record must have been inserted when we locked it in the first place
    assert (i != mDatabase.end());

    if (i->second == 0)
    {
      mDatabase.erase(i);
    }
  }

  mLockedRecords.erase(aor);
  mRecordUnlocked.broadcast();
}

Here is the call graph for this function:

RegistrationPersistenceManager::update_status_t InMemoryRegistrationDatabase::updateContact ( const resip::Uri aor,
const ContactInstanceRecord rec 
) [virtual]

Implements resip::RegistrationPersistenceManager.

Definition at line 122 of file InMemoryRegistrationDatabase.cxx.

References resip::RegistrationPersistenceManager::CONTACT_CREATED, resip::RegistrationPersistenceManager::CONTACT_UPDATED, mDatabase, and mDatabaseMutex.

{
  ContactList *contactList = 0;

  {
    Lock g(mDatabaseMutex);

    database_map_t::iterator i;
    i = mDatabase.find(aor);
    if (i == mDatabase.end() || i->second == 0)
    {
      contactList = new ContactList();
      mDatabase[aor] = contactList;
    }
    else
    {
      contactList = i->second;
    }

  }

  assert(contactList);

  ContactList::iterator j;

  // See if the contact is already present. We use URI matching rules here.
  for (j = contactList->begin(); j != contactList->end(); j++)
  {
    if (*j == rec)
    {
      *j=rec;
      return CONTACT_UPDATED;
    }
  }

  // This is a new contact, so we add it to the list.
  contactList->push_back(rec);
  return CONTACT_CREATED;
}

Member Data Documentation

Definition at line 59 of file InMemoryRegistrationDatabase.hxx.

Referenced by findNotExpired().

Definition at line 55 of file InMemoryRegistrationDatabase.hxx.

Referenced by lockRecord(), and unlockRecord().

Definition at line 56 of file InMemoryRegistrationDatabase.hxx.

Referenced by lockRecord(), and unlockRecord().

Definition at line 57 of file InMemoryRegistrationDatabase.hxx.

Referenced by lockRecord(), and unlockRecord().


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