| Sungtak Lee | bbe37b6 | 2018-08-29 15:15:48 -0700 | [diff] [blame^] | 1 | /* | 
 | 2 |  * Copyright (C) 2018 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 |  | 
 | 17 | #include "Connection.h" | 
 | 18 |  | 
 | 19 | namespace android { | 
 | 20 | namespace hardware { | 
 | 21 | namespace media { | 
 | 22 | namespace bufferpool { | 
 | 23 | namespace V2_0 { | 
 | 24 | namespace implementation { | 
 | 25 |  | 
 | 26 | // Methods from ::android::hardware::media::bufferpool::V2_0::IConnection follow. | 
 | 27 | Return<void> Connection::fetch(uint64_t transactionId, uint32_t bufferId, fetch_cb _hidl_cb) { | 
 | 28 |     ResultStatus status = ResultStatus::CRITICAL_ERROR; | 
 | 29 |     if (mInitialized && mAccessor) { | 
 | 30 |         if (bufferId != SYNC_BUFFERID) { | 
 | 31 |             const native_handle_t *handle = nullptr; | 
 | 32 |             status = mAccessor->fetch( | 
 | 33 |                     mConnectionId, transactionId, bufferId, &handle); | 
 | 34 |             if (status == ResultStatus::OK) { | 
 | 35 |                 _hidl_cb(status, Buffer{bufferId, handle}); | 
 | 36 |                 return Void(); | 
 | 37 |             } | 
 | 38 |         } else { | 
 | 39 |             mAccessor->cleanUp(false); | 
 | 40 |         } | 
 | 41 |     } | 
 | 42 |     _hidl_cb(status, Buffer{0, nullptr}); | 
 | 43 |     return Void(); | 
 | 44 | } | 
 | 45 |  | 
 | 46 | Connection::Connection() : mInitialized(false), mConnectionId(-1LL) {} | 
 | 47 |  | 
 | 48 | Connection::~Connection() { | 
 | 49 |     if (mInitialized && mAccessor) { | 
 | 50 |         mAccessor->close(mConnectionId); | 
 | 51 |     } | 
 | 52 | } | 
 | 53 |  | 
 | 54 | void Connection::initialize( | 
 | 55 |         const sp<Accessor>& accessor, ConnectionId connectionId) { | 
 | 56 |     if (!mInitialized) { | 
 | 57 |         mAccessor = accessor; | 
 | 58 |         mConnectionId = connectionId; | 
 | 59 |         mInitialized = true; | 
 | 60 |     } | 
 | 61 | } | 
 | 62 |  | 
 | 63 | ResultStatus Connection::allocate( | 
 | 64 |         const std::vector<uint8_t> ¶ms, BufferId *bufferId, | 
 | 65 |         const native_handle_t **handle) { | 
 | 66 |     if (mInitialized && mAccessor) { | 
 | 67 |         return mAccessor->allocate(mConnectionId, params, bufferId, handle); | 
 | 68 |     } | 
 | 69 |     return ResultStatus::CRITICAL_ERROR; | 
 | 70 | } | 
 | 71 |  | 
 | 72 | void Connection::cleanUp(bool clearCache) { | 
 | 73 |     if (mInitialized && mAccessor) { | 
 | 74 |         mAccessor->cleanUp(clearCache); | 
 | 75 |     } | 
 | 76 | } | 
 | 77 |  | 
 | 78 | // Methods from ::android::hidl::base::V1_0::IBase follow. | 
 | 79 |  | 
 | 80 | //IConnection* HIDL_FETCH_IConnection(const char* /* name */) { | 
 | 81 | //    return new Connection(); | 
 | 82 | //} | 
 | 83 |  | 
 | 84 | }  // namespace implementation | 
 | 85 | }  // namespace V2_0 | 
 | 86 | }  // namespace bufferpool | 
 | 87 | }  // namespace media | 
 | 88 | }  // namespace hardware | 
 | 89 | }  // namespace android |