1.4 KB of C++
Created 22 hours ago
— expires in 1 day
Viewed
86 times
https://dpaste.com/CX6U9S83Y
| #ifdef HAS_DBUS
void MainWindow::setRealtime() {
auto bus = QDBusConnection::systemBus();
if(!bus.isConnected()) {
std::cerr << "Cannot connect to the D-Bus system bus." << std::endl;
return;
}
std::cout << "sending d-bus message to rtkit..." << std::endl;
QDBusInterface intf("org.freedesktop.RealtimeKit1", "/org/freedesktop/RealtimeKit1", "org.freedesktop.RealtimeKit1", bus);
intf.setTimeout(5000);
unsigned max_prio = intf.property("MaxRealtimePriority").toUInt();
quint64 max_usec = intf.property("RTTimeUSecMax").toULongLong();
std::cout << "max prio is " << max_prio << " and max usec is " << max_usec << std::endl;
#ifdef Q_OS_LINUX
struct rlimit rlim{};
rlim.rlim_cur = max_usec;
rlim.rlim_max = max_usec;
setrlimit(RLIMIT_RTTIME, &rlim);
#endif
auto reply = intf.call("MakeThreadRealtime", static_cast<quint64>(gettid()), max_prio);
if(reply.type() == QDBusMessage::ErrorMessage) {
/* NOTE: not compatible with /proc mounted with hidepid, it will error here */
std::cerr << "got d-bus error: " << qUtf8Printable(reply.errorMessage()) << std::endl;
}else if(reply.type() == QDBusMessage::ReplyMessage) {
auto args = reply.arguments();
std::cout << "got reply with " << args.count() << " arguments" << std::endl;
}else{
std::cerr << "got unkown d-bus message type: " << reply.type() << std::endl;
}
}
#endif
|
#ifdef HAS_DBUS
void MainWindow::setRealtime() {
auto bus = QDBusConnection::systemBus();
if(!bus.isConnected()) {
std::cerr << "Cannot connect to the D-Bus system bus." << std::endl;
return;
}
std::cout << "sending d-bus message to rtkit..." << std::endl;
QDBusInterface intf("org.freedesktop.RealtimeKit1", "/org/freedesktop/RealtimeKit1", "org.freedesktop.RealtimeKit1", bus);
intf.setTimeout(5000);
unsigned max_prio = intf.property("MaxRealtimePriority").toUInt();
quint64 max_usec = intf.property("RTTimeUSecMax").toULongLong();
std::cout << "max prio is " << max_prio << " and max usec is " << max_usec << std::endl;
#ifdef Q_OS_LINUX
struct rlimit rlim{};
rlim.rlim_cur = max_usec;
rlim.rlim_max = max_usec;
setrlimit(RLIMIT_RTTIME, &rlim);
#endif
auto reply = intf.call("MakeThreadRealtime", static_cast<quint64>(gettid()), max_prio);
if(reply.type() == QDBusMessage::ErrorMessage) {
/* NOTE: not compatible with /proc mounted with hidepid, it will error here */
std::cerr << "got d-bus error: " << qUtf8Printable(reply.errorMessage()) << std::endl;
}else if(reply.type() == QDBusMessage::ReplyMessage) {
auto args = reply.arguments();
std::cout << "got reply with " << args.count() << " arguments" << std::endl;
}else{
std::cerr << "got unkown d-bus message type: " << reply.type() << std::endl;
}
}
#endif