refactor: improve Proxy signal subscription (#389)

This makes D-Bus proxy signal registration more flexible, more dynamic, and less error-prone since no `finishRegistration()` call is needed. A proxy can register to a signal at any time during its lifetime, and can unregister freely by simply destroying the associated slot.
This commit is contained in:
Stanislav Angelovič
2023-12-30 18:57:10 +01:00
parent bdf313bc60
commit 84932a6985
17 changed files with 227 additions and 202 deletions

View File

@@ -84,17 +84,8 @@ std::string ProxyGenerator::processInterface(Node& interface) const
<< tab << "static constexpr const char* INTERFACE_NAME = \"" << ifaceName << "\";" << endl << endl
<< "protected:" << endl
<< tab << className << "(sdbus::IProxy& proxy)" << endl
<< tab << tab << ": proxy_(&proxy)" << endl;
Nodes methods = interface["method"];
Nodes signals = interface["signal"];
Nodes properties = interface["property"];
std::string registration, declaration;
std::tie(registration, declaration) = processSignals(signals);
body << tab << "{" << endl
<< registration
<< tab << tab << ": proxy_(&proxy)" << endl
<< tab << "{" << endl
<< tab << "}" << endl << endl;
// Rule of Five
@@ -105,6 +96,18 @@ std::string ProxyGenerator::processInterface(Node& interface) const
body << tab << "~" << className << "() = default;" << endl << endl;
Nodes methods = interface["method"];
Nodes signals = interface["signal"];
Nodes properties = interface["property"];
std::string registration, declaration;
std::tie(registration, declaration) = processSignals(signals);
body << tab << "void registerProxy()" << endl
<< tab << "{" << endl
<< registration
<< tab << "}" << endl << endl;
if (!declaration.empty())
body << declaration << endl;