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