SharedMemoryParcelable.h revision 828bea5f61f3c40d24759cd8739dd95570883b56
1828bea5f61f3c40d24759cd8739dd95570883b56Phil Burk/*
2828bea5f61f3c40d24759cd8739dd95570883b56Phil Burk * Copyright 2016 The Android Open Source Project
3828bea5f61f3c40d24759cd8739dd95570883b56Phil Burk *
4828bea5f61f3c40d24759cd8739dd95570883b56Phil Burk * Licensed under the Apache License, Version 2.0 (the "License");
5828bea5f61f3c40d24759cd8739dd95570883b56Phil Burk * you may not use this file except in compliance with the License.
6828bea5f61f3c40d24759cd8739dd95570883b56Phil Burk * You may obtain a copy of the License at
7828bea5f61f3c40d24759cd8739dd95570883b56Phil Burk *
8828bea5f61f3c40d24759cd8739dd95570883b56Phil Burk *      http://www.apache.org/licenses/LICENSE-2.0
9828bea5f61f3c40d24759cd8739dd95570883b56Phil Burk *
10828bea5f61f3c40d24759cd8739dd95570883b56Phil Burk * Unless required by applicable law or agreed to in writing, software
11828bea5f61f3c40d24759cd8739dd95570883b56Phil Burk * distributed under the License is distributed on an "AS IS" BASIS,
12828bea5f61f3c40d24759cd8739dd95570883b56Phil Burk * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13828bea5f61f3c40d24759cd8739dd95570883b56Phil Burk * See the License for the specific language governing permissions and
14828bea5f61f3c40d24759cd8739dd95570883b56Phil Burk * limitations under the License.
15828bea5f61f3c40d24759cd8739dd95570883b56Phil Burk */
16828bea5f61f3c40d24759cd8739dd95570883b56Phil Burk
17828bea5f61f3c40d24759cd8739dd95570883b56Phil Burk#ifndef BINDING_SHAREDMEMORYPARCELABLE_H
18828bea5f61f3c40d24759cd8739dd95570883b56Phil Burk#define BINDING_SHAREDMEMORYPARCELABLE_H
19828bea5f61f3c40d24759cd8739dd95570883b56Phil Burk
20828bea5f61f3c40d24759cd8739dd95570883b56Phil Burk#include <stdint.h>
21828bea5f61f3c40d24759cd8739dd95570883b56Phil Burk
22828bea5f61f3c40d24759cd8739dd95570883b56Phil Burk#include <sys/mman.h>
23828bea5f61f3c40d24759cd8739dd95570883b56Phil Burk#include <binder/Parcel.h>
24828bea5f61f3c40d24759cd8739dd95570883b56Phil Burk#include <binder/Parcelable.h>
25828bea5f61f3c40d24759cd8739dd95570883b56Phil Burk
26828bea5f61f3c40d24759cd8739dd95570883b56Phil Burkusing android::status_t;
27828bea5f61f3c40d24759cd8739dd95570883b56Phil Burkusing android::Parcel;
28828bea5f61f3c40d24759cd8739dd95570883b56Phil Burkusing android::Parcelable;
29828bea5f61f3c40d24759cd8739dd95570883b56Phil Burk
30828bea5f61f3c40d24759cd8739dd95570883b56Phil Burknamespace oboe {
31828bea5f61f3c40d24759cd8739dd95570883b56Phil Burk
32828bea5f61f3c40d24759cd8739dd95570883b56Phil Burk// Arbitrary limits for sanity checks. TODO remove after debugging.
33828bea5f61f3c40d24759cd8739dd95570883b56Phil Burk#define MAX_SHARED_MEMORIES (32)
34828bea5f61f3c40d24759cd8739dd95570883b56Phil Burk#define MAX_MMAP_OFFSET (32 * 1024)
35828bea5f61f3c40d24759cd8739dd95570883b56Phil Burk#define MAX_MMAP_SIZE (32 * 1024)
36828bea5f61f3c40d24759cd8739dd95570883b56Phil Burk
37828bea5f61f3c40d24759cd8739dd95570883b56Phil Burk/**
38828bea5f61f3c40d24759cd8739dd95570883b56Phil Burk * This is a parcelable description of a shared memory referenced by a file descriptor.
39828bea5f61f3c40d24759cd8739dd95570883b56Phil Burk * It may be divided into several regions.
40828bea5f61f3c40d24759cd8739dd95570883b56Phil Burk */
41828bea5f61f3c40d24759cd8739dd95570883b56Phil Burkclass SharedMemoryParcelable : public Parcelable {
42828bea5f61f3c40d24759cd8739dd95570883b56Phil Burkpublic:
43828bea5f61f3c40d24759cd8739dd95570883b56Phil Burk    SharedMemoryParcelable();
44828bea5f61f3c40d24759cd8739dd95570883b56Phil Burk    virtual ~SharedMemoryParcelable();
45828bea5f61f3c40d24759cd8739dd95570883b56Phil Burk
46828bea5f61f3c40d24759cd8739dd95570883b56Phil Burk    void setup(int fd, int32_t sizeInBytes);
47828bea5f61f3c40d24759cd8739dd95570883b56Phil Burk
48828bea5f61f3c40d24759cd8739dd95570883b56Phil Burk    virtual status_t writeToParcel(Parcel* parcel) const override;
49828bea5f61f3c40d24759cd8739dd95570883b56Phil Burk
50828bea5f61f3c40d24759cd8739dd95570883b56Phil Burk    virtual status_t readFromParcel(const Parcel* parcel) override;
51828bea5f61f3c40d24759cd8739dd95570883b56Phil Burk
52828bea5f61f3c40d24759cd8739dd95570883b56Phil Burk    oboe_result_t resolve(int32_t offsetInBytes, int32_t sizeInBytes, void **regionAddressPtr);
53828bea5f61f3c40d24759cd8739dd95570883b56Phil Burk
54828bea5f61f3c40d24759cd8739dd95570883b56Phil Burk    int32_t getSizeInBytes();
55828bea5f61f3c40d24759cd8739dd95570883b56Phil Burk
56828bea5f61f3c40d24759cd8739dd95570883b56Phil Burk    oboe_result_t validate();
57828bea5f61f3c40d24759cd8739dd95570883b56Phil Burk
58828bea5f61f3c40d24759cd8739dd95570883b56Phil Burk    void dump();
59828bea5f61f3c40d24759cd8739dd95570883b56Phil Burk
60828bea5f61f3c40d24759cd8739dd95570883b56Phil Burkprotected:
61828bea5f61f3c40d24759cd8739dd95570883b56Phil Burk    int mFd = -1;
62828bea5f61f3c40d24759cd8739dd95570883b56Phil Burk    int32_t mSizeInBytes = 0;
63828bea5f61f3c40d24759cd8739dd95570883b56Phil Burk    uint8_t *mResolvedAddress = nullptr;
64828bea5f61f3c40d24759cd8739dd95570883b56Phil Burk};
65828bea5f61f3c40d24759cd8739dd95570883b56Phil Burk
66828bea5f61f3c40d24759cd8739dd95570883b56Phil Burk} /* namespace oboe */
67828bea5f61f3c40d24759cd8739dd95570883b56Phil Burk
68828bea5f61f3c40d24759cd8739dd95570883b56Phil Burk#endif //BINDING_SHAREDMEMORYPARCELABLE_H
69