blob: c71da9eb6f2c1acbe32a2226ee49c70e4fb4fa88 [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 Huber84f89de2016-07-28 15:39:51 -070017#ifndef FQNAME_H_
18
19#define FQNAME_H_
20
21#include <android-base/macros.h>
22#include <string>
Andreas Huber0e00de42016-08-03 09:56:02 -070023#include <vector>
Andreas Huber84f89de2016-07-28 15:39:51 -070024
25namespace android {
26
27struct FQName {
Andreas Huberda51b8e2016-07-28 16:00:57 -070028 explicit FQName();
Andreas Huber84f89de2016-07-28 15:39:51 -070029 explicit FQName(const std::string &s);
30
Andreas Huber68f24592016-07-29 14:53:48 -070031 FQName(const std::string &package,
32 const std::string &version,
33 const std::string &name);
34
Andreas Huber84f89de2016-07-28 15:39:51 -070035 bool isValid() const;
36 bool setTo(const std::string &s);
37
38 void applyDefaults(
39 const std::string &defaultPackage,
40 const std::string &defaultVersion);
41
42 std::string package() const;
43 std::string version() const;
Iliyan Malchev800273d2016-09-02 15:25:07 -070044
45 // The next two methods return the name part of the FQName, that is, the
46 // part after the version field. For example:
47 //
48 // package android.hardware.tests.foo@1.0;
49 // interface IFoo {
50 // struct bar {
51 // struct baz {
52 // ...
53 // };
54 // };
55 // };
56 //
57 // package android.hardware.tests.bar@1.0;
58 // import android.hardware.tests.foo@1.0;
59 // interface {
60 // struct boo {
61 // IFoo.bar.baz base;
62 // };
63 // }
64 //
65 // The FQName for base is android.hardware.tests.foo@1.0::IFoo.bar.baz; so
66 // FQName::name() will return "IFoo.bar.baz". FQName::names() will return
67 // std::vector<std::string>{"IFoo","bar","baz"}
68
Andreas Huber84f89de2016-07-28 15:39:51 -070069 std::string name() const;
Iliyan Malchev800273d2016-09-02 15:25:07 -070070 std::vector<std::string> names() const;
Andreas Huber84f89de2016-07-28 15:39:51 -070071
Andreas Huber68f24592016-07-29 14:53:48 -070072 bool isFullyQualified() const;
73
Andreas Huberda51b8e2016-07-28 16:00:57 -070074 void print() const;
Andreas Huber68f24592016-07-29 14:53:48 -070075 std::string string() const;
76
77 bool operator<(const FQName &other) const;
Andreas Huberd2943e12016-08-05 11:59:31 -070078 bool operator==(const FQName &other) const;
Andreas Huber84f89de2016-07-28 15:39:51 -070079
Steven Moreland197d56c2016-09-09 10:03:58 -070080 // Must be called on an interface
81 // ::android::hardware::Foo::V1_0::IBar
82 // -> Bar
83 std::string getInterfaceBaseName() const;
84
Steven Moreland9c387612016-09-07 09:54:26 -070085 // the following comments all assume that the FQName
86 // is ::android::hardware::Foo::V1_0::IBar::Baz
87
88 // returns highest type in the hidl namespace, i.e.
89 // ::android::hardware::Foo::V1_0::IBar
90 const FQName getTopLevelType() const;
91
92 // returns an unambiguous fully qualified name which can be
93 // baked into a token, i.e.
94 // android_hardware_Foo_V1_0_IBar_Baz
95 std::string tokenName() const;
96
Andreas Huber0e00de42016-08-03 09:56:02 -070097 // Returns an absolute C++ namespace prefix, i.e.
Andreas Huber2831d512016-08-15 09:33:47 -070098 // ::android::hardware::Foo::V1_0.
Andreas Huber0e00de42016-08-03 09:56:02 -070099 std::string cppNamespace() const;
100
Steven Moreland979e0992016-09-07 09:18:08 -0700101 // Returns a name qualified assuming we are in cppNamespace, i.e.
102 // IBar::Baz.
103 std::string cppLocalName() const;
104
Andreas Huber0e00de42016-08-03 09:56:02 -0700105 // Returns a fully qualified absolute C++ type name, i.e.
Steven Moreland9c387612016-09-07 09:54:26 -0700106 // ::android::hardware::Foo::V1_0::IBar::Baz.
Andreas Huber0e00de42016-08-03 09:56:02 -0700107 std::string cppName() const;
108
Andreas Huber2831d512016-08-15 09:33:47 -0700109 // Returns the java package name, i.e. "android.hardware.Foo.V1_0".
110 std::string javaPackage() const;
111
112 // Returns the fully qualified java type name,
Steven Moreland9c387612016-09-07 09:54:26 -0700113 // i.e. "android.hardware.Foo.V1_0.IBar.Baz"
Andreas Huber2831d512016-08-15 09:33:47 -0700114 std::string javaName() const;
115
Andreas Huber39fa7182016-08-19 14:27:33 -0700116 bool endsWith(const FQName &other) const;
117
Andreas Huber0e00de42016-08-03 09:56:02 -0700118 void getPackageComponents(std::vector<std::string> *components) const;
119
120 void getPackageAndVersionComponents(
121 std::vector<std::string> *components,
122 bool cpp_compatible) const;
123
Martijn Coenena21f1492016-09-08 15:55:14 +0200124 std::string getPackageMajorVersion() const;
125
126 std::string getPackageMinorVersion() const;
Steven Moreland197d56c2016-09-09 10:03:58 -0700127
Andreas Huber84f89de2016-07-28 15:39:51 -0700128private:
129 bool mValid;
130 std::string mPackage;
131 std::string mVersion;
132 std::string mName;
Andreas Huber84f89de2016-07-28 15:39:51 -0700133};
134
135} // namespace android
136
137#endif // FQNAME_H_