diff options
author | Kim van der Riet <kpvdr@apache.org> | 2006-11-03 21:27:48 +0000 |
---|---|---|
committer | Kim van der Riet <kpvdr@apache.org> | 2006-11-03 21:27:48 +0000 |
commit | 7847c1c0326e654845868ab4ab4ec27863a3e777 (patch) | |
tree | 9fbda427bca0f2b65de557d0f4914d3cbd968909 /cpp/src | |
parent | d817d3a1228da29ef39d177235c2878c282e0d27 (diff) | |
download | qpid-python-7847c1c0326e654845868ab4ab4ec27863a3e777.tar.gz |
Added protocol version and version exception classes in preparation for multi-protocol generation.
git-svn-id: https://svn.apache.org/repos/asf/incubator/qpid/trunk/qpid@471002 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'cpp/src')
-rw-r--r-- | cpp/src/qpid/framing/ProtocolInitiation.cpp | 12 | ||||
-rw-r--r-- | cpp/src/qpid/framing/ProtocolInitiation.h | 13 | ||||
-rw-r--r-- | cpp/src/qpid/framing/ProtocolVersion.cpp | 61 | ||||
-rw-r--r-- | cpp/src/qpid/framing/ProtocolVersion.h | 49 | ||||
-rw-r--r-- | cpp/src/qpid/framing/ProtocolVersionException.cpp | 63 | ||||
-rw-r--r-- | cpp/src/qpid/framing/ProtocolVersionException.h | 52 |
6 files changed, 240 insertions, 10 deletions
diff --git a/cpp/src/qpid/framing/ProtocolInitiation.cpp b/cpp/src/qpid/framing/ProtocolInitiation.cpp index aebdf6709e..23e2a24355 100644 --- a/cpp/src/qpid/framing/ProtocolInitiation.cpp +++ b/cpp/src/qpid/framing/ProtocolInitiation.cpp @@ -19,7 +19,9 @@ qpid::framing::ProtocolInitiation::ProtocolInitiation(){} -qpid::framing::ProtocolInitiation::ProtocolInitiation(u_int8_t _major, u_int8_t _minor) : pmajor(_major), pminor(_minor){} +qpid::framing::ProtocolInitiation::ProtocolInitiation(u_int8_t _major, u_int8_t _minor) : version(_major, _minor) {} + +qpid::framing::ProtocolInitiation::ProtocolInitiation(const qpid::framing::ProtocolVersion& p) : version(p) {} qpid::framing::ProtocolInitiation::~ProtocolInitiation(){} @@ -30,8 +32,8 @@ void qpid::framing::ProtocolInitiation::encode(Buffer& buffer){ buffer.putOctet('P'); buffer.putOctet(1);//class buffer.putOctet(1);//instance - buffer.putOctet(pmajor); - buffer.putOctet(pminor); + buffer.putOctet(version.major_); + buffer.putOctet(version.minor_); } bool qpid::framing::ProtocolInitiation::decode(Buffer& buffer){ @@ -42,8 +44,8 @@ bool qpid::framing::ProtocolInitiation::decode(Buffer& buffer){ buffer.getOctet();//P buffer.getOctet();//class buffer.getOctet();//instance - pmajor = buffer.getOctet(); - pminor = buffer.getOctet(); + version.major_ = buffer.getOctet(); + version.minor_ = buffer.getOctet(); return true; }else{ return false; diff --git a/cpp/src/qpid/framing/ProtocolInitiation.h b/cpp/src/qpid/framing/ProtocolInitiation.h index b0c1338cbf..7ce6af4a39 100644 --- a/cpp/src/qpid/framing/ProtocolInitiation.h +++ b/cpp/src/qpid/framing/ProtocolInitiation.h @@ -18,6 +18,7 @@ #include "qpid/framing/amqp_types.h" #include "qpid/framing/Buffer.h" #include "qpid/framing/AMQDataBlock.h" +#include "qpid/framing/ProtocolVersion.h" #ifndef _ProtocolInitiation_ #define _ProtocolInitiation_ @@ -27,18 +28,20 @@ namespace framing { class ProtocolInitiation : virtual public AMQDataBlock { - u_int8_t pmajor; - u_int8_t pminor; - +private: + ProtocolVersion version; + public: ProtocolInitiation(); ProtocolInitiation(u_int8_t major, u_int8_t minor); + ProtocolInitiation(const ProtocolVersion& p); virtual ~ProtocolInitiation(); virtual void encode(Buffer& buffer); virtual bool decode(Buffer& buffer); inline virtual u_int32_t size() const { return 8; } - inline u_int8_t getMajor(){ return pmajor; } - inline u_int8_t getMinor(){ return pminor; } + inline u_int8_t getMajor(){ return version.major_; } + inline u_int8_t getMinor(){ return version.minor_; } + inline const ProtocolVersion& getVersion() const { return version; } }; } diff --git a/cpp/src/qpid/framing/ProtocolVersion.cpp b/cpp/src/qpid/framing/ProtocolVersion.cpp new file mode 100644 index 0000000000..62fb11590e --- /dev/null +++ b/cpp/src/qpid/framing/ProtocolVersion.cpp @@ -0,0 +1,61 @@ +/* + * + * Copyright (c) 2006 The Apache Software Foundation + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + */ +#include "qpid/framing/ProtocolVersion.h" +#include <sstream> + +using namespace qpid::framing; + +ProtocolVersion::ProtocolVersion() {} + +ProtocolVersion::ProtocolVersion(u_int8_t _major, u_int8_t _minor) : + major_(_major), + minor_(_minor) +{} + +ProtocolVersion::ProtocolVersion(const ProtocolVersion::ProtocolVersion& p): + major_(p.major_), + minor_(p.minor_) +{} + +ProtocolVersion::~ProtocolVersion() +{} + +bool ProtocolVersion::equals(u_int8_t _major, u_int8_t _minor) const +{ + return major_ == _major && minor_ == _minor; +} + +bool ProtocolVersion::equals(const ProtocolVersion::ProtocolVersion& p) const +{ + return major_ == p.major_ && minor_ == p.minor_; +} + +const std::string ProtocolVersion::toString() const +{ + std::stringstream ss; + ss << major_ << "-" << minor_; + return ss.str(); +} + +ProtocolVersion::ProtocolVersion ProtocolVersion::operator=(const ProtocolVersion& p) +{ + major_ = p.major_; + minor_ = p.minor_; + return *this; +} + diff --git a/cpp/src/qpid/framing/ProtocolVersion.h b/cpp/src/qpid/framing/ProtocolVersion.h new file mode 100644 index 0000000000..25cf469943 --- /dev/null +++ b/cpp/src/qpid/framing/ProtocolVersion.h @@ -0,0 +1,49 @@ +/* + * + * Copyright (c) 2006 The Apache Software Foundation + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + */ +#ifndef _ProtocolVersion_ +#define _ProtocolVersion_ + +#include "qpid/framing/amqp_types.h" + +namespace qpid +{ +namespace framing +{ + +class ProtocolVersion +{ +public: + u_int8_t major_; + u_int8_t minor_; + + ProtocolVersion(); + ProtocolVersion(u_int8_t _major, u_int8_t _minor); + ProtocolVersion(const ProtocolVersion& p); + virtual ~ProtocolVersion(); + + virtual bool equals(u_int8_t _major, u_int8_t _minor) const; + virtual bool equals(const ProtocolVersion& p) const; + virtual const std::string toString() const; + ProtocolVersion operator=(const ProtocolVersion& p); +}; + +} // namespace framing +} // namespace qpid + + +#endif // ifndef _ProtocolVersion_ diff --git a/cpp/src/qpid/framing/ProtocolVersionException.cpp b/cpp/src/qpid/framing/ProtocolVersionException.cpp new file mode 100644 index 0000000000..0ba500aad8 --- /dev/null +++ b/cpp/src/qpid/framing/ProtocolVersionException.cpp @@ -0,0 +1,63 @@ +/* + * + * Copyright (c) 2006 The Apache Software Foundation + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + */ +#include "qpid/framing/ProtocolVersionException.h" +#include <sstream> + +using namespace qpid::framing; + +ProtocolVersionException::ProtocolVersionException() throw () +{ +} + +ProtocolVersionException::ProtocolVersionException(const std::string& str) throw () : Exception(str) +{ +} + +ProtocolVersionException::ProtocolVersionException(const char* str) throw () : Exception(str) +{ +} + +ProtocolVersionException::ProtocolVersionException(const ProtocolVersion& versionFound_, const std::string& str) throw () : Exception(str) + +{ + versionFound = versionFound_; +} + +ProtocolVersionException::ProtocolVersionException(const ProtocolVersion& versionFound_, const char* str) throw () : Exception(str) + +{ + versionFound = versionFound_; +} + +ProtocolVersionException::~ProtocolVersionException() throw () +{ +} + +const char* ProtocolVersionException::what() const throw() +{ + std::stringstream ss; + ss << "ProtocolVersionException: AMQP Version " << versionFound.toString() << " found: " << whatStr; + return ss.str().c_str(); +} + +std::string ProtocolVersionException::toString() const throw() +{ + std::stringstream ss; + ss << "ProtocolVersionException: AMQP Version " << versionFound.toString() << " found: " << whatStr; + return ss.str(); +} diff --git a/cpp/src/qpid/framing/ProtocolVersionException.h b/cpp/src/qpid/framing/ProtocolVersionException.h new file mode 100644 index 0000000000..7decd8bcc6 --- /dev/null +++ b/cpp/src/qpid/framing/ProtocolVersionException.h @@ -0,0 +1,52 @@ +/* + * + * Copyright (c) 2006 The Apache Software Foundation + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + */ + +#ifndef _ProtocolVersionException_ +#define _ProtocolVersionException_ + +#include "qpid/Exception.h" +#include "qpid/framing/ProtocolVersion.h" +#include <string> +#include <vector> + +namespace qpid +{ +namespace framing +{ + +class ProtocolVersionException : virtual public qpid::Exception +{ +protected: + ProtocolVersion versionFound; + +public: + ProtocolVersionException() throw (); + ProtocolVersionException(const std::string& str) throw (); + ProtocolVersionException(const char* str) throw (); + ProtocolVersionException(const ProtocolVersion& versionFound_, const std::string& str) throw (); + ProtocolVersionException(const ProtocolVersion& versionFound_, const char* str) throw (); + virtual ~ProtocolVersionException() throw (); + + virtual const char* what() const throw(); + virtual std::string toString() const throw(); +}; // class ProtocolVersionException + +} // namespace framing +} // namespace qpid + +#endif //ifndef _ProtocolVersionException_ |