blob: 0365472c1e2434876dd443ed14062b0e1dc04ed1 [file] [log] [blame]
Andreas Huber5345ec22016-07-29 13:33:27 -07001#ifndef COORDINATOR_H_
2
3#define COORDINATOR_H_
4
5#include <android-base/macros.h>
Andreas Hubere61e3f72016-08-03 10:22:03 -07006#include <functional>
Andreas Huber5345ec22016-07-29 13:33:27 -07007#include <string>
8#include <utils/KeyedVector.h>
Andreas Huberdca261f2016-08-04 13:47:51 -07009#include <vector>
Andreas Huber5345ec22016-07-29 13:33:27 -070010
11namespace android {
12
13struct AST;
14struct FQName;
Andreas Huberfd4afab2016-08-03 13:02:57 -070015struct Type;
Andreas Huber5345ec22016-07-29 13:33:27 -070016
17struct Coordinator {
Andreas Huberdca261f2016-08-04 13:47:51 -070018 Coordinator(
19 const std::vector<std::string> &packageRootPaths,
20 const std::vector<std::string> &packageRoots);
21
Andreas Huber5345ec22016-07-29 13:33:27 -070022 ~Coordinator();
23
Andreas Huber68f24592016-07-29 14:53:48 -070024 AST *parse(const FQName &fqName);
Andreas Huber5345ec22016-07-29 13:33:27 -070025
Andreas Huberfd4afab2016-08-03 13:02:57 -070026 Type *lookupType(const FQName &fqName) const;
Andreas Huber5345ec22016-07-29 13:33:27 -070027
Andreas Huberdca261f2016-08-04 13:47:51 -070028 // Given package-root paths of ["hardware/interfaces",
29 // "vendor/<something>/interfaces"], package roots of
30 // ["android.hardware", "vendor.<something>.hardware"], and a
31 // FQName of "android.hardware.nfc@1.0::INfc, then getPackagePath()
32 // will return "harware/interfaces/nfc/V1_0".
33
Andreas Huber881227d2016-08-02 14:20:21 -070034 std::string getPackagePath(
35 const FQName &fqName, bool relative = false) const;
Andreas Huber5345ec22016-07-29 13:33:27 -070036
Andreas Huberdca261f2016-08-04 13:47:51 -070037 // Given package roots of ["android.hardware",
38 // "vendor.<something>.hardware"] and a FQName of
39 // "android.hardware.nfc@1.0::INfc, the getPackageRoot() will
40 // return "android.hardware".
41
42 std::string getPackageRoot(const FQName &fqName) const;
43
Andreas Huberd2943e12016-08-05 11:59:31 -070044 // Given an FQName of "android.hardware.nfc@1.0::INfc", return
45 // "android/hardware/".
46 std::string convertPackageRootToPath(const FQName &fqName) const;
47
48 status_t getPackageInterfaceFiles(
49 const FQName &package,
50 std::vector<std::string> *fileNames) const;
51
52 status_t getPackageInterfaces(
53 const FQName &package,
54 std::vector<FQName> *packageInterfaces) const;
55
56 static bool MakeParentHierarchy(const std::string &path);
Andreas Hubere61e3f72016-08-03 10:22:03 -070057
Andreas Huber5345ec22016-07-29 13:33:27 -070058private:
Andreas Huberdca261f2016-08-04 13:47:51 -070059 // A list of top-level directories (mPackageRootPaths)
60 // corresponding to a list of package roots (mPackageRoots). For
61 // example, if mPackageRootPaths[0] == "hardware/interfaces" and
62 // mPackageRoots[0] == "android.hardware" this means that all
63 // packages starting with "android.hardware" will be looked up in
64 // "hardware/interfaces".
65 std::vector<std::string> mPackageRootPaths;
66 std::vector<std::string> mPackageRoots;
Andreas Huber68f24592016-07-29 14:53:48 -070067 KeyedVector<FQName, AST *> mCache;
Andreas Huber5345ec22016-07-29 13:33:27 -070068
Andreas Huberdca261f2016-08-04 13:47:51 -070069 std::vector<std::string>::const_iterator findPackageRoot(
70 const FQName &fqName) const;
71
Andreas Huber5345ec22016-07-29 13:33:27 -070072 DISALLOW_COPY_AND_ASSIGN(Coordinator);
73};
74
75} // namespace android
76
77#endif // COORDINATOR_H_