1 /*
2 * Copyright (C) 2022 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 "include/Analyzer.h"
18
19 using std::unique_ptr;
20 using std::unordered_map;
21
22 namespace android {
23 namespace aidl {
24
25 using analyzeFn = android::status_t (*)(uint32_t _aidl_code, const android::Parcel& _aidl_data,
26 const android::Parcel& _aidl_reply);
27
Analyzer(const std::string & package,const std::string & interface,analyzeFn function)28 Analyzer::Analyzer(const std::string& package, const std::string& interface, analyzeFn function)
29 : mPackageName(package), mInterfaceName(interface), mAnalyzeFunction(function) {}
30
getPackageName() const31 const std::string& Analyzer::getPackageName() const {
32 return mPackageName;
33 }
34
getInterfaceName() const35 const std::string& Analyzer::getInterfaceName() const {
36 return mInterfaceName;
37 }
38
getAnalyzeFunction() const39 const analyzeFn& Analyzer::getAnalyzeFunction() const {
40 return mAnalyzeFunction;
41 }
42
getAnalyzers()43 unordered_map<std::string, unique_ptr<Analyzer>>& Analyzer::getAnalyzers() {
44 static unordered_map<std::string, unique_ptr<Analyzer>> gAnalyzers;
45 return gAnalyzers;
46 }
47
installAnalyzer(std::unique_ptr<Analyzer> install)48 void Analyzer::installAnalyzer(std::unique_ptr<Analyzer> install) {
49 getAnalyzers().insert_or_assign(install->getPackageName(), std::move(install));
50 }
51
52 } // namespace aidl
53 } // namespace android
54