added support for optionals in unpackProperties
- Added support for optionals
- Added support for pointers
- Removed support for moving data from input container
- Removed support for container types other than std::vector
Tested:
- Unit tests are passing
- Examples which use unpackProperties are working correctly
Signed-off-by: Krzysztof Grobelny <krzysztof.grobelny@intel.com>
Change-Id: I3dbd7333237a1373d784187951ad6abe217567d1
diff --git a/example/get-all-properties.cpp b/example/get-all-properties.cpp
index 330e0c1..53d2466 100644
--- a/example/get-all-properties.cpp
+++ b/example/get-all-properties.cpp
@@ -61,26 +61,26 @@
++fatalErrors_;
}
- void logBadProperty(const std::string& badProperty)
+ void logUnpackError(const sdbusplus::UnpackErrorReason reason,
+ const std::string& property)
{
- std::cerr << "BadProperty: " << badProperty << "\n";
+ std::cerr << "UnpackError: " << static_cast<int>(reason) << ", "
+ << property << "\n";
++fatalErrors_;
}
void logExpectedException(
const sdbusplus::exception::UnpackPropertyError& error)
{
- std::cout << "As expected " << error.what() << " => "
- << error.propertyName << " is missing because "
- << error.reason << "\n";
+ std::cout << "As expected " << error.what() << "\n";
}
void asyncGetAllPropertiesStringTypeOnly()
{
sdbusplus::asio::getAllProperties(
bus_, demoServiceName, demoObjectPath, demoInterfaceName,
- [this](boost::system::error_code ec,
- std::vector<std::pair<
+ [this](const boost::system::error_code ec,
+ const std::vector<std::pair<
std::string, std::variant<std::monostate, std::string>>>&
properties) -> void {
if (ec)
@@ -89,22 +89,25 @@
return;
}
{
- std::string greetings;
- std::string goodbyes;
- std::optional<std::string> badProperty =
- sdbusplus::unpackPropertiesNoThrow(
- properties, propertyGrettingName, greetings,
- propertyGoodbyesName, goodbyes);
+ const std::string* greetings = nullptr;
+ const std::string* goodbyes = nullptr;
+ const bool success = sdbusplus::unpackPropertiesNoThrow(
+ [this](const sdbusplus::UnpackErrorReason reason,
+ const std::string& property) {
+ logUnpackError(reason, property);
+ },
+ properties, propertyGrettingName, greetings,
+ propertyGoodbyesName, goodbyes);
- if (badProperty)
+ if (success)
{
- logBadProperty(*badProperty);
+ std::cout << "value of greetings: " << *greetings
+ << "\n";
+ std::cout << "value of goodbyes: " << *goodbyes << "\n";
}
else
{
- std::cout << "value of greetings: " << greetings
- << "\n";
- std::cout << "value of goodbyes: " << goodbyes << "\n";
+ ++fatalErrors_;
}
}
@@ -129,8 +132,8 @@
{
sdbusplus::asio::getAllProperties(
bus_, demoServiceName, demoObjectPath, demoInterfaceName,
- [this](boost::system::error_code ec,
- std::vector<std::pair<
+ [this](const boost::system::error_code ec,
+ const std::vector<std::pair<
std::string,
std::variant<std::monostate, std::string, uint32_t>>>&
properties) -> void {