1 /* 2 * Copyright (C) 2018 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_SENSORS_TEST_SHARED_MEMORY_H 18 #define ANDROID_SENSORS_TEST_SHARED_MEMORY_H 19 20 #include "GrallocWrapper.h" 21 22 #include <android-base/macros.h> 23 #include <android/hardware/sensors/1.0/types.h> 24 25 #include <cutils/ashmem.h> 26 27 class SensorsTestSharedMemory { 28 using SharedMemType = ::android::hardware::sensors::V1_0::SharedMemType; 29 using SharedMemInfo = ::android::hardware::sensors::V1_0::SharedMemInfo; 30 using Event = ::android::hardware::sensors::V1_0::Event; 31 32 public: 33 static SensorsTestSharedMemory* create(SharedMemType type, size_t size); 34 SharedMemInfo getSharedMemInfo() const; 35 char* getBuffer() const; 36 size_t getSize() const; 37 std::vector<Event> parseEvents(int64_t lastCounter = -1, size_t offset = 0) const; 38 virtual ~SensorsTestSharedMemory(); 39 40 private: 41 SensorsTestSharedMemory(SharedMemType type, size_t size); 42 43 SharedMemType mType; 44 native_handle_t* mNativeHandle; 45 size_t mSize; 46 char* mBuffer; 47 std::unique_ptr<::android::GrallocWrapper> mGrallocWrapper; 48 49 DISALLOW_COPY_AND_ASSIGN(SensorsTestSharedMemory); 50 }; 51 52 #endif // ANDROID_SENSORS_TEST_SHARED_MEMORY_H 53