blob: 310b35ed6437e41b5b2ba5726357e6cd9f8a9711 [file] [log] [blame]
François Gaffie20f06f92015-03-24 09:01:14 +01001/*
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#define LOG_TAG "APM::AudioPolicyEngine/Strategy"
18
19#include "Strategy.h"
20
21using std::string;
22
François Gaffief19cf792018-05-30 17:22:17 +020023namespace android {
24namespace audio_policy {
François Gaffie20f06f92015-03-24 09:01:14 +010025
26status_t Element<routing_strategy>::setIdentifier(routing_strategy identifier)
27{
28 if (identifier >= NUM_STRATEGIES) {
29 return BAD_VALUE;
30 }
31 mIdentifier = identifier;
32 ALOGD("%s: Strategy %s identifier 0x%X", __FUNCTION__, getName().c_str(), identifier);
33 return NO_ERROR;
34}
35
36/**
37 * Set the device associated to this strategy.
François Gaffiec7ce9a22016-05-09 11:07:52 +020038 * It checks if the output device is valid.
François Gaffie20f06f92015-03-24 09:01:14 +010039 *
40 * @param[in] devices selected for the given strategy.
41 *
42 * @return NO_ERROR if the device is either valid or none, error code otherwise.
43 */
44template <>
45status_t Element<routing_strategy>::set<audio_devices_t>(audio_devices_t devices)
46{
François Gaffiec7ce9a22016-05-09 11:07:52 +020047 if (!audio_is_output_devices(devices) || devices == AUDIO_DEVICE_NONE) {
François Gaffie20f06f92015-03-24 09:01:14 +010048 ALOGE("%s: trying to set an invalid device 0x%X for strategy %s",
49 __FUNCTION__, devices, getName().c_str());
50 return BAD_VALUE;
51 }
52 ALOGD("%s: 0x%X for strategy %s", __FUNCTION__, devices, getName().c_str());
53 mApplicableDevices = devices;
54 return NO_ERROR;
55}
56
57template <>
58audio_devices_t Element<routing_strategy>::get<audio_devices_t>() const
59{
60 ALOGV("%s: 0x%X for strategy %s", __FUNCTION__, mApplicableDevices, getName().c_str());
61 return mApplicableDevices;
62}
63
64} // namespace audio_policy
65} // namespace android
66