• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 #ifndef EPHEMERAL_STORAGE_H_
18 
19 #define EPHEMERAL_STORAGE_H_
20 
21 #include <android-base/macros.h>
22 #include <hidl/HidlSupport.h>
23 #include <jni.h>
24 #include <utils/Vector.h>
25 
26 namespace android {
27 
28 #define DECLARE_ALLOC_METHODS(Suffix,Type)                          \
29     const ::android::hardware::hidl_vec<Type> *                     \
30     allocTemporary ## Suffix ## Vector(                             \
31             JNIEnv *env, Type ## Array arrayObj);
32 
33 struct EphemeralStorage {
34     EphemeralStorage();
35     ~EphemeralStorage();
36 
37     void release(JNIEnv *env);
38 
39     hardware::hidl_string *allocStringArray(size_t size);
40 
41     void *allocTemporaryStorage(size_t size);
42 
43     const ::android::hardware::hidl_string *allocTemporaryString(
44             JNIEnv *env, jstring stringObj);
45 
46     DECLARE_ALLOC_METHODS(Int8,jbyte)
47     DECLARE_ALLOC_METHODS(Int16,jshort)
48     DECLARE_ALLOC_METHODS(Int32,jint)
49     DECLARE_ALLOC_METHODS(Int64,jlong)
50     DECLARE_ALLOC_METHODS(Float,jfloat)
51     DECLARE_ALLOC_METHODS(Double,jdouble)
52 
53 private:
54     enum Type {
55         TYPE_STRING_ARRAY,
56         TYPE_STORAGE,
57         TYPE_STRING,
58         TYPE_Int8_ARRAY,
59         TYPE_Int16_ARRAY,
60         TYPE_Int32_ARRAY,
61         TYPE_Int64_ARRAY,
62         TYPE_Float_ARRAY,
63         TYPE_Double_ARRAY,
64     };
65 
66     struct Item {
67         Type mType;
68         jobject mObj;
69         void *mPtr;
70     };
71 
72     Vector<Item> mItems;
73 
74     DISALLOW_COPY_AND_ASSIGN(EphemeralStorage);
75 };
76 
77 #undef DECLARE_ALLOC_METHODS
78 
79 }  // namespace android
80 
81 #endif  // EPHEMERAL_STORAGE_H_
82