blob: a8f600cc8756ad5a4decc00c205889efc50a83b7 [file] [log] [blame]
Andreas Huber1aec3972016-08-26 09:26:32 -07001/*
2 * Copyright (C) 2016 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
Andreas Huber5345ec22016-07-29 13:33:27 -070017#ifndef COORDINATOR_H_
18
19#define COORDINATOR_H_
20
21#include <android-base/macros.h>
Andreas Hubere61e3f72016-08-03 10:22:03 -070022#include <functional>
Andreas Huber39fa7182016-08-19 14:27:33 -070023#include <set>
Andreas Huber5345ec22016-07-29 13:33:27 -070024#include <string>
25#include <utils/KeyedVector.h>
Andreas Huberdca261f2016-08-04 13:47:51 -070026#include <vector>
Andreas Huber5345ec22016-07-29 13:33:27 -070027
28namespace android {
29
30struct AST;
31struct FQName;
Andreas Huberfd4afab2016-08-03 13:02:57 -070032struct Type;
Andreas Huber5345ec22016-07-29 13:33:27 -070033
34struct Coordinator {
Andreas Huberdca261f2016-08-04 13:47:51 -070035 Coordinator(
36 const std::vector<std::string> &packageRootPaths,
37 const std::vector<std::string> &packageRoots);
38
Andreas Huber5345ec22016-07-29 13:33:27 -070039 ~Coordinator();
40
Andreas Huber39fa7182016-08-19 14:27:33 -070041 // Attempts to parse the interface/types referred to by fqName.
42 // Parsing an interface also parses the associated package's types.hal
43 // file if it exists.
44 // If "parsedASTs" is non-NULL, successfully parsed ASTs are inserted
45 // into the set.
46 AST *parse(const FQName &fqName, std::set<AST *> *parsedASTs = nullptr);
Andreas Huber5345ec22016-07-29 13:33:27 -070047
Andreas Huberdca261f2016-08-04 13:47:51 -070048 // Given package-root paths of ["hardware/interfaces",
49 // "vendor/<something>/interfaces"], package roots of
50 // ["android.hardware", "vendor.<something>.hardware"], and a
51 // FQName of "android.hardware.nfc@1.0::INfc, then getPackagePath()
Iliyan Malchev5bb14022016-08-09 15:04:39 -070052 // will return "hardware/interfaces/nfc/V1_0".
Andreas Huberdca261f2016-08-04 13:47:51 -070053
Andreas Huber881227d2016-08-02 14:20:21 -070054 std::string getPackagePath(
55 const FQName &fqName, bool relative = false) const;
Andreas Huber5345ec22016-07-29 13:33:27 -070056
Andreas Huberdca261f2016-08-04 13:47:51 -070057 // Given package roots of ["android.hardware",
58 // "vendor.<something>.hardware"] and a FQName of
Iliyan Malchev5bb14022016-08-09 15:04:39 -070059 // "android.hardware.nfc@1.0::INfc, then getPackageRoot() will
Andreas Huberdca261f2016-08-04 13:47:51 -070060 // return "android.hardware".
61
62 std::string getPackageRoot(const FQName &fqName) const;
63
Iliyan Malchev5bb14022016-08-09 15:04:39 -070064 // Given package-root paths of ["hardware/interfaces",
65 // "vendor/<something>/interfaces"], package roots of
66 // ["android.hardware", "vendor.<something>.hardware"], and a
67 // FQName of "android.hardware.nfc@1.0::INfc, then getPackageRootPath()
68 // will return "hardware/interfaces".
69
70 std::string getPackageRootPath(const FQName &fqName) const;
71
Andreas Huberd2943e12016-08-05 11:59:31 -070072 // Given an FQName of "android.hardware.nfc@1.0::INfc", return
73 // "android/hardware/".
74 std::string convertPackageRootToPath(const FQName &fqName) const;
75
76 status_t getPackageInterfaceFiles(
77 const FQName &package,
78 std::vector<std::string> *fileNames) const;
79
Iliyan Malchev5bb14022016-08-09 15:04:39 -070080 status_t appendPackageInterfacesToSet(
Andreas Huberd2943e12016-08-05 11:59:31 -070081 const FQName &package,
82 std::vector<FQName> *packageInterfaces) const;
83
84 static bool MakeParentHierarchy(const std::string &path);
Andreas Hubere61e3f72016-08-03 10:22:03 -070085
Andreas Huber5345ec22016-07-29 13:33:27 -070086private:
Andreas Huberdca261f2016-08-04 13:47:51 -070087 // A list of top-level directories (mPackageRootPaths)
88 // corresponding to a list of package roots (mPackageRoots). For
89 // example, if mPackageRootPaths[0] == "hardware/interfaces" and
90 // mPackageRoots[0] == "android.hardware" this means that all
91 // packages starting with "android.hardware" will be looked up in
92 // "hardware/interfaces".
93 std::vector<std::string> mPackageRootPaths;
94 std::vector<std::string> mPackageRoots;
Andreas Huber68f24592016-07-29 14:53:48 -070095 KeyedVector<FQName, AST *> mCache;
Andreas Huber5345ec22016-07-29 13:33:27 -070096
Andreas Huberdca261f2016-08-04 13:47:51 -070097 std::vector<std::string>::const_iterator findPackageRoot(
98 const FQName &fqName) const;
99
Andreas Huber5345ec22016-07-29 13:33:27 -0700100 DISALLOW_COPY_AND_ASSIGN(Coordinator);
101};
102
103} // namespace android
104
105#endif // COORDINATOR_H_