1 /****************************************************************************** 2 * 3 * Copyright 2020 NXP 4 * 5 * Licensed under the Apache License, Version 2.0 (the "License"); 6 * you may not use this file except in compliance with the License. 7 * You may obtain a copy of the License at 8 * 9 * http://www.apache.org/licenses/LICENSE-2.0 10 * 11 * Unless required by applicable law or agreed to in writing, software 12 * distributed under the License is distributed on an "AS IS" BASIS, 13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 * See the License for the specific language governing permissions and 15 * limitations under the License. 16 * 17 ******************************************************************************/ 18 #pragma once 19 #include <pthread.h> 20 21 #include <android/hardware/nfc/1.0/types.h> 22 #include <phEseStatus.h> 23 #include <phNxpEseFeatures.h> 24 #include <utils/RefBase.h> 25 #include <vendor/nxp/nxpnfc/2.0/INxpNfc.h> 26 #include "hal_nxpese.h" 27 using vendor::nxp::nxpnfc::V2_0::INxpNfc; 28 29 class ThreadMutex { 30 public: 31 ThreadMutex(); 32 virtual ~ThreadMutex(); 33 void lock(); 34 void unlock(); 35 operator pthread_mutex_t*() { return &mMutex; } 36 37 private: 38 pthread_mutex_t mMutex; 39 }; 40 41 class ThreadCondVar : public ThreadMutex { 42 public: 43 ThreadCondVar(); 44 virtual ~ThreadCondVar(); 45 void signal(); 46 void wait(); 47 operator pthread_cond_t*() { return &mCondVar; } 48 operator pthread_mutex_t*() { 49 return ThreadMutex::operator pthread_mutex_t*(); 50 } 51 52 private: 53 pthread_cond_t mCondVar; 54 }; 55 56 class AutoThreadMutex { 57 public: 58 AutoThreadMutex(ThreadMutex& m); 59 virtual ~AutoThreadMutex(); 60 operator ThreadMutex&() { return mm; } 61 operator pthread_mutex_t*() { return (pthread_mutex_t*)mm; } 62 63 private: 64 ThreadMutex& mm; 65 }; 66 67 class NfcAdaptation { 68 public: 69 virtual ~NfcAdaptation(); 70 void Initialize(); 71 static NfcAdaptation& GetInstance(); 72 static ESESTATUS resetEse(uint64_t level); 73 static ESESTATUS setEseUpdateState(void* p_data); 74 ese_nxp_IoctlInOutData_t* mCurrentIoctlData; 75 76 private: 77 NfcAdaptation(); 78 static NfcAdaptation* mpInstance; 79 static ThreadMutex sLock; 80 static ThreadMutex sIoctlLock; 81 ThreadCondVar mCondVar; 82 static ThreadCondVar mHalIoctlEvent; 83 static android::sp<INxpNfc> mHalNxpNfc; 84 }; 85