Qt
Internal/Contributor docs for the Qt SDK. Note: These are NOT official API docs; those are found at https://doc.qt.io/
Loading...
Searching...
No Matches
cfx_timer.cpp
Go to the documentation of this file.
1// Copyright 2017 The PDFium Authors
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 "core/fxcrt/cfx_timer.h"
8
9#include <map>
10
11#include "third_party/base/check.h"
12
13namespace {
14
15using TimerMap = std::map<int32_t, CFX_Timer*>;
16TimerMap* g_pwl_timer_map = nullptr;
17
18} // namespace
19
20// static
22 CHECK(!g_pwl_timer_map);
23 g_pwl_timer_map = new TimerMap();
24}
25
26// static
28 delete g_pwl_timer_map;
29 g_pwl_timer_map = nullptr;
30}
31
33 CallbackIface* pCallbackIface,
34 int32_t nInterval)
36 DCHECK(m_pCallbackIface);
37 if (m_pHandlerIface) {
38 m_nTimerID = m_pHandlerIface->SetTimer(nInterval, TimerProc);
39 if (HasValidID())
40 (*g_pwl_timer_map)[m_nTimerID] = this;
41 }
42}
43
45 if (HasValidID()) {
46 g_pwl_timer_map->erase(m_nTimerID);
47 if (m_pHandlerIface)
48 m_pHandlerIface->KillTimer(m_nTimerID);
49 }
50}
51
52// static
53void CFX_Timer::TimerProc(int32_t idEvent) {
54 auto it = g_pwl_timer_map->find(idEvent);
55 if (it != g_pwl_timer_map->end()) {
56 it->second->m_pCallbackIface->OnTimerFired();
57 }
58}
bool HasValidID() const
Definition cfx_timer.h:46
static void DestroyGlobals()
Definition cfx_timer.cpp:27
CFX_Timer(HandlerIface *pHandlerIface, CallbackIface *pCallbackIface, int32_t nInterval)
Definition cfx_timer.cpp:32
static void InitializeGlobals()
Definition cfx_timer.cpp:21
#define CHECK(cvref)