Andreas Huber | 5345ec2 | 2016-07-29 13:33:27 -0700 | [diff] [blame] | 1 | #ifndef COORDINATOR_H_ |
| 2 | |
| 3 | #define COORDINATOR_H_ |
| 4 | |
| 5 | #include <android-base/macros.h> |
Andreas Huber | e61e3f7 | 2016-08-03 10:22:03 -0700 | [diff] [blame] | 6 | #include <functional> |
Andreas Huber | 5345ec2 | 2016-07-29 13:33:27 -0700 | [diff] [blame] | 7 | #include <string> |
| 8 | #include <utils/KeyedVector.h> |
Andreas Huber | dca261f | 2016-08-04 13:47:51 -0700 | [diff] [blame] | 9 | #include <vector> |
Andreas Huber | 5345ec2 | 2016-07-29 13:33:27 -0700 | [diff] [blame] | 10 | |
| 11 | namespace android { |
| 12 | |
| 13 | struct AST; |
| 14 | struct FQName; |
Andreas Huber | fd4afab | 2016-08-03 13:02:57 -0700 | [diff] [blame] | 15 | struct Type; |
Andreas Huber | 5345ec2 | 2016-07-29 13:33:27 -0700 | [diff] [blame] | 16 | |
| 17 | struct Coordinator { |
Andreas Huber | dca261f | 2016-08-04 13:47:51 -0700 | [diff] [blame] | 18 | Coordinator( |
| 19 | const std::vector<std::string> &packageRootPaths, |
| 20 | const std::vector<std::string> &packageRoots); |
| 21 | |
Andreas Huber | 5345ec2 | 2016-07-29 13:33:27 -0700 | [diff] [blame] | 22 | ~Coordinator(); |
| 23 | |
Andreas Huber | 68f2459 | 2016-07-29 14:53:48 -0700 | [diff] [blame] | 24 | AST *parse(const FQName &fqName); |
Andreas Huber | 5345ec2 | 2016-07-29 13:33:27 -0700 | [diff] [blame] | 25 | |
Andreas Huber | fd4afab | 2016-08-03 13:02:57 -0700 | [diff] [blame] | 26 | Type *lookupType(const FQName &fqName) const; |
Andreas Huber | 5345ec2 | 2016-07-29 13:33:27 -0700 | [diff] [blame] | 27 | |
Andreas Huber | dca261f | 2016-08-04 13:47:51 -0700 | [diff] [blame] | 28 | // 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 Huber | 881227d | 2016-08-02 14:20:21 -0700 | [diff] [blame] | 34 | std::string getPackagePath( |
| 35 | const FQName &fqName, bool relative = false) const; |
Andreas Huber | 5345ec2 | 2016-07-29 13:33:27 -0700 | [diff] [blame] | 36 | |
Andreas Huber | dca261f | 2016-08-04 13:47:51 -0700 | [diff] [blame] | 37 | // 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 Huber | d2943e1 | 2016-08-05 11:59:31 -0700 | [diff] [blame^] | 44 | // 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 Huber | e61e3f7 | 2016-08-03 10:22:03 -0700 | [diff] [blame] | 57 | |
Andreas Huber | 5345ec2 | 2016-07-29 13:33:27 -0700 | [diff] [blame] | 58 | private: |
Andreas Huber | dca261f | 2016-08-04 13:47:51 -0700 | [diff] [blame] | 59 | // 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 Huber | 68f2459 | 2016-07-29 14:53:48 -0700 | [diff] [blame] | 67 | KeyedVector<FQName, AST *> mCache; |
Andreas Huber | 5345ec2 | 2016-07-29 13:33:27 -0700 | [diff] [blame] | 68 | |
Andreas Huber | dca261f | 2016-08-04 13:47:51 -0700 | [diff] [blame] | 69 | std::vector<std::string>::const_iterator findPackageRoot( |
| 70 | const FQName &fqName) const; |
| 71 | |
Andreas Huber | 5345ec2 | 2016-07-29 13:33:27 -0700 | [diff] [blame] | 72 | DISALLOW_COPY_AND_ASSIGN(Coordinator); |
| 73 | }; |
| 74 | |
| 75 | } // namespace android |
| 76 | |
| 77 | #endif // COORDINATOR_H_ |