-
Hello, First of all forgive me for asking such a likely simple question. This is my first time working with dbus, and this library. I am having trouble receiving a signal from an interface on the dbus. I am trying to use the
You can see the documentation for this bus here I am able to invoke each function and receive the object paths successfully. The signal I am looking for appears in
However it is not received by my program: void start_session() {
const char* bus_name = "org.gnome.Mutter.ScreenCast";
const char* object_path = "/org/gnome/Mutter/ScreenCast";
auto connection = sdbus::createSessionBusConnection();
auto screencast_proxy = sdbus::createProxy(*connection, bus_name, object_path);
printf("dbus connected\n");
int version = screencast_proxy->getProperty("Version")
.onInterface("org.gnome.Mutter.ScreenCast");
printf("version: %i\n", version);
// Create a session and receive its object path
sdbus::ObjectPath session_path;
screencast_proxy->callMethod("CreateSession")
.onInterface("org.gnome.Mutter.ScreenCast")
.withArguments(std::map<std::string, sdbus::Variant>{
{"dummy", 0}
})
.storeResultsTo(session_path);
printf("session path: %s\n", session_path.c_str());
// Open the Session object path
session_proxy = sdbus::createProxy(*connection, bus_name, session_path);
// Invoke RecordMonitor and receive the returned Stream object path
sdbus::ObjectPath stream_path;
session_proxy->callMethod("RecordMonitor")
.onInterface("org.gnome.Mutter.ScreenCast.Session")
.withArguments(
"",
std::map<std::string, sdbus::Variant>{
{"cursor-mode", 0}, // 0: hidden 1: embedded in framebuffer 2: included in metadata
{"is-recording", true}
}
)
.storeResultsTo(stream_path);
printf("stream path: %s\n", stream_path.c_str());
// Open the Stream object path
stream_proxy = sdbus::createProxy(*connection, bus_name, stream_path);
// subscribe for PipeWireStreamAdded signal
stream_proxy->uponSignal("PipeWireStreamAdded")
.onInterface("org.gnome.Mutter.ScreenCast.Stream")
.call([](uint32_t& node_id){ printf("SIGNAL. RECEIVED. node_id:%i\n", node_id); });
session.stream_proxy->finishRegistration();
printf("registered PipeWireStreamAdded signal callback\n");
// Start the session. The PipeWireStreamAdded signal is sent after this.
session.session_proxy->callMethod("Start").onInterface("org.gnome.Mutter.ScreenCast.Session");
printf("started screen cast session\n");
while(1); // don't exit
}
Expected behaviour: Program should print "started screen cast session" followed by "SIGNAL RECEIVED. node_id: [some uitn32_t]" upon receiving the signal. Actual behaviour: Program prints "started screen cast session". Signal appears in dbus-monitor. No further output. Can anybody see what I am doing wrong? I suspect perhaps I need to be using an event loop - however I can't figure out how to start the event loop to listen for the signal before invoking the Cheers. |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 4 replies
-
To answer my own question... As I hinted at in my question, the solution is to subscribe to the signal and enter the event loop in a new thread: std::thread signal_thread ([&connection, bus_name, stream_path](){
stream_proxy = sdbus::createProxy(*connection, bus_name, stream_path);
// subscribe for PipeWireStreamAdded signal
stream_proxy->uponSignal("PipeWireStreamAdded")
.onInterface("org.gnome.Mutter.ScreenCast.Stream")
.call([&session](uint32_t& node_id){
printf("SIGNAL. RECEIVED.%i\n", node_id);
connection->leaveEventLoop(); // we only needed this one signal. we can leave now.
});
session.stream_proxy->finishRegistration();
connection->enterEventLoop();
});
printf("registered PipeWireStreamAdded signal callback\n");
session.session_proxy->callMethod("Start").onInterface("org.gnome.Mutter.ScreenCast.Session");
printf("started screen cast session\n");
signal_thread.join(); // wait until we know the node id
Hopefully this can help someone else out.... Took me longer than it should have to figure it out! |
Beta Was this translation helpful? Give feedback.
To answer my own question...
As I hinted at in my question, the solution is to subscribe to the signal and enter the event loop in a new thread: