blob: 3761f99b1c2d2e8c4c8f83ce16da72390fbad1ac [file] [log] [blame]
Martijn Coenen30791002016-12-01 15:40:46 +01001/*
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#define LOG_TAG "libhidlmemory"
17
18#include <hidlmemory/mapping.h>
19
20#include <android-base/logging.h>
21#include <android/hidl/memory/1.0/IMapper.h>
22#include <hidl/HidlSupport.h>
23
24using android::sp;
25using android::hidl::memory::V1_0::IMemory;
26
27namespace android {
28namespace hardware {
29
30sp<IMemory> mapMemory(const hidl_memory &memory) {
31 using android::hidl::memory::V1_0::IMapper;
32
33 sp<IMapper> mapper = IMapper::getService(memory.name(), true /* getStub */);
34
35 if (mapper == nullptr) {
36 LOG(FATAL) << "Could not fetch mapper for " << memory.name() << " shared memory";
37 }
38
39 if (mapper->isRemote()) {
40 LOG(FATAL) << "IMapper must be a passthrough service.";
41 }
42
Martijn Coenend272cb92017-01-02 15:20:38 +010043 Return<sp<IMemory>> ret = mapper->mapMemory(memory);
Martijn Coenen30791002016-12-01 15:40:46 +010044
45 if (!ret.isOk()) {
46 LOG(FATAL) << "hidl_memory map returned transport error.";
47 }
48
Martijn Coenend272cb92017-01-02 15:20:38 +010049 return ret;
Martijn Coenen30791002016-12-01 15:40:46 +010050}
51
52} // namespace hardware
Martijn Coenend272cb92017-01-02 15:20:38 +010053} // namespace android