Yate
Message Class Reference

A message container class. More...

#include <yatengine.h>

Inheritance diagram for Message:
NamedList String GenObject

Public Member Functions

 Message (const char *name, const char *retval=0, bool broadcast=false)
 
 Message (const Message &original)
 
 Message (const Message &original, bool broadcast)
 
 ~Message ()
 
virtual void * getObject (const String &name) const
 
StringretValue ()
 
const StringretValue () const
 
RefObjectuserData () const
 
void userData (RefObject *data)
 
void * userObject (const String &name) const
 
void setNotify (bool notify=true)
 
bool broadcast () const
 
void resetMsg (Time tm=Time::now())
 
TimemsgTime ()
 
const TimemsgTime () const
 
TimemsgTimeEnqueue ()
 
const TimemsgTimeEnqueue () const
 
TimemsgTimeDispatch ()
 
const TimemsgTimeDispatch () const
 
Messageoperator= (const char *value)
 
String encode (const char *id) const
 
String encode (bool received, const char *id) const
 
int decode (const char *str, String &id)
 
int decode (const char *str, bool &received, const char *id)
 
- Public Member Functions inherited from NamedList
 NamedList (const char *name)
 
 NamedList (const NamedList &original)
 
 NamedList (const char *name, const NamedList &original, const String &prefix)
 
NamedListoperator= (const NamedList &value)
 
unsigned int length () const
 
unsigned int count () const
 
void clearParams ()
 
NamedListaddParam (NamedString *param)
 
NamedListaddParam (const char *name, const char *value, bool emptyOK=true)
 
NamedListaddParam (const char *name, int64_t value)
 
NamedListaddParam (const char *name, uint64_t value)
 
NamedListaddParam (const char *name, int32_t value)
 
NamedListaddParam (const char *name, uint32_t value)
 
NamedListaddParam (const char *name, double value)
 
NamedListaddParam (const char *name, bool value)
 
NamedListaddParam (const char *name, unsigned int flags, const TokenDict *tokens, bool unknownflag=true)
 
NamedListaddParam (const char *name, uint64_t flags, const TokenDict64 *tokens, bool unknownflag=true)
 
NamedListaddParamHex (const char *name, const void *buf, unsigned int len, char sep=0)
 
NamedListsetParam (NamedString *param)
 
NamedListsetParam (const String &name, const char *value)
 
NamedListsetParam (const String &name, int64_t value)
 
NamedListsetParam (const String &name, uint64_t value)
 
NamedListsetParam (const String &name, int32_t value)
 
NamedListsetParam (const String &name, uint32_t value)
 
NamedListsetParam (const String &name, double value)
 
NamedListsetParam (const String &name, bool value)
 
NamedListsetParam (const String &name, unsigned int flags, const TokenDict *tokens, bool unknownflag=true)
 
NamedListsetParam (const String &name, uint64_t flags, const TokenDict64 *tokens, bool unknownflag=true)
 
NamedListsetParamHex (const String &name, const void *buf, unsigned int len, char sep=0)
 
NamedListclearParam (const String &name, char childSep=0, const String *value=0)
 
NamedListclearParam (NamedString *param, bool delParam=true)
 
NamedListcopyParam (const NamedList &original, const String &name, char childSep=0)
 
NamedListcopyParams (bool replace, const NamedList &original, bool copyUserData=false)
 
NamedListcopyParams (const NamedList &original)
 
NamedListcopyParams (const NamedList &original, ObjList *list, char childSep=0)
 
NamedListcopyParams (const NamedList &original, const String &list, char childSep=0)
 
NamedListcopySubParams (const NamedList &original, const String &prefix, bool skipPrefix=true, bool replace=false)
 
bool hasSubParams (const char *prefix) const
 
int getIndex (const NamedString *param) const
 
int getIndex (const String &name) const
 
NamedStringgetParam (const String &name) const
 
NamedStringgetParam (unsigned int index) const
 
const Stringoperator[] (const String &name) const
 
const char * getValue (const String &name, const char *defvalue=0) const
 
int getIntValue (const String &name, int defvalue=0, int minvalue=INT_MIN, int maxvalue=INT_MAX, bool clamp=true) const
 
int getIntValue (const String &name, const TokenDict *tokens, int defvalue=0) const
 
int getIntValue (const String &name, const TokenDictStr *tokens, int defvalue=0) const
 
int64_t getInt64Value (const String &name, int64_t defvalue=0, int64_t minvalue=LLONG_MIN, int64_t maxvalue=LLONG_MAX, bool clamp=true) const
 
int64_t getInt64ValueDict (const String &name, const TokenDict64 *tokens, int64_t defvalue=0) const
 
int64_t getInt64ValueDict (const String &name, const TokenDictStr64 *tokens, int64_t defvalue=0) const
 
uint64_t getUInt64Value (const String &name, uint64_t defvalue=0, uint64_t minvalue=0, uint64_t maxvalue=ULLONG_MAX, bool clamp=true) const
 
double getDoubleValue (const String &name, double defvalue=0.0) const
 
bool getBoolValue (const String &name, bool defvalue=false) const
 
int replaceParams (String &str, bool sqlEsc=false, char extraEsc=0) const
 
void dump (String &str, const char *separator, char quote=0, bool force=false) const
 
bool dump (String &str, unsigned int flags, const char *separator, const char *nameSep=0, const char *prefix=0, char quote=0) const
 
ObjListparamList ()
 
const ObjListparamList () const
 
- Public Member Functions inherited from String
 String ()
 
 String (const char *value, int len=-1)
 
 String (char value, unsigned int repeat=1)
 
 String (int32_t value)
 
 String (uint32_t value)
 
 String (int64_t value)
 
 String (uint64_t value)
 
 String (bool value)
 
 String (double value)
 
 String (const String &value)
 
 String (const String *value)
 
virtual ~String ()
 
const char * c_str () const
 
const char * safe () const
 
const char * safe (const char *defStr) const
 
unsigned int length () const
 
bool null () const
 
int lenUtf8 (uint32_t maxChar=0x10ffff, bool overlong=false) const
 
int fixUtf8 (const char *replace=0, uint32_t maxChar=0x10ffff, bool overlong=false)
 
unsigned int encodeFlags (const TokenDict *tokens) const
 
uint64_t encodeFlags (const TokenDict64 *tokens) const
 
StringdecodeFlags (unsigned int flags, const TokenDict *tokens, bool unknownflag=true)
 
StringdecodeFlags (uint64_t flags, const TokenDict64 *tokens, bool unknownflag=true)
 
bool checkBOM () const
 
bool stripBOM ()
 
unsigned int hash () const
 
void clear ()
 
char at (int index) const
 
String substr (int offs, int len=-1) const
 
StringtrimBlanks ()
 
StringtrimSpaces ()
 
virtual const StringtoString () const
 
int toInteger (int defvalue=0, int base=0, int minvalue=INT_MIN, int maxvalue=INT_MAX, bool clamp=true) const
 
int toInteger (const TokenDict *tokens, int defvalue=0, int base=0) const
 
int toInteger (const TokenDictStr *tokens, int defvalue=0, int base=0) const
 
long int toLong (long int defvalue=0, int base=0, long int minvalue=LONG_MIN, long int maxvalue=LONG_MAX, bool clamp=true) const
 
int64_t toInt64 (int64_t defvalue=0, int base=0, int64_t minvalue=LLONG_MIN, int64_t maxvalue=LLONG_MAX, bool clamp=true) const
 
int64_t toInt64Dict (const TokenDict64 *tokens, int64_t defvalue=0, int base=0) const
 
int64_t toInt64Dict (const TokenDictStr64 *tokens, int64_t defvalue=0, int base=0) const
 
uint64_t toUInt64 (uint64_t defvalue=0, int base=0, uint64_t minvalue=0, uint64_t maxvalue=ULLONG_MAX, bool clamp=true) const
 
double toDouble (double defvalue=0.0) const
 
bool toBoolean (bool defvalue=false) const
 
bool isBoolean () const
 
StringtoUpper ()
 
StringtoLower ()
 
char operator[] (signed int index) const
 
char operator[] (unsigned int index) const
 
 operator const char * () const
 
Stringassign (const char *value, int len=-1)
 
Stringassign (char value, unsigned int repeat=1)
 
Stringhexify (const void *data, unsigned int len, char sep=0, bool upCase=false)
 
Stringoperator= (const String &value)
 
Stringoperator= (const String *value)
 
Stringoperator= (const char *value)
 
Stringoperator= (char value)
 
Stringoperator= (int32_t value)
 
Stringoperator= (uint32_t value)
 
Stringoperator= (int64_t value)
 
Stringoperator= (uint64_t value)
 
Stringoperator= (bool value)
 
Stringoperator= (double value)
 
Stringoperator+= (const char *value)
 
Stringoperator+= (char value)
 
Stringoperator+= (int32_t value)
 
Stringoperator+= (uint32_t value)
 
Stringoperator+= (int64_t value)
 
Stringoperator+= (uint64_t value)
 
Stringoperator+= (bool value)
 
Stringoperator+= (double value)
 
bool operator== (const char *value) const
 
bool operator!= (const char *value) const
 
bool operator== (const String &value) const
 
bool operator!= (const String &value) const
 
bool operator&= (const char *value) const
 
bool operator|= (const char *value) const
 
Stringoperator<< (const char *value)
 
Stringoperator<< (char value)
 
Stringoperator<< (int32_t value)
 
Stringoperator<< (uint32_t value)
 
Stringoperator<< (int64_t value)
 
Stringoperator<< (uint64_t value)
 
Stringoperator<< (bool value)
 
Stringoperator<< (double value)
 
Stringoperator>> (const char *skip)
 
Stringoperator>> (char &store)
 
Stringoperator>> (UChar &store)
 
Stringoperator>> (int &store)
 
Stringoperator>> (unsigned int &store)
 
Stringoperator>> (bool &store)
 
Stringappend (const char *value, int len)
 
Stringappend (const char *value, const char *separator=0, bool force=false)
 
Stringappend (const ObjList *list, const char *separator=0, bool force=false)
 
Stringappend (const ObjList &list, const char *separator=0, bool force=false)
 
Stringappend (char value, unsigned int len=1)
 
Stringappend (double value, unsigned int decimals=3)
 
Stringinsert (unsigned int pos, const char *value, int len=-1)
 
Stringinsert (unsigned int pos, char value, unsigned int len=1)
 
Stringprintf (const char *format,...)
 
Stringprintf (unsigned int length, const char *format,...)
 
StringprintfAppend (const char *format,...)
 
StringprintfAppend (unsigned int length, const char *format,...)
 
StringappendFixed (unsigned int fixedLength, const char *str, unsigned int len=-1, char fill=' ', int align=Left)
 
StringappendFixed (unsigned int fixedLength, const String &str, char fill=' ', int align=Left)
 
int find (char what, unsigned int offs=0) const
 
int find (const char *what, unsigned int offs=0) const
 
int rfind (char what) const
 
int rfind (const char *what) const
 
bool startsWith (const char *what, bool wordBreak=false, bool caseInsensitive=false) const
 
bool endsWith (const char *what, bool wordBreak=false, bool caseInsensitive=false) const
 
bool startSkip (const char *what, bool wordBreak=true, bool caseInsensitive=false)
 
StringreplaceChars (const char *what, const char *repl, bool inPlace=false, int wLen=-1, int rLen=-1, bool *chg=0)
 
StringremoveChars (const char *what, int wLen=-1, bool *chg=0)
 
StringextractTo (const char *sep, String &store)
 
StringextractTo (const char *sep, bool &store)
 
StringextractTo (const char *sep, int &store, int base=0)
 
StringextractTo (const char *sep, int &store, const TokenDict *tokens, int base=0)
 
StringextractTo (const char *sep, double &store)
 
virtual bool matches (const String &value) const
 
bool matches (const Regexp &rexp)
 
int matchOffset (int index=0) const
 
int matchLength (int index=0) const
 
String matchString (int index=0) const
 
String replaceMatches (const String &templ) const
 
int matchCount () const
 
ObjListsplit (ObjList &list, char separator, bool emptyOK=true) const
 
ObjListsplit (ObjList &list, const Regexp &reg, bool emptyOK=true) const
 
ObjListsplit (char separator, bool emptyOK=true) const
 
ObjListsplit (const Regexp &reg, bool emptyOK=true) const
 
String msgEscape (char extraEsc=0) const
 
String msgUnescape (int *errptr=0, char extraEsc=0) const
 
String sqlEscape (char extraEsc=0) const
 
StringuriEscapeTo (String &buf, char extraEsc=0, const char *noEsc=0) const
 
String uriEscape (char extraEsc=0, const char *noEsc=0) const
 
StringuriUnescapeTo (String &buf, bool setPartial=false, int *errptr=0) const
 
StringuriUnescapeStr (bool setPartial=false, int *errptr=0)
 
String uriUnescape (int *errptr=0, bool setPartial=true) const
 
- Public Member Functions inherited from GenObject
 GenObject ()
 
virtual ~GenObject ()
 
virtual bool alive () const
 
virtual void destruct ()
 
virtual const StringtraceId () const
 
NamedCountergetObjCounter () const
 
NamedCountersetObjCounter (NamedCounter *counter)
 

Protected Member Functions

virtual void dispatched (bool accepted)
 
- Protected Member Functions inherited from String
virtual void changed ()
 

Friends

class MessageDispatcher
 

Additional Inherited Members

- Public Types inherited from NamedList
enum  DumpFlags {
  DumpAddSeparator = 0x0001 , DumpForcePrefix = 0x0001 , DumpName = 0x0002 , DumpQuoteName = 0x0004 ,
  DumpEmptyName = 0x0008 , DumpQuoteParamName = 0x0010 , DumpDontQuoteParamValue = 0x0020
}
 
- Public Types inherited from String
enum  Align { Left = 0 , Center , Right }
 
- Static Public Member Functions inherited from NamedList
static const NamedListempty ()
 
- Static Public Member Functions inherited from String
static const Stringempty ()
 
static const char * boolText (bool value)
 
static int lenUtf8 (const char *value, uint32_t maxChar=0x10ffff, bool overlong=false)
 
static bool checkBOM (const char *str)
 
static bool stripBOM (const char *&str)
 
static bool stripBOM (char *&str)
 
static unsigned int hash (const char *value, unsigned int h=0)
 
static String msgEscape (const char *str, char extraEsc=0)
 
static String msgUnescape (const char *str, int *errptr=0, char extraEsc=0)
 
static String sqlEscape (const char *str, char extraEsc=0)
 
static StringuriEscapeTo (String &buf, const char *str, char extraEsc=0, const char *noEsc=0)
 
static StringuriEscapeTo (String &buf, const char *str, const char *extraEsc, const char *noEsc=0)
 
static String uriEscape (const char *str, char extraEsc=0, const char *noEsc=0)
 
static String uriEscape (const char *str, const char *extraEsc, const char *noEsc=0)
 
static StringuriUnescapeTo (String &buf, const char *str, bool setPartial=false, int *errptr=0)
 
static String uriUnescape (const char *str, int *errptr=0, bool setPartial=true)
 
static const Stringatom (const String *&str, const char *val)
 
static unsigned int c_starts_with (const char *str, const char *what, int lenStr=-1, int lenWhat=-1, bool caseInsensitive=false)
 
static unsigned int c_ends_with (const char *str, const char *what, int lenStr=-1, int lenWhat=-1, bool caseInsensitive=false)
 
static unsigned int c_skip (const char *&str, const char *what, int lenStr=-1, int lenWhat=-1, bool caseInsensitive=false)
 
static unsigned int c_skip_chars (const char *&str, const char *what, int len=-1, bool skipFound=true)
 
static char * c_replace_chars (const char *str, const char *what, const char *repl=0, bool inPlace=false, int wLen=-1, int rLen=-1, bool *chg=0)
 
- Static Public Member Functions inherited from GenObject
static void * getObject (const String &name, const GenObject *obj)
 
static bool getObjCounting ()
 
static void setObjCounting (bool enable)
 
static NamedCountergetObjCounter (const String &name, bool create=true)
 
static ObjListgetObjCounters ()
 

Detailed Description

A message container class.

This class holds the messages that are moved around in the engine.

Constructor & Destructor Documentation

◆ Message() [1/3]

Message ( const char * name,
const char * retval = 0,
bool broadcast = false )
explicit

Creates a new message.

Parameters
nameName of the message - must not be NULL or empty
retvalDefault return value
broadcastBroadcast flag, true if handling the mesage must not stop it

◆ Message() [2/3]

Message ( const Message & original)

Copy constructor. Note that user data and notification are not copied

Parameters
originalMessage we are copying from

◆ Message() [3/3]

Message ( const Message & original,
bool broadcast )

Copy constructor that can alter the broadcast flag. Note that user data and notification are not copied

Parameters
originalMessage we are copying from
broadcastBroadcast flag, true if handling the mesage must not stop it

◆ ~Message()

~Message ( )

Destruct the message and dereferences any user data

Member Function Documentation

◆ broadcast()

bool broadcast ( ) const
inline

Retrieve the broadcast flag

Returns
True if the message is a broadcast (handling does not stop it)

◆ decode() [1/2]

int decode ( const char * str,
bool & received,
const char * id )

Decode a string from an external communication interface that is an answer to a specific external processing request.

Parameters
strString to decode
receivedPointer to variable to store the dispatch return value
idThe identifier expected
Returns
-2 for success, -1 if the string was not the expected answer, index of first erroneous character if failed

◆ decode() [2/2]

int decode ( const char * str,
String & id )

Decode a string from an external communication interface for processing in the engine. The message is modified accordingly.

Parameters
strString to decode
idA String object in which the identifier is stored
Returns
-2 for success, -1 if the string was not a text form of a message, index of first erroneous character if failed

◆ dispatched()

virtual void dispatched ( bool accepted)
protectedvirtual

Notify the message it has been dispatched. The default behaviour is to call the dispatched() method of the user data if it implements MessageNotifier

Parameters
acceptedTrue if one handler accepted the message

◆ encode() [1/2]

String encode ( bool received,
const char * id ) const

Encode the message into a string adequate for sending as answer to an external communication interface

Parameters
receivedTrue if message was processed locally
idUnique identifier to add to the string

◆ encode() [2/2]

String encode ( const char * id) const

Encode the message into a string adequate for sending for processing to an external communication interface

Parameters
idUnique identifier to add to the string

◆ getObject()

virtual void * getObject ( const String & name) const
virtual

Get a pointer to a derived class given that class name

Parameters
nameName of the class we are asking for
Returns
Pointer to the requested class or NULL if this object doesn't implement it

Reimplemented from NamedList.

◆ msgTime() [1/2]

Time & msgTime ( )
inline

Retrieve a reference to the creation time of the message.

Returns
A reference to the Time when the message was created

◆ msgTime() [2/2]

const Time & msgTime ( ) const
inline

Retrieve a const reference to the creation time of the message.

Returns
A reference to the Time when the message was created

◆ msgTimeDispatch() [1/2]

Time & msgTimeDispatch ( )
inline

Retrieve a reference to the time when message was dispatched.

Returns
A reference to the Time when the message was dispatched May be 0 if the message was not dispatched yet or time tracking is not enabled in dispatcher

◆ msgTimeDispatch() [2/2]

const Time & msgTimeDispatch ( ) const
inline

Retrieve a const reference to the time when message was dispatched.

Returns
A reference to the Time when the message was dispatched May be 0 if the message was not dispatched yet or time tracking is not enabled in dispatcher

◆ msgTimeEnqueue() [1/2]

Time & msgTimeEnqueue ( )
inline

Retrieve a reference to the time when message was put in dispatcher.

Returns
A reference to the Time when the message was put in dispatcher queue. May be 0 if the message was not put in queue or time tracking is not enabled in dispatcher

◆ msgTimeEnqueue() [2/2]

const Time & msgTimeEnqueue ( ) const
inline

Retrieve a const reference to the time when message was put in dispatcher.

Returns
A reference to the Time when the message was put in dispatcher queue. May be 0 if the message was not put in queue or time tracking is not enabled in dispatcher

◆ operator=()

Message & operator= ( const char * value)
inline

Name assignment operator

References String::operator=().

◆ resetMsg()

void resetMsg ( Time tm = Time::now())

Reset message. This method should be used when message is going to be re-dispatched. Reset message time, track param, return value.

Parameters
tmTime to set, defaults to current time

◆ retValue() [1/2]

String & retValue ( )
inline

Retrieve a reference to the value returned by the message.

Returns
A reference to the value the message will return

◆ retValue() [2/2]

const String & retValue ( ) const
inline

Retrieve a const reference to the value returned by the message.

Returns
A reference to the value the message will return

◆ setNotify()

void setNotify ( bool notify = true)
inline

Enable or disable notification of any MessageNotifier that was set as user data. This method must be called after userData()

Parameters
notifyTrue to have the message call the notifier

◆ userData() [1/2]

RefObject * userData ( ) const
inline

Retrieve the object associated with the message

Returns
Pointer to arbitrary user RefObject

◆ userData() [2/2]

void userData ( RefObject * data)

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.

Parameters
dataPointer to arbitrary user data

◆ userObject()

void * userObject ( const String & name) const
inline

Get a pointer to a derived class of user data given that class name

Parameters
nameName of the class we are asking for
Returns
Pointer to the requested class or NULL if user object id NULL or doesn't implement it

References RefObject::getObject().


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