@@ -143,9 +143,6 @@ template <typename T>
143143struct DBusDataTransform {
144144 using Wire = T;
145145 using Data = T;
146-
147- static DBusResult<Data> fromWire (Wire&& wire) { return DBusResult<T>(std::move (wire)); }
148- static Wire toWire (const Data& value) { return value; }
149146};
150147
151148namespace bindable_p {
@@ -166,6 +163,20 @@ struct BindableType {
166163 using Type = Meta::Type;
167164};
168165
166+ template <typename T, typename = void >
167+ struct HasFromWire : std::false_type {};
168+
169+ template <typename T>
170+ struct HasFromWire <T, std::void_t <decltype (T::fromWire(std::declval<typename T::Wire>()))>>
171+ : std::true_type {};
172+
173+ template <typename T, typename = void >
174+ struct HasToWire : std::false_type {};
175+
176+ template <typename T>
177+ struct HasToWire <T, std::void_t <decltype (T::toWire(std::declval<typename T::Data>()))>>
178+ : std::true_type {};
179+
169180} // namespace bindable_p
170181
171182template <
@@ -206,12 +217,14 @@ class DBusBindableProperty: public DBusPropertyCore {
206217 QDBusError store (const QVariant& variant) override {
207218 DBusResult<DataType> result;
208219
209- if constexpr (std::is_same_v<WireType, BaseType>) {
210- result = demarshallVariant<DataType>(variant);
211- } else {
220+ if constexpr (bindable_p::HasFromWire<Transform>::value) {
212221 auto wireResult = demarshallVariant<WireType>(variant);
213222 if (!wireResult.isValid ()) return wireResult.error ;
214223 result = Transform::fromWire (std::move (wireResult.value ));
224+ } else if constexpr (std::is_same_v<WireType, BaseType>) {
225+ result = demarshallVariant<DataType>(variant);
226+ } else {
227+ return QDBusError (QDBusError::NotSupported, " This property cannot be deserialized" );
215228 }
216229
217230 if (!result.isValid ()) return result.error ;
@@ -225,10 +238,12 @@ class DBusBindableProperty: public DBusPropertyCore {
225238 }
226239
227240 QVariant serialize () override {
228- if constexpr (std::is_same_v<WireType, BaseType>) {
241+ if constexpr (bindable_p::HasToWire<Transform>::value) {
242+ return QVariant::fromValue (Transform::toWire (this ->bindable ()->value ()));
243+ } else if constexpr (std::is_same_v<WireType, BaseType>) {
229244 return QVariant::fromValue (this ->bindable ()->value ());
230245 } else {
231- return QVariant::fromValue ( Transform::toWire ( this -> bindable ()-> value ()) );
246+ return QVariant ( );
232247 }
233248 }
234249
0 commit comments