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 | 84f89de | 2016-07-28 15:39:51 -0700 | [diff] [blame] | 17 | #ifndef FQNAME_H_ |
| 18 | |
| 19 | #define FQNAME_H_ |
| 20 | |
| 21 | #include <android-base/macros.h> |
| 22 | #include <string> |
Andreas Huber | 0e00de4 | 2016-08-03 09:56:02 -0700 | [diff] [blame] | 23 | #include <vector> |
Andreas Huber | 84f89de | 2016-07-28 15:39:51 -0700 | [diff] [blame] | 24 | |
| 25 | namespace android { |
| 26 | |
| 27 | struct FQName { |
Andreas Huber | da51b8e | 2016-07-28 16:00:57 -0700 | [diff] [blame] | 28 | explicit FQName(); |
Andreas Huber | 84f89de | 2016-07-28 15:39:51 -0700 | [diff] [blame] | 29 | explicit FQName(const std::string &s); |
| 30 | |
Andreas Huber | 68f2459 | 2016-07-29 14:53:48 -0700 | [diff] [blame] | 31 | FQName(const std::string &package, |
| 32 | const std::string &version, |
Yifan Hong | b44a6c8 | 2016-09-22 15:50:18 -0700 | [diff] [blame] | 33 | const std::string &name, |
| 34 | const std::string &valueName = ""); |
Andreas Huber | 68f2459 | 2016-07-29 14:53:48 -0700 | [diff] [blame] | 35 | |
Yifan Hong | 327cfe1 | 2016-10-03 10:29:42 -0700 | [diff] [blame] | 36 | // a synonym to FQName(names.join(".")) |
| 37 | FQName(const std::vector<std::string> &names); |
| 38 | |
Yifan Hong | f24fa85 | 2016-09-23 11:03:15 -0700 | [diff] [blame] | 39 | FQName(const FQName& other); |
| 40 | |
Andreas Huber | 84f89de | 2016-07-28 15:39:51 -0700 | [diff] [blame] | 41 | bool isValid() const; |
Yifan Hong | b44a6c8 | 2016-09-22 15:50:18 -0700 | [diff] [blame] | 42 | bool isIdentifier() const; |
Andreas Huber | 84f89de | 2016-07-28 15:39:51 -0700 | [diff] [blame] | 43 | bool setTo(const std::string &s); |
| 44 | |
| 45 | void applyDefaults( |
| 46 | const std::string &defaultPackage, |
| 47 | const std::string &defaultVersion); |
| 48 | |
| 49 | std::string package() const; |
Yifan Hong | 90ea87f | 2016-11-01 14:25:47 -0700 | [diff] [blame] | 50 | // Return version in the form "@1.0" if it is present, otherwise empty string. |
| 51 | std::string atVersion() const; |
| 52 | // Return version in the form "1.0" if it is present, otherwise empty string. |
Andreas Huber | 84f89de | 2016-07-28 15:39:51 -0700 | [diff] [blame] | 53 | std::string version() const; |
Iliyan Malchev | 800273d | 2016-09-02 15:25:07 -0700 | [diff] [blame] | 54 | |
| 55 | // The next two methods return the name part of the FQName, that is, the |
| 56 | // part after the version field. For example: |
| 57 | // |
| 58 | // package android.hardware.tests.foo@1.0; |
| 59 | // interface IFoo { |
| 60 | // struct bar { |
| 61 | // struct baz { |
| 62 | // ... |
| 63 | // }; |
| 64 | // }; |
| 65 | // }; |
| 66 | // |
| 67 | // package android.hardware.tests.bar@1.0; |
| 68 | // import android.hardware.tests.foo@1.0; |
| 69 | // interface { |
| 70 | // struct boo { |
| 71 | // IFoo.bar.baz base; |
| 72 | // }; |
| 73 | // } |
| 74 | // |
| 75 | // The FQName for base is android.hardware.tests.foo@1.0::IFoo.bar.baz; so |
| 76 | // FQName::name() will return "IFoo.bar.baz". FQName::names() will return |
| 77 | // std::vector<std::string>{"IFoo","bar","baz"} |
| 78 | |
Andreas Huber | 84f89de | 2016-07-28 15:39:51 -0700 | [diff] [blame] | 79 | std::string name() const; |
Iliyan Malchev | 800273d | 2016-09-02 15:25:07 -0700 | [diff] [blame] | 80 | std::vector<std::string> names() const; |
Andreas Huber | 84f89de | 2016-07-28 15:39:51 -0700 | [diff] [blame] | 81 | |
Yifan Hong | b44a6c8 | 2016-09-22 15:50:18 -0700 | [diff] [blame] | 82 | // The next two methods returns two parts of the FQName, that is, |
| 83 | // the first part package + version + name, the second part valueName. |
| 84 | FQName typeName() const; |
| 85 | std::string valueName() const; |
| 86 | |
Andreas Huber | 68f2459 | 2016-07-29 14:53:48 -0700 | [diff] [blame] | 87 | bool isFullyQualified() const; |
| 88 | |
Yifan Hong | b44a6c8 | 2016-09-22 15:50:18 -0700 | [diff] [blame] | 89 | // true if: |
| 90 | // 1. (package)?(version)?(name):(valueName) |
| 91 | // 2. (valueName), aka a single identifier |
| 92 | bool isValidValueName() const; |
| 93 | |
Andreas Huber | da51b8e | 2016-07-28 16:00:57 -0700 | [diff] [blame] | 94 | void print() const; |
Andreas Huber | 68f2459 | 2016-07-29 14:53:48 -0700 | [diff] [blame] | 95 | std::string string() const; |
| 96 | |
| 97 | bool operator<(const FQName &other) const; |
Andreas Huber | d2943e1 | 2016-08-05 11:59:31 -0700 | [diff] [blame] | 98 | bool operator==(const FQName &other) const; |
Andreas Huber | 84f89de | 2016-07-28 15:39:51 -0700 | [diff] [blame] | 99 | |
Steven Moreland | 197d56c | 2016-09-09 10:03:58 -0700 | [diff] [blame] | 100 | // Must be called on an interface |
| 101 | // ::android::hardware::Foo::V1_0::IBar |
| 102 | // -> Bar |
| 103 | std::string getInterfaceBaseName() const; |
| 104 | |
Yifan Hong | 1977ea3 | 2016-10-05 12:49:08 -0700 | [diff] [blame] | 105 | // Replace whatever after :: with "types" |
| 106 | // android.hardware.foo@1.0::Abc.Type:VALUE |
| 107 | // -> android.hardware.foo@1.0::types |
| 108 | FQName getTypesForPackage() const; |
| 109 | |
Steven Moreland | 9c38761 | 2016-09-07 09:54:26 -0700 | [diff] [blame] | 110 | // the following comments all assume that the FQName |
Yifan Hong | 1977ea3 | 2016-10-05 12:49:08 -0700 | [diff] [blame] | 111 | // is android.hardware.foo@1.0::IBar.Baz.Bam |
Steven Moreland | 9c38761 | 2016-09-07 09:54:26 -0700 | [diff] [blame] | 112 | |
| 113 | // returns highest type in the hidl namespace, i.e. |
Yifan Hong | 1977ea3 | 2016-10-05 12:49:08 -0700 | [diff] [blame] | 114 | // android.hardware.foo@1.0::IBar |
Steven Moreland | 9c38761 | 2016-09-07 09:54:26 -0700 | [diff] [blame] | 115 | const FQName getTopLevelType() const; |
| 116 | |
| 117 | // returns an unambiguous fully qualified name which can be |
| 118 | // baked into a token, i.e. |
| 119 | // android_hardware_Foo_V1_0_IBar_Baz |
| 120 | std::string tokenName() const; |
| 121 | |
Andreas Huber | 0e00de4 | 2016-08-03 09:56:02 -0700 | [diff] [blame] | 122 | // Returns an absolute C++ namespace prefix, i.e. |
Andreas Huber | 2831d51 | 2016-08-15 09:33:47 -0700 | [diff] [blame] | 123 | // ::android::hardware::Foo::V1_0. |
Andreas Huber | 0e00de4 | 2016-08-03 09:56:02 -0700 | [diff] [blame] | 124 | std::string cppNamespace() const; |
| 125 | |
Steven Moreland | 979e099 | 2016-09-07 09:18:08 -0700 | [diff] [blame] | 126 | // Returns a name qualified assuming we are in cppNamespace, i.e. |
| 127 | // IBar::Baz. |
| 128 | std::string cppLocalName() const; |
| 129 | |
Andreas Huber | 0e00de4 | 2016-08-03 09:56:02 -0700 | [diff] [blame] | 130 | // Returns a fully qualified absolute C++ type name, i.e. |
Steven Moreland | 9c38761 | 2016-09-07 09:54:26 -0700 | [diff] [blame] | 131 | // ::android::hardware::Foo::V1_0::IBar::Baz. |
Andreas Huber | 0e00de4 | 2016-08-03 09:56:02 -0700 | [diff] [blame] | 132 | std::string cppName() const; |
| 133 | |
Andreas Huber | 2831d51 | 2016-08-15 09:33:47 -0700 | [diff] [blame] | 134 | // Returns the java package name, i.e. "android.hardware.Foo.V1_0". |
| 135 | std::string javaPackage() const; |
| 136 | |
| 137 | // Returns the fully qualified java type name, |
Steven Moreland | 9c38761 | 2016-09-07 09:54:26 -0700 | [diff] [blame] | 138 | // i.e. "android.hardware.Foo.V1_0.IBar.Baz" |
Andreas Huber | 2831d51 | 2016-08-15 09:33:47 -0700 | [diff] [blame] | 139 | std::string javaName() const; |
| 140 | |
Andreas Huber | 39fa718 | 2016-08-19 14:27:33 -0700 | [diff] [blame] | 141 | bool endsWith(const FQName &other) const; |
| 142 | |
Andreas Huber | 0e00de4 | 2016-08-03 09:56:02 -0700 | [diff] [blame] | 143 | void getPackageComponents(std::vector<std::string> *components) const; |
| 144 | |
| 145 | void getPackageAndVersionComponents( |
| 146 | std::vector<std::string> *components, |
| 147 | bool cpp_compatible) const; |
| 148 | |
Martijn Coenen | a21f149 | 2016-09-08 15:55:14 +0200 | [diff] [blame] | 149 | std::string getPackageMajorVersion() const; |
| 150 | |
| 151 | std::string getPackageMinorVersion() const; |
Steven Moreland | 197d56c | 2016-09-09 10:03:58 -0700 | [diff] [blame] | 152 | |
Andreas Huber | 84f89de | 2016-07-28 15:39:51 -0700 | [diff] [blame] | 153 | private: |
Yifan Hong | f24fa85 | 2016-09-23 11:03:15 -0700 | [diff] [blame] | 154 | bool mValid; |
| 155 | bool mIsIdentifier; |
Andreas Huber | 84f89de | 2016-07-28 15:39:51 -0700 | [diff] [blame] | 156 | std::string mPackage; |
Yifan Hong | 90ea87f | 2016-11-01 14:25:47 -0700 | [diff] [blame] | 157 | std::string mMajor; |
| 158 | std::string mMinor; |
Andreas Huber | 84f89de | 2016-07-28 15:39:51 -0700 | [diff] [blame] | 159 | std::string mName; |
Yifan Hong | b44a6c8 | 2016-09-22 15:50:18 -0700 | [diff] [blame] | 160 | std::string mValueName; |
Yifan Hong | 90ea87f | 2016-11-01 14:25:47 -0700 | [diff] [blame] | 161 | |
| 162 | void setVersion(const std::string &v); |
Andreas Huber | 84f89de | 2016-07-28 15:39:51 -0700 | [diff] [blame] | 163 | }; |
| 164 | |
| 165 | } // namespace android |
| 166 | |
| 167 | #endif // FQNAME_H_ |