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