summaryrefslogtreecommitdiff
path: root/fpdfsdk/fpdfxfa/fpdfxfa_util.cpp
blob: 13501df94998a613d5913946cf781c66d3ff56ab (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
// Copyright 2014 PDFium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com

#include "fpdfsdk/fpdfxfa/fpdfxfa_util.h"

#include <vector>

#include "fpdfsdk/include/cpdfsdk_environment.h"
#include "fpdfsdk/include/fsdk_define.h"

std::vector<CFWL_TimerInfo*>* CXFA_FWLAdapterTimerMgr::s_TimerArray = nullptr;

FWL_Error CXFA_FWLAdapterTimerMgr::Start(IFWL_Timer* pTimer,
                                         uint32_t dwElapse,
                                         bool bImmediately,
                                         IFWL_TimerInfo** pTimerInfo) {
  if (!m_pEnv)
    return FWL_Error::Indefinite;

  int32_t id_event = m_pEnv->SetTimer(dwElapse, TimerProc);
  if (!s_TimerArray)
    s_TimerArray = new std::vector<CFWL_TimerInfo*>;

  s_TimerArray->push_back(new CFWL_TimerInfo(id_event, pTimer));
  *pTimerInfo = s_TimerArray->back();
  return FWL_Error::Succeeded;
}

FWL_Error CXFA_FWLAdapterTimerMgr::Stop(IFWL_TimerInfo* pTimerInfo) {
  if (!pTimerInfo || !m_pEnv)
    return FWL_Error::Indefinite;

  CFWL_TimerInfo* pInfo = static_cast<CFWL_TimerInfo*>(pTimerInfo);
  m_pEnv->KillTimer(pInfo->idEvent);
  if (s_TimerArray) {
    auto it = std::find(s_TimerArray->begin(), s_TimerArray->end(), pInfo);
    if (it != s_TimerArray->end()) {
      s_TimerArray->erase(it);
      delete pInfo;
    }
  }
  return FWL_Error::Succeeded;
}

// static
void CXFA_FWLAdapterTimerMgr::TimerProc(int32_t idEvent) {
  if (!s_TimerArray)
    return;

  for (CFWL_TimerInfo* pInfo : *s_TimerArray) {
    if (pInfo->idEvent == idEvent) {
      pInfo->pTimer->Run(pInfo);
      break;
    }
  }
}