The resource list is now keeping its items ordered by their priority (higher priority first).

git-svn-id: http://voip.null.ro/svn/yate@2501 acf43c95-373e-0410-b603-e72c3f656dc1
This commit is contained in:
marian 2009-03-02 09:44:05 +00:00
parent 3de7f75ef7
commit ea702fe128
2 changed files with 13 additions and 11 deletions

View File

@ -1237,15 +1237,6 @@ void JIDResource::addTo(XMLElement* element, bool addInfo)
/**
* JIDResourceList
*/
// Add a resource to the list
bool JIDResourceList::add(const String& name)
{
Lock lock(this);
if (get(name))
return false;
m_resources.append(new JIDResource(name));
return true;
}
// Add a resource to the list
bool JIDResourceList::add(JIDResource* resource)
@ -1257,7 +1248,17 @@ bool JIDResourceList::add(JIDResource* resource)
TelEngine::destruct(resource);
return false;
}
m_resources.append(resource);
// Add resource in the proper place
ObjList* o = m_resources.skipNull();
for (; o; o = o->skipNext()) {
JIDResource* tmp = static_cast<JIDResource*>(o->get());
if (resource->priority() >= tmp->priority())
break;
}
if (o)
o->insert(resource);
else
m_resources.append(resource);
return true;
}

View File

@ -2248,7 +2248,8 @@ public:
* @param name The resource name
* @return False if the the resource already exists in the list
*/
bool add(const String& name);
inline bool add(const String& name)
{ return add(new JIDResource(name)); }
/**
* Add a resource to the list if not already there.