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 #include "PolicySubsystem.h"
18 #include "SubsystemObjectFactory.h"
19 #include "PolicyMappingKeys.h"
20 #include "Strategy.h"
21 #include "Stream.h"
22 #include "InputSource.h"
23 #include "VolumeProfile.h"
24 #include "Usage.h"
25 #include <AudioPolicyPluginInterface.h>
26 #include <AudioPolicyEngineInstance.h>
27 #include <utils/Log.h>
28
29 using android::audio_policy::EngineInstance;
30
31 const char *const PolicySubsystem::mKeyName = "Name";
32 const char *const PolicySubsystem::mKeyIdentifier = "Identifier";
33 const char *const PolicySubsystem::mKeyCategory = "Category";
34 const char *const PolicySubsystem::mKeyAmend1 = "Amend1";
35 const char *const PolicySubsystem::mKeyAmend2 = "Amend2";
36 const char *const PolicySubsystem::mKeyAmend3 = "Amend3";
37
38
39 const char *const PolicySubsystem::mStreamComponentName = "Stream";
40 const char *const PolicySubsystem::mStrategyComponentName = "Strategy";
41 const char *const PolicySubsystem::mInputSourceComponentName = "InputSource";
42 const char *const PolicySubsystem::mUsageComponentName = "Usage";
43 const char *const PolicySubsystem::mVolumeProfileComponentName = "VolumeProfile";
44
PolicySubsystem(const std::string & name)45 PolicySubsystem::PolicySubsystem(const std::string &name)
46 : CSubsystem(name),
47 mPluginInterface(NULL)
48 {
49 // Try to connect a Plugin Interface from Audio Policy Engine
50 EngineInstance *engineInstance = EngineInstance::getInstance();
51
52 ALOG_ASSERT(engineInstance != NULL, "NULL Plugin Interface");
53
54 // Retrieve the Route Interface
55 mPluginInterface = engineInstance->queryInterface<android::AudioPolicyPluginInterface>();
56 ALOG_ASSERT(mPluginInterface != NULL, "NULL Plugin Interface");
57
58 // Provide mapping keys to the core, necessary when parsing the XML Structure files.
59 addContextMappingKey(mKeyName);
60 addContextMappingKey(mKeyCategory);
61 addContextMappingKey(mKeyIdentifier);
62 addContextMappingKey(mKeyAmend1);
63 addContextMappingKey(mKeyAmend2);
64 addContextMappingKey(mKeyAmend3);
65
66 // Provide creators to upper layer
67 addSubsystemObjectFactory(
68 new TSubsystemObjectFactory<Stream>(
69 mStreamComponentName,
70 (1 << MappingKeyAmend1) | (1 << MappingKeyIdentifier))
71 );
72 addSubsystemObjectFactory(
73 new TSubsystemObjectFactory<Strategy>(
74 mStrategyComponentName,
75 (1 << MappingKeyAmend1) | (1 << MappingKeyIdentifier))
76 );
77 addSubsystemObjectFactory(
78 new TSubsystemObjectFactory<Usage>(
79 mUsageComponentName,
80 (1 << MappingKeyAmend1) | (1 << MappingKeyIdentifier))
81 );
82 addSubsystemObjectFactory(
83 new TSubsystemObjectFactory<InputSource>(
84 mInputSourceComponentName,
85 (1 << MappingKeyAmend1) | (1 << MappingKeyIdentifier))
86 );
87 addSubsystemObjectFactory(
88 new TSubsystemObjectFactory<VolumeProfile>(
89 mVolumeProfileComponentName,
90 (1 << MappingKeyAmend1) | (1 << MappingKeyIdentifier) | (1 << MappingKeyIdentifier))
91 );
92 }
93
94 // Retrieve Route interface
getPolicyPluginInterface() const95 android::AudioPolicyPluginInterface *PolicySubsystem::getPolicyPluginInterface() const
96 {
97 ALOG_ASSERT(mPluginInterface != NULL, "NULL Plugin Interface");
98 return mPluginInterface;
99 }
100