forked from Kistler-Group/sdbus-cpp
docs: fix examples in using-sdbus-c++.md (#441)
Update in using documentation to version v2.0 syntax making examples work out of the box
This commit is contained in:
committed by
GitHub
parent
50cc636058
commit
e6b87b106c
@ -275,7 +275,7 @@ void concatenate(sdbus::MethodCall call)
|
|||||||
|
|
||||||
// Return error if there are no numbers in the collection
|
// Return error if there are no numbers in the collection
|
||||||
if (numbers.empty())
|
if (numbers.empty())
|
||||||
throw sdbus::Error("org.sdbuscpp.Concatenator.Error", "No numbers provided");
|
throw sdbus::Error(sdbus::Error::Name{"org.sdbuscpp.Concatenator.Error"}, "No numbers provided");
|
||||||
|
|
||||||
std::string result;
|
std::string result;
|
||||||
for (auto number : numbers)
|
for (auto number : numbers)
|
||||||
@ -310,8 +310,8 @@ int main(int argc, char *argv[])
|
|||||||
|
|
||||||
// Register D-Bus methods and signals on the concatenator object, and exports the object.
|
// Register D-Bus methods and signals on the concatenator object, and exports the object.
|
||||||
sdbus::InterfaceName interfaceName{"org.sdbuscpp.Concatenator"};
|
sdbus::InterfaceName interfaceName{"org.sdbuscpp.Concatenator"};
|
||||||
concatenator->addVTable( sdbus::MethodVTableItem{"concatenate", sdbus::Signature{"ais"}, {}, sdbus::Signature{"s"}, {}, &concatenate, {}}
|
concatenator->addVTable( sdbus::MethodVTableItem{sdbus::MethodName{"concatenate"}, sdbus::Signature{"ais"}, {}, sdbus::Signature{"s"}, {}, &concatenate, {}}
|
||||||
, sdbus::SignalVTableItem{"concatenated", sdbus::Signature{"s"}, {}, {}} )
|
, sdbus::SignalVTableItem{sdbus::MethodName{"concatenated"}, sdbus::Signature{"s"}, {}, {}} )
|
||||||
.forInterface(interfaceName);
|
.forInterface(interfaceName);
|
||||||
|
|
||||||
// Run the I/O event loop on the bus connection.
|
// Run the I/O event loop on the bus connection.
|
||||||
@ -364,7 +364,7 @@ int main(int argc, char *argv[])
|
|||||||
std::vector<int> numbers = {1, 2, 3};
|
std::vector<int> numbers = {1, 2, 3};
|
||||||
std::string separator = ":";
|
std::string separator = ":";
|
||||||
|
|
||||||
MethodName concatenate{"concatenate"};
|
sdbus::MethodName concatenate{"concatenate"};
|
||||||
// Invoke concatenate on given interface of the object
|
// Invoke concatenate on given interface of the object
|
||||||
{
|
{
|
||||||
auto method = concatenatorProxy->createMethodCall(interfaceName, concatenate);
|
auto method = concatenatorProxy->createMethodCall(interfaceName, concatenate);
|
||||||
@ -375,7 +375,7 @@ int main(int argc, char *argv[])
|
|||||||
assert(result == "1:2:3");
|
assert(result == "1:2:3");
|
||||||
}
|
}
|
||||||
|
|
||||||
/ // Invoke concatenate again, this time with no numbers and we shall get an error
|
// Invoke concatenate again, this time with no numbers and we shall get an error
|
||||||
{
|
{
|
||||||
auto method = concatenatorProxy->createMethodCall(interfaceName, concatenate);
|
auto method = concatenatorProxy->createMethodCall(interfaceName, concatenate);
|
||||||
method << std::vector<int>() << separator;
|
method << std::vector<int>() << separator;
|
||||||
@ -519,7 +519,7 @@ int main(int argc, char *argv[])
|
|||||||
{
|
{
|
||||||
// Return error if there are no numbers in the collection
|
// Return error if there are no numbers in the collection
|
||||||
if (numbers.empty())
|
if (numbers.empty())
|
||||||
throw sdbus::Error("org.sdbuscpp.Concatenator.Error", "No numbers provided");
|
throw sdbus::Error(sdbus::Error::Name{"org.sdbuscpp.Concatenator.Error"}, "No numbers provided");
|
||||||
|
|
||||||
std::string result;
|
std::string result;
|
||||||
for (auto number : numbers)
|
for (auto number : numbers)
|
||||||
@ -534,8 +534,8 @@ int main(int argc, char *argv[])
|
|||||||
};
|
};
|
||||||
|
|
||||||
// Register D-Bus methods and signals on the concatenator object, and exports the object.
|
// Register D-Bus methods and signals on the concatenator object, and exports the object.
|
||||||
concatenator->addVTable( sdbus::registerMethod("concatenate").implementedAs(std::move(concatenate))
|
concatenator->addVTable(sdbus::registerMethod("concatenate").implementedAs(std::move(concatenate)),
|
||||||
, sdbus::registerSignal{"concatenated").withParameters<std::string>() )
|
sdbus::registerSignal("concatenated").withParameters<std::string>())
|
||||||
.forInterface("org.sdbuscpp.Concatenator");
|
.forInterface("org.sdbuscpp.Concatenator");
|
||||||
|
|
||||||
// Run the loop on the connection.
|
// Run the loop on the connection.
|
||||||
|
Reference in New Issue
Block a user