blob: 09204880881b7ce1bdea8a4e8c9035348239eccb [file] [log] [blame]
Andreas Huber9266f992016-08-25 11:21:21 -07001/*
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#ifndef ANDROID_OS_HW_BLOB_H
18#define ANDROID_OS_HW_BLOB_H
19
20#include <android-base/macros.h>
21#include <jni.h>
22#include <hidl/HidlSupport.h>
Yifan Hongddf31f62016-11-15 16:02:40 -080023#include <hwbinder/Parcel.h>
Andreas Huber9266f992016-08-25 11:21:21 -070024#include <utils/RefBase.h>
25#include <utils/Vector.h>
26
27namespace android {
28
29struct JHwBlob : public RefBase {
30 static void InitClass(JNIEnv *env);
31
32 static sp<JHwBlob> SetNativeContext(
33 JNIEnv *env, jobject thiz, const sp<JHwBlob> &context);
34
35 static sp<JHwBlob> GetNativeContext(JNIEnv *env, jobject thiz);
36
37 static jobject NewObject(JNIEnv *env, const void *ptr, size_t handle);
38 static jobject NewObject(JNIEnv *env, size_t size);
39
40 JHwBlob(JNIEnv *env, jobject thiz, size_t size);
41
42 void setTo(const void *ptr, size_t handle);
43
44 status_t getHandle(size_t *handle) const;
45
46 status_t read(size_t offset, void *data, size_t size) const;
47 status_t write(size_t offset, const void *data, size_t size);
48
49 status_t getString(
50 size_t offset, const android::hardware::hidl_string **s) const;
51
52 const void *data() const;
53 size_t size() const;
54
55 status_t putBlob(size_t offset, const sp<JHwBlob> &blob);
56
57 status_t writeToParcel(hardware::Parcel *parcel) const;
58
59 status_t writeEmbeddedToParcel(
60 hardware::Parcel *parcel,
61 size_t parentHandle,
62 size_t parentOffset) const;
63
64protected:
65 virtual ~JHwBlob();
66
67private:
68 struct BlobInfo {
69 size_t mOffset;
70 sp<JHwBlob> mBlob;
71 };
72
73 jclass mClass;
74 jobject mObject;
75
76 void *mBuffer;
77 size_t mSize;
78 bool mOwnsBuffer;
79
80 size_t mHandle;
81
82 Vector<BlobInfo> mSubBlobs;
83
84 DISALLOW_COPY_AND_ASSIGN(JHwBlob);
85};
86
87int register_android_os_HwBlob(JNIEnv *env);
88
89} // namespace android
90
91#endif // ANDROID_OS_HW_BLOB_H
92