From 82b8a71bc106fefd295416235229fb8085e04aff Mon Sep 17 00:00:00 2001 From: Tristan Matthews <tristan.matthews@savoirfairelinux.com> Date: Fri, 14 Nov 2014 14:12:57 -0500 Subject: [PATCH] daemon: std::to_string not available on Android Refs #60545 Change-Id: I94bcc65e61433755ca73dd019722d0da569e657d --- daemon/src/Makefile.am | 1 + daemon/src/dht/dhtcpp/dht.cpp | 3 +- daemon/src/sip/sipvoiplink.cpp | 3 +- daemon/src/string_utils.h | 63 ++++++++++++++++++++++++++++++++++ 4 files changed, 68 insertions(+), 2 deletions(-) create mode 100644 daemon/src/string_utils.h diff --git a/daemon/src/Makefile.am b/daemon/src/Makefile.am index 05a660c632..50e72a67d6 100644 --- a/daemon/src/Makefile.am +++ b/daemon/src/Makefile.am @@ -118,6 +118,7 @@ libsflphone_la_SOURCES = conference.cpp \ account_schema.h \ registration_states.h \ map_utils.h \ + string_utils.h \ rw_mutex.h \ sflphone.h \ sflphone_api.cpp diff --git a/daemon/src/dht/dhtcpp/dht.cpp b/daemon/src/dht/dhtcpp/dht.cpp index 5303bf8a6d..e79b12d677 100644 --- a/daemon/src/dht/dhtcpp/dht.cpp +++ b/daemon/src/dht/dhtcpp/dht.cpp @@ -27,6 +27,7 @@ THE SOFTWARE. #include "dht.h" #include "logger.h" +#include "string_utils.h" extern "C" { #include <gnutls/gnutls.h> @@ -1228,7 +1229,7 @@ Dht::dumpBucket(const Bucket& b, std::ostream& out) const inet_ntop(AF_INET6, &sin6->sin6_addr, (char*)buf.data(), buf.size()); port = ntohs(sin6->sin6_port); } else { - out << "unknown("+std::to_string(n.ss.ss_family)+")"; + out << "unknown("+sfl::to_string(n.ss.ss_family)+")"; port = 0; } buf.resize(std::char_traits<char>::length(buf.c_str())); diff --git a/daemon/src/sip/sipvoiplink.cpp b/daemon/src/sip/sipvoiplink.cpp index 758bef792e..2e8d6c4b9f 100644 --- a/daemon/src/sip/sipvoiplink.cpp +++ b/daemon/src/sip/sipvoiplink.cpp @@ -42,6 +42,7 @@ #include "sipcall.h" #include "sipaccount.h" #include "sip_utils.h" +#include "string_utils.h" #if HAVE_DHT #include "dht/dhtaccount.h" @@ -1330,7 +1331,7 @@ SIPVoIPLink::resolveSrvName(const std::string &name, pjsip_transport_type_e type 0, type, {{(char*)name.data(), (pj_ssize_t)name.size()}, 0}, }; - auto token = std::hash<std::string>()(name + std::to_string(type)); + auto token = std::hash<std::string>()(name + sfl::to_string(type)); { std::lock_guard<std::mutex> lock(resolveMutex_); resolveCallbacks_[token] = [cb](pj_status_t s, const pjsip_server_addresses* r) { diff --git a/daemon/src/string_utils.h b/daemon/src/string_utils.h new file mode 100644 index 0000000000..24bd3e4a21 --- /dev/null +++ b/daemon/src/string_utils.h @@ -0,0 +1,63 @@ +/* + * Copyright (C) 2014 Savoir-Faire Linux Inc. + * + * Author: Tristan Matthews <tristan.matthews@savoirfairelinux.com> + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Additional permission under GNU GPL version 3 section 7: + * + * If you modify this program, or any covered work, by linking or + * combining it with the OpenSSL project's OpenSSL library (or a + * modified version of that library), containing parts covered by the + * terms of the OpenSSL or SSLeay licenses, Savoir-Faire Linux Inc. + * grants you additional permission to convey the resulting work. + * Corresponding Source for a non-source form of such a combination + * shall include the source code for the parts of OpenSSL used as well + * as that of the covered work. + */ + +#ifndef STRING_UTILS_H +#define STRING_UTILS_H + +namespace sfl { + +#ifdef __ANDROID__ + +#include <string> +#include <sstream> + +template <typename T> +std::string to_string(T &&value) +{ + std::ostringstream os; + + os << value; + return os.str(); +} + +#else + +template <typename T> +std::string to_string(T &&value) +{ + return std::to_string(std::forward<T>(value)); +} + +#endif + +} + +#endif // H_UTF8_UTILS -- GitLab