|
TOBI Interface A
0.1
|
00001 /* 00002 This file is part of the TOBI Interface A (TiA) library. 00003 00004 Commercial Usage 00005 Licensees holding valid Graz University of Technology Commercial 00006 licenses may use this file in accordance with the Graz University 00007 of Technology Commercial License Agreement provided with the 00008 Software or, alternatively, in accordance with the terms contained in 00009 a written agreement between you and Graz University of Technology. 00010 00011 -------------------------------------------------- 00012 00013 GNU Lesser General Public License Usage 00014 Alternatively, this file may be used under the terms of the GNU Lesser 00015 General Public License version 3.0 as published by the Free Software 00016 Foundation and appearing in the file lgpl.txt included in the 00017 packaging of this file. Please review the following information to 00018 ensure the GNU General Public License version 3.0 requirements will be 00019 met: http://www.gnu.org/copyleft/lgpl.html. 00020 00021 In case of GNU Lesser General Public License Usage ,the TiA library 00022 is distributed in the hope that it will be useful, 00023 but WITHOUT ANY WARRANTY; without even the implied warranty of 00024 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00025 GNU General Public License for more details. 00026 00027 You should have received a copy of the GNU Lesser General Public License 00028 along with the TiA library. If not, see <http://www.gnu.org/licenses/>. 00029 00030 Copyright 2010 Graz University of Technology 00031 Contact: TiA@tobi-project.org 00032 */ 00033 00041 #ifndef CONTROLMESSAGES_H 00042 #define CONTROLMESSAGES_H 00043 00044 // Standard 00045 #include <assert.h> 00046 #include <iostream> 00047 00048 // boost 00049 #include <boost/cstdint.hpp> 00050 00051 // local 00052 #include "tia/ss_meta_info.h" 00053 00054 namespace tia 00055 { 00056 00057 // forward declarations 00058 class ControlMsgEncoder; 00059 class ControlMsgDecoder; 00060 00061 static const std::string MESSAGE_VERSION("0.1"); 00062 00063 //----------------------------------------------------------------------------- 00064 00065 class ControlMsg 00066 { 00067 public: 00068 enum MsgType { 00069 KeepAlive = 0, 00070 GetConfig, 00071 Config, 00072 GetDataConnection, 00073 DataConnection, 00074 StartTransmission, 00075 StopTransmission, 00076 OkReply, 00077 ErrorReply 00078 }; 00079 00081 virtual ~ControlMsg(){} 00083 MsgType msgType() const { return msg_type_; } 00084 00086 void setSender(const std::string& sender) { sender_ = sender; } 00088 std::string sender() const { return sender_; } 00090 virtual void writeMsg(ControlMsgEncoder& encoder, std::ostream& stream) const = 0; 00092 virtual void readMsg(ControlMsgDecoder& decoder) = 0; 00094 virtual ControlMsg* clone() const = 0; 00095 00096 protected: 00098 ControlMsg(MsgType msg_type) : msg_type_(msg_type) {} 00099 00100 private: 00101 MsgType msg_type_; 00102 std::string sender_; 00103 }; 00104 00105 //----------------------------------------------------------------------------- 00106 00107 class KeepAliveMsg : public ControlMsg 00108 { 00109 public: 00110 KeepAliveMsg() : ControlMsg(ControlMsg::KeepAlive) {} 00111 virtual ~KeepAliveMsg(){} 00112 00113 virtual void writeMsg(ControlMsgEncoder& encoder, std::ostream& stream) const; 00114 00115 virtual void readMsg(ControlMsgDecoder& decoder); 00116 00117 virtual ControlMsg* clone() const { return new KeepAliveMsg(); }; 00118 }; 00119 00120 //----------------------------------------------------------------------------- 00121 00122 class GetConfigMsg : public ControlMsg 00123 { 00124 public: 00125 GetConfigMsg() : ControlMsg(ControlMsg::GetConfig) {} 00126 virtual ~GetConfigMsg(){} 00127 00128 virtual void writeMsg(ControlMsgEncoder& encoder, std::ostream& stream) const; 00129 00130 virtual void readMsg(ControlMsgDecoder& decoder); 00131 00132 virtual ControlMsg* clone() const { return new GetConfigMsg(); }; 00133 }; 00134 00135 //----------------------------------------------------------------------------- 00136 00137 class StopTransmissionMsg : public ControlMsg 00138 { 00139 public: 00140 StopTransmissionMsg() : ControlMsg(ControlMsg::StopTransmission) {} 00141 virtual ~StopTransmissionMsg(){} 00142 00143 virtual void writeMsg(ControlMsgEncoder& encoder, std::ostream& stream) const; 00144 00145 virtual void readMsg(ControlMsgDecoder& decoder); 00146 00147 virtual ControlMsg* clone() const { return new StopTransmissionMsg(); }; 00148 }; 00149 00150 //----------------------------------------------------------------------------- 00151 00152 class GetDataConnectionMsg : public ControlMsg 00153 { 00154 public: 00155 enum ConnectionType { 00156 Udp = 1, 00157 Tcp 00158 }; 00159 00160 public: 00161 GetDataConnectionMsg() : ControlMsg(ControlMsg::GetDataConnection), connection_type_(Tcp) {} 00162 virtual ~GetDataConnectionMsg(){} 00163 00164 int connectionType() const { return connection_type_; } 00165 void setConnectionType(int type) { connection_type_ = type; } 00166 00167 virtual void writeMsg(ControlMsgEncoder& encoder, std::ostream& stream) const; 00168 00169 virtual void readMsg(ControlMsgDecoder& decoder); 00170 00171 virtual ControlMsg* clone() const { return new GetDataConnectionMsg(); }; 00172 00173 private: 00174 int connection_type_; 00175 }; 00176 00177 //----------------------------------------------------------------------------- 00178 00179 class DataConnectionMsg : public ControlMsg 00180 { 00181 public: 00182 DataConnectionMsg() : ControlMsg(ControlMsg::DataConnection) 00183 {} 00184 00186 virtual ~DataConnectionMsg(){} 00187 00188 virtual void writeMsg(ControlMsgEncoder& encoder, std::ostream& stream) const; 00189 00190 virtual void readMsg(ControlMsgDecoder& decoder); 00191 00192 virtual ControlMsg* clone() const { return new DataConnectionMsg(); }; 00193 00194 std::string address() const { return address_; } 00195 void setAddress(const std::string& addr){ address_ = addr; } 00196 00197 boost::uint16_t port() const { return port_; } 00198 void setPort(boost::uint16_t port) { port_ = port; } 00199 00200 private: 00201 std::string address_; 00202 boost::uint16_t port_; 00203 }; 00204 00205 //----------------------------------------------------------------------------- 00206 00207 class StartTransmissionMsg : public ControlMsg 00208 { 00209 public: 00210 StartTransmissionMsg() : ControlMsg(ControlMsg::StartTransmission) {} 00211 virtual ~StartTransmissionMsg(){} 00212 00213 virtual void writeMsg(ControlMsgEncoder& encoder, std::ostream& stream) const; 00214 00215 virtual void readMsg(ControlMsgDecoder& decoder); 00216 00217 virtual ControlMsg* clone() const { return new StartTransmissionMsg(); }; 00218 }; 00219 00220 //----------------------------------------------------------------------------- 00221 00222 class ConfigMsg : public ControlMsg 00223 { 00224 public: 00225 ConfigMsg(); 00226 00227 virtual ~ConfigMsg(); 00228 00229 virtual void writeMsg(ControlMsgEncoder& encoder, std::ostream& stream) const; 00230 00231 virtual void readMsg(ControlMsgDecoder& decoder); 00232 00233 virtual ControlMsg* clone() const { return new ConfigMsg(); }; 00234 00235 public: 00236 SubjectInfo subject_info; 00237 SignalInfo signal_info; 00238 }; 00239 00240 //----------------------------------------------------------------------------- 00242 class ReplyMsg : public ControlMsg 00243 { 00244 public: 00245 static ReplyMsg error() { return ReplyMsg(ErrorReply); } 00246 static ReplyMsg ok() { return ReplyMsg(OkReply); } 00247 00249 virtual ~ReplyMsg(){} 00250 00251 virtual void writeMsg(ControlMsgEncoder& encoder, std::ostream& stream) const; 00252 00253 virtual void readMsg(ControlMsgDecoder& decoder); 00254 00255 virtual ControlMsg* clone() const { return new ReplyMsg(msgType()); }; 00256 00257 protected: 00258 ReplyMsg(MsgType type) : ControlMsg(type) 00259 {} 00260 }; 00261 00262 } // Namespace tobiss 00263 00264 #endif //CONTROLMESSAGES_H 00265 00266 // End Of File