120f06f996337c9bf79d0b112083f6427a122ebabFrançois Gaffie/*
220f06f996337c9bf79d0b112083f6427a122ebabFrançois Gaffie * Copyright (C) 2015 The Android Open Source Project
320f06f996337c9bf79d0b112083f6427a122ebabFrançois Gaffie *
420f06f996337c9bf79d0b112083f6427a122ebabFrançois Gaffie * Licensed under the Apache License, Version 2.0 (the "License");
520f06f996337c9bf79d0b112083f6427a122ebabFrançois Gaffie * you may not use this file except in compliance with the License.
620f06f996337c9bf79d0b112083f6427a122ebabFrançois Gaffie * You may obtain a copy of the License at
720f06f996337c9bf79d0b112083f6427a122ebabFrançois Gaffie *
820f06f996337c9bf79d0b112083f6427a122ebabFrançois Gaffie *      http://www.apache.org/licenses/LICENSE-2.0
920f06f996337c9bf79d0b112083f6427a122ebabFrançois Gaffie *
1020f06f996337c9bf79d0b112083f6427a122ebabFrançois Gaffie * Unless required by applicable law or agreed to in writing, software
1120f06f996337c9bf79d0b112083f6427a122ebabFrançois Gaffie * distributed under the License is distributed on an "AS IS" BASIS,
1220f06f996337c9bf79d0b112083f6427a122ebabFrançois Gaffie * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
1320f06f996337c9bf79d0b112083f6427a122ebabFrançois Gaffie * See the License for the specific language governing permissions and
1420f06f996337c9bf79d0b112083f6427a122ebabFrançois Gaffie * limitations under the License.
1520f06f996337c9bf79d0b112083f6427a122ebabFrançois Gaffie */
1620f06f996337c9bf79d0b112083f6427a122ebabFrançois Gaffie
1720f06f996337c9bf79d0b112083f6427a122ebabFrançois Gaffie#pragma once
1820f06f996337c9bf79d0b112083f6427a122ebabFrançois Gaffie
1920f06f996337c9bf79d0b112083f6427a122ebabFrançois Gaffie#include <stdint.h>
2020f06f996337c9bf79d0b112083f6427a122ebabFrançois Gaffie#include <string>
2120f06f996337c9bf79d0b112083f6427a122ebabFrançois Gaffie#include <utils/Errors.h>
2220f06f996337c9bf79d0b112083f6427a122ebabFrançois Gaffie#include <system/audio.h>
2320f06f996337c9bf79d0b112083f6427a122ebabFrançois Gaffie#include <utils/Log.h>
2420f06f996337c9bf79d0b112083f6427a122ebabFrançois Gaffie
2520f06f996337c9bf79d0b112083f6427a122ebabFrançois Gaffienamespace android
2620f06f996337c9bf79d0b112083f6427a122ebabFrançois Gaffie{
2720f06f996337c9bf79d0b112083f6427a122ebabFrançois Gaffienamespace audio_policy
2820f06f996337c9bf79d0b112083f6427a122ebabFrançois Gaffie{
2920f06f996337c9bf79d0b112083f6427a122ebabFrançois Gaffie
3020f06f996337c9bf79d0b112083f6427a122ebabFrançois Gaffietemplate <typename Key>
3120f06f996337c9bf79d0b112083f6427a122ebabFrançois Gaffieclass Element
3220f06f996337c9bf79d0b112083f6427a122ebabFrançois Gaffie{
3320f06f996337c9bf79d0b112083f6427a122ebabFrançois Gaffiepublic:
3420f06f996337c9bf79d0b112083f6427a122ebabFrançois Gaffie    Element(const std::string &name)
3520f06f996337c9bf79d0b112083f6427a122ebabFrançois Gaffie        : mName(name)
3620f06f996337c9bf79d0b112083f6427a122ebabFrançois Gaffie    {}
3720f06f996337c9bf79d0b112083f6427a122ebabFrançois Gaffie    ~Element() {}
3820f06f996337c9bf79d0b112083f6427a122ebabFrançois Gaffie
3920f06f996337c9bf79d0b112083f6427a122ebabFrançois Gaffie    /**
4020f06f996337c9bf79d0b112083f6427a122ebabFrançois Gaffie     * Returns identifier of this policy element
4120f06f996337c9bf79d0b112083f6427a122ebabFrançois Gaffie     *
4220f06f996337c9bf79d0b112083f6427a122ebabFrançois Gaffie     * @returns string representing the name of this policy element
4320f06f996337c9bf79d0b112083f6427a122ebabFrançois Gaffie     */
4420f06f996337c9bf79d0b112083f6427a122ebabFrançois Gaffie    const std::string &getName() const { return mName; }
4520f06f996337c9bf79d0b112083f6427a122ebabFrançois Gaffie
4620f06f996337c9bf79d0b112083f6427a122ebabFrançois Gaffie    /**
4720f06f996337c9bf79d0b112083f6427a122ebabFrançois Gaffie    * Set the unique identifier for this policy element.
4820f06f996337c9bf79d0b112083f6427a122ebabFrançois Gaffie    *
4920f06f996337c9bf79d0b112083f6427a122ebabFrançois Gaffie    * @tparam Key type of the unique identifier.
5020f06f996337c9bf79d0b112083f6427a122ebabFrançois Gaffie    * @param[in] identifier to be set.
5120f06f996337c9bf79d0b112083f6427a122ebabFrançois Gaffie    *
5220f06f996337c9bf79d0b112083f6427a122ebabFrançois Gaffie    * @return NO_ERROR if the identifier is valid and set correctly, error code otherwise.
5320f06f996337c9bf79d0b112083f6427a122ebabFrançois Gaffie    */
5420f06f996337c9bf79d0b112083f6427a122ebabFrançois Gaffie    status_t setIdentifier(Key identifier)
5520f06f996337c9bf79d0b112083f6427a122ebabFrançois Gaffie    {
5620f06f996337c9bf79d0b112083f6427a122ebabFrançois Gaffie        mIdentifier = identifier;
5720f06f996337c9bf79d0b112083f6427a122ebabFrançois Gaffie        return NO_ERROR;
5820f06f996337c9bf79d0b112083f6427a122ebabFrançois Gaffie    }
5920f06f996337c9bf79d0b112083f6427a122ebabFrançois Gaffie
6020f06f996337c9bf79d0b112083f6427a122ebabFrançois Gaffie    /**
6120f06f996337c9bf79d0b112083f6427a122ebabFrançois Gaffie     * @return the unique identifier of this policy element.
6220f06f996337c9bf79d0b112083f6427a122ebabFrançois Gaffie     */
6320f06f996337c9bf79d0b112083f6427a122ebabFrançois Gaffie    const Key &getIdentifier() const { return mIdentifier; }
6420f06f996337c9bf79d0b112083f6427a122ebabFrançois Gaffie
6520f06f996337c9bf79d0b112083f6427a122ebabFrançois Gaffie    /**
6620f06f996337c9bf79d0b112083f6427a122ebabFrançois Gaffie     * A Policy element may implement getter/setter function for a given property.
6720f06f996337c9bf79d0b112083f6427a122ebabFrançois Gaffie     * Property may be routing_strategy, audio_stream_type_t, audio_usage_t, audio_source_t
6820f06f996337c9bf79d0b112083f6427a122ebabFrançois Gaffie     * or a string.
6920f06f996337c9bf79d0b112083f6427a122ebabFrançois Gaffie     *
7020f06f996337c9bf79d0b112083f6427a122ebabFrançois Gaffie     * @tparam Property for which this policy element has setter / getter.
7120f06f996337c9bf79d0b112083f6427a122ebabFrançois Gaffie     * @return the property kept track by this policy base element.
7220f06f996337c9bf79d0b112083f6427a122ebabFrançois Gaffie     */
7320f06f996337c9bf79d0b112083f6427a122ebabFrançois Gaffie    template <typename Property>
7420f06f996337c9bf79d0b112083f6427a122ebabFrançois Gaffie    Property get() const;
7520f06f996337c9bf79d0b112083f6427a122ebabFrançois Gaffie
7620f06f996337c9bf79d0b112083f6427a122ebabFrançois Gaffie    /**
7720f06f996337c9bf79d0b112083f6427a122ebabFrançois Gaffie     * A Policy element may implement getter/setter function for a given property.
7820f06f996337c9bf79d0b112083f6427a122ebabFrançois Gaffie     * Property may be routing_strategy, audio_stream_type_t, audio_usage_t, audio_source_t
7920f06f996337c9bf79d0b112083f6427a122ebabFrançois Gaffie     * or a string.
8020f06f996337c9bf79d0b112083f6427a122ebabFrançois Gaffie     *
8120f06f996337c9bf79d0b112083f6427a122ebabFrançois Gaffie     * @tparam Property for which this policy element has setter / getter.
8220f06f996337c9bf79d0b112083f6427a122ebabFrançois Gaffie     *
8320f06f996337c9bf79d0b112083f6427a122ebabFrançois Gaffie     * @param[in] property value to be assigned for this policy base element.
8420f06f996337c9bf79d0b112083f6427a122ebabFrançois Gaffie     *
8520f06f996337c9bf79d0b112083f6427a122ebabFrançois Gaffie     * @return the property kept track by this policy base element.
8620f06f996337c9bf79d0b112083f6427a122ebabFrançois Gaffie     */
8720f06f996337c9bf79d0b112083f6427a122ebabFrançois Gaffie    template <typename Property>
8820f06f996337c9bf79d0b112083f6427a122ebabFrançois Gaffie    status_t set(Property property);
8920f06f996337c9bf79d0b112083f6427a122ebabFrançois Gaffie
9020f06f996337c9bf79d0b112083f6427a122ebabFrançois Gaffieprivate:
9120f06f996337c9bf79d0b112083f6427a122ebabFrançois Gaffie    /* Copy facilities are put private to disable copy. */
9220f06f996337c9bf79d0b112083f6427a122ebabFrançois Gaffie    Element(const Element &object);
9320f06f996337c9bf79d0b112083f6427a122ebabFrançois Gaffie    Element &operator=(const Element &object);
9420f06f996337c9bf79d0b112083f6427a122ebabFrançois Gaffie
9520f06f996337c9bf79d0b112083f6427a122ebabFrançois Gaffie    std::string mName; /**< Unique literal Identifier of a policy base element*/
9620f06f996337c9bf79d0b112083f6427a122ebabFrançois Gaffie    Key mIdentifier; /**< Unique numerical Identifier of a policy base element*/
9720f06f996337c9bf79d0b112083f6427a122ebabFrançois Gaffie};
9820f06f996337c9bf79d0b112083f6427a122ebabFrançois Gaffie} // namespace audio_policy
9920f06f996337c9bf79d0b112083f6427a122ebabFrançois Gaffie} // namespace android
100