Skip to content

Commit 0430ae0

Browse files
authored
fix: fix the return type of the slot-returning overloads (#494)
1 parent 6212b12 commit 0430ae0

2 files changed

Lines changed: 24 additions & 4 deletions

File tree

include/sdbus-c++/StandardInterfaces.h

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -217,7 +217,7 @@ namespace sdbus {
217217
}
218218

219219
template <typename _Function>
220-
PendingAsyncCall SetAsync(const InterfaceName& interfaceName, const PropertyName& propertyName, const sdbus::Variant& value, _Function&& callback, return_slot_t)
220+
[[nodiscard]] Slot SetAsync(const InterfaceName& interfaceName, const PropertyName& propertyName, const sdbus::Variant& value, _Function&& callback, return_slot_t)
221221
{
222222
return m_proxy.setPropertyAsync(propertyName).onInterface(interfaceName).toValue(value).uponReplyInvoke(std::forward<_Function>(callback), return_slot);
223223
}
@@ -229,7 +229,7 @@ namespace sdbus {
229229
}
230230

231231
template <typename _Function>
232-
PendingAsyncCall SetAsync(std::string_view interfaceName, std::string_view propertyName, const sdbus::Variant& value, _Function&& callback, return_slot_t)
232+
[[nodiscard]] Slot SetAsync(std::string_view interfaceName, std::string_view propertyName, const sdbus::Variant& value, _Function&& callback, return_slot_t)
233233
{
234234
return m_proxy.setPropertyAsync(propertyName).onInterface(interfaceName).toValue(value).uponReplyInvoke(std::forward<_Function>(callback), return_slot);
235235
}
@@ -261,7 +261,7 @@ namespace sdbus {
261261
}
262262

263263
template <typename _Function>
264-
PendingAsyncCall GetAllAsync(const InterfaceName& interfaceName, _Function&& callback, return_slot_t)
264+
[[nodiscard]] Slot GetAllAsync(const InterfaceName& interfaceName, _Function&& callback, return_slot_t)
265265
{
266266
return m_proxy.getAllPropertiesAsync().onInterface(interfaceName).uponReplyInvoke(std::forward<_Function>(callback), return_slot);
267267
}
@@ -273,7 +273,7 @@ namespace sdbus {
273273
}
274274

275275
template <typename _Function>
276-
PendingAsyncCall GetAllAsync(std::string_view interfaceName, _Function&& callback, return_slot_t)
276+
[[nodiscard]] Slot GetAllAsync(std::string_view interfaceName, _Function&& callback, return_slot_t)
277277
{
278278
return m_proxy.getAllPropertiesAsync().onInterface(interfaceName).uponReplyInvoke(std::forward<_Function>(callback), return_slot);
279279
}

tests/integrationtests/DBusStandardInterfacesTests.cpp

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -127,6 +127,26 @@ TYPED_TEST(SdbusTestObject, SetsPropertyAsynchronouslyViaPropertiesInterface)
127127
ASSERT_THAT(this->m_proxy->action(), Eq(newActionValue));
128128
}
129129

130+
TYPED_TEST(SdbusTestObject, CancelsAsynchronousPropertySettingViaPropertiesInterface)
131+
{
132+
uint32_t newActionValue = 2346;
133+
std::promise<void> promise;
134+
auto future = promise.get_future();
135+
136+
{
137+
auto slot = this->m_proxy->SetAsync(INTERFACE_NAME, "action", sdbus::Variant{newActionValue}, [&](std::optional<sdbus::Error> err)
138+
{
139+
if (!err)
140+
promise.set_value();
141+
else
142+
promise.set_exception(std::make_exception_ptr(*std::move(err)));
143+
}, sdbus::return_slot);
144+
// Now the slot is destroyed, cancelling the async call
145+
}
146+
147+
ASSERT_THAT(future.wait_for(300ms), Eq(std::future_status::timeout));
148+
}
149+
130150
TYPED_TEST(SdbusTestObject, SetsPropertyAsynchronouslyViaPropertiesInterfaceWithFuture)
131151
{
132152
uint32_t newActionValue = 2347;

0 commit comments

Comments
 (0)