From 6fc6a64fa3b0a9e4577eb763590f531c0a50a27b Mon Sep 17 00:00:00 2001 From: Eric Laurent Date: Sat, 25 Apr 2015 05:18:59 +0000 Subject: Revert "Add a configurable version of the policy engine based on PFW" This reverts commit 65c3781db3443531deacecfbda5c7e7e82868a34. Change-Id: Ib61cd70f97c4c4f4b503fb845643627d6896f4f9 --- services/audiopolicy/utilities/Android.mk | 7 - services/audiopolicy/utilities/convert/Android.mk | 30 -- services/audiopolicy/utilities/convert/convert.h | 383 ---------------------- 3 files changed, 420 deletions(-) delete mode 100644 services/audiopolicy/utilities/Android.mk delete mode 100755 services/audiopolicy/utilities/convert/Android.mk delete mode 100644 services/audiopolicy/utilities/convert/convert.h (limited to 'services/audiopolicy/utilities') diff --git a/services/audiopolicy/utilities/Android.mk b/services/audiopolicy/utilities/Android.mk deleted file mode 100644 index ccf33f2..0000000 --- a/services/audiopolicy/utilities/Android.mk +++ /dev/null @@ -1,7 +0,0 @@ - -LOCAL_PATH := $(call my-dir) - -# Recursive call sub-folder Android.mk -# -include $(call all-makefiles-under,$(LOCAL_PATH)) - diff --git a/services/audiopolicy/utilities/convert/Android.mk b/services/audiopolicy/utilities/convert/Android.mk deleted file mode 100755 index 947dec5..0000000 --- a/services/audiopolicy/utilities/convert/Android.mk +++ /dev/null @@ -1,30 +0,0 @@ -LOCAL_PATH := $(call my-dir) - -########################### -# convert static lib target - -include $(CLEAR_VARS) - -LOCAL_EXPORT_C_INCLUDE_DIRS := $(LOCAL_PATH)/ - -LOCAL_MODULE := libutilities_convert - -include $(BUILD_STATIC_LIBRARY) - -######################### -# convert static lib host - -include $(CLEAR_VARS) - -LOCAL_EXPORT_C_INCLUDE_DIRS := $(LOCAL_PATH)/ - -LOCAL_MODULE := libutilities_convert_host - -LOCAL_CFLAGS = -O0 --coverage - -LOCAL_LDFLAGS = --coverage - -LOCAL_MODULE_TAGS := tests - -include $(BUILD_HOST_STATIC_LIBRARY) - diff --git a/services/audiopolicy/utilities/convert/convert.h b/services/audiopolicy/utilities/convert/convert.h deleted file mode 100644 index 980b5d5..0000000 --- a/services/audiopolicy/utilities/convert/convert.h +++ /dev/null @@ -1,383 +0,0 @@ -/* - * Copyright (C) 2015 The Android Open Source Project - * - * 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. - */ - -#pragma once - -#include -#include -#include -#include -#include -#include - -namespace android -{ - -namespace utilities -{ - -/** - * Convert a given source type to a given destination type. - * - * String conversion to T reads the value of the type T in the given string. - * The function does not allow to have white spaces around the value to parse - * and tries to parse the whole string, which means that if some bytes were not - * read in the string, the function fails. - * Hexadecimal representation (ie. numbers starting with 0x) is supported only - * for integral types conversions. - * - * Numeric conversion to string formats the source value to decimal space. - * - * Vector to vector conversion calls convertTo on each element. - * - * @tparam srcType source type, default value is string type - * @tparam dstType destination type - * @param[in] input The source to convert from. - * @param[out] result Converted value if success, undefined on failure. - * - * @return true if conversion was successful, false otherwise. - */ -template -static inline bool convertTo(const srcType &input, dstType &result); - -/* details namespace is here to hide implementation details to header end user. It - * is NOT intended to be used outside. */ -namespace details -{ - -/** Helper class to limit instantiation of templates */ -template -struct ConversionFromStringAllowed; -template -struct ConversionToStringAllowed; - -/* List of allowed types for conversion */ -template <> -struct ConversionFromStringAllowed {}; -template <> -struct ConversionFromStringAllowed {}; -template <> -struct ConversionFromStringAllowed {}; -template <> -struct ConversionFromStringAllowed {}; -template <> -struct ConversionFromStringAllowed {}; -template <> -struct ConversionFromStringAllowed {}; -template <> -struct ConversionFromStringAllowed {}; -template <> -struct ConversionFromStringAllowed {}; -template <> -struct ConversionFromStringAllowed {}; - -template <> -struct ConversionToStringAllowed {}; -template <> -struct ConversionToStringAllowed {}; -template <> -struct ConversionToStringAllowed {}; -template <> -struct ConversionToStringAllowed {}; -template <> -struct ConversionToStringAllowed {}; -template <> -struct ConversionToStringAllowed {}; - -/** - * Set the decimal precision to 10 digits. - * Note that this setting is aligned with Android Audio Parameter - * policy concerning float storage into string. - */ -static const uint32_t gFloatPrecision = 10; - -template -static inline bool fromString(const std::string &str, T &result) -{ - /* Check that conversion to that type is allowed. - * If this fails, this means that this template was not intended to be used - * with this type, thus that the result is undefined. */ - ConversionFromStringAllowed(); - - if (str.find_first_of(std::string("\r\n\t\v ")) != std::string::npos) { - return false; - } - - /* Check for a '-' in string. If type is unsigned and a - is found, the - * parsing fails. This is made necessary because "-1" is read as 65535 for - * uint16_t, for example */ - if (str.find("-") != std::string::npos - && !std::numeric_limits::is_signed) { - return false; - } - - std::stringstream ss(str); - - /* Sadly, the stream conversion does not handle hexadecimal format, thus - * check is done manually */ - if (str.substr(0, 2) == "0x") { - if (std::numeric_limits::is_integer) { - ss >> std::hex >> result; - } else { - /* Conversion undefined for non integers */ - return false; - } - } else { - ss >> result; - } - - return ss.eof() && !ss.fail() && !ss.bad(); -} - -template -static inline bool toString(const T &value, std::string &str) -{ - /* Check that conversion from that type is allowed. - * If this fails, this means that this template was not intended to be used - * with this type, thus that the result is undefined. */ - ConversionToStringAllowed(); - - std::stringstream oss; - oss.precision(gFloatPrecision); - oss << value; - str = oss.str(); - return !oss.fail() && !oss.bad(); -} - -template -class Converter; - -template -class Converter -{ -public: - static inline bool run(const std::string &str, dstType &result) - { - return fromString(str, result); - } -}; - -template -class Converter -{ -public: - static inline bool run(const srcType &str, std::string &result) - { - return toString(str, result); - } -}; - -/** Convert a vector by applying convertTo on each element. - * - * @tparam SrcElem Type of the src elements. - * @tparam DstElem Type of the destination elements. - */ -template -class Converter, std::vector > -{ -public: - typedef const std::vector Src; - typedef std::vector Dst; - - static inline bool run(Src &src, Dst &dst) - { - typedef typename Src::const_iterator SrcIt; - dst.clear(); - dst.reserve(src.size()); - for (SrcIt it = src.begin(); it != src.end(); ++it) { - DstElem dstElem; - if (not convertTo(*it, dstElem)) { - return false; - } - dst.push_back(dstElem); - } - return true; - } -}; - -} // namespace details - -template -static inline bool convertTo(const srcType &input, dstType &result) -{ - return details::Converter::run(input, result); -} - -/** - * Specialization for int16_t of convertTo template function. - * - * This function follows the same paradigm than it's generic version. - * - * The specific implementation is made necessary because the stlport version of - * string streams is bugged and does not fail when giving overflowed values. - * This specialisation can be safely removed when stlport behaviour is fixed. - * - * @param[in] str the string to parse. - * @param[out] result reference to object where to store the result. - * - * @return true if conversion was successful, false otherwise. - */ -template <> -inline bool convertTo(const std::string &str, int16_t &result) -{ - int64_t res; - - if (!convertTo(str, res)) { - return false; - } - - if (res > std::numeric_limits::max() || res < std::numeric_limits::min()) { - return false; - } - - result = static_cast(res); - return true; -} - -/** - * Specialization for float of convertTo template function. - * - * This function follows the same paradigm than it's generic version and is - * based on it but makes furthers checks on the returned value. - * - * The specific implementation is made necessary because the stlport conversion - * from string to float behaves differently than GNU STL: overflow produce - * +/-Infinity rather than an error. - * - * @param[in] str the string to parse. - * @param[out] result reference to object where to store the result. - * - * @return true if conversion was successful, false otherwise. - */ -template <> -inline bool convertTo(const std::string &str, float &result) -{ - if (!details::Converter::run(str, result)) { - return false; - } - - if (std::abs(result) == std::numeric_limits::infinity() || - result == std::numeric_limits::quiet_NaN()) { - return false; - } - - return true; -} - -/** - * Specialization for double of convertTo template function. - * - * This function follows the same paradigm than it's generic version and is - * based on it but makes furthers checks on the returned value. - * - * The specific implementation is made necessary because the stlport conversion - * from string to double behaves differently than GNU STL: overflow produce - * +/-Infinity rather than an error. - * - * @param[in] str the string to parse. - * @param[out] result reference to object where to store the result. - * - * @return true if conversion was successful, false otherwise. - */ -template <> -inline bool convertTo(const std::string &str, double &result) -{ - if (!details::Converter::run(str, result)) { - return false; - } - - if (std::abs(result) == std::numeric_limits::infinity() || - result == std::numeric_limits::quiet_NaN()) { - return false; - } - - return true; -} - -/** - * Specialization for boolean of convertTo template function. - * - * This function follows the same paradigm than it's generic version. - * This function accepts to parse boolean as "0/1" or "false/true" or - * "FALSE/TRUE". - * The specific implementation is made necessary because the behaviour of - * string streams when parsing boolean values is not sufficient to fit our - * requirements. Indeed, parsing "true" will correctly parse the value, but the - * end of stream is not reached which makes the ss.eof() fails in the generic - * implementation. - * - * @param[in] str the string to parse. - * @param[out] result reference to object where to store the result. - * - * @return true if conversion was successful, false otherwise. - */ -template <> -inline bool convertTo(const std::string &str, bool &result) -{ - if (str == "0" || str == "FALSE" || str == "false") { - result = false; - return true; - } - - if (str == "1" || str == "TRUE" || str == "true") { - result = true; - return true; - } - - return false; -} - -/** - * Specialization for boolean to string of convertTo template function. - * - * This function follows the same paradigm than it's generic version. - * This function arbitrarily decides to return "false/true". - * It is compatible with the specialization from string to boolean. - * - * @param[in] isSet boolean to convert to a string. - * @param[out] result reference to object where to store the result. - * - * @return true if conversion was successful, false otherwise. - */ -template <> -inline bool convertTo(const bool &isSet, std::string &result) -{ - result = isSet ? "true" : "false"; - return true; -} - -/** - * Specialization for string to string of convertTo template function. - * - * This function is a dummy conversion from string to string. - * In case of clients using template as well, this implementation avoids adding extra - * specialization to bypass the conversion from string to string. - * - * @param[in] str the string to parse. - * @param[out] result reference to object where to store the result. - * - * @return true if conversion was successful, false otherwise. - */ -template <> -inline bool convertTo(const std::string &str, std::string &result) -{ - result = str; - return true; -} - -} // namespace utilities - -} // namespace android -- cgit v1.1