Can uponSignal take a variadic lambda? #195
-
I have a case where I don't control the signal I'm receiving and it varies in what is passed. I'm trying to do something like what is below, but getting compiler issues. Can you recommend how to handle this case? What I have so far...
Used by:
|
Beta Was this translation helpful? Give feedback.
Replies: 3 comments 3 replies
-
As an alternative, is there a way to catch an exception when this passed lambda is called with incorrect arguments? |
Beta Was this translation helpful? Give feedback.
-
@Radagan This isn't possible. The callback must have a concrete signature, because this signature is the source of information for sdbus-c++ introspection mechanisms to find out what data and of what type to read from the incoming signal. sdbus-c++ can't do the message reading in a completely generic way. I have not yet seen the case of a D-Bus message with data of varying type. I'm not sure if this is correct design. Typically, such messages use the However, if you don't control the contents of D-Bus signal, the only option for you is to use basic sdbus-c++ API. Like in the client-side example here: https://github.com/Kistler-Group/sdbus-cpp/blob/master/docs/using-sdbus-c%2B%2B.md#implementing-the-concatenator-example-using-basic-sdbus-c-api-layer |
Beta Was this translation helpful? Give feedback.
-
@Radagan Yes, while(true)
{
try
{
connection->enterEventLoop(); // Blocking
}
catch (const sdbus::Error& e)
{
processException(e); // Process sdbus-c++ error and then enter the event loop again
}
} |
Beta Was this translation helpful? Give feedback.
@Radagan This isn't possible. The callback must have a concrete signature, because this signature is the source of information for sdbus-c++ introspection mechanisms to find out what data and of what type to read from the incoming signal. sdbus-c++ can't do the message reading in a completely generic way.
I have not yet seen the case of a D-Bus message with data of varying type. I'm not sure if this is correct design. Typically, such messages use the
Variant
type (the type which is there for exactly such cases). Then the client introspects the variant data to see what's inside for that specific D-Bus message.However, if you don't control the contents of D-Bus signal, the only option for …