Commit Graph

881 Commits

Author SHA1 Message Date
Ievgenii Meshcheriakov
24e504d9df QDBusConnectionPrivate: Fix race in sendWithReply()
The message processing may finish before watcherHelper is
setup. Use locking and an additional check for message
processing completion to avoid the race condition.

Move the code to new function inside QDBusPendingCallPrivate,
close to where the waiting without GUI is done.

Add assertions that check that watcherHelper is not overwritten.

Change-Id: I24e54598135edf293c41b3a80369b0a3b46f775c
Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
2023-09-22 21:02:45 +02:00
Ievgenii Meshcheriakov
178a5d15ef QDBusConnectionPrivate: Protect access to serverConnectionNames with mutex
This list is accessed by ~QDBusServerConnection in a user thead.

Task-number: QTBUG-116621
Change-Id: Ic115612b2a0f12fd9f69f38f4662dc36fffbf178
Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
2023-09-18 15:50:43 +02:00
Ievgenii Meshcheriakov
eacff46af4 QtDBus: Check if QDBusServer is destroyed before accessing it
Also lock before accessing serverObject member, it is cleared
by ~QDBusServer().

Task-number: QTBUG-116621
Change-Id: I14c96e34316a46fe43ecd929e44cd1800ba8b803
Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
2023-09-18 15:50:43 +02:00
Nicolas Fella
b2e5f70490 QDBusConnection: Print error from prepareHook
When the operation fails we print a warning, but that warning does not
include the error message that prepareHook internally collects but
ignores.

Printing the error is useful for debugging.

Pick-to: 6.6
Change-Id: I946c4781942115a17ffd43a79bff7676b6674be1
Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
2023-09-17 23:39:04 +02:00
Ievgenii Meshcheriakov
e49d8444dc QDBusArgumentPrivate: Disable copy and move, make constructor protected
Disable copy and move for the class because it is polymorphic.

Make the constructor protected because instances of this
class are not supposed to be created directly.

Mark drived classes final.

Change-Id: Ia6f2d640f3642ad4a6ecb3830fba152155e237b3
Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
2023-09-14 11:50:46 +02:00
Ievgenii Meshcheriakov
37af09adf0 QtDBus: Resolve libdbus functions in a thread-safe way
Use atomic pointers.

While at it, declare the function type with `using` instead
of a typedef for better readability, do the declaration
locally so that less preprocessor concatenation is needed,
use reinterpret_cast instead of C-style cast.

Change-Id: I5ed0d35b7ddfdd62ef6c12403fe7052019453f34
Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
2023-09-14 11:50:28 +02:00
Ievgenii Meshcheriakov
bfdefa81f8 QDBusArgumentPrivate: Specify direction as argument to constructor
This avoids having direction member uninitialized by mistake. Make the
member variable const as it is never modified.

While at it, make Direction and enum class.

Change-Id: I53814ae9e1d6bcf786433674619145a1ee61e063
Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
2023-09-14 11:50:24 +02:00
Ievgenii Meshcheriakov
946992b9b0 QDBusArgumentPrivate: Use type-safe enum for flags
Declare flags as QDBusConnection::ConnectionCapabilities
instead of bare int. Do the same for derived classes
QDBusMarshaller and QDBusDemarshaller. Make the constructors
explicit, replacing useless `inline` where it was used.
Make flags argument default to empty flags.

Change-Id: I6caedde06b2ef41d725f15348ee780d1cc20b355
Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
2023-09-14 11:50:22 +02:00
Ievgenii Meshcheriakov
e4eabbf3e4 QDBusArgumentPrivate: Initialize member variables inline
For better readability and ease of modification.
Do the same for derived classes.

Change-Id: I9601f0b280feb5e3d0e71ed4a3405fdd9cca8dd2
Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
2023-09-14 11:50:18 +02:00
Ievgenii Meshcheriakov
f2a2c669f6 qdbus_symbols: Make major version list contexpr
It is never modified.

Change-Id: Ie87a0705e258c5977f352afdcfc3bee513b3bfb6
Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
2023-09-12 16:21:20 +02:00
Ievgenii Meshcheriakov
d08d99a57b qdbus_symbols: Use QFunctionPointer typedef
This makes function declarations much easier to read.

Change-Id: Ib05433cda97a39f4a3b8c2759c32309a60716bfb
Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
2023-09-12 16:21:17 +02:00
Ievgenii Meshcheriakov
5fa733e632 qdbus_symbols.cpp: Include qdbus_symbols_p.h
Remove external declarations from the source file.

Change-Id: I9e43666fd646a2d3372607a4514f727ee80d2daf
Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
2023-09-12 16:21:15 +02:00
Ievgenii Meshcheriakov
9d4e4deaa2 QDBusArgumentPrivate::createSignature: Accept QMetaType as argument
This gives more information than an int, also simplifies the code
slightly.

Change-Id: I76c00230386d74c70d294e638b4927de883f03ff
Reviewed-by: Marc Mutz <marc.mutz@qt.io>
2023-09-12 16:21:00 +02:00
Ievgenii Meshcheriakov
7e3d29f618 QDBusConnectionPrivate: Use write lock inside handleSignal()
Slots like (un)registerServiceNoLock() modify shared state and
should be run with write lock taken. Having only read lock results
in hard to reproduce crashes.

Task-number: QTBUG-116621
Change-Id: I4456b64f9f2200378012822143e1a05345859d62
Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
2023-09-11 15:26:56 +02:00
Ievgenii Meshcheriakov
9ff099e966 QDBusArgumentPrivate: Remove duplicate public sections
Do the same for the derived classes.

Change-Id: Ieec1d222a96775d57af91f9c6757648561b75e53
Reviewed-by: Giuseppe D'Angelo <giuseppe.dangelo@kdab.com>
Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org>
2023-09-11 15:26:56 +02:00
Ievgenii Meshcheriakov
4c2f944958 QDBusConnectionPrivate: Remove parent argument
This class is reference counted, having a parent would
interfere with this reference counting code.

Change-Id: I5ab4fdfa74af94d8b760bd3600bd1f828e3d2b91
Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
2023-09-11 15:26:56 +02:00
Jaishree Vyas
29eb5d8ace Doc: All overviews list categorization
The \generate list names are added for each categorized section with
some explanation. Here, calling the overviews as
explanations-(name of the section). The idea is to give general terms
instead of specific phrases like 'core' etc, for better understanding.

Task-number: QTBUG-115347
Pick-to: 6.5 6.6
Change-Id: I673e38c0e9193b7f7d54008bfcf82c2d3a10be3f
Reviewed-by: Topi Reiniö <topi.reinio@qt.io>
2023-09-11 15:26:56 +02:00
Ievgenii Meshcheriakov
087d267a44 QDBusConnectionPrivate: Remove declaration of messageFilter()
The function is declared but never defined.

Change-Id: Ic9c4369ecaee3103b74d2dc9b84cbece99379603
Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
2023-09-11 00:32:40 +02:00
Ievgenii Meshcheriakov
fa78a9f5bd QtDBus: Remove uses of Q_UNUSED on used variables
This also includes variables only used in Q_ASSERT, those
don't generate warnings anymore even when asserts are disabled.

Change-Id: Ia557120d442c100c9437b106a01a4079d48640af
Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
2023-09-11 00:32:40 +02:00
Ievgenii Meshcheriakov
dad421222c QDBus: Use type-safe object tree node flags
Change-Id: I7078b11d19d7a6444a020e0d400efbaea22f84a8
Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
2023-09-11 00:32:40 +02:00
Ievgenii Meshcheriakov
588700dbfa QDBusSlotCache: Include flags into the hash key
This removes the need for doing two separate iteration to find
entries in the hash. Also QMultyHash can now be replaced by
plain QHash.

Change-Id: Ie704e74c1dbb0c8e40d22a7cd572fcc8a3bfcd5d
Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
2023-09-11 00:32:40 +02:00
Ahmad Samir
ac9e968755 Remove redundant QPair includes
Nothing in those files uses QPair; and a local build finished fine without them.

Task-number: QTBUG-115841
Change-Id: I669cfecaa9129bce6b31e464826287f138b159db
Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
2023-09-06 17:24:40 +00:00
Ievgenii Meshcheriakov
a296f091c5 QDBusConnectionPrivate: Remove duplicated public sections
Seeing a public keyword may make the reader mistakenly
believe that the section above is not public.

Change-Id: I074d54ed5f6a5b5911d4c6038d33e14d2c58abe0
Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
2023-09-04 12:03:07 +02:00
Ivan Solovev
d85663ced8 QDBusServiceWatcher: fix binding loops
This class has two bindable properties - watchedServices and watchMode.
What makes this class non-trivial is the fact that these properties
depend on each other - setWatchedServices() need an up-to-date
watchMode to set up the services, and setWatchMode() needs an
up-to-date list of services in order to update the mode on them.

Update the setters in such way that they remove the bindings from
the updated property, and at the same time trigger the re-evaluation
of the property they depend on.
This includes refactoring of the helper setConnection() method in such
way that it does not cause property re-evaluation, and also update
of the {add,remove}Service() helper functions to take the watchMode as
an input parameter.

The public {add,remove}WatchedService() methods were updated similarly.
The logic of the removeWatchedService() method was additionally
updated to do some changes to the properties only if the
service-to-be-removed actually existed in the list.

Task-number: QTBUG-116346
Pick-to: 6.6 6.5
Change-Id: If46cf926c7ace9dc4893d8daaef088f61e41c21a
Reviewed-by: Ulf Hermann <ulf.hermann@qt.io>
2023-09-03 18:21:18 +02:00
Ievgenii Meshcheriakov
5cad1d7a04 QDBusCallDeliveryEvent: Remove unused flags member
Also remove flags argument of QDBusConnectionPrivate::deliverCall().

Change-Id: Idd569f531891ffd21e6f57c17e5d03539c3fd230
Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
2023-09-03 12:38:55 +02:00
Ievgenii Meshcheriakov
074c664b5c QDBusConnectionPrivate: Emit newConnection signal on QDBusServer directly
Remove indirection via _q_newConnection() because the server object
may not exist anymore when this method is invoked.

This amends commit d865e3ef1d.

Task-number: QTBUG-116621
Change-Id: I5f9a667bc0e2e3cd36492c24767505031fe0e1d7
Reviewed-by: Mårten Nordheim <marten.nordheim@qt.io>
Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org>
2023-09-02 02:37:59 +02:00
Ievgenii Meshcheriakov
d865e3ef1d QDBusServer: Remove private slot
Use QMetaObject::invokeMethod() to schedule call to
QDBusConnectionPrivate::_q_newConnectioni() instead.
This also gets rid of a by name signal/slot connection.

Change-Id: I8725c4e3815c5580c5561bdddda0ab722b06346e
Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
2023-08-28 22:03:03 +02:00
Ievgenii Meshcheriakov
f87d214000 QDBusPendingCall: Remove private slot
Use connection to a lambda instead. This makes
QDBusPendingCallWatcherPrivate obsolete and it is also removed.

Change-Id: I3d80ff2da25609c694322e5fef4231600ba346b4
Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
2023-08-28 22:03:02 +02:00
Ievgenii Meshcheriakov
a6027d4c59 QtDBus: Use invokeMethod accepting member functions with arguments
This makes the code slightly more readable.

Rename one overload of QDBusConnectionManager::doConnectToBus to
avoid using qOverload.

Change-Id: Id878e5baade539c3f748b5bf66a5aff726604b89
Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
Reviewed-by: Mårten Nordheim <marten.nordheim@qt.io>
2023-08-26 17:24:19 +02:00
Ievgenii Meshcheriakov
712149802b QDBusconnectionPrivate: Replace permanent connections with invokeMethod
Change-Id: Ife8d4495a98e34c8364293f3423b52f65ac187c4
Reviewed-by: Mårten Nordheim <marten.nordheim@qt.io>
Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
2023-08-26 17:24:13 +02:00
Ievgenii Meshcheriakov
e073d7d20c QDBusServer: Delegate construction to two-argument constructor
This reduces code duplication.

Change-Id: Ia637045f9495d68dba41bc146c9ba807f5619c5d
Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
2023-08-22 16:26:02 +02:00
Ievgenii Meshcheriakov
a1ab2297a9 QDBusConnectionManager: Remove unused member variables
Change-Id: If9e452e81db0fefa10704b83e6447ccef0763b59
Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
2023-08-22 16:26:02 +02:00
Ievgenii Meshcheriakov
12a0eee1f8 QDBusConnectionManager: Move all locking inside the class
Make `mutex` member private and make all former users call
new public member functions that perform locking. Make
old non-locking member functions private.

Change-Id: I29092d1bd785aa6b830183c1c1fe125b16e0d633
Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
2023-08-22 16:26:02 +02:00
Ievgenii Meshcheriakov
3c4a092cf7 QDBusConnectionManager: Use invokeMethod() to create connections
Use QMetaObject::invokeMethod() with a lambda instead of setting
up a permanent signal/slot connections with BlockingQueuedConnection
type. This makes the code flow easier to follow.

Change-Id: I0e77433e3fb96f99ed39f2d14dad737d444d3269
Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
2023-08-22 16:26:02 +02:00
Ievgenii Meshcheriakov
7c9e61a3fe QDBusConnectionManager: Use invokeMethod() to create servers
Use QMetaObject::invokeMethod() with a lambda instead of setting
up a permanent signal/slot connections with BlockingQueuedConnection
type. This makes the code flow easier to follow.

Change-Id: Ib6566e7a4694ecbd69900b645d020b3331fb3462
Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
2023-08-21 12:18:33 +02:00
Ievgenii Meshcheriakov
338de68395 QDBusConnectionManager: Move to a separate source file
Split the source code into a separate file for easier code
navigation and to better match the rest of Qt.

Update the link to the blog post explaining the
preventDllUnload() function, mention the blog post title
to make it easier to find it again when the link breaks.

Change-Id: I061d72bc795110f03352abf10fc639ddd6243527
Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
2023-08-21 12:18:33 +02:00
Ievgenii Meshcheriakov
57410e5d7d QDBusAdaptorConnector: Initialize cached index in a thread safe way
Move the definition of cachedRelaySlotMethodIndex inside
relaySlotMethodIndex() to get thread-safe initialization.

Change-Id: I48683078f4dc610e9c7d1591287cf2d1dcfe8778
Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
2023-08-18 15:22:42 +02:00
Ievgenii Meshcheriakov
9c386ebb0d QDBusConnectionPrivate: Define _q_newConnection outside of extern "C" block
That's weird and I have no idea how that worked.

Change-Id: I6ecb967e108256ebf1609e08ef02fc2ec83ef2ca
Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
2023-08-16 14:56:51 +02:00
Thiago Macieira
56bd5d60c9 Fix registration of QtDBus types' metatypes
By actually registering them.

Commit 850d850c5a changed from
qMetaTypeId<QDBusArgument>() to QMetaType::fromType<QDBusArgument>() and
in Qt 6, fromType() does not register the type with the database. That
means the lines became runtime no-ops at that time or during the
QMetaType updates since 6.0. All they did was instantiate the C++ inline
variable.

The testing also detected we didn't register QList<QDBusVariant> as an
alias for the "av" signature. I'm not entirely sure you're allowed to
use this because QtDBus does not like re-registration of the built-in
types, and "av" is already assigned to QVariantList. This is no trouble
for the parser, anyway.

Minor change to qdbuscpp2xml to allow reading from stdin, so we don't
have to create temporary files.

Pick-to: 6.5 6.6
Fixes: QTBUG-115964
Change-Id: I80612a7d275c41f1baf0fffd177a14925e7d23ac
Reviewed-by: Ievgenii Meshcheriakov <ievgenii.meshcheriakov@qt.io>
2023-08-14 20:19:36 -07:00
Ievgenii Meshcheriakov
e8e8e1082e QDBusConnectionManager: Register metatypes in the constructor
Call QDBusMetaTypeId::init() in the cosntructor. This ensures that
the custom metatype registry is not destroyed before the instance
of the connection manager.

Task-number: QTBUG-58732
Pick-to: 6.6
Change-Id: I8c7c4c23deab2c7e11c6389a8976666ccf6baf48
Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org>
Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
2023-08-15 01:11:03 +02:00
Ievgenii Meshcheriakov
8a3330be38 Revert "QDbus: Avoid memory leak in registerComplexDBusType"
This reverts commit 4c1df115ec.

We cannot guarantee that there are no more QMetaType
instances that reference the interfaces being destroyed.
All such instances will become invalid after the interface
destruction with no way to verify that.

Pick-to: 6.6 6.5
Change-Id: Iad17fe88753143734b8b817dda184e3c3818575c
Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
2023-08-11 22:30:30 +02:00
Ievgenii Meshcheriakov
df485fff26 QDBusMetaType: Check that Q_GLOBAL_STATIC is not destroyed before using it
Combine the lock and the custom types list into one struct
so that the check code does not have to be duplicated.

Pick-to: 6.6
Task-number: QTBUG-58732
Change-Id: Ib61d5be3a3cb6465acc5834e5dcbc735fb8b4d8e
Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org>
2023-08-11 22:30:00 +02:00
Ievgenii Meshcheriakov
90e0c6693b QtDBus: Remove assertion inside qDBusAddTimeout()
The assertion is triggered when a timer cannot be started. This
is normal occurrence when an application exits before all pending
D-Bus calls are processed. And there is a code handling such failure
in the same function. Qt also prints a warning message in this
case:

    QEventDispatcherGlib::registerTimer: invalid arguments

Task-number: QTBUG-58732
Pick-to: 6.6
Change-Id: I37859443fa90ae1bf7da1572ac9b02a54c8e1b99
Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
2023-08-11 15:45:45 +02:00
Ievgenii Meshcheriakov
52a464bad0 QtDBus: Encapsulate hooks addition and invocation into QDBusSpyHookList
This makes the rest of the code slightly cleaner.

Change-Id: I67606b369f00d54fc24f7d6f41c004a728d37b5f
Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
2023-08-11 15:45:18 +02:00
Ievgenii Meshcheriakov
50aba545ff QtDBus: Make access to spy hook list thread safe
Introduce a mutex that protects access to the spy hooks list.

Also don't pass around raw pointers to the spy hook list,
those can change when new hooks are added and storage is
reallocated. Change the type of the hooks list to QList
to take advantage of copy-on-write in common case.

Check whether the global static is destroyed in qDBusAddSpyHook().

Change-Id: I440a88ce088d6fb5817660c8e1e02901281b842f
Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
2023-08-11 15:45:14 +02:00
Ievgenii Meshcheriakov
9fb3bd05a8 QDBus: Make QObject * argument to generateSubObjectXml() const
Only const members of the object are used inside the function body.

This addresses a review comment for 0f37c47713

Change-Id: I873d87104eb2483c4388929487d750d4a7d44bf3
Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
2023-08-10 19:45:51 +02:00
Fabian Kosmale
4c1df115ec QDbus: Avoid memory leak in registerComplexDBusType
QMetaType does not own the interface from which it is constructed.
Consequently, we end up with a memory leak.
This is not a huge issue, given that the map of meta-types is static,
and the application is about to be close when can discard it anyway, but
it causes avoidable sanitizer warnings, which are annoying when
debugging more severe memory leaks.

Pick-to: 6.6 6.5
Change-Id: Ifee3f4e19835536f4a6cfa4f6866ab621581ad4f
Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
2023-08-03 11:28:38 +02:00
Thiago Macieira
ee593cdde6 QDBusXmlParser: downgrade property name mismatches to warnings
This has happened before: there's a disagreement on whether property
names need to be identifiers or not. In Qt, we insist they are, and if
this code had been around before, other specifications from other teams
in freedesktop.org and gnome.org would have adhered to this rule. But it
wasn't, so such properties exist (see [1]).

Commit bcc93850fc converted the check that
had bene here all along as a proper error for qdbusxml2cpp. So downgrade
it a warning and move on.

An alternative implementation would keep on going and install this
property with the invalid name, but qdbusxml2cpp and other generators
may want to ignore such property names later on. I'm not implementing
this in a bug fix (or at all).

[1] https://fprint.freedesktop.org/fprintd-dev/Device.html

Fixes: QTBUG-115596
Task-number: QTBUG-2597
Pick-to: 6.6
Change-Id: Ifbf974a4d10745b099b1fffd1776fb8cc9239125
Reviewed-by: Ievgenii Meshcheriakov <ievgenii.meshcheriakov@qt.io>
2023-08-01 21:52:55 -07:00
Ievgenii Meshcheriakov
ee43dacbea QDBusPendingCallPrivate: Remove declaration of fromMessage()
The member function is never implemented.

Change-Id: Iee93c7d24df40b48b897d937889bb9556b8feb1a
Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org>
Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
2023-07-31 16:01:22 +02:00
Jaishree Vyas
7c2ecfcf29 Doc: List of all Qt overviews which are now termed as explanation
The autogenerated list of overviews was adding the \group command which
included all the groups instead of overviews.
The idea here is to categorize the overviews later on once we have
the list of all overviews.

Task-number: QTBUG-114762
Pick-to: 6.5 6.6
Change-Id: I3cf53886be277abc86b5ec54d399cd6933fbe882
Reviewed-by: Kai Köhne <kai.koehne@qt.io>
Reviewed-by: Leena Miettinen <riitta-leena.miettinen@qt.io>
2023-07-19 10:36:59 +02:00