118
129
namespace remote_client
135
exception_ptr make_exception(QDBusPendingCallWatcher const& call)
137
QDBusPendingReply<QString> reply = call;
138
auto msg = reply.argumentAt<0>();
139
return make_exception_ptr(T(msg));
143
exception_ptr make_exception<NotExistsException>(QDBusPendingCallWatcher const& call)
145
QDBusPendingReply<QString, QString> reply = call;
146
auto msg = reply.argumentAt<0>();
147
auto key = reply.argumentAt<1>();
148
return make_exception_ptr(NotExistsException(msg, key));
152
exception_ptr make_exception<ExistsException>(QDBusPendingCallWatcher const& call)
154
QDBusPendingReply<QString, QString, QString> reply = call;
155
auto msg = reply.argumentAt<0>();
156
auto id = reply.argumentAt<1>();
157
auto name = reply.argumentAt<2>();
158
return make_exception_ptr(ExistsException(msg, id, name));
162
exception_ptr make_exception<ResourceException>(QDBusPendingCallWatcher const& call)
164
QDBusPendingReply<QString, int> reply = call;
165
auto msg = reply.argumentAt<0>();
166
auto error_code = reply.argumentAt<1>();
167
return make_exception_ptr(ResourceException(msg, error_code));
170
static const map<QString, function<exception_ptr(QDBusPendingCallWatcher const& call)>> exception_factories =
172
{ "NotExistsException", make_exception<NotExistsException> },
173
{ "ExistsException", make_exception<ExistsException> },
174
{ "ResourceException", make_exception<ResourceException> },
175
{ "RemoteCommsException", make_exception<RemoteCommsException> },
176
{ "ConflictException", make_exception<ConflictException> },
177
{ "PermissionException", make_exception<PermissionException> },
178
{ "QuotaException", make_exception<QuotaException> },
179
{ "CancelledException", make_exception<CancelledException> },
180
{ "LogicException", make_exception<LogicException> },
181
{ "InvalidArgumentException", make_exception<InvalidArgumentException> },
182
{ "UnknownException", make_exception<LocalCommsException> } // Yes, LocalCommsException is intentional
187
std::exception_ptr unmarshal_exception(QDBusPendingCallWatcher const& call)
189
assert(call.isError());
191
int err = call.error().type();
192
if (err != QDBusError::Other)
194
return make_exception_ptr(LocalCommsException(call.error().message()));
197
auto exception_type = call.error().name();
198
if (!exception_type.startsWith(DBUS_ERROR_PREFIX))
200
QString msg = "unmarshal_exception(): unknown exception type received from server: " + exception_type
201
+ ": " + call.error().message();
202
return make_exception_ptr(LocalCommsException(msg));
204
exception_type = exception_type.remove(0, strlen(DBUS_ERROR_PREFIX));
206
auto factory_it = exception_factories.find(exception_type);
207
if (factory_it == exception_factories.end())
209
QString msg = "unmarshal_exception(): unknown exception type received from server: " + exception_type
210
+ ": " + call.error().message();
211
return make_exception_ptr(LocalCommsException(msg));
213
return factory_it->second(call);
216
} // namespace remote_client
217
} // namespace internal
218
} // namespace client
220
} // namespace storage