00001 /** 00002 * @file OutMessage.h 00003 * 00004 * Declaration of class OutMessageQueue, OutBinaryMessage, OutTextMessage and OutMessage. 00005 * 00006 * Include that file in implementation files that only want to write to MessageQueues. 00007 * (Usually it lasts to include "Tools/Debugging/Debugging.h") 00008 * 00009 * @author Martin Lötzsch 00010 */ 00011 00012 #ifndef __OutMessage_h_ 00013 #define __OutMessage_h_ 00014 00015 #include "Tools/Streams/OutStreams.h" 00016 #include "Platform/MessageQueueBase.h" 00017 00018 /** 00019 * @class OutMessageQueue. 00020 * 00021 * A PhysicalOutStream that writes the data to a MessageQueue. 00022 */ 00023 class OutMessageQueue : public PhysicalOutStream 00024 { 00025 private: 00026 /** The queue where the data is written to */ 00027 MessageQueueBase* queue; 00028 00029 public: 00030 /** Default constructor */ 00031 OutMessageQueue(); 00032 00033 protected: 00034 /** 00035 * opens the stream. 00036 * @param q A pointer to the message queue base 00037 */ 00038 void open(MessageQueueBase* q); 00039 00040 /** 00041 * The function writes a number of bytes into a physical stream. 00042 * @param p The address the data is located at. 00043 * @param size The number of bytes to be written. 00044 */ 00045 virtual void writeToStream(const void* p,int size); 00046 }; 00047 00048 /** 00049 * @class OutBinaryMessage 00050 * 00051 * A binary stream into a message queue. 00052 */ 00053 class OutBinaryMessage : public OutStream<OutMessageQueue,OutBinary> 00054 { 00055 public: 00056 /** 00057 * Constructor 00058 * @param q A pointer to the message queue base 00059 */ 00060 OutBinaryMessage(MessageQueueBase* q); 00061 }; 00062 00063 /** 00064 * @class OutTextMessage 00065 * 00066 * A text stream into a message queue. 00067 */ 00068 class OutTextMessage : public OutStream<OutMessageQueue,OutText> 00069 { 00070 public: 00071 /** 00072 * Constructor 00073 * @param q A pointer to the message queue base 00074 */ 00075 OutTextMessage(MessageQueueBase* q); 00076 }; 00077 00078 /** 00079 * @class OutTextRawMessage 00080 * 00081 * A text stream into a message queue. 00082 */ 00083 class OutTextRawMessage : public OutStream<OutMessageQueue,OutTextRaw> 00084 { 00085 public: 00086 /** 00087 * Constructor 00088 * @param q A pointer to the message queue base 00089 */ 00090 OutTextRawMessage(MessageQueueBase* q); 00091 }; 00092 00093 /** 00094 * @class OutMessage 00095 * 00096 * An Interface for writing messages into a MessageQueue. 00097 * 00098 * Use the bin or text member for formated writing into a message queue. 00099 */ 00100 class OutMessage 00101 { 00102 private: 00103 /** 00104 * The message queue where the messages are written into. 00105 */ 00106 MessageQueueBase& queue; 00107 00108 public: 00109 /** An interface for writing binary messages into the queue */ 00110 OutBinaryMessage bin; 00111 00112 /** An interface for writing text messages into the queue */ 00113 OutTextMessage text; 00114 00115 /** 00116 * An interface for writing text messages in a raw style (see class OutTextRaw) 00117 * into the queue 00118 */ 00119 OutTextMessage textRaw; 00120 00121 /** 00122 * Constructor 00123 * @param queue A reference to a MessageQueueBase 00124 */ 00125 OutMessage(MessageQueueBase& queue); 00126 00127 /** 00128 * Finishes the message and allows to write a new message. 00129 * Call that function after the writing of every message. 00130 * @param id The type id of the message 00131 */ 00132 void finishMessage(MessageID id); 00133 00134 //protected: 00135 /** 00136 * Finishes the message and allows to write a new message. 00137 * @param id The type id of the message 00138 * @param timeStamp The time stamp of the message 00139 * @param teamColor the team color of the robot that sent the message 00140 * @param playerNumber the player number of the robot that sent the message 00141 * @param messageWasSentFromAPhysicalRobot If true, then the message was sent 00142 * from a physical robot. 00143 */ 00144 void finishMessage(MessageID id, unsigned long timeStamp, 00145 Player::teamColor teamColor,Player::playerNumber playerNumber, 00146 bool messageWasSentFromAPhysicalRobot); 00147 00148 /** The player's team color that is attached to new messages */ 00149 Player::teamColor teamColorForNewMessages; 00150 00151 /** The player number that is attached to new messages */ 00152 Player::playerNumber playerNumberForNewMessages; 00153 00154 /** gives the MessageQueue class access to protected members */ 00155 friend class MessageQueue; 00156 00157 /** gives the LogPlayer class access to protected members */ 00158 friend class LogPlayer; 00159 00160 /** gives the CRemoteCamToolBar class access to protected members */ 00161 friend class CRemoteCamToolBar; 00162 00163 /** gives the InMessage class access to protected members */ 00164 friend class InMessage; 00165 00166 /** gives the operator that copies a InMessage to another queue access to protected members */ 00167 friend void operator >> (InMessage& message, MessageQueue& queue); 00168 00169 /** gives the In streaming opeator access to protected members */ 00170 friend In& operator>>(In& stream,MessageQueue& messageQueue); 00171 }; 00172 00173 00174 #endif //__OutMessage_h_
1.3.6