|
reSIProcate/DialogUsageManager
9694
|
Trivial implementation of a persistence manager. More...
#include <InMemoryRegistrationDatabase.hxx>


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< Uri > | mLockedRecords |
| Mutex | mLockedRecordsMutex |
| Condition | mRecordUnlocked |
| bool | mCheckExpiry |
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.
typedef std::map<Uri,ContactList *> resip::InMemoryRegistrationDatabase::database_map_t [private] |
Definition at line 51 of file InMemoryRegistrationDatabase.hxx.
| InMemoryRegistrationDatabase::InMemoryRegistrationDatabase | ( | bool | checkExpiry = false | ) |
| checkExpiry | if 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] |
| 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;
}

| 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;
}

| 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);
}

| 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);
}

| 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;
}
}
}

| 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();
}

| 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;
}
bool resip::InMemoryRegistrationDatabase::mCheckExpiry [private] |
Definition at line 59 of file InMemoryRegistrationDatabase.hxx.
Referenced by findNotExpired().
Definition at line 52 of file InMemoryRegistrationDatabase.hxx.
Referenced by addAor(), aorIsRegistered(), findNotExpired(), getAors(), getContacts(), lockRecord(), removeAor(), removeContact(), unlockRecord(), updateContact(), and ~InMemoryRegistrationDatabase().
Definition at line 53 of file InMemoryRegistrationDatabase.hxx.
Referenced by addAor(), aorIsRegistered(), getAors(), getContacts(), lockRecord(), removeAor(), removeContact(), unlockRecord(), and updateContact().
std::set<Uri> resip::InMemoryRegistrationDatabase::mLockedRecords [private] |
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().
1.7.5.1