File: com.h

package info (click to toggle)
lsp-plugins 1.2.5-1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm
  • size: 91,856 kB
  • sloc: cpp: 427,831; xml: 57,779; makefile: 9,961; php: 1,005; sh: 18
file content (96 lines) | stat: -rw-r--r-- 2,997 bytes parent folder | download | duplicates (2)
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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
/*
 * Copyright (C) 2020 Linux Studio Plugins Project <https://lsp-plug.in/>
 *           (C) 2020 Vladimir Sadovnikov <sadko4u@gmail.com>
 *
 * This file is part of lsp-ws-lib
 * Created on: 22 июл. 2022 г.
 *
 * lsp-ws-lib is free software: you can redistribute it and/or modify
 * it under the terms of the GNU Lesser General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * any later version.
 *
 * lsp-ws-lib is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public License
 * along with lsp-ws-lib. If not, see <https://www.gnu.org/licenses/>.
 */

#ifndef PRIVATE_WIN_COM_H_
#define PRIVATE_WIN_COM_H_

#include <lsp-plug.in/common/types.h>

#ifdef PLATFORM_WINDOWS

#define LSP_IUNKNOWN_IFACE \
    private: \
        ULONG                   nRefCount; \
    \
    public: /* IUnknown */ \
        virtual HRESULT STDMETHODCALLTYPE QueryInterface(REFIID iid, void **ppvObject) override; \
        virtual ULONG STDMETHODCALLTYPE AddRef() override; \
        virtual ULONG STDMETHODCALLTYPE Release() override;

#define LSP_IUNKNOWN_IMPL(Class, ParentIface) \
    HRESULT STDMETHODCALLTYPE Class::QueryInterface(REFIID iid, void **ppvObject) \
    { \
        if (IsEqualIID(iid, IID_IUnknown) || \
            IsEqualIID(iid, __uuidof(ParentIface))) \
        { \
            *ppvObject = safe_acquire(this); \
            return S_OK; \
        } \
    \
        *ppvObject = NULL; \
        return E_NOINTERFACE; \
    } \
    \
    ULONG STDMETHODCALLTYPE Class::AddRef() \
    { \
        return InterlockedIncrement(&nRefCount); \
    } \
    \
    ULONG STDMETHODCALLTYPE Class::Release() \
    { \
        ULONG newCount = InterlockedDecrement(&nRefCount); \
        if (newCount == 0) \
            delete this; \
        return newCount; \
    }

namespace lsp
{
    namespace ws
    {
        namespace win
        {
            // Releases reference, if non-null.
            template <class T>
                static inline void safe_release(T * &obj)
                {
                    if (obj != NULL)
                    {
                        obj->Release();
                        obj = NULL;
                    }
                }

            // Acquires an additional reference, if non-null.
            template <class T>
                inline T *safe_acquire(T * obj)
                {
                    if (obj != NULL)
                        obj->AddRef();
                    return obj;
                }
        } /* namespace win */
    } /* namespace ws */
} /* namespace lsp */

#endif /* PLATFORM_WINDOWS */

#endif /* PRIVATE_WIN_COM_H_ */