PolicySubsystem.cpp revision 65c3781db3443531deacecfbda5c7e7e82868a34
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 29using android::audio_policy::EngineInstance; 30 31const char *const PolicySubsystem::mKeyName = "Name"; 32const char *const PolicySubsystem::mKeyIdentifier = "Identifier"; 33const char *const PolicySubsystem::mKeyCategory = "Category"; 34const char *const PolicySubsystem::mKeyAmend1 = "Amend1"; 35const char *const PolicySubsystem::mKeyAmend2 = "Amend2"; 36const char *const PolicySubsystem::mKeyAmend3 = "Amend3"; 37 38 39const char *const PolicySubsystem::mStreamComponentName = "Stream"; 40const char *const PolicySubsystem::mStrategyComponentName = "Strategy"; 41const char *const PolicySubsystem::mInputSourceComponentName = "InputSource"; 42const char *const PolicySubsystem::mUsageComponentName = "Usage"; 43const char *const PolicySubsystem::mVolumeProfileComponentName = "VolumeProfile"; 44 45PolicySubsystem::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 if (engineInstance == NULL) { 53 ALOG_ASSERT(engineInstance != NULL, "NULL Plugin Interface"); 54 return; 55 } 56 // Retrieve the Route Interface 57 mPluginInterface = engineInstance->queryInterface<android::AudioPolicyPluginInterface>(); 58 if (mPluginInterface == NULL) { 59 // bailing out 60 ALOG_ASSERT(mPluginInterface != NULL, "NULL Plugin Interface"); 61 return; 62 } 63 64 // Provide mapping keys to the core, necessary when parsing the XML Structure files. 65 addContextMappingKey(mKeyName); 66 addContextMappingKey(mKeyCategory); 67 addContextMappingKey(mKeyIdentifier); 68 addContextMappingKey(mKeyAmend1); 69 addContextMappingKey(mKeyAmend2); 70 addContextMappingKey(mKeyAmend3); 71 72 // Provide creators to upper layer 73 addSubsystemObjectFactory( 74 new TSubsystemObjectFactory<Stream>( 75 mStreamComponentName, 76 (1 << MappingKeyAmend1) | (1 << MappingKeyIdentifier)) 77 ); 78 addSubsystemObjectFactory( 79 new TSubsystemObjectFactory<Strategy>( 80 mStrategyComponentName, 81 (1 << MappingKeyAmend1) | (1 << MappingKeyIdentifier)) 82 ); 83 addSubsystemObjectFactory( 84 new TSubsystemObjectFactory<Usage>( 85 mUsageComponentName, 86 (1 << MappingKeyAmend1) | (1 << MappingKeyIdentifier)) 87 ); 88 addSubsystemObjectFactory( 89 new TSubsystemObjectFactory<InputSource>( 90 mInputSourceComponentName, 91 (1 << MappingKeyAmend1) | (1 << MappingKeyIdentifier)) 92 ); 93 addSubsystemObjectFactory( 94 new TSubsystemObjectFactory<VolumeProfile>( 95 mVolumeProfileComponentName, 96 (1 << MappingKeyAmend1) | (1 << MappingKeyIdentifier) | (1 << MappingKeyIdentifier)) 97 ); 98} 99 100// Retrieve Route interface 101android::AudioPolicyPluginInterface *PolicySubsystem::getPolicyPluginInterface() const 102{ 103 ALOG_ASSERT(mPluginInterface != NULL, "NULL Plugin Interface"); 104 return mPluginInterface; 105} 106