00001 ////////////////////////////////////////////////////////////////////////////////////////////////// 00002 /*! \file Message.h 00003 * \brief Interface to the Message class. 00004 * \author $Author: simpliciter $ 00005 * \version $Revision: 1.2 $ 00006 * \date $Date: 2003/06/12 19:48:35 $ 00007 *////////////////////////////////////////////////////////////////////////////////////////////////// 00008 /*! 00009 */ 00010 ////////////////////////////////////////////////////////////////////////////////////////////////// 00011 00012 #ifndef __SSSL_MESSAGE_H__ 00013 #define __SSSL_MESSAGE_H__ 00014 #include <string> 00015 #include <vector> 00016 using namespace std; 00017 00018 /** \brief Encapsulation of messages with commands and data to be passed between spacecraft. 00019 * 00020 * The message class is used to wrap up message destinations, senders, commands, and parameters. 00021 * The class facilitates the serialization (converting to a string) and parsing (converting from a string) of 00022 * messages that are passed over some communications link. 00023 * \par Example: 00024 \code 00025 vector<double> parms; 00026 parms.push_back(4); 00027 parms.push_back(3); 00028 parms.push_back(2); 00029 Message testMsg("TYPHON", "THECLA", "SetWheelSpeeds", parms); 00030 \endcode 00031 The message is @em to TYPHON and @em from THECLA. These values should be stored in a table of hosts. The command, 00032 @em SetWheelSpeeds is the text string of the command, and @em parms is the vector of double values that are 00033 sent with the message. 00034 */ 00035 class Message 00036 { 00037 public: 00038 // Constructors/Deconstructors 00039 /** @brief Creates a message with the specified destination, sender, command and parameters. */ 00040 Message(string dest, string sender, string command, vector<double> params) : m_Destination(dest), m_Sender(sender), m_Command(command), m_Parameters(params.begin(), params.end()) {} 00041 00042 /** @brief Creates a message object from a serialized (string) message. */ 00043 Message(string _incomingMsg) { Parse(_incomingMsg); } 00044 00045 virtual ~Message() {}; 00046 00047 // Facilitators 00048 /** @brief Parses a serialized (string) incoming message, and fills out the Message object fields. */ 00049 void Parse(string _incomingMsg); 00050 00051 /** @brief Converts the message object into a serialized string of data in ASCII format. */ 00052 string Serialize() const; 00053 00054 // Inspectors 00055 /** @brief Returns the current destination of the message. */ 00056 string GetDestination() const {return m_Destination;}; 00057 00058 /** @brief Returns the current sender of the message. */ 00059 string GetSender() const {return m_Sender;}; 00060 00061 /** @brief Returns the current command to be sent with the message. */ 00062 string GetCommand() const {return m_Command;}; 00063 00064 /** @brief Returns a specific parameter value from a message. */ 00065 double GetParameter(int paramNumber) const {return m_Parameters[paramNumber];}; 00066 00067 /** @brief Returns the entire parameter list of the message. */ 00068 vector<double> GetParameters() const {return m_Parameters;}; 00069 00070 // Mutators 00071 /** @brief Set a new destination for the message. */ 00072 void SetDestination(const string& newDestination) {m_Destination = newDestination;}; 00073 00074 /** @brief Change the command of the message. */ 00075 void SetCommand(const string& newCommand) {m_Command = newCommand;}; 00076 00077 protected: 00078 // Data Members 00079 string m_Destination; /**< Message destination referring to the device's name */ 00080 string m_Sender; /**< Message sender referring to the device's name */ 00081 string m_Command; /**< String naming the command in the body of the message */ 00082 vector<double> m_Parameters;/**< variable length vector of command parameters */ 00083 private: 00084 00085 }; 00086 00087 #endif 00088 00089 00090 // Do not change the comments below - they will be added automatically by CVS 00091 /***************************************************************************** 00092 * $Log: Message.h,v $ 00093 * Revision 1.2 2003/06/12 19:48:35 simpliciter 00094 * Fixed doxygen syntax. 00095 * 00096 * Revision 1.1.1.1 2003/06/06 18:44:15 simpliciter 00097 * Initial submission. 00098 * 00099 * 00100 ******************************************************************************/ 00101