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