Coverage Report

Created: 2026-08-14 10:22

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/libreoffice/vcl/inc/saltimer.hxx
Line
Count
Source
1
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2
/*
3
 * This file is part of the LibreOffice project.
4
 *
5
 * This Source Code Form is subject to the terms of the Mozilla Public
6
 * License, v. 2.0. If a copy of the MPL was not distributed with this
7
 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
8
 *
9
 * This file incorporates work covered by the following license notice:
10
 *
11
 *   Licensed to the Apache Software Foundation (ASF) under one or more
12
 *   contributor license agreements. See the NOTICE file distributed
13
 *   with this work for additional information regarding copyright
14
 *   ownership. The ASF licenses this file to you under the Apache
15
 *   License, Version 2.0 (the "License"); you may not use this file
16
 *   except in compliance with the License. You may obtain a copy of
17
 *   the License at http://www.apache.org/licenses/LICENSE-2.0 .
18
 */
19
20
#pragma once
21
22
#include <sal/config.h>
23
#include <vcl/dllapi.h>
24
#include "salwtype.hxx"
25
26
/*
27
 * note: there will be only a single instance of SalTimer
28
 * SalTimer originally had only static methods, but
29
 * this needed to be virtualized for the sal plugin migration
30
 */
31
32
class VCL_PLUGIN_PUBLIC SalTimer
33
{
34
    SALTIMERPROC        m_pProc;
35
36
public:
37
30
    SalTimer() : m_pProc( nullptr ) {}
38
    virtual ~SalTimer();
39
40
    // AutoRepeat and Restart
41
    virtual void            Start( sal_uInt64 nMS ) = 0;
42
    virtual void            Stop() = 0;
43
44
    // Callbacks (indepen in \sv\source\app\timer.cxx)
45
    void            SetCallback( SALTIMERPROC pProc )
46
30
    {
47
30
        m_pProc = pProc;
48
30
    }
49
50
    void            CallCallback()
51
6.62k
    {
52
6.62k
        if( m_pProc )
53
6.62k
            m_pProc();
54
6.62k
    }
55
};
56
57
class VersionedEvent
58
{
59
    /**
60
     * The "additional event data" members on macOS are integers, so we can't
61
     * use an unsigned integer and rely on the defined unsigned overflow in
62
     * InvalidateEvent().
63
     */
64
    sal_Int32 m_nEventVersion;
65
    bool      m_bIsValidVersion;
66
67
public:
68
0
    VersionedEvent() : m_nEventVersion( 0 ), m_bIsValidVersion( false ) {}
69
70
    sal_Int32 GetNextEventVersion()
71
0
    {
72
0
        InvalidateEvent();
73
0
        m_bIsValidVersion = true;
74
0
        return m_nEventVersion;
75
0
    }
76
77
    void InvalidateEvent()
78
0
    {
79
0
        if ( m_bIsValidVersion )
80
0
        {
81
0
            if ( m_nEventVersion == SAL_MAX_INT32 )
82
0
                m_nEventVersion = 0;
83
0
            else
84
0
                ++m_nEventVersion;
85
0
            m_bIsValidVersion = false;
86
0
        }
87
0
    }
88
89
    bool ExistsValidEvent() const
90
0
    {
91
0
        return m_bIsValidVersion;
92
0
    }
93
94
    bool IsValidEventVersion( const sal_Int32 nEventVersion ) const
95
0
    {
96
0
        return m_bIsValidVersion && nEventVersion == m_nEventVersion;
97
0
    }
98
};
99
100
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */