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