The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2007 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 | #ifndef ANDROID_IMEMORY_H |
| 18 | #define ANDROID_IMEMORY_H |
| 19 | |
| 20 | #include <stdint.h> |
| 21 | #include <sys/types.h> |
| 22 | #include <sys/mman.h> |
| 23 | |
| 24 | #include <utils/RefBase.h> |
| 25 | #include <utils/Errors.h> |
Mathias Agopian | 0795272 | 2009-05-19 19:08:10 -0700 | [diff] [blame] | 26 | #include <binder/IInterface.h> |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 27 | |
| 28 | namespace android { |
| 29 | |
| 30 | // ---------------------------------------------------------------------------- |
| 31 | |
| 32 | class IMemoryHeap : public IInterface |
| 33 | { |
| 34 | public: |
| 35 | DECLARE_META_INTERFACE(MemoryHeap); |
| 36 | |
| 37 | // flags returned by getFlags() |
| 38 | enum { |
Mathias Agopian | 92c3b39 | 2010-04-19 19:09:03 -0700 | [diff] [blame] | 39 | READ_ONLY = 0x00000001 |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 40 | }; |
| 41 | |
| 42 | virtual int getHeapID() const = 0; |
| 43 | virtual void* getBase() const = 0; |
| 44 | virtual size_t getSize() const = 0; |
| 45 | virtual uint32_t getFlags() const = 0; |
Anu Sundararajan | f24c4cd | 2011-06-22 15:58:59 -0500 | [diff] [blame] | 46 | virtual uint32_t getOffset() const = 0; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 47 | |
| 48 | // these are there just for backward source compatibility |
| 49 | int32_t heapID() const { return getHeapID(); } |
| 50 | void* base() const { return getBase(); } |
| 51 | size_t virtualSize() const { return getSize(); } |
| 52 | }; |
| 53 | |
| 54 | class BnMemoryHeap : public BnInterface<IMemoryHeap> |
| 55 | { |
| 56 | public: |
| 57 | virtual status_t onTransact( |
| 58 | uint32_t code, |
| 59 | const Parcel& data, |
| 60 | Parcel* reply, |
| 61 | uint32_t flags = 0); |
Mathias Agopian | aaf834a | 2009-05-22 19:00:22 -0700 | [diff] [blame] | 62 | |
| 63 | BnMemoryHeap(); |
| 64 | protected: |
| 65 | virtual ~BnMemoryHeap(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 66 | }; |
| 67 | |
| 68 | // ---------------------------------------------------------------------------- |
| 69 | |
| 70 | class IMemory : public IInterface |
| 71 | { |
| 72 | public: |
| 73 | DECLARE_META_INTERFACE(Memory); |
| 74 | |
| 75 | virtual sp<IMemoryHeap> getMemory(ssize_t* offset=0, size_t* size=0) const = 0; |
| 76 | |
| 77 | // helpers |
| 78 | void* fastPointer(const sp<IBinder>& heap, ssize_t offset) const; |
| 79 | void* pointer() const; |
| 80 | size_t size() const; |
| 81 | ssize_t offset() const; |
| 82 | }; |
| 83 | |
| 84 | class BnMemory : public BnInterface<IMemory> |
| 85 | { |
| 86 | public: |
| 87 | virtual status_t onTransact( |
| 88 | uint32_t code, |
| 89 | const Parcel& data, |
| 90 | Parcel* reply, |
| 91 | uint32_t flags = 0); |
Mathias Agopian | aaf834a | 2009-05-22 19:00:22 -0700 | [diff] [blame] | 92 | |
| 93 | BnMemory(); |
| 94 | protected: |
| 95 | virtual ~BnMemory(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 96 | }; |
| 97 | |
| 98 | // ---------------------------------------------------------------------------- |
| 99 | |
| 100 | }; // namespace android |
| 101 | |
| 102 | #endif // ANDROID_IMEMORY_H |