PDA

View Full Version : <QtDBus/QtDBus> / <dbus/dbus.h>



migel
1st August 2011, 22:06
1. Is it possible to send a message via <dbus/dbus.h> and receive it using Qt one ?
2. Is it possible to send a message as root and receive it from app which runs on different user ? (linux)

1a. I have troubles to read the message that's why the question. This is my code:

Send <dbus/dbus.h>

dbus_error_init(&_dbusError);
_dbusConnection = dbus_bus_get(DBUS_BUS_SYSTEM, &_dbusError);

if (dbus_error_is_set(&_dbusError)) {
logger("Dbus Connection Error");
dbus_error_free(&_dbusError);
return;

} else {
logger("Dbus Connected");
}

_dbusMessage = dbus_message_new_signal("/", "com.app.message", "app");
if (NULL == _dbusMessage) {
logger("Message Null");
exit(1);
} else {
logger("Dbus new signal");
}

dbus_message_iter_init_append(_dbusMessage, &_dbusMessageIter);
if (!dbus_message_iter_append_basic(&_dbusMessageIter, DBUS_TYPE_STRING, &message)) {
logger("Couldn't append dbus message");
} else {
stringstream s;
s << message;
logger("Dbus Messgae append - " + s.str());
}

if (!dbus_connection_send(_dbusConnection, _dbusMessage, &_dbusSerial)) {
logger("Couldn't send dbus message");
} else {
logger("Dbus Messgae sent");
}

dbus_connection_flush(_dbusConnection);
dbus_message_unref(_dbusMessage);

Read <QtDBus/QtDBus> example from ping pong


QString Pong::ping(const QString &arg)
{
QMetaObject::invokeMethod(QCoreApplication::instan ce(), "quit");
return QString("ping(\"%1\") got called").arg(arg);
}

int main(int argc, char **argv)
{
QCoreApplication app(argc, argv);

if (!QDBusConnection::sessionBus().isConnected()) {
cout << "Cannot connect to the D-Bus session bus" << endl;
return 1;
}

if (!QDBusConnection::sessionBus().registerService("com.app.message")) {
cout << "error" << endl;
exit(1);
}

Pong pong;
QDBusConnection::sessionBus().registerObject("/", &pong, QDBusConnection::ExportAllSlots);


app.exec();
return 0;
}

Thanks for looking

migel
2nd August 2011, 16:30
really no one, is it not newbie... ?

NullPointer
2nd August 2011, 21:23
Hi,

Are you able to invoke your method using qdbus or qdbusviewer?

Now, send messages from root to other users, I don't think this is possible, since for each session, a "dbus-deamon --session" is called, and in man --session says :"Use the standard configuration file for the per-login-session message bus.".

Hth.

migel
3rd August 2011, 16:09
hmm I think its working different way. I don't send send message to the user session, root writes to system dbus session, and the user reads it from.