blob: 37fd75fe80db4bf1959ec9e1982c168943e4d169 [file] [log] [blame]
Fan Xuca70b7b2018-10-31 13:20:12 -07001/*
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 <bufferhub/BufferClient.h>
Fan Xu18d90ea2018-11-06 15:46:44 -080018#include <bufferhub/BufferHubService.h>
Fan Xuca70b7b2018-10-31 13:20:12 -070019#include <hidl/HidlSupport.h>
20
21namespace android {
22namespace frameworks {
23namespace bufferhub {
24namespace V1_0 {
25namespace implementation {
26
27using hardware::hidl_handle;
28using hardware::Void;
29
Fan Xu18d90ea2018-11-06 15:46:44 -080030BufferClient* BufferClient::create(BufferHubService* service,
31 const std::shared_ptr<BufferNode>& node) {
32 if (!service) {
33 ALOGE("%s: service cannot be nullptr.", __FUNCTION__);
34 return nullptr;
35 } else if (!node) {
36 ALOGE("%s: node cannot be nullptr.", __FUNCTION__);
37 return nullptr;
38 }
39 return new BufferClient(service, node);
40}
41
Fan Xuca70b7b2018-10-31 13:20:12 -070042Return<void> BufferClient::duplicate(duplicate_cb _hidl_cb) {
Fan Xu18d90ea2018-11-06 15:46:44 -080043 if (!mBufferNode) {
44 // Should never happen
45 ALOGE("%s: node is missing.", __FUNCTION__);
46 _hidl_cb(/*token=*/hidl_handle(), /*status=*/BufferHubStatus::BUFFER_FREED);
47 return Void();
48 }
49
50 sp<BufferHubService> service = mService.promote();
51 if (service == nullptr) {
52 // Should never happen. Kill the process.
53 LOG_FATAL("%s: service died.", __FUNCTION__);
54 }
55
56 const hidl_handle token = service->registerToken(this);
57 _hidl_cb(/*token=*/token, /*status=*/BufferHubStatus::NO_ERROR);
Fan Xuca70b7b2018-10-31 13:20:12 -070058 return Void();
59}
60
61} // namespace implementation
62} // namespace V1_0
63} // namespace bufferhub
64} // namespace frameworks
65} // namespace android