Andreas Huber | 1aec397 | 2016-08-26 09:26:32 -0700 | [diff] [blame] | 1 | /* |
| 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 Huber | 5345ec2 | 2016-07-29 13:33:27 -0700 | [diff] [blame] | 17 | #ifndef COORDINATOR_H_ |
| 18 | |
| 19 | #define COORDINATOR_H_ |
| 20 | |
| 21 | #include <android-base/macros.h> |
Andreas Huber | e61e3f7 | 2016-08-03 10:22:03 -0700 | [diff] [blame] | 22 | #include <functional> |
Steven Moreland | d537ab0 | 2016-09-12 10:32:01 -0700 | [diff] [blame] | 23 | #include <map> |
Andreas Huber | 39fa718 | 2016-08-19 14:27:33 -0700 | [diff] [blame] | 24 | #include <set> |
Andreas Huber | 5345ec2 | 2016-07-29 13:33:27 -0700 | [diff] [blame] | 25 | #include <string> |
Steven Moreland | d537ab0 | 2016-09-12 10:32:01 -0700 | [diff] [blame] | 26 | #include <utils/Errors.h> |
Andreas Huber | dca261f | 2016-08-04 13:47:51 -0700 | [diff] [blame] | 27 | #include <vector> |
Andreas Huber | 5345ec2 | 2016-07-29 13:33:27 -0700 | [diff] [blame] | 28 | |
| 29 | namespace android { |
| 30 | |
| 31 | struct AST; |
| 32 | struct FQName; |
Andreas Huber | fd4afab | 2016-08-03 13:02:57 -0700 | [diff] [blame] | 33 | struct Type; |
Andreas Huber | 5345ec2 | 2016-07-29 13:33:27 -0700 | [diff] [blame] | 34 | |
| 35 | struct Coordinator { |
Andreas Huber | dca261f | 2016-08-04 13:47:51 -0700 | [diff] [blame] | 36 | Coordinator( |
| 37 | const std::vector<std::string> &packageRootPaths, |
| 38 | const std::vector<std::string> &packageRoots); |
| 39 | |
Andreas Huber | 5345ec2 | 2016-07-29 13:33:27 -0700 | [diff] [blame] | 40 | ~Coordinator(); |
| 41 | |
Andreas Huber | 39fa718 | 2016-08-19 14:27:33 -0700 | [diff] [blame] | 42 | // Attempts to parse the interface/types referred to by fqName. |
| 43 | // Parsing an interface also parses the associated package's types.hal |
| 44 | // file if it exists. |
| 45 | // If "parsedASTs" is non-NULL, successfully parsed ASTs are inserted |
| 46 | // into the set. |
| 47 | AST *parse(const FQName &fqName, std::set<AST *> *parsedASTs = nullptr); |
Andreas Huber | 5345ec2 | 2016-07-29 13:33:27 -0700 | [diff] [blame] | 48 | |
Andreas Huber | dca261f | 2016-08-04 13:47:51 -0700 | [diff] [blame] | 49 | // Given package-root paths of ["hardware/interfaces", |
| 50 | // "vendor/<something>/interfaces"], package roots of |
| 51 | // ["android.hardware", "vendor.<something>.hardware"], and a |
| 52 | // FQName of "android.hardware.nfc@1.0::INfc, then getPackagePath() |
Iliyan Malchev | 5bb1402 | 2016-08-09 15:04:39 -0700 | [diff] [blame] | 53 | // will return "hardware/interfaces/nfc/V1_0". |
Andreas Huber | dca261f | 2016-08-04 13:47:51 -0700 | [diff] [blame] | 54 | |
Andreas Huber | 881227d | 2016-08-02 14:20:21 -0700 | [diff] [blame] | 55 | std::string getPackagePath( |
| 56 | const FQName &fqName, bool relative = false) const; |
Andreas Huber | 5345ec2 | 2016-07-29 13:33:27 -0700 | [diff] [blame] | 57 | |
Andreas Huber | dca261f | 2016-08-04 13:47:51 -0700 | [diff] [blame] | 58 | // Given package roots of ["android.hardware", |
| 59 | // "vendor.<something>.hardware"] and a FQName of |
Iliyan Malchev | 5bb1402 | 2016-08-09 15:04:39 -0700 | [diff] [blame] | 60 | // "android.hardware.nfc@1.0::INfc, then getPackageRoot() will |
Andreas Huber | dca261f | 2016-08-04 13:47:51 -0700 | [diff] [blame] | 61 | // return "android.hardware". |
| 62 | |
| 63 | std::string getPackageRoot(const FQName &fqName) const; |
| 64 | |
Iliyan Malchev | 5bb1402 | 2016-08-09 15:04:39 -0700 | [diff] [blame] | 65 | // Given package-root paths of ["hardware/interfaces", |
| 66 | // "vendor/<something>/interfaces"], package roots of |
| 67 | // ["android.hardware", "vendor.<something>.hardware"], and a |
| 68 | // FQName of "android.hardware.nfc@1.0::INfc, then getPackageRootPath() |
| 69 | // will return "hardware/interfaces". |
| 70 | |
| 71 | std::string getPackageRootPath(const FQName &fqName) const; |
| 72 | |
Andreas Huber | d2943e1 | 2016-08-05 11:59:31 -0700 | [diff] [blame] | 73 | // Given an FQName of "android.hardware.nfc@1.0::INfc", return |
| 74 | // "android/hardware/". |
| 75 | std::string convertPackageRootToPath(const FQName &fqName) const; |
| 76 | |
| 77 | status_t getPackageInterfaceFiles( |
| 78 | const FQName &package, |
| 79 | std::vector<std::string> *fileNames) const; |
| 80 | |
Steven Moreland | aa18683 | 2016-09-26 13:51:43 -0700 | [diff] [blame] | 81 | status_t appendPackageInterfacesToVector( |
Andreas Huber | d2943e1 | 2016-08-05 11:59:31 -0700 | [diff] [blame] | 82 | const FQName &package, |
| 83 | std::vector<FQName> *packageInterfaces) const; |
| 84 | |
| 85 | static bool MakeParentHierarchy(const std::string &path); |
Andreas Huber | e61e3f7 | 2016-08-03 10:22:03 -0700 | [diff] [blame] | 86 | |
Andreas Huber | 5345ec2 | 2016-07-29 13:33:27 -0700 | [diff] [blame] | 87 | private: |
Andreas Huber | dca261f | 2016-08-04 13:47:51 -0700 | [diff] [blame] | 88 | // A list of top-level directories (mPackageRootPaths) |
| 89 | // corresponding to a list of package roots (mPackageRoots). For |
| 90 | // example, if mPackageRootPaths[0] == "hardware/interfaces" and |
| 91 | // mPackageRoots[0] == "android.hardware" this means that all |
| 92 | // packages starting with "android.hardware" will be looked up in |
| 93 | // "hardware/interfaces". |
| 94 | std::vector<std::string> mPackageRootPaths; |
| 95 | std::vector<std::string> mPackageRoots; |
Steven Moreland | d537ab0 | 2016-09-12 10:32:01 -0700 | [diff] [blame] | 96 | std::map<FQName, AST *> mCache; |
Andreas Huber | 5345ec2 | 2016-07-29 13:33:27 -0700 | [diff] [blame] | 97 | |
Andreas Huber | dca261f | 2016-08-04 13:47:51 -0700 | [diff] [blame] | 98 | std::vector<std::string>::const_iterator findPackageRoot( |
| 99 | const FQName &fqName) const; |
| 100 | |
Andreas Huber | 5345ec2 | 2016-07-29 13:33:27 -0700 | [diff] [blame] | 101 | DISALLOW_COPY_AND_ASSIGN(Coordinator); |
| 102 | }; |
| 103 | |
| 104 | } // namespace android |
| 105 | |
| 106 | #endif // COORDINATOR_H_ |