VOS::Message Class Reference
[libvos]
#include <vos/vos/message.hh>
Inheritance diagram for VOS::Message:

Detailed Description
This class handles storing, generating and parsing of the messages that are sent between virtual objects.
Definition at line 95 of file message.hh.
Public Types
- Normal
- LowLatency
- Bulk
- enum Priority { Normal, LowLatency, Bulk }
Public Member Functions
- Message ()
- Message (Vobject *v, const std::string &method, bool withnonce, Priority priority=Normal)
- Message (Vobject *v, Message *in_reply_to, const std::string &method, Priority priority=Normal)
- Message (Message &m)
- ~Message ()
- void setType (const std::string &s)
- void setTo (const std::string &s)
- void setFrom (const std::string &s)
- void setMethod (const std::string &s)
- void setNonce (uint32_t n)
- void setTimestamp (const std::string &s)
- Set the timestamp (optional, useful for applications, not actually used by VOS core).
- Set the timestamp (optional, useful for applications, not actually used by VOS core).
- void setSourceSite (Site *source_site)
- std::string getType () const
- std::string getTo () const
- std::string getFrom () const
- std::string getMethod () const
- uint32_t getNonce () const
- std::string getTimestamp () const
- bool hasTo () const
- bool hasFrom () const
- bool hasMethod () const
- bool hasNonce () const
- bool hasTimestamp () const
- VUtil::vRef< Site > getSourceSite () const
- int numFields () const
- void generateNonce ()
- bool hasField (const std::string &key) const
- VUtil::vRef< MsgField > getField (const std::string &key) const
- VUtil::vRef< MsgField > getField (int n) const
- void insertField (int n, const std::string &key, const std::string &val, bool quoted=false)
- void insertField (int n, const std::string &key, double val)
- void insertField (int n, const std::string &key, int val)
- void insertField (int n, const std::string &key, unsigned int val)
- void appendField (const std::string &key, const std::string &val, bool quoted=false)
- void appendField (const std::string &key, double val)
- void appendField (const std::string &key, int val)
- void removeField (int n)
- void removeField (const std::string &s)
- void clearFields ()
- Clear all the fields of this message added with insertField() or appendField().
- Clear all the fields of this message added with insertField() or appendField().
- void setFormatFunc (std::string *(*func)(const std::string &type, const std::string &to, const std::string &from, const std::string &method, uint32_t nonce, const std::string ×tamp, const std::deque< VUtil::vRef< MsgField > > &fields, bool withLength))
- const std::string & getFormattedString (bool withLength=true) const
- Get the message formatted with the function supplied in setFormatFunc().
- Get the message formatted with the function supplied in setFormatFunc().
- void setPriority (Priority p)
- Priority getPriority ()
- void setSendingCompletedCallback (SendingCompletedCallback *scc)
- SendingCompletedCallback * getSendingCompletedCallback ()
Friends
- class msgFlexLexer
Member Enumeration Documentation
Constructor & Destructor Documentation
| VOS::Message::Message | ( | ) |
Create a new message.
| VOS::Message::Message | ( | Vobject * | v, | |
| const std::string & | method, | |||
| bool | withnonce, | |||
| Priority | priority = Normal | |||
| ) |
Initialize this message.
Will set the message type as "message", set the "to" field to v->getURLstr(), set the method field with the supplied method, and optionally generate a random value for the nonce field.
- Parameters:
-
v used to set the "to" field method used to set the "method" field withnonce if true, generate a random string for the nonce field
| VOS::Message::Message | ( | Vobject * | v, | |
| Message * | in_reply_to, | |||
| const std::string & | method, | |||
| Priority | priority = Normal | |||
| ) |
Initialize this message as a reply to a message.
Will set the message type as "update", set "to" using in_reply_to->getFrom(), set "from" using v->getURLstr(), and set the nonce using in_reply_to->getNonce(), and set the method to the supplied.
- Parameters:
-
v used to initialize the "from" fields in_reply_to used to initalize the "to" and "nonce" fields method used to initialize the "method" field
| VOS::Message::Message | ( | Message & | m | ) |
Copy a message.
| VOS::Message::~Message | ( | ) |
Destroy this message.
Member Function Documentation
| void VOS::Message::appendField | ( | const std::string & | key, | |
| int | val | |||
| ) | [inline] |
Append a new field.
- Parameters:
-
key the key (or tag) to associate the value with val the value of this field
Definition at line 347 of file message.hh.
| void VOS::Message::appendField | ( | const std::string & | key, | |
| double | val | |||
| ) | [inline] |
Append a new field.
- Parameters:
-
key the key (or tag) to associate the value with val the value of this field
Definition at line 340 of file message.hh.
| void VOS::Message::appendField | ( | const std::string & | key, | |
| const std::string & | val, | |||
| bool | quoted = false | |||
| ) | [inline] |
Append a new field.
- Parameters:
-
key the key (or tag) to associate the value with val the value of this field quoted not used and should be removed...
Definition at line 333 of file message.hh.
| void VOS::Message::clearFields | ( | ) |
Clear all the fields of this message added with insertField() or appendField().
| void VOS::Message::generateNonce | ( | ) |
Have the message fill in the nonce field with a random nonce.
| VUtil::vRef<MsgField> VOS::Message::getField | ( | int | n | ) | const |
Get the first field which matches the supplied key.
Note that this field list is SEPARATE from the type/to/from/method/nonce fields.
- Parameters:
-
n the field at position n, where n is the array offset from 0.
- Returns:
- the first instance of a field which matchs that tag
- Exceptions:
-
NoSuchFieldError if the field is not found
| VUtil::vRef<MsgField> VOS::Message::getField | ( | const std::string & | key | ) | const |
Get the first field which matches the supplied key.
Note that this field list is SEPARATE from the type/to/from/method/nonce fields.
- Parameters:
-
key the tag to match
- Returns:
- the first instance of a field which matchs that tag
- Exceptions:
-
NoSuchFieldError if the field is not found
Referenced by LocalHello::handleHello().
| const std::string& VOS::Message::getFormattedString | ( | bool | withLength = true |
) | const |
Get the message formatted with the function supplied in setFormatFunc().
- Returns:
- the formatted std::string
| std::string VOS::Message::getFrom | ( | ) | const |
Get the from field.
- Returns:
- the from field setFrom() has a bit more information about this field.
Referenced by LocalHello::handleHello().
| std::string VOS::Message::getMethod | ( | ) | const |
Get the method field.
- Returns:
- the method field setMethod() has a bit more information about this field.
| uint32_t VOS::Message::getNonce | ( | ) | const |
Get the nonce field.
- Returns:
- the nonce field setNonce() has a bit more information about this field.
| Priority VOS::Message::getPriority | ( | ) | [inline] |
Definition at line 390 of file message.hh.
| SendingCompletedCallback* VOS::Message::getSendingCompletedCallback | ( | ) |
| VUtil::vRef<Site> VOS::Message::getSourceSite | ( | ) | const |
Get the source site.
This is the site that actually generated this message. MAY BE ZERO IF THE MESSAGE WAS GENERATED LOCALLY. If so, you'll need to do the following to determine the source site: Site::findSite(URL(themsg.getFrom()).getHostAndPort())
- Returns:
- the source site
| std::string VOS::Message::getTimestamp | ( | ) | const |
Get the timestamp field.
- Returns:
- the timestamp field setTimestamp() has a bit more information about this field.
| std::string VOS::Message::getTo | ( | ) | const |
| std::string VOS::Message::getType | ( | ) | const |
- Returns:
- the type field. setType() has a bit more information about this field.
| bool VOS::Message::hasField | ( | const std::string & | key | ) | const |
| bool VOS::Message::hasFrom | ( | ) | const |
Get whether there is anything in the from field.
- Returns:
- if there is a from field setFrom() has a bit more information about this field.
| bool VOS::Message::hasMethod | ( | ) | const |
Get whether there is anything in the method field.
- Returns:
- if there is a method field setMethod() has a bit more information about this field.
| bool VOS::Message::hasNonce | ( | ) | const |
Get whether there is anything in the nonce field.
- Returns:
- if there is a nonce field setNonce() has a bit more information about this field.
| bool VOS::Message::hasTimestamp | ( | ) | const |
Get whether there is anything in the timestamp field.
- Returns:
- if there is a timestamp field setTimestamp() has a bit more information about this field.
| bool VOS::Message::hasTo | ( | ) | const |
Get whether there is anything in the to field.
- Returns:
- if there is a to field setTo() has a bit more information about this field.
| void VOS::Message::insertField | ( | int | n, | |
| const std::string & | key, | |||
| unsigned int | val | |||
| ) |
Insert a new field.
- Parameters:
-
n the position, as explained above key the key (or tag) to associate the value with val the value of this field
| void VOS::Message::insertField | ( | int | n, | |
| const std::string & | key, | |||
| int | val | |||
| ) |
Insert a new field.
- Parameters:
-
n the position, as explained above key the key (or tag) to associate the value with val the value of this field
| void VOS::Message::insertField | ( | int | n, | |
| const std::string & | key, | |||
| double | val | |||
| ) |
Insert a new field.
Insert a new field.
- Note:
- On positions: if a position is zero or positive, its meaning is as you would expect, expressing the offset into an array of fields. However, if the position is negative, it expresses the offset from the end of the list. This means for a list of length m, -1 is the last item in the list (equal to position position m - 1) and -m is the first item (equal to positive position 0). If the position is positive, the field is inserted such that it now occupies that position, and all fields starting from the previous occupant of that position onward are moved up one. If the position in negative, the field is similarly inserted so that it now occupies that position. For example, position -1 will append the field to the end of the list, position -2 will insert the field in the second-to-last position, etc.
- Parameters:
-
n the position, as explained above key the key (or tag) to associate the value with val the value of this field quoted not really used and should be removed...
- Parameters:
-
n the position, as explained above key the key (or tag) to associate the value with val the value of this field
| void VOS::Message::insertField | ( | int | n, | |
| const std::string & | key, | |||
| const std::string & | val, | |||
| bool | quoted = false | |||
| ) |
Insert a new field.
- Note:
- On positions: if a position is zero or positive, its meaning is as you would expect, expressing the offset into an array of fields. However, if the position is negative, it expresses the offset from the end of the list. This means for a list of length m, -1 is the last item in the list (equal to position position m - 1) and -m is the first item (equal to positive position 0). If the position is positive, the field is inserted such that it now occupies that position, and all fields starting from the previous occupant of that position onward are moved up one. If the position in negative, the field is similarly inserted so that it now occupies that position. For example, position -1 will append the field to the end of the list, position -2 will insert the field in the second-to-last position, etc.
- Parameters:
-
n the position, as explained above key the key (or tag) to associate the value with val the value of this field quoted not really used and should be removed...
| int VOS::Message::numFields | ( | ) | const |
Get the number of ordinary fields.
- Returns:
- the number of ordinary fields in this message
| void VOS::Message::removeField | ( | const std::string & | s | ) |
Remove the first instance of a field with the supplied key.
- Parameters:
-
s the key of the field to remove
| void VOS::Message::removeField | ( | int | n | ) |
Remove an existing field at some position.
See insertField() for details about the legal numerical values of the position.
- Parameters:
-
n the position
| void VOS::Message::setFormatFunc | ( | std::string *(*)(const std::string &type, const std::string &to, const std::string &from, const std::string &method, uint32_t nonce, const std::string ×tamp, const std::deque< VUtil::vRef< MsgField > > &fields, bool withLength) | func | ) |
Set the function which converts this message structure into a string.
End users don't need to call this, as it is set to the default when the message is constructed.
- Note:
- The more object-oriented way of doing this would be to create a function object type. This interface may change.
| void VOS::Message::setFrom | ( | const std::string & | s | ) |
Set whom this message is sent by.
This should probably be the URL std::string of the object which is generating this message.
- Parameters:
-
s the from field
| void VOS::Message::setMethod | ( | const std::string & | s | ) |
Set the method action this message is expressing.
- Parameters:
-
s the method field
| void VOS::Message::setNonce | ( | uint32_t | n | ) |
Set the nonce field.
The nonce is used to match a match a reply against a request (because the reply bears the same nonce as the originating message.)
- Parameters:
-
s the nonce field
| void VOS::Message::setPriority | ( | Priority | p | ) | [inline] |
Definition at line 389 of file message.hh.
| void VOS::Message::setSendingCompletedCallback | ( | SendingCompletedCallback * | scc | ) |
| void VOS::Message::setSourceSite | ( | Site * | source_site | ) |
Set the source site.
This is not a field in the message itself, but rather is used to set the site originating this message (that is to say, which socket the message was received on.) This is compared against the "from" field to provide a simple filter against really obvious spoofing. You do not need to set this if you are creating a new message to be sent; rather it is set for messages received from the network.
- Parameters:
-
source_site the source site
| void VOS::Message::setTimestamp | ( | const std::string & | s | ) |
Set the timestamp (optional, useful for applications, not actually used by VOS core).
- Parameters:
-
s the timestamp field
| void VOS::Message::setTo | ( | const std::string & | s | ) |
Set whom this message is intended for.
This should probably be the URL std::string of the object to which the message is destined.
- Parameters:
-
s the to field
| void VOS::Message::setType | ( | const std::string & | s | ) |
Set what type of message this is.
You probably want it to be either "message" or "update".
- Parameters:
-
s the types
Friends And Related Function Documentation
friend class msgFlexLexer [friend] |
Definition at line 395 of file message.hh.
The documentation for this class was generated from the following file:
- /home/tetron/hack/vos/libs/vos/vos/message.hh