Element.h revision 65c3781db3443531deacecfbda5c7e7e82868a34
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
25namespace android
26{
27namespace audio_policy
28{
29
30template <typename Key>
31class Element
32{
33public:
34    Element(const std::string &name)
35        : mName(name)
36    {}
37    ~Element() {}
38
39    /**
40     * Returns identifier of this policy element
41     *
42     * @returns string representing the name of this policy element
43     */
44    const std::string &getName() const { return mName; }
45
46    /**
47    * Set the unique identifier for this policy element.
48    *
49    * @tparam Key type of the unique identifier.
50    * @param[in] identifier to be set.
51    *
52    * @return NO_ERROR if the identifier is valid and set correctly, error code otherwise.
53    */
54    status_t setIdentifier(Key identifier)
55    {
56        mIdentifier = identifier;
57        return NO_ERROR;
58    }
59
60    /**
61     * @return the unique identifier of this policy element.
62     */
63    const Key &getIdentifier() const { return mIdentifier; }
64
65    /**
66     * A Policy element may implement getter/setter function for a given property.
67     * Property may be routing_strategy, audio_stream_type_t, audio_usage_t, audio_source_t
68     * or a string.
69     *
70     * @tparam Property for which this policy element has setter / getter.
71     * @return the property kept track by this policy base element.
72     */
73    template <typename Property>
74    Property get() const;
75
76    /**
77     * A Policy element may implement getter/setter function for a given property.
78     * Property may be routing_strategy, audio_stream_type_t, audio_usage_t, audio_source_t
79     * or a string.
80     *
81     * @tparam Property for which this policy element has setter / getter.
82     *
83     * @param[in] property value to be assigned for this policy base element.
84     *
85     * @return the property kept track by this policy base element.
86     */
87    template <typename Property>
88    status_t set(Property property);
89
90private:
91    /* Copy facilities are put private to disable copy. */
92    Element(const Element &object);
93    Element &operator=(const Element &object);
94
95    std::string mName; /**< Unique literal Identifier of a policy base element*/
96    Key mIdentifier; /**< Unique numerical Identifier of a policy base element*/
97};
98} // namespace audio_policy
99} // namespace android
100