MCPcopy Create free account
hub / github.com/Kistler-Group/sdbus-cpp / processProperties

Method processProperties

tools/xml2cpp-codegen/ProxyGenerator.cpp:332–480  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

330}
331
332std::tuple<std::string, std::string> ProxyGenerator::processProperties(const Nodes& properties) const
333{
334 std::ostringstream propertySS, asyncDeclarationSS;
335 for (const auto& property : properties)
336 {
337 auto propertyName = property->get("name");
338 auto propertyNameSafe = mangle_name(propertyName);
339 auto propertyAccess = property->get("access");
340 auto propertySignature = property->get("type");
341
342 auto propertyType = signature_to_type(propertySignature);
343 auto propertyArg = std::string("value");
344 auto propertyTypeArg = std::string("const ") + propertyType + "& " + propertyArg;
345
346 std::optional<AsyncImpl> asyncImplGet;
347 std::optional<AsyncImpl> asyncImplSet;
348
349 Nodes annotations = (*property)["annotation"];
350 for (const auto& annotation : annotations)
351 {
352 const auto annotationName = annotation->get("name");
353 const auto annotationValue = annotation->get("value");
354
355 if (annotationName == "org.freedesktop.DBus.Property.Get.Async" && annotationValue == "client") // Server-side not supported (may be in the future)
356 asyncImplGet = AsyncImpl::Callback; // Default to callback
357 else if (annotationName == "org.freedesktop.DBus.Property.Get.Async.ClientImpl" && annotationValue == "callback")
358 asyncImplGet = AsyncImpl::Callback;
359 else if (annotationName == "org.freedesktop.DBus.Property.Get.Async.ClientImpl" && (annotationValue == "future" || annotationValue == "std::future"))
360 asyncImplGet = AsyncImpl::Future;
361 else if (annotationName == "org.freedesktop.DBus.Property.Get.Async.ClientImpl" && (annotationValue == "awaitable" || annotationValue == "coroutine"))
362 asyncImplGet = AsyncImpl::Awaitable;
363 else if (annotationName == "org.freedesktop.DBus.Property.Set.Async" && annotationValue == "client") // Server-side not supported (may be in the future)
364 asyncImplSet = AsyncImpl::Callback; // Default to callback
365 else if (annotationName == "org.freedesktop.DBus.Property.Set.Async.ClientImpl" && annotationValue == "callback")
366 asyncImplSet = AsyncImpl::Callback;
367 else if (annotationName == "org.freedesktop.DBus.Property.Set.Async.ClientImpl" && (annotationValue == "future" || annotationValue == "std::future"))
368 asyncImplSet = AsyncImpl::Future;
369 else if (annotationName == "org.freedesktop.DBus.Property.Set.Async.ClientImpl" && (annotationValue == "awaitable" || annotationValue == "coroutine"))
370 asyncImplSet = AsyncImpl::Awaitable;
371 }
372
373 if (propertyAccess == "read" || propertyAccess == "readwrite")
374 {
375 // Determine return type based on async implementation
376 std::string realRetType;
377 if (asyncImplGet.has_value())
378 {
379 if (*asyncImplGet == AsyncImpl::Future)
380 realRetType = "std::future<sdbus::Variant>";
381 else if (*asyncImplGet == AsyncImpl::Awaitable)
382 realRetType = "sdbus::Awaitable<sdbus::Variant>";
383 else // Callback
384 realRetType = "sdbus::PendingAsyncCall";
385 }
386 else
387 {
388 realRetType = propertyType;
389 }

Callers

nothing calls this directly

Calls 3

mangle_nameFunction · 0.85
signature_to_typeFunction · 0.85
getMethod · 0.45

Tested by

no test coverage detected