From 5a26a09958318032868d82a7d2d0207464e1af2d Mon Sep 17 00:00:00 2001 From: imarom Date: Tue, 12 Apr 2016 14:26:10 +0300 Subject: events API and RX core util. --- src/stateless/cp/trex_api_class.h | 30 ++++++++++++++++++++++++++---- 1 file changed, 26 insertions(+), 4 deletions(-) (limited to 'src/stateless/cp/trex_api_class.h') diff --git a/src/stateless/cp/trex_api_class.h b/src/stateless/cp/trex_api_class.h index 78933d23..748d1478 100644 --- a/src/stateless/cp/trex_api_class.h +++ b/src/stateless/cp/trex_api_class.h @@ -75,20 +75,42 @@ public: m_handler = utl_generate_random_str(seed, 8); } + std::string ver(int major, int minor) { + std::stringstream ss; + ss << major << "." << minor; + return ss.str(); + } + + std::string get_server_ver() { + return ver(m_major, m_major); + } + std::string & verify_api(int major, int minor) { std::stringstream ss; ss << "API type '" << type_to_name(m_type) << "': "; - + assert(m_type < API_CLASS_TYPE_MAX); + bool fail = false; + /* for now a simple major check */ if (major < m_major) { - ss << "server has a major newer API version - server: '" << m_major << "', client: '" << major << "'"; - throw TrexAPIException(ss.str()); + ss << "server has a newer major API version"; + fail = true; } if (major > m_major) { - ss << "server has an older API version - server: '" << m_major << "', client: '" << major << "'"; + ss << "server has an older major API version"; + fail = true; + } + + if (minor > m_minor) { + ss << "client revision API is newer than server"; + fail = true; + } + + if (fail) { + ss << " - server: '" << get_server_ver() << "', client: '" << ver(major, minor) << "'"; throw TrexAPIException(ss.str()); } -- cgit 1.2.3-korg