Avoiding a potential performance loss in unused message notifiers.

git-svn-id: http://voip.null.ro/svn/yate@678 acf43c95-373e-0410-b603-e72c3f656dc1
This commit is contained in:
paulc 2006-02-02 14:15:29 +00:00
parent 10a75ea364
commit e7e9d8a560
2 changed files with 15 additions and 1 deletions

View File

@ -26,7 +26,7 @@
using namespace TelEngine;
Message::Message(const char* name, const char* retval)
: NamedList(name), m_return(retval), m_data(0)
: NamedList(name), m_return(retval), m_data(0), m_notify(false)
{
XDebug(DebugAll,"Message::Message(\"%s\",\"%s\") [%p]",name,retval,this);
}
@ -48,6 +48,7 @@ void Message::userData(RefObject* data)
{
if (data == m_data)
return;
m_notify = false;
RefObject* tmp = m_data;
if (data && !data->ref())
data = 0;
@ -58,6 +59,8 @@ void Message::userData(RefObject* data)
void Message::dispatched(bool accepted)
{
if (!m_notify)
return;
MessageNotifier* hook = YOBJECT(MessageNotifier,m_data);
if (hook)
hook->dispatched(*this,accepted);

View File

@ -252,6 +252,7 @@ public:
/**
* Set obscure data associated with the message.
* The user data is reference counted to avoid stray pointers.
* Note that setting new user data will disable any notification.
* @param data Pointer to arbitrary user data
*/
void userData(RefObject* data);
@ -264,6 +265,15 @@ public:
inline void* userObject(const String& name) const
{ return m_data ? m_data->getObject(name) : 0; }
/**
* Enable or disable notification of any @ref MessageNotifier that was set
* as user data. This method must be called after userData()
* @param notify True to have the message call the notifier
*/
inline void setNotify(bool notify = true)
{ m_notify = notify; }
/**
* Retrive a reference to the creation time of the message.
* @return A reference to the Time when the message was created
@ -336,6 +346,7 @@ private:
String m_return;
Time m_time;
RefObject* m_data;
bool m_notify;
void commonEncode(String& str) const;
int commonDecode(const char* str, int offs);
};