OLD | NEW |
| (Empty) |
1 // Copyright 2014 PDFium Authors. All rights reserved. | |
2 // Use of this source code is governed by a BSD-style license that can be | |
3 // found in the LICENSE file. | |
4 | |
5 // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com | |
6 | |
7 #include "fpdfsdk/include/fpdfxfa/fpdfxfa_util.h" | |
8 | |
9 #include <vector> | |
10 | |
11 #include "fpdfsdk/include/fsdk_define.h" | |
12 #include "fpdfsdk/include/fsdk_mgr.h" | |
13 | |
14 std::vector<CFWL_TimerInfo*>* CXFA_FWLAdapterTimerMgr::s_TimerArray = nullptr; | |
15 | |
16 FWL_ERR CXFA_FWLAdapterTimerMgr::Start(IFWL_Timer* pTimer, | |
17 FX_DWORD dwElapse, | |
18 FWL_HTIMER& hTimer, | |
19 FX_BOOL bImmediately) { | |
20 if (!m_pEnv) | |
21 return FWL_ERR_Indefinite; | |
22 | |
23 uint32_t uIDEvent = m_pEnv->FFI_SetTimer(dwElapse, TimerProc); | |
24 if (!s_TimerArray) | |
25 s_TimerArray = new std::vector<CFWL_TimerInfo*>; | |
26 s_TimerArray->push_back(new CFWL_TimerInfo(uIDEvent, pTimer)); | |
27 hTimer = reinterpret_cast<FWL_HTIMER>(s_TimerArray->back()); | |
28 return FWL_ERR_Succeeded; | |
29 } | |
30 | |
31 FWL_ERR CXFA_FWLAdapterTimerMgr::Stop(FWL_HTIMER hTimer) { | |
32 if (!hTimer || !m_pEnv) | |
33 return FWL_ERR_Indefinite; | |
34 | |
35 CFWL_TimerInfo* pInfo = reinterpret_cast<CFWL_TimerInfo*>(hTimer); | |
36 m_pEnv->FFI_KillTimer(pInfo->uIDEvent); | |
37 if (s_TimerArray) { | |
38 auto it = std::find(s_TimerArray->begin(), s_TimerArray->end(), pInfo); | |
39 if (it != s_TimerArray->end()) { | |
40 s_TimerArray->erase(it); | |
41 delete pInfo; | |
42 } | |
43 } | |
44 return FWL_ERR_Succeeded; | |
45 } | |
46 | |
47 // static | |
48 void CXFA_FWLAdapterTimerMgr::TimerProc(int32_t idEvent) { | |
49 if (!s_TimerArray) | |
50 return; | |
51 | |
52 for (CFWL_TimerInfo* pInfo : *s_TimerArray) { | |
53 if (pInfo->uIDEvent == idEvent) { | |
54 pInfo->pTimer->Run(reinterpret_cast<FWL_HTIMER>(pInfo)); | |
55 break; | |
56 } | |
57 } | |
58 } | |
OLD | NEW |