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 #pragma once
18 
19 class EngineInterface;
20 class AudioPolicyPluginInterface;
21 
22 namespace android {
23 namespace audio_policy {
24 
25 class Engine;
26 
27 class EngineInstance
28 {
29 protected:
30     EngineInstance();
31 
32 public:
33     virtual ~EngineInstance();
34 
35     /**
36      * Get Audio Policy Engine instance.
37      *
38      * @return pointer to Route Manager Instance object.
39      */
40     static EngineInstance *getInstance();
41 
42     /**
43      * Interface query.
44      * The first client of an interface of the policy engine will start the singleton.
45      *
46      * @tparam RequestedInterface: interface that the client is wishing to retrieve.
47      *
48      * @return interface handle.
49      */
50     template <class RequestedInterface>
51     RequestedInterface *queryInterface() const;
52 
53 protected:
54     /**
55      * Get Audio Policy Engine instance.
56      *
57      * @return Audio Policy Engine singleton.
58      */
59     Engine *getEngine() const;
60 
61 private:
62     /* Copy facilities are put private to disable copy. */
63     EngineInstance(const EngineInstance &object);
64     EngineInstance &operator=(const EngineInstance &object);
65 };
66 
67 /**
68  * Limit template instantation to supported type interfaces.
69  * Compile time error will claim if invalid interface is requested.
70  */
71 template <>
72 EngineInterface *EngineInstance::queryInterface() const;
73 
74 template <>
75 AudioPolicyPluginInterface *EngineInstance::queryInterface() const;
76 
77 } // namespace audio_policy
78 
79 } // namespace android
80