File: FQName.h

package info (click to toggle)
android-platform-system-tools-hidl 10.0.0%2Br36-3.1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 2,936 kB
  • sloc: cpp: 21,933; yacc: 1,416; java: 1,239; lex: 496; sh: 360; python: 44; xml: 20; makefile: 12
file content (259 lines) | stat: -rw-r--r-- 8,821 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
/*
 * Copyright (C) 2016 The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

#ifndef FQNAME_H_

#define FQNAME_H_

#include <string>
#include <vector>

namespace android {

struct FQName {
    __attribute__((warn_unused_result)) static bool parse(const std::string& s, FQName* into);

    explicit FQName();

    FQName(const std::string& package, const std::string& version, const std::string& name = "",
           const std::string& valueName = "");

    FQName(const FQName& other);

    bool isIdentifier() const;

    // Returns false if string isn't a valid FQName object.
    __attribute__((warn_unused_result)) bool setTo(const std::string& s);
    __attribute__((warn_unused_result)) bool setTo(const std::string& package, size_t majorVer,
                                                   size_t minorVer, const std::string& name = "",
                                                   const std::string& valueName = "");

    void applyDefaults(
            const std::string &defaultPackage,
            const std::string &defaultVersion);

    const std::string& package() const;
    // Return version in the form "@1.0" if it is present, otherwise empty string.
    std::string atVersion() const;
    // Return version in the form "1.0" if it is present, otherwise empty string.
    std::string version() const;
    // Return version in the form "V1_0" if it is present, otherwise empty string.
    std::string sanitizedVersion() const;
    // Return true only if version is present.
    bool hasVersion() const;
    // Return pair of (major, minor) version. Defaults to 0, 0.
    std::pair<size_t, size_t> getVersion() const;

    FQName withVersion(size_t major, size_t minor) const;

    // The next two methods return the name part of the FQName, that is, the
    // part after the version field.  For example:
    //
    // package android.hardware.tests.foo@1.0;
    // interface IFoo {
    //    struct bar {
    //        struct baz {
    //            ...
    //        };
    //    };
    // };
    //
    // package android.hardware.tests.bar@1.0;
    // import android.hardware.tests.foo@1.0;
    // interface {
    //    struct boo {
    //        IFoo.bar.baz base;
    //    };
    // }
    //
    // The FQName for base is android.hardware.tests.foo@1.0::IFoo.bar.baz; so
    // FQName::name() will return "IFoo.bar.baz". FQName::names() will return
    // std::vector<std::string>{"IFoo","bar","baz"}

    const std::string& name() const;
    std::vector<std::string> names() const;

    // The next two methods returns two parts of the FQName, that is,
    // the first part package + version + name, the second part valueName.
    FQName typeName() const;
    const std::string& valueName() const;

    // has package version and name
    bool isFullyQualified() const;

    // true if:
    // 1. (package)?(version)?(name):(valueName)
    // 2. (valueName), aka a single identifier
    bool isValidValueName() const;

    // Interface names start with 'I'
    bool isInterfaceName() const;

    std::string string() const;

    bool operator<(const FQName &other) const;
    bool operator==(const FQName &other) const;
    bool operator!=(const FQName &other) const;

    // Must be called on an interface
    // android.hardware.foo@1.0::IBar
    // -> Bar
    std::string getInterfaceBaseName() const;

    // Must be called on an interface
    // android.hardware.foo@1.0::IBar
    // -> ABar
    std::string getInterfaceAdapterName() const;

    // Must be called on an interface
    // android.hardware.foo@1.0::IBar
    // -> IBar
    const std::string& getInterfaceName() const;

    // Must be called on an interface
    // android.hardware.foo@1.0::IBar
    // -> IHwBar
    std::string getInterfaceHwName() const;

    // Must be called on an interface
    // android.hardware.foo@1.0::IBar
    // -> BpHwBar
    std::string getInterfaceProxyName() const;

    // Must be called on an interface
    // android.hardware.foo@1.0::IBar
    // -> BnHwBar
    std::string getInterfaceStubName() const;

    // Must be called on an interface
    // android.hardware.foo@1.0::IBar
    // -> BsBar
    std::string getInterfacePassthroughName() const;

    // Must be called on an interface
    // android.hardware.foo@1.0::IBar
    // -> android.hardware.foo@1.0::BpBar
    FQName getInterfaceProxyFqName() const;

    // Must be called on an interface
    // android.hardware.foo@1.0::IBar
    // -> android.hardware.foo@1.0::ABar
    FQName getInterfaceAdapterFqName() const;

    // Must be called on an interface
    // android.hardware.foo@1.0::IBar
    // -> android.hardware.foo@1.0::BnBar
    FQName getInterfaceStubFqName() const;

    // Must be called on an interface
    // android.hardware.foo@1.0::IBar
    // -> android.hardware.foo@1.0::BsBar
    FQName getInterfacePassthroughFqName() const;

    // Replace whatever after :: with "types"
    // android.hardware.foo@1.0::Abc.Type:VALUE
    // -> android.hardware.foo@1.0::types
    FQName getTypesForPackage() const;

    // android.hardware.foo@1.0::Abc.Type:VALUE
    // -> android.hardware.foo@1.0
    FQName getPackageAndVersion() const;

    // the following comments all assume that the FQName
    // is android.hardware.foo@1.0::IBar.Baz.Bam

    // returns highest type in the hidl namespace, i.e.
    // android.hardware.foo@1.0::IBar
    FQName getTopLevelType() const;

    // returns an unambiguous fully qualified name which can be
    // baked into a token, i.e.
    // android_hardware_Foo_V1_0_IBar_Baz
    std::string tokenName() const;

    // Returns an absolute C++ namespace prefix, i.e.
    // ::android::hardware::Foo::V1_0.
    std::string cppNamespace() const;

    // Returns a name qualified assuming we are in cppNamespace, i.e.
    // IBar::Baz.
    std::string cppLocalName() const;

    // Returns a fully qualified absolute C++ type name, i.e.
    // ::android::hardware::Foo::V1_0::IBar::Baz.
    std::string cppName() const;

    // Returns the java package name, i.e. "android.hardware.Foo.V1_0".
    std::string javaPackage() const;

    // Returns the fully qualified java type name,
    // i.e. "android.hardware.Foo.V1_0.IBar.Baz"
    std::string javaName() const;

    bool endsWith(const FQName &other) const;

    // If this is android.hardware@1.0::IFoo
    // package = "and" -> false
    // package = "android" -> true
    // package = "android.hardware@1.0" -> false
    bool inPackage(const std::string &package) const;

    void getPackageComponents(std::vector<std::string> *components) const;

    void getPackageAndVersionComponents(
            std::vector<std::string> *components,
            bool cpp_compatible) const;

    // return major and minor version if they exist, else abort program.
    // Existence of version can be checked via hasVersion().
    size_t getPackageMajorVersion() const;
    size_t getPackageMinorVersion() const;

    // minor-- if result doesn't underflow, else abort.
    FQName downRev() const;

   private:
    bool mIsIdentifier;
    std::string mPackage;
    // mMajor == 0 means empty.
    size_t mMajor = 0;
    size_t mMinor = 0;
    std::string mName;
    std::string mValueName;

    void clear();

    __attribute__((warn_unused_result)) bool setVersion(const std::string& v);
    __attribute__((warn_unused_result)) bool parseVersion(const std::string& majorStr,
                                                          const std::string& minorStr);
    __attribute__((warn_unused_result)) static bool parseVersion(const std::string& majorStr,
                                                                 const std::string& minorStr,
                                                                 size_t* majorVer,
                                                                 size_t* minorVer);
    __attribute__((warn_unused_result)) static bool parseVersion(const std::string& v,
                                                                 size_t* majorVer,
                                                                 size_t* minorVer);
    static void clearVersion(size_t* majorVer, size_t* minorVer);

    void clearVersion();
};

extern const FQName gIBaseFqName;
extern const FQName gIManagerFqName;

}  // namespace android

#endif  // FQNAME_H_