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 #define LOG_TAG "libhidlmemory" 17 18 #include <map> 19 #include <mutex> 20 #include <string> 21 22 #include <hidlmemory/mapping.h> 23 24 #include <android-base/logging.h> 25 #include <hidl/HidlSupport.h> 26 #include "HidlMemoryCache.h" 27 28 using android::hardware::HidlMemoryCache; 29 using android::hidl::memory::block::V1_0::MemoryBlock; 30 using android::hidl::memory::token::V1_0::IMemoryToken; 31 using android::hidl::memory::V1_0::IMemory; 32 33 namespace android { 34 namespace hardware { 35 36 sp<IMemory> mapMemory(const ::android::hidl::memory::block::V1_0::MemoryBlock& block) { 37 sp<HidlMemoryCache> c = HidlMemoryCache::getInstance(); 38 return c->map(block); 39 } 40 41 sp<RefBase> lockMemoryCache(const sp<::android::hidl::memory::token::V1_0::IMemoryToken> key) { 42 sp<HidlMemoryCache> c = HidlMemoryCache::getInstance(); 43 return c->lockGuard(key); 44 } 45 46 } // namespace hardware 47 } // namespace android 48