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
17#include <sys/mman.h>
18
19#include "AshmemMemory.h"
20
21namespace android {
22namespace hidl {
23namespace memory {
24namespace V1_0 {
25namespace implementation {
26
27AshmemMemory::AshmemMemory(const hidl_memory& memory, void* data)
28  : mMemory(memory),
29    mData(data)
30{}
31
32AshmemMemory::~AshmemMemory()
33{
34    // TODO: Move implementation to mapper class
35    munmap(mData, mMemory.size());
36}
37
38// Methods from ::android::hidl::memory::V1_0::IMemory follow.
39Return<void> AshmemMemory::update() {
40    // NOOP (since non-remoted memory)
41    return Void();
42}
43
44Return<void> AshmemMemory::updateRange(uint64_t /* start */, uint64_t /* length */) {
45    // NOOP (since non-remoted memory)
46    return Void();
47}
48
49Return<void> AshmemMemory::read() {
50    // NOOP (since non-remoted memory)
51    return Void();
52}
53
54Return<void> AshmemMemory::readRange(uint64_t /* start */, uint64_t /* length */) {
55    // NOOP (since non-remoted memory)
56    return Void();
57}
58
59Return<void> AshmemMemory::commit() {
60    // NOOP (since non-remoted memory)
61    return Void();
62}
63
64Return<void*> AshmemMemory::getPointer() {
65    return mData;
66}
67
68Return<uint64_t> AshmemMemory::getSize() {
69    return mMemory.size();
70}
71
72}  // namespace implementation
73}  // namespace V1_0
74}  // namespace memory
75}  // namespace hidl
76}  // namespace android
77