forked from Kistler-Group/sdbus-cpp
refactor: add strong types to public API (#414)
This introduces strong types for `std::string`-based D-Bus types. This facilitates safer, less error-prone and more expressive API.
What previously was `auto proxy = createProxy("org.sdbuscpp.concatenator", "/org/sdbuscpp/concatenator");` is now written like `auto proxy = createProxy(ServiceName{"org.sdbuscpp.concatenator"}, ObjectPath{"/org/sdbuscpp/concatenator"});`.
These types are:
* `ObjectPath` type for the object path (the type has been around already but now is also used consistently in sdbus-c++ API for object path strings),
* `InterfaceName` type for D-Bus interface names,
* `BusName` (and its aliases `ServiceName` and `ConnectionName`) type for bus/service/connection names,
* `MemberName` (and its aliases `MethodName`, `SignalName` and `PropertyName`) type for D-Bus method, signal and property names,
* `Signature` type for the D-Bus signature (the type has been around already but now is also used consistently in sdbus-c++ API for signature strings),
* `Error::Name` type for D-Bus error names.
This commit is contained in:
@@ -43,7 +43,7 @@ uint64_t totalDuration = 0;
|
||||
class PerftestProxy final : public sdbus::ProxyInterfaces<org::sdbuscpp::perftests_proxy>
|
||||
{
|
||||
public:
|
||||
PerftestProxy(std::string destination, std::string objectPath)
|
||||
PerftestProxy(sdbus::ServiceName destination, sdbus::ObjectPath objectPath)
|
||||
: ProxyInterfaces(std::move(destination), std::move(objectPath))
|
||||
{
|
||||
registerProxy();
|
||||
@@ -101,9 +101,9 @@ std::string createRandomString(size_t length)
|
||||
//-----------------------------------------
|
||||
int main(int /*argc*/, char */*argv*/[])
|
||||
{
|
||||
const char* destinationName = "org.sdbuscpp.perftests";
|
||||
const char* objectPath = "/org/sdbuscpp/perftests";
|
||||
PerftestProxy client(destinationName, objectPath);
|
||||
sdbus::ServiceName destination{"org.sdbuscpp.perftests"};
|
||||
sdbus::ObjectPath objectPath{"/org/sdbuscpp/perftests"};
|
||||
PerftestProxy client(std::move(destination), std::move(objectPath));
|
||||
|
||||
const unsigned int repetitions{20};
|
||||
unsigned int msgCount = 1000;
|
||||
|
||||
@@ -16,7 +16,7 @@ namespace sdbuscpp {
|
||||
class perftests_adaptor
|
||||
{
|
||||
public:
|
||||
static constexpr const char* INTERFACE_NAME = "org.sdbuscpp.perftests";
|
||||
static inline const sdbus::InterfaceName INTERFACE_NAME{"org.sdbuscpp.perftests"};
|
||||
|
||||
protected:
|
||||
perftests_adaptor(sdbus::IObject& object)
|
||||
|
||||
@@ -16,7 +16,7 @@ namespace sdbuscpp {
|
||||
class perftests_proxy
|
||||
{
|
||||
public:
|
||||
static constexpr const char* INTERFACE_NAME = "org.sdbuscpp.perftests";
|
||||
static inline const sdbus::InterfaceName INTERFACE_NAME{"org.sdbuscpp.perftests"};
|
||||
|
||||
protected:
|
||||
perftests_proxy(sdbus::IProxy& proxy)
|
||||
|
||||
@@ -40,7 +40,7 @@ std::string createRandomString(size_t length);
|
||||
class PerftestAdaptor final : public sdbus::AdaptorInterfaces<org::sdbuscpp::perftests_adaptor>
|
||||
{
|
||||
public:
|
||||
PerftestAdaptor(sdbus::IConnection& connection, std::string objectPath)
|
||||
PerftestAdaptor(sdbus::IConnection& connection, sdbus::ObjectPath objectPath)
|
||||
: AdaptorInterfaces(connection, std::move(objectPath))
|
||||
{
|
||||
registerAdaptor();
|
||||
@@ -92,11 +92,11 @@ std::string createRandomString(size_t length)
|
||||
//-----------------------------------------
|
||||
int main(int /*argc*/, char */*argv*/[])
|
||||
{
|
||||
const char* serviceName = "org.sdbuscpp.perftests";
|
||||
sdbus::ServiceName serviceName{"org.sdbuscpp.perftests"};
|
||||
auto connection = sdbus::createSystemBusConnection(serviceName);
|
||||
|
||||
const char* objectPath = "/org/sdbuscpp/perftests";
|
||||
PerftestAdaptor server(*connection, objectPath);
|
||||
sdbus::ObjectPath objectPath{"/org/sdbuscpp/perftests"};
|
||||
PerftestAdaptor server(*connection, std::move(objectPath));
|
||||
|
||||
connection->enterEventLoop();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user