From 29607a6d463d0e7b2a7d0720c647f3fe71af3cde Mon Sep 17 00:00:00 2001 From: Edouard DUPIN Date: Mon, 28 Aug 2017 00:04:49 +0200 Subject: [PATCH] [DEV] continue removing stl --- enet/Http.cpp | 114 ++++++++++++++++----------------- enet/Http.hpp | 58 ++++++++--------- enet/Tcp.cpp | 10 +-- enet/Tcp.hpp | 12 ++-- enet/TcpClient.cpp | 36 +++++------ enet/TcpClient.hpp | 2 +- enet/TcpServer.cpp | 18 +++--- enet/TcpServer.hpp | 6 +- enet/WebSocket.cpp | 28 ++++---- enet/WebSocket.hpp | 34 +++++----- enet/enet.cpp | 2 +- test/main-client-http.cpp | 8 +-- test/main-client-websocket.cpp | 16 ++--- test/main-client.cpp | 4 +- test/main-server-http.cpp | 20 +++--- test/main-server-websocket.cpp | 14 ++-- test/main-server.cpp | 6 +- 17 files changed, 194 insertions(+), 194 deletions(-) diff --git a/enet/Http.cpp b/enet/Http.cpp index 65a263a..a509b63 100644 --- a/enet/Http.cpp +++ b/enet/Http.cpp @@ -6,19 +6,19 @@ #include #include -#include +#include #include #include -static std::string escapeChar(const std::string& _value) { +static etk::String escapeChar(const etk::String& _value) { return _value; } -static std::string unEscapeChar(const std::string& _value) { +static etk::String unEscapeChar(const etk::String& _value) { return _value; } -static std::string removeStartAndStopSpace(const std::string& _value) { - std::string out; +static etk::String removeStartAndStopSpace(const etk::String& _value) { + etk::String out; out.reserve(_value.size()); bool findSpace = false; for (auto &it : _value) { @@ -36,7 +36,7 @@ static std::string removeStartAndStopSpace(const std::string& _value) { return out; } -static std::map protocolName = { +static etk::Map protocolName = { {enet::HTTPAnswerCode::c100_continue, "Continue"}, {enet::HTTPAnswerCode::c101_switchingProtocols, "Switching Protocols"}, {enet::HTTPAnswerCode::c103_checkpoint, "Checkpoint"}, @@ -84,14 +84,14 @@ static std::map protocolName = { -static std::map getErrorList() { - static std::map g_list; +static etk::Map getErrorList() { + static etk::Map g_list; return g_list; } enet::Http::Http(enet::Tcp _connection, bool _isServer) : m_isServer(_isServer), - m_connection(std::move(_connection)), + m_connection(etk::move(_connection)), m_headerIsSend(false), m_thread(nullptr), m_threadRunning(false) { @@ -178,9 +178,9 @@ void enet::Http::stop(bool _inThreadStop){ } /* void enet::Http::writeAnswerHeader(enum enet::HTTPAnswerCode _value) { - std::string out; + etk::String out; out = "HTTP/1.1 "; - out += etk::to_string(int32_t(_value)); + out += etk::toString(int32_t(_value)); auto it = protocolName.find(_value); if (it == protocolName.end() ) { out += " ???"; @@ -194,10 +194,10 @@ void enet::Http::writeAnswerHeader(enum enet::HTTPAnswerCode _value) { */ namespace etk { template <> - bool from_string(enum enet::HTTPAnswerCode& _variableRet, const std::string& _value) { + bool from_string(enum enet::HTTPAnswerCode& _variableRet, const etk::String& _value) { _variableRet = enet::HTTPAnswerCode::c000_unknow; for (auto &it : protocolName) { - if (etk::to_string(int32_t(it.first)) == _value) { + if (etk::toString(int32_t(it.first)) == _value) { _variableRet = it.first; return true; } @@ -205,11 +205,11 @@ namespace etk { return false; } template <> - std::string to_string(const enum enet::HTTPAnswerCode& _value) { - return etk::to_string(int32_t(_value)); + etk::String toString(const enum enet::HTTPAnswerCode& _value) { + return etk::toString(int32_t(_value)); } template <> - bool from_string(enum enet::HTTPReqType& _variableRet, const std::string& _value) { + bool from_string(enum enet::HTTPReqType& _variableRet, const etk::String& _value) { _variableRet = enet::HTTPReqType::HTTP_GET; if (_value == "GET") { _variableRet = enet::HTTPReqType::HTTP_GET; @@ -230,7 +230,7 @@ namespace etk { return false; } template <> - std::string to_string(const enum enet::HTTPReqType& _value) { + etk::String toString(const enum enet::HTTPReqType& _value) { switch (_value) { case enet::HTTPReqType::HTTP_GET: return "GET"; case enet::HTTPReqType::HTTP_HEAD: return "HEAD"; @@ -241,7 +241,7 @@ namespace etk { return "UNKNOW"; } template <> - bool from_string(enum enet::HTTPProtocol& _variableRet, const std::string& _value) { + bool from_string(enum enet::HTTPProtocol& _variableRet, const etk::String& _value) { _variableRet = enet::HTTPProtocol::http_0_1; if (_value == "HTTP/0.1") { _variableRet = enet::HTTPProtocol::http_0_1; return true; } if (_value == "HTTP/0.2") { _variableRet = enet::HTTPProtocol::http_0_2; return true; } @@ -289,7 +289,7 @@ namespace etk { return false; } template <> - std::string to_string(const enum enet::HTTPProtocol& _value) { + etk::String toString(const enum enet::HTTPProtocol& _value) { switch (_value) { case enet::HTTPProtocol::http_0_1: return "HTTP/0.1"; case enet::HTTPProtocol::http_0_2: return "HTTP/0.2"; @@ -345,7 +345,7 @@ void enet::Http::setRequestHeader(const enet::HttpRequest& _req) { if (m_requestHeader.getKey("User-Agent") == "") { m_requestHeader.setKey("User-Agent", "e-net (ewol network interface)"); } - std::string value = m_requestHeader.generate(); + etk::String value = m_requestHeader.generate(); write(value, false); } @@ -354,14 +354,14 @@ void enet::Http::setAnswerHeader(const enet::HttpAnswer& _req) { if (m_requestHeader.getKey("User-Agent") == "") { m_requestHeader.setKey("User-Agent", "e-net (ewol network interface)"); } - std::string value = m_answerHeader.generate(); + etk::String value = m_answerHeader.generate(); write(value, false); } void enet::Http::getHeader() { ENET_VERBOSE("Read HTTP Header [START]"); bool headerEnded = false; - std::string header; + etk::String header; while (m_connection.getConnectionStatus() == enet::Tcp::status::link) { char type = '?'; int32_t len = m_connection.read(&type, 1); @@ -396,7 +396,7 @@ void enet::Http::getHeader() { ENET_VERBOSE("Read HTTP Header [STOP] : '" << header << "'"); m_headerIsSend = true; // parse header : - std::vector list = etk::split(header, '\n'); + etk::Vector list = etk::split(header, '\n'); for (auto &it : list) { if ( it.size()>0 && it[it.size()-1] == '\r') { @@ -404,7 +404,7 @@ void enet::Http::getHeader() { } } //parse first element: - std::vector listLineOne = etk::split(list[0], ' '); + etk::Vector listLineOne = etk::split(list[0], ' '); if (listLineOne.size() < 2) { ENET_ERROR("can not parse answear : " << listLineOne); // answer bad request and close connection ... @@ -459,7 +459,7 @@ void enet::Http::getHeader() { m_answerHeader.setErrorCode(valueErrorCode); // get comment: - std::string comment; + etk::String comment; for (size_t iii=2; iii& _values) { +bool enet::Http::post(const etk::String& _address, const etk::Map& _values) { m_header.m_map.clear(); // First create body : - std::string body; + etk::String body; for (auto &it : _values) { if (body.size() > 0) { body += "&"; @@ -551,16 +551,16 @@ bool enet::Http::post(const std::string& _address, const std::mapsecond; @@ -609,8 +609,8 @@ std::string enet::HttpHeader::getKey(const std::string& _key) const { return ""; } -std::string enet::HttpHeader::generateKeys() const { - std::string out; +etk::String enet::HttpHeader::generateKeys() const { + etk::String out; for (auto &it : m_map) { if ( it.first != "" && it.second != "") { @@ -629,7 +629,7 @@ enet::HttpHeader::HttpHeader(): // ----------------------------------------------------------------------------------------- -enet::HttpAnswer::HttpAnswer(enum HTTPAnswerCode _code, const std::string& _help): +enet::HttpAnswer::HttpAnswer(enum HTTPAnswerCode _code, const etk::String& _help): m_what(_code), m_helpMessage(_help) { @@ -649,11 +649,11 @@ void enet::HttpAnswer::display() const { } } -std::string enet::HttpAnswer::generate() const { - std::string out; - out += etk::to_string(m_protocol); +etk::String enet::HttpAnswer::generate() const { + etk::String out; + out += etk::toString(m_protocol); out += " "; - out += etk::to_string(int32_t(m_what)); + out += etk::toString(int32_t(m_what)); out += " "; if (m_helpMessage != "") { out += escapeChar(m_helpMessage); @@ -671,12 +671,12 @@ std::string enet::HttpAnswer::generate() const { return out; } enet::HttpServer::HttpServer(enet::Tcp _connection) : - enet::Http(std::move(_connection), true) { + enet::Http(etk::move(_connection), true) { } enet::HttpClient::HttpClient(enet::Tcp _connection) : - enet::Http(std::move(_connection), false) { + enet::Http(etk::move(_connection), false) { } // ----------------------------------------------------------------------------------------- @@ -701,13 +701,13 @@ void enet::HttpRequest::display() const { } } -std::string enet::HttpRequest::generate() const { - std::string out; - out += etk::to_string(m_req); +etk::String enet::HttpRequest::generate() const { + etk::String out; + out += etk::toString(m_req); out += " "; out += m_uri; out += " "; - out += etk::to_string(m_protocol); + out += etk::toString(m_protocol); out += "\r\n"; out += generateKeys(); out += "\r\n"; @@ -715,17 +715,17 @@ std::string enet::HttpRequest::generate() const { } -std::ostream& enet::operator <<(std::ostream& _os, enum enet::HTTPProtocol _obj) { - _os << "enet::HTTPProtocol::" < -#include -#include +#include +#include #include #include #include @@ -64,7 +64,7 @@ namespace enet { c505_httpVersionNotSupported, //!< The server does not support the HTTP protocol version used in the request c511_networkAuthenticationRequired, //!< The client needs to authenticate to gain network access }; - std::ostream& operator <<(std::ostream& _os, enum enet::HTTPAnswerCode _obj); + etk::Stream& operator <<(etk::Stream& _os, enum enet::HTTPAnswerCode _obj); enum class HTTPProtocol { http_0_1, @@ -111,18 +111,18 @@ namespace enet { http_3_9, http_3_10, }; - std::ostream& operator <<(std::ostream& _os, enum enet::HTTPProtocol _obj); + etk::Stream& operator <<(etk::Stream& _os, enum enet::HTTPProtocol _obj); class HttpHeader { protected: // key, val - std::map m_map; + etk::Map m_map; enum HTTPProtocol m_protocol; public: - void setKey(const std::string& _key, const std::string& _value); - void rmKey(const std::string& _key); - std::string getKey(const std::string& _key) const; + void setKey(const etk::String& _key, const etk::String& _value); + void rmKey(const etk::String& _key); + etk::String getKey(const etk::String& _key) const; protected: - std::string generateKeys() const; + etk::String generateKeys() const; public: enum HTTPProtocol getProtocol() const { return m_protocol; @@ -132,27 +132,27 @@ namespace enet { } HttpHeader(); virtual ~HttpHeader() = default; - virtual std::string generate() const = 0; + virtual etk::String generate() const = 0; }; class HttpAnswer : public HttpHeader { private: enet::HTTPAnswerCode m_what; - std::string m_helpMessage; + etk::String m_helpMessage; public: - HttpAnswer(enum HTTPAnswerCode _code = enet::HTTPAnswerCode::c400_badRequest, const std::string& _help=""); + HttpAnswer(enum HTTPAnswerCode _code = enet::HTTPAnswerCode::c400_badRequest, const etk::String& _help=""); void display() const; - std::string generate() const; + etk::String generate() const; void setErrorCode(enum HTTPAnswerCode _value) { m_what = _value; } enum HTTPAnswerCode getErrorCode() const { return m_what; } - void setHelp(const std::string& _value) { + void setHelp(const etk::String& _value) { m_helpMessage = _value; } - const std::string& getHelp() const { + const etk::String& getHelp() const { return m_helpMessage; } }; @@ -163,26 +163,26 @@ namespace enet { HTTP_PUT, HTTP_DELETE, }; - std::ostream& operator <<(std::ostream& _os, enum enet::HTTPReqType _obj); + etk::Stream& operator <<(etk::Stream& _os, enum enet::HTTPReqType _obj); class HttpRequest : public HttpHeader { private: // key, val enum HTTPReqType m_req; - std::string m_uri; + etk::String m_uri; public: HttpRequest(enum enet::HTTPReqType _type=enet::HTTPReqType::HTTP_GET); void display() const; - std::string generate() const; + etk::String generate() const; void setType(enum enet::HTTPReqType _value) { m_req = _value; } enum enet::HTTPReqType getType() const{ return m_req; } - void setUri(const std::string& _value) { + void setUri(const etk::String& _value) { m_uri = _value; } - const std::string& getUri() const { + const etk::String& getUri() const { return m_uri; } }; @@ -218,7 +218,7 @@ namespace enet { bool m_headerIsSend; std::thread* m_thread; bool m_threadRunning; - std::vector m_temporaryBuffer; + etk::Vector m_temporaryBuffer; private: void threadCallback(); private: @@ -230,7 +230,7 @@ namespace enet { return m_connection.getConnectionStatus() == enet::Tcp::status::link; } public: - using Observer = std::function&)>; //!< Define an Observer: function pointer + using Observer = std::function&)>; //!< Define an Observer: function pointer Observer m_observer; /** * @brief Connect an function member on the signal with the shared_ptr object. @@ -239,8 +239,8 @@ namespace enet { * @param[in] _args Argument optinnal the user want to add. */ template - void connect(CLASS_TYPE* _class, void (CLASS_TYPE::*_func)(std::vector&)) { - m_observer = [=](std::vector& _value){ + void connect(CLASS_TYPE* _class, void (CLASS_TYPE::*_func)(etk::Vector&)) { + m_observer = [=](etk::Vector& _value){ (*_class.*_func)(_value); }; } @@ -289,7 +289,7 @@ namespace enet { * @return >0 byte size on the socket write * @return -1 an error occured. */ - int32_t write(const std::string& _data, bool _writeBackSlashZero = true) { + int32_t write(const etk::String& _data, bool _writeBackSlashZero = true) { if (_data.size() == 0) { return 0; } @@ -306,7 +306,7 @@ namespace enet { * @return -1 an error occured. */ template - int32_t write(const std::vector& _data) { + int32_t write(const etk::Vector& _data) { if (_data.size() == 0) { return 0; } @@ -326,9 +326,9 @@ namespace enet { setRequestHeader(_header); } public: - //bool get(const std::string& _address); - //bool post(const std::string& _address, const std::map& _values); - //bool post(const std::string& _address, const std::string& _contentType, const std::string& _data); + //bool get(const etk::String& _address); + //bool post(const etk::String& _address, const etk::Map& _values); + //bool post(const etk::String& _address, const etk::String& _contentType, const etk::String& _data); public: /** * @brief Connect an function member on the signal with the shared_ptr object. diff --git a/enet/Tcp.cpp b/enet/Tcp.cpp index cba79ee..c11f32d 100644 --- a/enet/Tcp.cpp +++ b/enet/Tcp.cpp @@ -51,15 +51,15 @@ enet::Tcp::Tcp() : } #ifdef __TARGET_OS__Windows - enet::Tcp::Tcp(SOCKET _idSocket, const std::string& _name) : + enet::Tcp::Tcp(SOCKET _idSocket, const etk::String& _name) : #else - enet::Tcp::Tcp(int32_t _idSocket, const std::string& _name) : + enet::Tcp::Tcp(int32_t _idSocket, const etk::String& _name) : #endif m_socketId(_idSocket), m_name(_name), m_status(status::link) { #ifdef ENET_STORE_INPUT - m_nodeStoreInput = etk::FSNode("CACHE:StoreTCPdata_" + etk::to_string(baseID++) + ".tcp"); + m_nodeStoreInput = etk::FSNode("CACHE:StoreTCPdata_" + etk::toString(baseID++) + ".tcp"); m_nodeStoreInput.fileOpenWrite(); #endif } @@ -69,7 +69,7 @@ enet::Tcp::Tcp(Tcp&& _obj) : m_name(_obj.m_name), m_status(_obj.m_status) { #ifdef ENET_STORE_INPUT - m_nodeStoreInput = etk::FSNode("CACHE:StoreTCPdata_" + etk::to_string(baseID++) + ".tcp"); + m_nodeStoreInput = etk::FSNode("CACHE:StoreTCPdata_" + etk::toString(baseID++) + ".tcp"); m_nodeStoreInput.fileOpenWrite(); #endif #ifdef __TARGET_OS__Windows @@ -88,7 +88,7 @@ enet::Tcp::~Tcp() { enet::Tcp& enet::Tcp::operator = (enet::Tcp&& _obj) { unlink(); #ifdef ENET_STORE_INPUT - m_nodeStoreInput = etk::FSNode("CACHE:StoreTCPdata_" + etk::to_string(baseID++) + ".tcp"); + m_nodeStoreInput = etk::FSNode("CACHE:StoreTCPdata_" + etk::toString(baseID++) + ".tcp"); m_nodeStoreInput.fileOpenWrite(); #endif m_socketId = _obj.m_socketId; diff --git a/enet/Tcp.hpp b/enet/Tcp.hpp index 9705436..d037771 100644 --- a/enet/Tcp.hpp +++ b/enet/Tcp.hpp @@ -34,9 +34,9 @@ namespace enet { public: Tcp(); #ifdef __TARGET_OS__Windows - Tcp(SOCKET _idSocket, const std::string& _name); + Tcp(SOCKET _idSocket, const etk::String& _name); #else - Tcp(int32_t _idSocket, const std::string& _name); + Tcp(int32_t _idSocket, const etk::String& _name); #endif // move constructor Tcp(Tcp&& _obj); @@ -46,13 +46,13 @@ namespace enet { Tcp& operator= (Tcp& _obj) = delete; virtual ~Tcp(); private: - std::string m_name; //!< hostname/IP:port. + etk::String m_name; //!< hostname/IP:port. public: /** * @brief Get the decriptive name hot the host:port * @return the string requested */ - const std::string& getName() { + const etk::String& getName() { return m_name; } public: @@ -102,7 +102,7 @@ namespace enet { * @return >0 byte size on the socket write * @return -1 an error occured. */ - int32_t write(const std::string& _data, bool _writeBackSlashZero = true) { + int32_t write(const etk::String& _data, bool _writeBackSlashZero = true) { if (_data.size() == 0) { return 0; } @@ -119,7 +119,7 @@ namespace enet { * @return -1 an error occured. */ template - int32_t write(const std::vector& _data) { + int32_t write(const etk::Vector& _data) { if (_data.size() == 0) { return 0; } diff --git a/enet/TcpClient.cpp b/enet/TcpClient.cpp index 6bfca3a..13f5542 100644 --- a/enet/TcpClient.cpp +++ b/enet/TcpClient.cpp @@ -24,26 +24,26 @@ #endif enet::Tcp enet::connectTcpClient(uint8_t _ip1, uint8_t _ip2, uint8_t _ip3, uint8_t _ip4, uint16_t _port, uint32_t _numberRetry, echrono::Duration _timeOut) { - std::string tmpname; - tmpname = etk::to_string(_ip1); + etk::String tmpname; + tmpname = etk::toString(_ip1); tmpname += "."; - tmpname += etk::to_string(_ip2); + tmpname += etk::toString(_ip2); tmpname += "."; - tmpname += etk::to_string(_ip3); + tmpname += etk::toString(_ip3); tmpname += "."; - tmpname += etk::to_string(_ip4); - return std::move(enet::connectTcpClient(tmpname, _port, _numberRetry, _timeOut)); + tmpname += etk::toString(_ip4); + return etk::move(enet::connectTcpClient(tmpname, _port, _numberRetry, _timeOut)); } #ifdef __TARGET_OS__Windows - enet::Tcp enet::connectTcpClient(const std::string& _hostname, uint16_t _port, uint32_t _numberRetry, echrono::Duration _timeOut) { + enet::Tcp enet::connectTcpClient(const etk::String& _hostname, uint16_t _port, uint32_t _numberRetry, echrono::Duration _timeOut) { if (enet::isInit() == false) { ENET_ERROR("Need call enet::init(...) before accessing to the socket"); - return std::move(enet::Tcp()); + return etk::move(enet::Tcp()); } if (_hostname == "") { ENET_ERROR("get connection wihtout hostname"); - return std::move(enet::Tcp()); + return etk::move(enet::Tcp()); } SOCKET socketId = INVALID_SOCKET; ENET_INFO("Start connection on " << _hostname << ":" << _port); @@ -67,7 +67,7 @@ enet::Tcp enet::connectTcpClient(uint8_t _ip1, uint8_t _ip2, uint8_t _ip3, uint8 // Resolve the server address and port struct addrinfo* result = nullptr; - std::string portValue = etk::to_string(_port); + etk::String portValue = etk::toString(_port); int iResult = getaddrinfo(_hostname.c_str(), portValue.c_str(), &hints, &result); if (iResult != 0) { ENET_ERROR("getaddrinfo failed with error: " << iResult); @@ -106,21 +106,21 @@ enet::Tcp enet::connectTcpClient(uint8_t _ip1, uint8_t _ip2, uint8_t _ip3, uint8 } if (socketId == INVALID_SOCKET) { ENET_ERROR("ERROR connecting ... (after all try)"); - return std::move(enet::Tcp()); + return etk::move(enet::Tcp()); } ENET_DEBUG("Connection done"); - return std::move(enet::Tcp(socketId, _hostname + ":" + etk::to_string(_port))); + return etk::move(enet::Tcp(socketId, _hostname + ":" + etk::toString(_port))); } #else #include - enet::Tcp enet::connectTcpClient(const std::string& _hostname, uint16_t _port, uint32_t _numberRetry, echrono::Duration _timeOut) { + enet::Tcp enet::connectTcpClient(const etk::String& _hostname, uint16_t _port, uint32_t _numberRetry, echrono::Duration _timeOut) { if (enet::isInit() == false) { ENET_ERROR("Need call enet::init(...) before accessing to the socket"); - return std::move(enet::Tcp()); + return etk::move(enet::Tcp()); } if (_hostname == "") { ENET_ERROR("get connection wihtout hostname"); - return std::move(enet::Tcp()); + return etk::move(enet::Tcp()); } int32_t socketId = -1; ENET_INFO("Start connection on " << _hostname << ":" << _port); @@ -147,7 +147,7 @@ enet::Tcp enet::connectTcpClient(uint8_t _ip1, uint8_t _ip2, uint8_t _ip3, uint8 addr.s_addr = inet_addr(_hostname.c_str()); if (addr.s_addr == INADDR_NONE) { ENET_ERROR("The IPv4 address entered must be a legal address" << _hostname.c_str()); - return std::move(enet::Tcp()); + return etk::move(enet::Tcp()); } else { // TODO : This is deprecated use getaddrinfo like windows ... server = gethostbyaddr((char *) &addr, 4, AF_INET); @@ -183,10 +183,10 @@ enet::Tcp enet::connectTcpClient(uint8_t _ip1, uint8_t _ip2, uint8_t _ip3, uint8 } if (socketId<0) { ENET_ERROR("ERROR connecting ... (after all try)"); - return std::move(enet::Tcp()); + return etk::move(enet::Tcp()); } ENET_INFO("Connection done"); - return std::move(enet::Tcp(socketId, _hostname + ":" + etk::to_string(_port))); + return etk::move(enet::Tcp(socketId, _hostname + ":" + etk::toString(_port))); } #endif diff --git a/enet/TcpClient.hpp b/enet/TcpClient.hpp index e2a0654..5a7b018 100644 --- a/enet/TcpClient.hpp +++ b/enet/TcpClient.hpp @@ -10,5 +10,5 @@ namespace enet { enet::Tcp connectTcpClient(uint8_t _ip1, uint8_t _ip2, uint8_t _ip3, uint8_t _ip4, uint16_t _port, uint32_t _numberRetry=5, echrono::Duration _timeOut = echrono::seconds(1)); - enet::Tcp connectTcpClient(const std::string& _hostname, uint16_t _port, uint32_t _numberRetry=5, echrono::Duration _timeOut = echrono::seconds(1)); + enet::Tcp connectTcpClient(const etk::String& _hostname, uint16_t _port, uint32_t _numberRetry=5, echrono::Duration _timeOut = echrono::seconds(1)); } diff --git a/enet/TcpServer.cpp b/enet/TcpServer.cpp index a689db4..3c6a465 100644 --- a/enet/TcpServer.cpp +++ b/enet/TcpServer.cpp @@ -37,18 +37,18 @@ enet::TcpServer::~TcpServer() { } void enet::TcpServer::setIpV4(uint8_t _fist, uint8_t _second, uint8_t _third, uint8_t _quatro) { - std::string tmpname; - tmpname = etk::to_string(_fist); + etk::String tmpname; + tmpname = etk::toString(_fist); tmpname += "."; - tmpname += etk::to_string(_second); + tmpname += etk::toString(_second); tmpname += "."; - tmpname += etk::to_string(_third); + tmpname += etk::toString(_third); tmpname += "."; - tmpname += etk::to_string(_quatro); + tmpname += etk::toString(_quatro); setHostNane(tmpname); } -void enet::TcpServer::setHostNane(const std::string& _name) { +void enet::TcpServer::setHostNane(const etk::String& _name) { if (_name == m_host) { return; } @@ -79,7 +79,7 @@ void enet::TcpServer::setPort(uint16_t _port) { hints.ai_flags = AI_PASSIVE; // Resolve the server address and port - std::string portValue = etk::to_string(m_port); + etk::String portValue = etk::toString(m_port); int iResult = getaddrinfo(nullptr, portValue.c_str(), &hints, &result); if (iResult != 0) { ENET_ERROR("getaddrinfo failed with error: " << iResult); @@ -153,7 +153,7 @@ void enet::TcpServer::setPort(uint16_t _port) { enet::Tcp enet::TcpServer::waitNext() { if (enet::isInit() == false) { ENET_ERROR("Need call enet::init(...) before accessing to the socket"); - return std::move(enet::Tcp()); + return etk::move(enet::Tcp()); } ENET_INFO("End binding Socket ... (start listen)"); #ifdef __TARGET_OS__Windows @@ -182,7 +182,7 @@ enet::Tcp enet::TcpServer::waitNext() { return enet::Tcp(); } ENET_INFO("End configuring Socket ... Find New one"); - return enet::Tcp(socketIdClient, m_host + ":" + etk::to_string(m_port)); + return enet::Tcp(socketIdClient, m_host + ":" + etk::toString(m_port)); } diff --git a/enet/TcpServer.hpp b/enet/TcpServer.hpp index 576394c..a9a6be3 100644 --- a/enet/TcpServer.hpp +++ b/enet/TcpServer.hpp @@ -26,7 +26,7 @@ namespace enet { TcpServer(); virtual ~TcpServer(); private: - std::string m_host; //!< hostname/IP to connect with. + etk::String m_host; //!< hostname/IP to connect with. public: /** * @brief Set the connection IP id. @@ -40,12 +40,12 @@ namespace enet { * @brief set the Host name is the same things as set an Ip adress, but in test mode "127.0.0.1" or "localhost". * @param[in] _name Host name to connect. */ - void setHostNane(const std::string& _name); + void setHostNane(const etk::String& _name); /** * @brief Get the decriptive name hot the host * @return the string requested */ - const std::string& getHostName() { + const etk::String& getHostName() { return m_host; } private: diff --git a/enet/WebSocket.cpp b/enet/WebSocket.cpp index 6ead8aa..bfb6838 100644 --- a/enet/WebSocket.cpp +++ b/enet/WebSocket.cpp @@ -6,7 +6,7 @@ #include #include -#include +#include #include #include #include @@ -40,19 +40,19 @@ enet::WebSocket::WebSocket(enet::Tcp _connection, bool _isServer) : m_interface(nullptr), m_observer(nullptr), m_observerUriCheck(nullptr) { - setInterface(std::move(_connection), _isServer); + setInterface(etk::move(_connection), _isServer); } void enet::WebSocket::setInterface(enet::Tcp _connection, bool _isServer) { _connection.setTCPNoDelay(true); if (_isServer == true) { - ememory::SharedPtr interface = ememory::makeShared(std::move(_connection)); + ememory::SharedPtr interface = ememory::makeShared(etk::move(_connection)); m_interface = interface; if (interface != nullptr) { interface->connectHeader(this, &enet::WebSocket::onReceiveRequest); } } else { - ememory::SharedPtr interface = ememory::makeShared(std::move(_connection)); + ememory::SharedPtr interface = ememory::makeShared(etk::move(_connection)); m_interface = interface; if (interface != nullptr) { interface->connectHeader(this, &enet::WebSocket::onReceiveAnswer); @@ -72,7 +72,7 @@ enet::WebSocket::~WebSocket() { stop(true); } -static std::string generateKey() { +static etk::String generateKey() { // create dynamic key: std::random_device rd; std::mt19937 e2(rd()); @@ -84,13 +84,13 @@ static std::string generateKey() { return algue::base64::encode(dataKey, 16); } -static std::string generateCheckKey(const std::string& _key) { - std::string out = _key + "258EAFA5-E914-47DA-95CA-C5AB0DC85B11"; - std::vector keyData = algue::sha1::encode(out); +static etk::String generateCheckKey(const etk::String& _key) { + etk::String out = _key + "258EAFA5-E914-47DA-95CA-C5AB0DC85B11"; + etk::Vector keyData = algue::sha1::encode(out); return algue::base64::encode(keyData); } -void enet::WebSocket::start(const std::string& _uri, const std::vector& _listProtocols) { +void enet::WebSocket::start(const etk::String& _uri, const etk::Vector& _listProtocols) { if (m_interface == nullptr) { ENET_ERROR("Nullptr interface ..."); return; @@ -108,7 +108,7 @@ void enet::WebSocket::start(const std::string& _uri, const std::vector listProtocol; + etk::Vector listProtocol; if (_data.getKey("Sec-WebSocket-Protocol") != "") { listProtocol = etk::split(_data.getKey("Sec-WebSocket-Protocol"),','); for (size_t iii=0; iii #include #include -#include -#include +#include +#include namespace enet { class WebSocket { protected: - std::vector m_sendBuffer; + etk::Vector m_sendBuffer; bool m_connectionValidate; ememory::SharedPtr m_interface; - std::vector m_buffer; - std::string m_checkKey; + etk::Vector m_buffer; + etk::String m_checkKey; echrono::Steady m_lastReceive; echrono::Steady m_lastSend; std::mutex m_mutex; @@ -34,7 +34,7 @@ namespace enet { WebSocket(enet::Tcp _connection, bool _isServer=false); void setInterface(enet::Tcp _connection, bool _isServer=false); virtual ~WebSocket(); - void start(const std::string& _uri="", const std::vector& _listProtocols=std::vector()); + void start(const etk::String& _uri="", const etk::Vector& _listProtocols=etk::Vector()); void stop(bool _inThread=false); bool isAlive() const { if (m_interface == nullptr) { @@ -46,13 +46,13 @@ namespace enet { void onReceiveRequest(const enet::HttpRequest& _data); void onReceiveAnswer(const enet::HttpAnswer& _data); protected: - std::string m_protocol; + etk::String m_protocol; public: - void setProtocol(const std::string& _protocol) { + void setProtocol(const etk::String& _protocol) { m_protocol = _protocol; } public: - using Observer = std::function&, bool)>; //!< Define an Observer: function pointer + using Observer = std::function&, bool)>; //!< Define an Observer: function pointer protected: Observer m_observer; public: @@ -63,8 +63,8 @@ namespace enet { * @param[in] _args Argument optinnal the user want to add. */ template - void connect(CLASS_TYPE* _class, void (CLASS_TYPE::*_func)(std::vector&, bool)) { - m_observer = [=](std::vector& _value, bool _isString){ + void connect(CLASS_TYPE* _class, void (CLASS_TYPE::*_func)(etk::Vector&, bool)) { + m_observer = [=](etk::Vector& _value, bool _isString){ (*_class.*_func)(_value, _isString); }; } @@ -73,7 +73,7 @@ namespace enet { } // Only server: public: - using ObserverUriCheck = std::function&)>; //!< Define an Observer: function pointer + using ObserverUriCheck = std::function&)>; //!< Define an Observer: function pointer protected: ObserverUriCheck m_observerUriCheck; public: @@ -84,8 +84,8 @@ namespace enet { * @param[in] _args Argument optinnal the user want to add. */ template - void connectUri(CLASS_TYPE* _class, bool (CLASS_TYPE::*_func)(const std::string&, const std::vector&)) { - m_observerUriCheck = [=](const std::string& _value, const std::vector& _protocols){ + void connectUri(CLASS_TYPE* _class, bool (CLASS_TYPE::*_func)(const etk::String&, const etk::Vector&)) { + m_observerUriCheck = [=](const etk::String& _value, const etk::Vector& _protocols){ return (*_class.*_func)(_value, _protocols); }; } @@ -98,7 +98,7 @@ namespace enet { uint8_t m_dataMask[4]; public: std::unique_lock getScopeLock() { - return std::move(std::unique_lock(m_mutex)); + return etk::move(std::unique_lock(m_mutex)); } /** * Compose the local header inside a temporary buffer ==> must lock external to prevent multiple simultaneous access @@ -128,7 +128,7 @@ namespace enet { * @return >0 byte size on the socket write * @return -1 an error occured. */ - int32_t write(const std::string& _data, bool _writeBackSlashZero = true) { + int32_t write(const etk::String& _data, bool _writeBackSlashZero = true) { if (_data.size() == 0) { return 0; } @@ -145,7 +145,7 @@ namespace enet { * @return -1 an error occured. */ template - int32_t write(const std::vector& _data) { + int32_t write(const etk::Vector& _data) { if (_data.size() == 0) { return 0; } diff --git a/enet/enet.cpp b/enet/enet.cpp index 8ddc6bf..63abffc 100644 --- a/enet/enet.cpp +++ b/enet/enet.cpp @@ -19,7 +19,7 @@ static bool& getInitSatatus() { void enet::init(int _argc, const char** _argv) { for (int32_t iii=0; iii<_argc; ++iii) { - std::string value = _argv[iii]; + etk::String value = _argv[iii]; if (etk::start_with(value, "--enet") == true) { ENET_ERROR("Unknow parameter type: '" << value << "'"); } diff --git a/test/main-client-http.cpp b/test/main-client-http.cpp index 9c9cd75..6812682 100644 --- a/test/main-client-http.cpp +++ b/test/main-client-http.cpp @@ -15,7 +15,7 @@ namespace appl { - void onReceiveData(std::vector& _data) { + void onReceiveData(etk::Vector& _data) { TEST_INFO("Receive Datas : " << _data.size() << " bytes"); TEST_INFO("data:" << (char*)&_data[0] << ""); } @@ -25,7 +25,7 @@ int main(int _argc, const char *_argv[]) { etk::init(_argc, _argv); enet::init(_argc, _argv); for (int32_t iii=0; iii<_argc ; ++iii) { - std::string data = _argv[iii]; + etk::String data = _argv[iii]; if ( data == "-h" || data == "--help") { TEST_PRINT(etk::getApplicationName() << " - help : "); @@ -38,11 +38,11 @@ int main(int _argc, const char *_argv[]) { TEST_INFO("== Test HTTP client =="); TEST_INFO("=================================="); // connect on TCP server: - enet::Tcp tcpConnection = std::move(enet::connectTcpClient("127.0.0.1", 12345)); + enet::Tcp tcpConnection = etk::move(enet::connectTcpClient("127.0.0.1", 12345)); // TODO : Check if connection is valid ... // Create a HTTP connection in Client mode - enet::HttpClient connection(std::move(tcpConnection)); + enet::HttpClient connection(etk::move(tcpConnection)); // Set callbacks: connection.connect(appl::onReceiveData); diff --git a/test/main-client-websocket.cpp b/test/main-client-websocket.cpp index 66b380d..d576b27 100644 --- a/test/main-client-websocket.cpp +++ b/test/main-client-websocket.cpp @@ -16,7 +16,7 @@ namespace appl { - void onReceiveData(std::vector& _data, bool _isString) { + void onReceiveData(etk::Vector& _data, bool _isString) { TEST_INFO("Receive Datas : " << _data.size() << " bytes"); if (_isString == true) { _data.resize(_data.size()+1); @@ -32,7 +32,7 @@ int main(int _argc, const char *_argv[]) { etk::init(_argc, _argv); enet::init(_argc, _argv); for (int32_t iii=0; iii<_argc ; ++iii) { - std::string data = _argv[iii]; + etk::String data = _argv[iii]; if ( data == "-h" || data == "--help") { TEST_PRINT(etk::getApplicationName() << " - help : "); @@ -45,19 +45,19 @@ int main(int _argc, const char *_argv[]) { TEST_INFO("== Test WebSocket client =="); TEST_INFO("=================================="); // connect on TCP server: - enet::Tcp tcpConnection = std::move(enet::connectTcpClient("127.0.0.1", 12345)); + enet::Tcp tcpConnection = etk::move(enet::connectTcpClient("127.0.0.1", 12345)); // TODO : Check if connection is valid ... // Create a HTTP connection in Client mode - enet::WebSocket connection(std::move(tcpConnection), false); + enet::WebSocket connection(etk::move(tcpConnection), false); // Set callbacks: connection.connect(appl::onReceiveData); // start http connection (the actual state is just TCP start ...) - std::vector protocols; - protocols.push_back("test1526/1.0"); - protocols.push_back("test1526/1.5"); - protocols.push_back("Hello"); + etk::Vector protocols; + protocols.pushBack("test1526/1.0"); + protocols.pushBack("test1526/1.5"); + protocols.pushBack("Hello"); connection.start("/plop.txt", protocols); // send some data to play ... diff --git a/test/main-client.cpp b/test/main-client.cpp index 4f127e9..cf6e1ae 100644 --- a/test/main-client.cpp +++ b/test/main-client.cpp @@ -17,7 +17,7 @@ int main(int _argc, const char *_argv[]) { etk::init(_argc, _argv); enet::init(_argc, _argv); for (int32_t iii=0; iii<_argc ; ++iii) { - std::string data = _argv[iii]; + etk::String data = _argv[iii]; if ( data == "-h" || data == "--help") { TEST_PRINT(etk::getApplicationName() << " - help : "); @@ -31,7 +31,7 @@ int main(int _argc, const char *_argv[]) { TEST_INFO("=================================="); // client mode ... // connect on TCP server: - enet::Tcp connection = std::move(enet::connectTcpClient("127.0.0.1", 12345)); + enet::Tcp connection = etk::move(enet::connectTcpClient("127.0.0.1", 12345)); TEST_INFO("CLIENT connect ..."); if (connection.getConnectionStatus() != enet::Tcp::status::link) { TEST_ERROR("can not link to the socket..."); diff --git a/test/main-server-http.cpp b/test/main-server-http.cpp index 985046f..7df914c 100644 --- a/test/main-server-http.cpp +++ b/test/main-server-http.cpp @@ -14,7 +14,7 @@ #include namespace appl { - void onReceiveData(enet::HttpServer* _interface, std::vector& _data) { + void onReceiveData(enet::HttpServer* _interface, etk::Vector& _data) { TEST_INFO("Receive Datas : " << _data.size() << " bytes"); } void onReceiveHeader(enet::HttpServer* _interface, const enet::HttpRequest& _data) { @@ -23,8 +23,8 @@ namespace appl { if (_data.getType() == enet::HTTPReqType::HTTP_GET) { if (_data.getUri() == "plop.txt") { enet::HttpAnswer answer(enet::HTTPAnswerCode::c200_ok); - std::string data = "coucou"; - answer.setKey("Content-Length", etk::to_string(data.size())); + etk::String data = "coucou"; + answer.setKey("Content-Length", etk::toString(data.size())); _interface->setHeader(answer); _interface->write(data); _interface->stop(true); @@ -42,7 +42,7 @@ int main(int _argc, const char *_argv[]) { etk::init(_argc, _argv); enet::init(_argc, _argv); for (int32_t iii=0; iii<_argc ; ++iii) { - std::string data = _argv[iii]; + etk::String data = _argv[iii]; if ( data == "-h" || data == "--help") { TEST_PRINT(etk::getApplicationName() << " - help : "); @@ -62,16 +62,16 @@ int main(int _argc, const char *_argv[]) { // Start listening ... interface.link(); // Wait a new connection .. - enet::Tcp tcpConnection = std::move(interface.waitNext()); + enet::Tcp tcpConnection = etk::move(interface.waitNext()); // Free Connected port interface.unlink(); // TODO : Check if connection is valid ... // Create a HTTP connection in Server mode - enet::HttpServer connection(std::move(tcpConnection)); + enet::HttpServer connection(etk::move(tcpConnection)); enet::HttpServer* tmp = &connection; // Set callbacks: - connection.connect([=](std::vector& _value){ + connection.connect([=](etk::Vector& _value){ appl::onReceiveData(tmp, _value); }); connection.connectHeader([=](const enet::HttpRequest& _value){ @@ -97,8 +97,8 @@ int main(int _argc, const char *_argv[]) { TEST_INFO("----------------------------"); TEST_INFO("POST data : "); - std::map values; - values.insert(std::make_pair("plop", "valuePlop")); + etk::Map values; + values.insert(etk::makePair("plop", "valuePlop")); if (connection.post("", values) == false) { TEST_ERROR("can not POST data..."); return -1; @@ -107,7 +107,7 @@ int main(int _argc, const char *_argv[]) { TEST_INFO("----------------------------"); TEST_INFO("POST xml : "); - if (connection.post("", "text/xml; charset=utf-8", "value1") == false) { + if (connection.post("", "text/xml; charset=utf-8", "value1") == false) { TEST_ERROR("can not POST XML data..."); return -1; } diff --git a/test/main-server-websocket.cpp b/test/main-server-websocket.cpp index 43cb787..d6a97f9 100644 --- a/test/main-server-websocket.cpp +++ b/test/main-server-websocket.cpp @@ -15,7 +15,7 @@ #include namespace appl { - void onReceiveData(enet::WebSocket* _interface, std::vector& _data, bool _isString) { + void onReceiveData(enet::WebSocket* _interface, etk::Vector& _data, bool _isString) { TEST_INFO("Receive Datas : " << _data.size() << " bytes"); if (_isString == true) { _data.resize(_data.size()+1); @@ -26,7 +26,7 @@ namespace appl { TEST_INFO("binary data: ... "); } } - bool onReceiveUri(enet::WebSocket* _interface, const std::string& _uri, const std::vector& _protocols) { + bool onReceiveUri(enet::WebSocket* _interface, const etk::String& _uri, const etk::Vector& _protocols) { TEST_INFO("Receive Header uri: " << _uri); for (auto &it : _protocols) { if (it == "test1526/1.5") { @@ -45,7 +45,7 @@ int main(int _argc, const char *_argv[]) { etk::init(_argc, _argv); enet::init(_argc, _argv); for (int32_t iii=0; iii<_argc ; ++iii) { - std::string data = _argv[iii]; + etk::String data = _argv[iii]; if ( data == "-h" || data == "--help") { TEST_PRINT(etk::getApplicationName() << " - help : "); @@ -65,19 +65,19 @@ int main(int _argc, const char *_argv[]) { // Start listening ... interface.link(); // Wait a new connection .. - enet::Tcp tcpConnection = std::move(interface.waitNext()); + enet::Tcp tcpConnection = etk::move(interface.waitNext()); // Free Connected port interface.unlink(); // TODO : Check if connection is valid ... // Create a HTTP connection in Server mode - enet::WebSocket connection(std::move(tcpConnection), true); + enet::WebSocket connection(etk::move(tcpConnection), true); enet::WebSocket* tmp = &connection; // Set callbacks: - connection.connect([=](std::vector& _value, bool _isString){ + connection.connect([=](etk::Vector& _value, bool _isString){ appl::onReceiveData(tmp, _value, _isString); }); - connection.connectUri([=](const std::string& _value, const std::vector& _protocols){ + connection.connectUri([=](const etk::String& _value, const etk::Vector& _protocols){ return appl::onReceiveUri(tmp, _value, _protocols); }); diff --git a/test/main-server.cpp b/test/main-server.cpp index 15d8519..1aeaf89 100644 --- a/test/main-server.cpp +++ b/test/main-server.cpp @@ -17,7 +17,7 @@ int main(int _argc, const char *_argv[]) { etk::init(_argc, _argv); enet::init(_argc, _argv); for (int32_t iii=0; iii<_argc ; ++iii) { - std::string data = _argv[iii]; + etk::String data = _argv[iii]; if ( data == "-h" || data == "--help") { TEST_PRINT(etk::getApplicationName() << " - help : "); @@ -37,13 +37,13 @@ int main(int _argc, const char *_argv[]) { // Start listening ... interface.link(); // Wait a new connection .. - enet::Tcp tcpConnection = std::move(interface.waitNext()); + enet::Tcp tcpConnection = etk::move(interface.waitNext()); // Free Connected port interface.unlink(); int32_t iii = 0; while (tcpConnection.getConnectionStatus() == enet::Tcp::status::link) { - int32_t len = tcpConnection.write("plop" + etk::to_string(iii)); + int32_t len = tcpConnection.write("plop" + etk::toString(iii)); TEST_INFO("write len=" << len); char data[1024]; len = tcpConnection.read(data, 1024);