Skip to content

Commit f176639

Browse files
sync: from linuxdeepin/dtkcore
Synchronize source files from linuxdeepin/dtkcore. Source-pull-request: linuxdeepin/dtkcore#506
1 parent 95f9c4e commit f176639

File tree

1 file changed

+13
-12
lines changed

1 file changed

+13
-12
lines changed

src/dsgapplication.cpp

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ static void dbusMessageDeleter(DBusMessage *msg) {
3939
}
4040

4141
// D-Bus utility functions using libdbus-1
42-
static bool checkDBusServiceActivatable(const QString &service)
42+
static bool checkDBusServiceActivatable(const QByteArray &serviceName)
4343
{
4444
auto error = std::unique_ptr<DBusError, void(*)(DBusError*)>(new DBusError, dbusErrorDeleter);
4545
dbus_error_init(error.get());
@@ -70,7 +70,7 @@ static bool checkDBusServiceActivatable(const QString &service)
7070
}
7171
auto msgGuard = std::unique_ptr<DBusMessage, void(*)(DBusMessage*)>(msg, dbusMessageDeleter);
7272

73-
const char *serviceName = service.toUtf8().constData();
73+
const char *serviceName = serviceName.constData();
7474
if (!dbus_message_append_args(msg, DBUS_TYPE_STRING, &serviceName, DBUS_TYPE_INVALID)) {
7575
qCWarning(dsgApp) << "Failed to append arguments to D-Bus message";
7676
return false;
@@ -140,7 +140,7 @@ static bool checkDBusServiceActivatable(const QString &service)
140140
while (dbus_message_iter_get_arg_type(&array_iter) == DBUS_TYPE_STRING) {
141141
const char *name;
142142
dbus_message_iter_get_basic(&array_iter, &name);
143-
if (service == QString::fromUtf8(name)) {
143+
if (serviceName == name) {
144144
found = true;
145145
break;
146146
}
@@ -150,7 +150,8 @@ static bool checkDBusServiceActivatable(const QString &service)
150150
return found;
151151
}
152152

153-
static QByteArray callDBusIdentifyMethod(const QString &service, const QString &path, const QString &interface, int pidfd)
153+
static QByteArray callDBusIdentifyMethod(const QByteArray &serviceName, const QByteArray &path,
154+
const QByteArray &interface, int pidfd)
154155
{
155156
auto error = std::unique_ptr<DBusError, void(*)(DBusError*)>(new DBusError, dbusErrorDeleter);
156157
dbus_error_init(error.get());
@@ -167,11 +168,11 @@ static QByteArray callDBusIdentifyMethod(const QString &service, const QString &
167168
}
168169
auto connGuard = std::unique_ptr<DBusConnection, void(*)(DBusConnection*)>(connection, dbusConnectionDeleter);
169170

170-
// Create method call
171+
// Create method call - string data is now managed by caller
171172
DBusMessage *msg = dbus_message_new_method_call(
172-
service.toUtf8().constData(),
173-
path.toUtf8().constData(),
174-
interface.toUtf8().constData(),
173+
serviceName.constData(),
174+
path.constData(),
175+
interface.constData(),
175176
"Identify"
176177
);
177178

@@ -222,7 +223,7 @@ static inline QByteArray getSelfAppId() {
222223
return DSGApplication::getId(QCoreApplication::applicationPid());
223224
}
224225

225-
static bool isServiceActivatable(const QString &service)
226+
static bool isServiceActivatable(const QByteArray &service)
226227
{
227228
return checkDBusServiceActivatable(service);
228229
}
@@ -273,9 +274,9 @@ QByteArray DSGApplication::id()
273274
* Get application ID for a given process ID
274275
*
275276
* This function has been updated to use libdbus-1 instead of Qt D-Bus to fix
276-
* the bug(pms:BUG-278055) where calling this function before QCoreApplication
277-
* initialization would fail. This is particularly important when the service
278-
* is being started by D-Bus activation and DSGApplication::id() is called
277+
* the bug(pms:BUG-278055) where calling this function before QCoreApplication
278+
* initialization would fail. This is particularly important when the service
279+
* is being started by D-Bus activation and DSGApplication::id() is called
279280
* during early startup.
280281
*
281282
* @param pid Process ID to get the application ID for

0 commit comments

Comments
 (0)