1/****************************************************************************
2**
3** Copyright (C) 2013 Laszlo Papp <lpapp@kde.org>
4** Contact: https://www.qt.io/licensing/
5**
6** This file is part of the QtSerialPort module of the Qt Toolkit.
7**
8** $QT_BEGIN_LICENSE:LGPL$
9** Commercial License Usage
10** Licensees holding valid commercial Qt licenses may use this file in
11** accordance with the commercial license agreement provided with the
12** Software or, alternatively, in accordance with the terms contained in
13** a written agreement between you and The Qt Company. For licensing terms
14** and conditions see https://www.qt.io/terms-conditions. For further
15** information use the contact form at https://www.qt.io/contact-us.
16**
17** GNU Lesser General Public License Usage
18** Alternatively, this file may be used under the terms of the GNU Lesser
19** General Public License version 3 as published by the Free Software
20** Foundation and appearing in the file LICENSE.LGPL3 included in the
21** packaging of this file. Please review the following information to
22** ensure the GNU Lesser General Public License version 3 requirements
23** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
24**
25** GNU General Public License Usage
26** Alternatively, this file may be used under the terms of the GNU
27** General Public License version 2.0 or (at your option) the GNU General
28** Public license version 3 or any later version approved by the KDE Free
29** Qt Foundation. The licenses are as published by the Free Software
30** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
31** included in the packaging of this file. Please review the following
32** information to ensure the GNU General Public License requirements will
33** be met: https://www.gnu.org/licenses/gpl-2.0.html and
34** https://www.gnu.org/licenses/gpl-3.0.html.
35**
36** $QT_END_LICENSE$
37**
38****************************************************************************/
39
40#ifndef QTUDEV_P_H
41#define QTUDEV_P_H
42
43//
44// W A R N I N G
45// -------------
46//
47// This file is not part of the Qt API. It exists purely as an
48// implementation detail. This header file may change from version to
49// version without notice, or even be removed.
50//
51// We mean it.
52//
53
54#ifdef LINK_LIBUDEV
55extern "C"
56{
57#include <libudev.h>
58}
59#else
60#include <QtCore/qlibrary.h>
61#include <QtCore/qstring.h>
62#include <QtCore/qdebug.h>
63
64#define GENERATE_SYMBOL_VARIABLE(returnType, symbolName, ...) \
65 typedef returnType (*fp_##symbolName)(__VA_ARGS__); \
66 static fp_##symbolName symbolName;
67
68#define RESOLVE_SYMBOL(symbolName) \
69 symbolName = (fp_##symbolName)resolveSymbol(udevLibrary, #symbolName); \
70 if (!symbolName) \
71 return false;
72
73struct udev;
74
75#define udev_list_entry_foreach(list_entry, first_entry) \
76 for (list_entry = first_entry; \
77 list_entry != nullptr; \
78 list_entry = udev_list_entry_get_next(list_entry))
79
80struct udev_device;
81struct udev_enumerate;
82struct udev_list_entry;
83
84GENERATE_SYMBOL_VARIABLE(struct ::udev *, udev_new);
85GENERATE_SYMBOL_VARIABLE(struct ::udev_enumerate *, udev_enumerate_new, struct ::udev *)
86GENERATE_SYMBOL_VARIABLE(int, udev_enumerate_add_match_subsystem, struct udev_enumerate *, const char *)
87GENERATE_SYMBOL_VARIABLE(int, udev_enumerate_scan_devices, struct udev_enumerate *)
88GENERATE_SYMBOL_VARIABLE(struct udev_list_entry *, udev_enumerate_get_list_entry, struct udev_enumerate *)
89GENERATE_SYMBOL_VARIABLE(struct udev_list_entry *, udev_list_entry_get_next, struct udev_list_entry *)
90GENERATE_SYMBOL_VARIABLE(struct udev_device *, udev_device_new_from_syspath, struct udev *udev, const char *syspath)
91GENERATE_SYMBOL_VARIABLE(const char *, udev_list_entry_get_name, struct udev_list_entry *)
92GENERATE_SYMBOL_VARIABLE(const char *, udev_device_get_devnode, struct udev_device *)
93GENERATE_SYMBOL_VARIABLE(const char *, udev_device_get_sysname, struct udev_device *)
94GENERATE_SYMBOL_VARIABLE(const char *, udev_device_get_driver, struct udev_device *)
95GENERATE_SYMBOL_VARIABLE(struct udev_device *, udev_device_get_parent, struct udev_device *)
96GENERATE_SYMBOL_VARIABLE(const char *, udev_device_get_subsystem, struct udev_device *)
97GENERATE_SYMBOL_VARIABLE(const char *, udev_device_get_property_value, struct udev_device *, const char *)
98GENERATE_SYMBOL_VARIABLE(void, udev_device_unref, struct udev_device *)
99GENERATE_SYMBOL_VARIABLE(void, udev_enumerate_unref, struct udev_enumerate *)
100GENERATE_SYMBOL_VARIABLE(void, udev_unref, struct udev *)
101
102inline QFunctionPointer resolveSymbol(QLibrary *udevLibrary, const char *symbolName)
103{
104 QFunctionPointer symbolFunctionPointer = udevLibrary->resolve(symbolName);
105 if (!symbolFunctionPointer)
106 qWarning("Failed to resolve the udev symbol: %s", symbolName);
107
108 return symbolFunctionPointer;
109}
110
111inline bool resolveSymbols(QLibrary *udevLibrary)
112{
113 if (!udevLibrary->isLoaded()) {
114 udevLibrary->setFileNameAndVersion(QStringLiteral("udev"), 1);
115 if (!udevLibrary->load()) {
116 udevLibrary->setFileNameAndVersion(QStringLiteral("udev"), 0);
117 if (!udevLibrary->load()) {
118 qWarning("Failed to load the library: %s, supported version(s): %i and %i", qPrintable(udevLibrary->fileName()), 1, 0);
119 return false;
120 }
121 }
122 }
123
124 RESOLVE_SYMBOL(udev_new)
125 RESOLVE_SYMBOL(udev_enumerate_new)
126 RESOLVE_SYMBOL(udev_enumerate_add_match_subsystem)
127 RESOLVE_SYMBOL(udev_enumerate_scan_devices)
128 RESOLVE_SYMBOL(udev_enumerate_get_list_entry)
129 RESOLVE_SYMBOL(udev_list_entry_get_next)
130 RESOLVE_SYMBOL(udev_device_new_from_syspath)
131 RESOLVE_SYMBOL(udev_list_entry_get_name)
132 RESOLVE_SYMBOL(udev_device_get_devnode)
133 RESOLVE_SYMBOL(udev_device_get_sysname)
134 RESOLVE_SYMBOL(udev_device_get_driver)
135 RESOLVE_SYMBOL(udev_device_get_parent)
136 RESOLVE_SYMBOL(udev_device_get_subsystem)
137 RESOLVE_SYMBOL(udev_device_get_property_value)
138 RESOLVE_SYMBOL(udev_device_unref)
139 RESOLVE_SYMBOL(udev_enumerate_unref)
140 RESOLVE_SYMBOL(udev_unref)
141
142 return true;
143}
144
145#endif
146
147#endif
148

source code of qtserialport/src/serialport/qtudev_p.h