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 | 295ad30 | 2016-08-16 11:35:00 -0700 | [diff] [blame] | 17 | #include "GenericBinder.h" |
| 18 | |
Iliyan Malchev | a72e0d2 | 2016-09-09 11:03:08 -0700 | [diff] [blame] | 19 | #include <hidl-util/Formatter.h> |
Andreas Huber | 295ad30 | 2016-08-16 11:35:00 -0700 | [diff] [blame] | 20 | |
| 21 | namespace android { |
| 22 | |
| 23 | GenericBinder::GenericBinder() {} |
| 24 | |
| 25 | bool GenericBinder::isBinder() const { |
| 26 | return true; |
| 27 | } |
| 28 | |
Steven Moreland | 979e099 | 2016-09-07 09:18:08 -0700 | [diff] [blame] | 29 | void GenericBinder::addNamedTypesToSet(std::set<const FQName> &) const { |
| 30 | // do nothing |
| 31 | } |
| 32 | |
Andreas Huber | 295ad30 | 2016-08-16 11:35:00 -0700 | [diff] [blame] | 33 | std::string GenericBinder::getCppType( |
Steven Moreland | 979e099 | 2016-09-07 09:18:08 -0700 | [diff] [blame] | 34 | StorageMode mode, |
Steven Moreland | 979e099 | 2016-09-07 09:18:08 -0700 | [diff] [blame] | 35 | bool specifyNamespaces) const { |
Steven Moreland | 979e099 | 2016-09-07 09:18:08 -0700 | [diff] [blame] | 36 | const std::string base = |
| 37 | std::string(specifyNamespaces ? "::android::" : "") |
| 38 | + "sp<" |
| 39 | + std::string(specifyNamespaces ? "::android::hardware::" : "") |
| 40 | + "IBinder>"; |
Andreas Huber | 295ad30 | 2016-08-16 11:35:00 -0700 | [diff] [blame] | 41 | |
| 42 | switch (mode) { |
| 43 | case StorageMode_Stack: |
| 44 | case StorageMode_Result: |
| 45 | return base; |
| 46 | |
| 47 | case StorageMode_Argument: |
| 48 | return "const " + base + "&"; |
| 49 | } |
| 50 | } |
| 51 | |
Yifan Hong | 4ed1347 | 2016-11-02 10:44:11 -0700 | [diff] [blame] | 52 | std::string GenericBinder::getJavaType(bool /* forInitializer */) const { |
Andreas Huber | 295ad30 | 2016-08-16 11:35:00 -0700 | [diff] [blame] | 53 | return "IHwBinder"; |
| 54 | } |
| 55 | |
| 56 | void GenericBinder::emitReaderWriter( |
| 57 | Formatter &out, |
| 58 | const std::string &name, |
| 59 | const std::string &parcelObj, |
| 60 | bool parcelObjIsPointer, |
| 61 | bool isReader, |
| 62 | ErrorMode mode) const { |
| 63 | const std::string parcelObjDeref = |
| 64 | parcelObj + (parcelObjIsPointer ? "->" : "."); |
| 65 | |
| 66 | if (isReader) { |
| 67 | out << "_hidl_err = "; |
| 68 | out << parcelObjDeref |
| 69 | << "readNullableStrongBinder(&" |
| 70 | << name |
| 71 | << ");\n"; |
| 72 | |
| 73 | handleError(out, mode); |
| 74 | } else { |
| 75 | out << "_hidl_err = "; |
| 76 | out << parcelObjDeref |
| 77 | << "writeStrongBinder(" |
| 78 | << name |
| 79 | << ");\n"; |
| 80 | |
| 81 | handleError(out, mode); |
| 82 | } |
| 83 | } |
| 84 | |
| 85 | void GenericBinder::emitJavaReaderWriter( |
| 86 | Formatter &out, |
| 87 | const std::string &parcelObj, |
| 88 | const std::string &argName, |
| 89 | bool isReader) const { |
| 90 | if (isReader) { |
| 91 | out << parcelObj |
Steven Moreland | 0f0c13d | 2016-10-28 16:57:45 -0700 | [diff] [blame] | 92 | << ".readStrongBinder();\n"; |
Andreas Huber | 295ad30 | 2016-08-16 11:35:00 -0700 | [diff] [blame] | 93 | } else { |
| 94 | out << parcelObj |
| 95 | << ".writeStrongBinder(" |
| 96 | << argName |
| 97 | << " == null ? null : " |
| 98 | << argName |
| 99 | << ");\n"; |
| 100 | } |
| 101 | } |
| 102 | |
Zhuoyao Zhang | 864c771 | 2016-08-16 15:35:28 -0700 | [diff] [blame] | 103 | status_t GenericBinder::emitVtsAttributeType(Formatter &) const { |
Andreas Huber | 295ad30 | 2016-08-16 11:35:00 -0700 | [diff] [blame] | 104 | return UNKNOWN_ERROR; |
| 105 | } |
| 106 | |
| 107 | } // namespace android |