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:
@@ -52,10 +52,14 @@
|
||||
namespace sdbus {
|
||||
class Variant;
|
||||
class ObjectPath;
|
||||
class InterfaceName;
|
||||
class MemberName;
|
||||
class Signature;
|
||||
template <typename... _ValueTypes> class Struct;
|
||||
class UnixFd;
|
||||
class MethodReply;
|
||||
class BusName;
|
||||
using ConnectionName = BusName;
|
||||
namespace internal {
|
||||
class ISdBus;
|
||||
}
|
||||
@@ -181,11 +185,11 @@ namespace sdbus {
|
||||
explicit operator bool() const;
|
||||
void clearFlags();
|
||||
|
||||
std::string getInterfaceName() const;
|
||||
std::string getMemberName() const;
|
||||
std::string getSender() const;
|
||||
std::string getPath() const;
|
||||
std::string getDestination() const;
|
||||
InterfaceName getInterfaceName() const;
|
||||
MemberName getMemberName() const;
|
||||
ConnectionName getSender() const;
|
||||
ObjectPath getPath() const;
|
||||
ConnectionName getDestination() const;
|
||||
void peekType(std::string& type, std::string& contents) const;
|
||||
bool isValid() const;
|
||||
bool isEmpty() const;
|
||||
@@ -281,7 +285,7 @@ namespace sdbus {
|
||||
|
||||
public:
|
||||
Signal() = default;
|
||||
void setDestination(const std::string& destination);
|
||||
void setDestination(const ConnectionName& destination);
|
||||
void send() const;
|
||||
};
|
||||
|
||||
|
||||
Reference in New Issue
Block a user