Interface.h revision c89340422f53046bfe24ff3e529161f9194120f8
11aec397b1fdea7db4120dbe55b6995bb2a9d9138Andreas Huber/*
21aec397b1fdea7db4120dbe55b6995bb2a9d9138Andreas Huber * Copyright (C) 2016 The Android Open Source Project
31aec397b1fdea7db4120dbe55b6995bb2a9d9138Andreas Huber *
41aec397b1fdea7db4120dbe55b6995bb2a9d9138Andreas Huber * Licensed under the Apache License, Version 2.0 (the "License");
51aec397b1fdea7db4120dbe55b6995bb2a9d9138Andreas Huber * you may not use this file except in compliance with the License.
61aec397b1fdea7db4120dbe55b6995bb2a9d9138Andreas Huber * You may obtain a copy of the License at
71aec397b1fdea7db4120dbe55b6995bb2a9d9138Andreas Huber *
81aec397b1fdea7db4120dbe55b6995bb2a9d9138Andreas Huber *      http://www.apache.org/licenses/LICENSE-2.0
91aec397b1fdea7db4120dbe55b6995bb2a9d9138Andreas Huber *
101aec397b1fdea7db4120dbe55b6995bb2a9d9138Andreas Huber * Unless required by applicable law or agreed to in writing, software
111aec397b1fdea7db4120dbe55b6995bb2a9d9138Andreas Huber * distributed under the License is distributed on an "AS IS" BASIS,
121aec397b1fdea7db4120dbe55b6995bb2a9d9138Andreas Huber * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
131aec397b1fdea7db4120dbe55b6995bb2a9d9138Andreas Huber * See the License for the specific language governing permissions and
141aec397b1fdea7db4120dbe55b6995bb2a9d9138Andreas Huber * limitations under the License.
151aec397b1fdea7db4120dbe55b6995bb2a9d9138Andreas Huber */
161aec397b1fdea7db4120dbe55b6995bb2a9d9138Andreas Huber
17c9410c7e62a33fd7599b2f3e025093a2d171577eAndreas Huber#ifndef INTERFACE_H_
18c9410c7e62a33fd7599b2f3e025093a2d171577eAndreas Huber
19c9410c7e62a33fd7599b2f3e025093a2d171577eAndreas Huber#define INTERFACE_H_
20c9410c7e62a33fd7599b2f3e025093a2d171577eAndreas Huber
21c9410c7e62a33fd7599b2f3e025093a2d171577eAndreas Huber#include "Scope.h"
2210fe0b55e774903fe37b658458053527da8b5a53Yifan Hong#include <vector>
23c9410c7e62a33fd7599b2f3e025093a2d171577eAndreas Huber
24c9410c7e62a33fd7599b2f3e025093a2d171577eAndreas Hubernamespace android {
25c9410c7e62a33fd7599b2f3e025093a2d171577eAndreas Huber
26c9410c7e62a33fd7599b2f3e025093a2d171577eAndreas Huberstruct Method;
2710fe0b55e774903fe37b658458053527da8b5a53Yifan Hongstruct InterfaceAndMethod;
28c9410c7e62a33fd7599b2f3e025093a2d171577eAndreas Huber
29c9410c7e62a33fd7599b2f3e025093a2d171577eAndreas Huberstruct Interface : public Scope {
30a4b53d0da8c1c6889c361fd30b913adc364163bcYifan Hong    Interface(const char *localName, const Location &location, Interface *super);
31c9410c7e62a33fd7599b2f3e025093a2d171577eAndreas Huber
3214ee6749f12bcd43477fe8110fbec38e15376b40Steven Moreland    bool addMethod(Method *method);
33c9410c7e62a33fd7599b2f3e025093a2d171577eAndreas Huber
34a2723d26427f7db19777dfed330047253e7a4e1bAndreas Huber    bool isInterface() const override;
35295ad30bf6212c16accc5095601b2a71d44b4c8bAndreas Huber    bool isBinder() const override;
36fe95aa243eb53df9cb46ca74192e760d7520b611Yifan Hong    bool isRootType() const { return mSuperType == nullptr; }
37c89340422f53046bfe24ff3e529161f9194120f8Yifan Hong    bool isIBase() const { return fqName() == gIBaseFqName; }
38c9410c7e62a33fd7599b2f3e025093a2d171577eAndreas Huber
396cb08cf9f021a01d9d2b1eaec6729aac6ae70708Andreas Huber    const Interface *superType() const;
40c9410c7e62a33fd7599b2f3e025093a2d171577eAndreas Huber
4114ee6749f12bcd43477fe8110fbec38e15376b40Steven Moreland    Method *lookupMethod(std::string name) const;
42fe95aa243eb53df9cb46ca74192e760d7520b611Yifan Hong    // Super type chain to root type.
43fe95aa243eb53df9cb46ca74192e760d7520b611Yifan Hong    // First element is superType().
44fe95aa243eb53df9cb46ca74192e760d7520b611Yifan Hong    std::vector<const Interface *> superTypeChain() const;
4510fe0b55e774903fe37b658458053527da8b5a53Yifan Hong    // Super type chain to root type, including myself.
4610fe0b55e774903fe37b658458053527da8b5a53Yifan Hong    // First element is this.
4710fe0b55e774903fe37b658458053527da8b5a53Yifan Hong    std::vector<const Interface *> typeChain() const;
4810fe0b55e774903fe37b658458053527da8b5a53Yifan Hong
4910fe0b55e774903fe37b658458053527da8b5a53Yifan Hong    // user defined methods (explicit definition in HAL files)
5010fe0b55e774903fe37b658458053527da8b5a53Yifan Hong    const std::vector<Method *> &userDefinedMethods() const;
5110fe0b55e774903fe37b658458053527da8b5a53Yifan Hong    // HIDL reserved methods (every interface has these implicitly defined)
5210fe0b55e774903fe37b658458053527da8b5a53Yifan Hong    const std::vector<Method *> &hidlReservedMethods() const;
5310fe0b55e774903fe37b658458053527da8b5a53Yifan Hong    // the sum of userDefinedMethods() and hidlReservedMethods().
5410fe0b55e774903fe37b658458053527da8b5a53Yifan Hong    std::vector<Method *> methods() const;
5510fe0b55e774903fe37b658458053527da8b5a53Yifan Hong
5610fe0b55e774903fe37b658458053527da8b5a53Yifan Hong    // userDefinedMethods() for all super type + methods()
5710fe0b55e774903fe37b658458053527da8b5a53Yifan Hong    // The order will be as follows (in the transaction code order):
5810fe0b55e774903fe37b658458053527da8b5a53Yifan Hong    // great-great-...-great-grand parent->userDefinedMethods()
5910fe0b55e774903fe37b658458053527da8b5a53Yifan Hong    // ...
6010fe0b55e774903fe37b658458053527da8b5a53Yifan Hong    // parent->userDefinedMethods()
6110fe0b55e774903fe37b658458053527da8b5a53Yifan Hong    // this->userDefinedMethods()
6210fe0b55e774903fe37b658458053527da8b5a53Yifan Hong    // this->hidlReservedMethods()
6310fe0b55e774903fe37b658458053527da8b5a53Yifan Hong    std::vector<InterfaceAndMethod> allMethodsFromRoot() const;
64881227d860c59471eee31d39946e96ce2daa35d6Andreas Huber
654078631353d6d34db21c890d1870e796eca6ea38Steven Moreland    std::string getBaseName() const;
664078631353d6d34db21c890d1870e796eca6ea38Steven Moreland
67158655a90308d8e5f03dc28b8330d5b0cce038f0Yifan Hong    FQName getHwName() const;
6860e52bde289712dc0e561872022f9c2432069e1aYifan Hong    FQName getProxyName() const;
6960e52bde289712dc0e561872022f9c2432069e1aYifan Hong    FQName getStubName() const;
70158655a90308d8e5f03dc28b8330d5b0cce038f0Yifan Hong    FQName getPassthroughName() const;
71158655a90308d8e5f03dc28b8330d5b0cce038f0Yifan Hong
724c865b72b320a46f326a335cfd326b66b0e10f67Andreas Huber    std::string getCppType(
734c865b72b320a46f326a335cfd326b66b0e10f67Andreas Huber            StorageMode mode,
744c865b72b320a46f326a335cfd326b66b0e10f67Andreas Huber            bool specifyNamespaces) const override;
75881227d860c59471eee31d39946e96ce2daa35d6Andreas Huber
764ed1347cd29e6e07acad368891bb03078c798abaYifan Hong    std::string getJavaType(bool forInitializer) const override;
77a588b23323213c525bf34dc0562679195afe611eZhuoyao Zhang    std::string getVtsType() const override;
782831d5145675ead9f2fb767bf5fe4ae56b88349fAndreas Huber
79881227d860c59471eee31d39946e96ce2daa35d6Andreas Huber    void emitReaderWriter(
80881227d860c59471eee31d39946e96ce2daa35d6Andreas Huber            Formatter &out,
81881227d860c59471eee31d39946e96ce2daa35d6Andreas Huber            const std::string &name,
82881227d860c59471eee31d39946e96ce2daa35d6Andreas Huber            const std::string &parcelObj,
83881227d860c59471eee31d39946e96ce2daa35d6Andreas Huber            bool parcelObjIsPointer,
84881227d860c59471eee31d39946e96ce2daa35d6Andreas Huber            bool isReader,
85881227d860c59471eee31d39946e96ce2daa35d6Andreas Huber            ErrorMode mode) const override;
86881227d860c59471eee31d39946e96ce2daa35d6Andreas Huber
872831d5145675ead9f2fb767bf5fe4ae56b88349fAndreas Huber    void emitJavaReaderWriter(
882831d5145675ead9f2fb767bf5fe4ae56b88349fAndreas Huber            Formatter &out,
892831d5145675ead9f2fb767bf5fe4ae56b88349fAndreas Huber            const std::string &parcelObj,
902831d5145675ead9f2fb767bf5fe4ae56b88349fAndreas Huber            const std::string &argName,
912831d5145675ead9f2fb767bf5fe4ae56b88349fAndreas Huber            bool isReader) const override;
922831d5145675ead9f2fb767bf5fe4ae56b88349fAndreas Huber
93864c771ca4ec8a01e31c7c243625b7a5f6316768Zhuoyao Zhang    status_t emitVtsAttributeType(Formatter &out) const override;
94864c771ca4ec8a01e31c7c243625b7a5f6316768Zhuoyao Zhang
95864c771ca4ec8a01e31c7c243625b7a5f6316768Zhuoyao Zhang    status_t emitVtsAttributeDeclaration(Formatter &out) const;
96864c771ca4ec8a01e31c7c243625b7a5f6316768Zhuoyao Zhang    status_t emitVtsMethodDeclaration(Formatter &out) const;
975158db484e5ab302368f191d75d5b1334c270e52Zhuoyao Zhang
9869e7c70e72dff0734d542b737ba8bb1178244218Steven Moreland    bool hasOnewayMethods() const;
9969e7c70e72dff0734d542b737ba8bb1178244218Steven Moreland
10070a59e1dc3dcf32f791d2dd7966111d4adf32ecaAndreas Huber    bool isJavaCompatible() const override;
10170a59e1dc3dcf32f791d2dd7966111d4adf32ecaAndreas Huber
102c9410c7e62a33fd7599b2f3e025093a2d171577eAndreas Huberprivate:
1036cb08cf9f021a01d9d2b1eaec6729aac6ae70708Andreas Huber    Interface *mSuperType;
10410fe0b55e774903fe37b658458053527da8b5a53Yifan Hong    std::vector<Method *> mUserMethods;
10510fe0b55e774903fe37b658458053527da8b5a53Yifan Hong    std::vector<Method *> mReservedMethods;
106ea081b35840e687dfe7a5c11d4a546f2bf2db99eAndreas Huber    mutable bool mIsJavaCompatibleInProgress;
10710fe0b55e774903fe37b658458053527da8b5a53Yifan Hong    Method *createDescriptorChainMethod() const;
108af712c083e79fb9990e56677cf4c80eacb9c3d3bMartijn Coenen    Method *createSyspropsChangedMethod() const;
109c9410c7e62a33fd7599b2f3e025093a2d171577eAndreas Huber
110c9410c7e62a33fd7599b2f3e025093a2d171577eAndreas Huber    DISALLOW_COPY_AND_ASSIGN(Interface);
111c9410c7e62a33fd7599b2f3e025093a2d171577eAndreas Huber};
112c9410c7e62a33fd7599b2f3e025093a2d171577eAndreas Huber
11310fe0b55e774903fe37b658458053527da8b5a53Yifan Hong// An interface / method tuple.
11410fe0b55e774903fe37b658458053527da8b5a53Yifan Hongstruct InterfaceAndMethod {
11510fe0b55e774903fe37b658458053527da8b5a53Yifan Hong    InterfaceAndMethod(const Interface *iface, Method *method)
11610fe0b55e774903fe37b658458053527da8b5a53Yifan Hong        : mInterface(iface),
11710fe0b55e774903fe37b658458053527da8b5a53Yifan Hong          mMethod(method) {}
11810fe0b55e774903fe37b658458053527da8b5a53Yifan Hong    Method *method() const { return mMethod; }
11910fe0b55e774903fe37b658458053527da8b5a53Yifan Hong    const Interface *interface() const { return mInterface; }
12010fe0b55e774903fe37b658458053527da8b5a53Yifan Hongprivate:
12110fe0b55e774903fe37b658458053527da8b5a53Yifan Hong    // do not own these objects.
12210fe0b55e774903fe37b658458053527da8b5a53Yifan Hong    const Interface *mInterface;
12310fe0b55e774903fe37b658458053527da8b5a53Yifan Hong    Method *mMethod;
12410fe0b55e774903fe37b658458053527da8b5a53Yifan Hong};
12510fe0b55e774903fe37b658458053527da8b5a53Yifan Hong
126c9410c7e62a33fd7599b2f3e025093a2d171577eAndreas Huber}  // namespace android
127c9410c7e62a33fd7599b2f3e025093a2d171577eAndreas Huber
128c9410c7e62a33fd7599b2f3e025093a2d171577eAndreas Huber#endif  // INTERFACE_H_
129c9410c7e62a33fd7599b2f3e025093a2d171577eAndreas Huber
130