| 320 | |
| 321 | |
| 322 | std::tuple<std::vector<std::string>, std::string> AdaptorGenerator::processProperties(const Nodes& properties) const |
| 323 | { |
| 324 | std::ostringstream declarationSS; |
| 325 | |
| 326 | std::vector<std::string> propertyRegistrations; |
| 327 | |
| 328 | for (const auto& property : properties) |
| 329 | { |
| 330 | std::ostringstream registrationSS; |
| 331 | |
| 332 | auto propertyName = property->get("name"); |
| 333 | auto propertyNameSafe = mangle_name(propertyName); |
| 334 | auto propertyAccess = property->get("access"); |
| 335 | auto propertySignature = property->get("type"); |
| 336 | |
| 337 | auto propertyType = signature_to_type(propertySignature); |
| 338 | auto propertyArg = std::string("value"); |
| 339 | auto propertyTypeArg = std::string("const ") + propertyType + "& " + propertyArg; |
| 340 | |
| 341 | auto annotations = getAnnotations(*property); |
| 342 | std::string annotationRegistration; |
| 343 | for (const auto& annotation : annotations) |
| 344 | { |
| 345 | const auto& annotationName = annotation.first; |
| 346 | const auto& annotationValue = annotation.second; |
| 347 | |
| 348 | if (annotationName == "org.freedesktop.DBus.Deprecated" && annotationValue == "true") |
| 349 | annotationRegistration += ".markAsDeprecated()"; |
| 350 | else if (annotationName == "org.freedesktop.DBus.Property.EmitsChangedSignal") |
| 351 | annotationRegistration += ".withUpdateBehavior(" + propertyAnnotationToFlag(annotationValue) + ")"; |
| 352 | else if (annotationName == "org.freedesktop.systemd1.Privileged" && annotationValue == "true") |
| 353 | annotationRegistration += ".markAsPrivileged()"; |
| 354 | else |
| 355 | std::cerr << "Node: " << propertyName << ": " |
| 356 | << "Option '" << annotationName << "' not allowed or supported in this context! Option ignored..." << std::endl; |
| 357 | } |
| 358 | |
| 359 | registrationSS << "sdbus::registerProperty(\"" |
| 360 | << propertyName << "\")"; |
| 361 | |
| 362 | if (propertyAccess == "read" || propertyAccess == "readwrite") |
| 363 | { |
| 364 | registrationSS << ".withGetter([this](){ return this->" << propertyNameSafe << "(); })"; |
| 365 | } |
| 366 | |
| 367 | if (propertyAccess == "readwrite" || propertyAccess == "write") |
| 368 | { |
| 369 | registrationSS |
| 370 | << ".withSetter([this](" << propertyTypeArg << ")" |
| 371 | "{ this->" << propertyNameSafe << "(" << propertyArg << "); })"; |
| 372 | } |
| 373 | |
| 374 | registrationSS << annotationRegistration; |
| 375 | |
| 376 | propertyRegistrations.push_back(registrationSS.str()); |
| 377 | |
| 378 | if (propertyAccess == "read" || propertyAccess == "readwrite") |
| 379 | declarationSS << tab << "virtual " << propertyType << " " << propertyNameSafe << "() = 0;" << endl; |
nothing calls this directly
no test coverage detected