summaryrefslogtreecommitdiffstats
path: root/services/audiopolicy/engineconfigurable/parameter-framework/plugin/PolicySubsystem.cpp
blob: bf3906df5dfd02679b8e15cc6e6dc4560db58871 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
/*
 * Copyright (C) 2015 The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

#include "PolicySubsystem.h"
#include "SubsystemObjectFactory.h"
#include "PolicyMappingKeys.h"
#include "Strategy.h"
#include "Stream.h"
#include "InputSource.h"
#include "VolumeProfile.h"
#include "Usage.h"
#include <AudioPolicyPluginInterface.h>
#include <AudioPolicyEngineInstance.h>
#include <utils/Log.h>

using android::audio_policy::EngineInstance;

const char *const PolicySubsystem::mKeyName = "Name";
const char *const PolicySubsystem::mKeyIdentifier = "Identifier";
const char *const PolicySubsystem::mKeyCategory = "Category";
const char *const PolicySubsystem::mKeyAmend1 = "Amend1";
const char *const PolicySubsystem::mKeyAmend2 = "Amend2";
const char *const PolicySubsystem::mKeyAmend3 = "Amend3";


const char *const PolicySubsystem::mStreamComponentName = "Stream";
const char *const PolicySubsystem::mStrategyComponentName = "Strategy";
const char *const PolicySubsystem::mInputSourceComponentName = "InputSource";
const char *const PolicySubsystem::mUsageComponentName = "Usage";
const char *const PolicySubsystem::mVolumeProfileComponentName = "VolumeProfile";

PolicySubsystem::PolicySubsystem(const std::string &name)
    : CSubsystem(name),
      mPluginInterface(NULL)
{
    // Try to connect a Plugin Interface from Audio Policy Engine
    EngineInstance *engineInstance = EngineInstance::getInstance();

    ALOG_ASSERT(engineInstance != NULL, "NULL Plugin Interface");

    // Retrieve the Route Interface
    mPluginInterface = engineInstance->queryInterface<android::AudioPolicyPluginInterface>();
    ALOG_ASSERT(mPluginInterface != NULL, "NULL Plugin Interface");

    // Provide mapping keys to the core, necessary when parsing the XML Structure files.
    addContextMappingKey(mKeyName);
    addContextMappingKey(mKeyCategory);
    addContextMappingKey(mKeyIdentifier);
    addContextMappingKey(mKeyAmend1);
    addContextMappingKey(mKeyAmend2);
    addContextMappingKey(mKeyAmend3);

    // Provide creators to upper layer
    addSubsystemObjectFactory(
        new TSubsystemObjectFactory<Stream>(
            mStreamComponentName,
            (1 << MappingKeyAmend1) | (1 << MappingKeyIdentifier))
        );
    addSubsystemObjectFactory(
        new TSubsystemObjectFactory<Strategy>(
            mStrategyComponentName,
            (1 << MappingKeyAmend1) | (1 << MappingKeyIdentifier))
        );
    addSubsystemObjectFactory(
        new TSubsystemObjectFactory<Usage>(
            mUsageComponentName,
            (1 << MappingKeyAmend1) | (1 << MappingKeyIdentifier))
        );
    addSubsystemObjectFactory(
        new TSubsystemObjectFactory<InputSource>(
            mInputSourceComponentName,
            (1 << MappingKeyAmend1) | (1 << MappingKeyIdentifier))
        );
    addSubsystemObjectFactory(
        new TSubsystemObjectFactory<VolumeProfile>(
            mVolumeProfileComponentName,
            (1 << MappingKeyAmend1) | (1 << MappingKeyIdentifier) | (1 << MappingKeyIdentifier))
        );
}

// Retrieve Route interface
android::AudioPolicyPluginInterface *PolicySubsystem::getPolicyPluginInterface() const
{
    ALOG_ASSERT(mPluginInterface != NULL, "NULL Plugin Interface");
    return mPluginInterface;
}