François Gaffie | 20f06f9 | 2015-03-24 09:01:14 +0100 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2015 The Android Open Source Project |
| 3 | * |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | * you may not use this file except in compliance with the License. |
| 6 | * You may obtain a copy of the License at |
| 7 | * |
| 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | * |
| 10 | * Unless required by applicable law or agreed to in writing, software |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | * See the License for the specific language governing permissions and |
| 14 | * limitations under the License. |
| 15 | */ |
| 16 | |
| 17 | #pragma once |
| 18 | |
| 19 | #include <stdint.h> |
| 20 | #include <string> |
| 21 | #include <utils/Errors.h> |
| 22 | #include <system/audio.h> |
| 23 | #include <utils/Log.h> |
| 24 | |
François Gaffie | f19cf79 | 2018-05-30 17:22:17 +0200 | [diff] [blame] | 25 | namespace android { |
| 26 | namespace audio_policy { |
François Gaffie | 20f06f9 | 2015-03-24 09:01:14 +0100 | [diff] [blame] | 27 | |
| 28 | template <typename Key> |
| 29 | class Element |
| 30 | { |
| 31 | public: |
| 32 | Element(const std::string &name) |
| 33 | : mName(name) |
| 34 | {} |
| 35 | ~Element() {} |
| 36 | |
| 37 | /** |
| 38 | * Returns identifier of this policy element |
| 39 | * |
| 40 | * @returns string representing the name of this policy element |
| 41 | */ |
| 42 | const std::string &getName() const { return mName; } |
| 43 | |
| 44 | /** |
| 45 | * Set the unique identifier for this policy element. |
| 46 | * |
| 47 | * @tparam Key type of the unique identifier. |
| 48 | * @param[in] identifier to be set. |
| 49 | * |
| 50 | * @return NO_ERROR if the identifier is valid and set correctly, error code otherwise. |
| 51 | */ |
| 52 | status_t setIdentifier(Key identifier) |
| 53 | { |
| 54 | mIdentifier = identifier; |
| 55 | return NO_ERROR; |
| 56 | } |
| 57 | |
| 58 | /** |
| 59 | * @return the unique identifier of this policy element. |
| 60 | */ |
| 61 | const Key &getIdentifier() const { return mIdentifier; } |
| 62 | |
| 63 | /** |
| 64 | * A Policy element may implement getter/setter function for a given property. |
François Gaffie | 6054a77 | 2018-11-06 13:10:58 +0100 | [diff] [blame] | 65 | * Property may be audio_stream_type_t, audio_usage_t, audio_source_t |
François Gaffie | 20f06f9 | 2015-03-24 09:01:14 +0100 | [diff] [blame] | 66 | * or a string. |
| 67 | * |
| 68 | * @tparam Property for which this policy element has setter / getter. |
| 69 | * @return the property kept track by this policy base element. |
| 70 | */ |
| 71 | template <typename Property> |
| 72 | Property get() const; |
| 73 | |
| 74 | /** |
| 75 | * A Policy element may implement getter/setter function for a given property. |
François Gaffie | 6054a77 | 2018-11-06 13:10:58 +0100 | [diff] [blame] | 76 | * Property may be audio_stream_type_t, audio_usage_t, audio_source_t |
François Gaffie | 20f06f9 | 2015-03-24 09:01:14 +0100 | [diff] [blame] | 77 | * or a string. |
| 78 | * |
| 79 | * @tparam Property for which this policy element has setter / getter. |
| 80 | * |
| 81 | * @param[in] property value to be assigned for this policy base element. |
| 82 | * |
| 83 | * @return the property kept track by this policy base element. |
| 84 | */ |
| 85 | template <typename Property> |
| 86 | status_t set(Property property); |
| 87 | |
| 88 | private: |
| 89 | /* Copy facilities are put private to disable copy. */ |
| 90 | Element(const Element &object); |
| 91 | Element &operator=(const Element &object); |
| 92 | |
| 93 | std::string mName; /**< Unique literal Identifier of a policy base element*/ |
| 94 | Key mIdentifier; /**< Unique numerical Identifier of a policy base element*/ |
| 95 | }; |
| 96 | } // namespace audio_policy |
| 97 | } // namespace android |