Added option to return a data sniffer safe and referenced.

git-svn-id: http://voip.null.ro/svn/yate@6175 acf43c95-373e-0410-b603-e72c3f656dc1
This commit is contained in:
paulc 2017-01-26 15:32:39 +00:00
parent b2c0b343a5
commit d71d9f38e4
4 changed files with 15 additions and 6 deletions

View File

@ -1013,6 +1013,15 @@ bool DataEndpoint::delSniffer(DataConsumer* sniffer)
return true;
}
DataConsumer* DataEndpoint::getSniffer(const String& name, bool ref)
{
if (name.null())
return 0;
Lock lock(s_dataMutex);
DataConsumer* sniffer = static_cast<DataConsumer*>(m_sniffers[name]);
return (ref && sniffer && !sniffer->ref()) ? 0 : sniffer;
}
void DataEndpoint::clearSniffers()
{
Lock lock(s_dataMutex);

View File

@ -246,15 +246,15 @@ bool AttachHandler::received(Message& msg)
if (snif) {
RefPointer<DataEndpoint> de = ch->setEndpoint();
// try to reinit sniffer if one already exists
MrcpConsumer* c = static_cast<MrcpConsumer*>(de->getSniffer(snif));
MrcpConsumer* c = static_cast<MrcpConsumer*>(de->getSniffer(snif,true));
if (c)
c->init(msg);
else {
c = new MrcpConsumer(ch->id(),snif,msg.getValue("format","slin"));
if (c->init(msg))
de->addSniffer(c);
c->deref();
}
c->deref();
}
return msg.getBoolValue("single");
}

View File

@ -555,7 +555,7 @@ bool AttachHandler::received(Message& msg)
if (snif) {
de = ch->setEndpoint();
// try to reinit sniffer if one already exists
ToneConsumer* c = static_cast<ToneConsumer*>(de->getSniffer(snif));
ToneConsumer* c = static_cast<ToneConsumer*>(de->getSniffer(snif,true));
if (c) {
c->init();
c->setFaxDivert(msg);
@ -564,8 +564,8 @@ bool AttachHandler::received(Message& msg)
c = new ToneConsumer(ch->id(),snif);
c->setFaxDivert(msg);
de->addSniffer(c);
c->deref();
}
c->deref();
}
return msg.getBoolValue("single");
}

View File

@ -1054,10 +1054,10 @@ public:
/**
* Find a sniffer by name
* @param name Name of the sniffer to find
* @param ref Increment the reference counter before returning
* @return Pointer to DataConsumer or NULL if not found
*/
inline DataConsumer* getSniffer(const String& name)
{ return static_cast<DataConsumer*>(m_sniffers[name]); }
DataConsumer* getSniffer(const String& name, bool ref = false);
/**
* Removes all sniffers from the list and dereferences them