Permalink
Browse files

Refactor UPnP error propagation

  • Loading branch information...
1 parent 30d15e4 commit 960b4a41a19a5dca5651a1f24167383e71b4e4c7 @phako committed Apr 4, 2012
Showing with 26 additions and 25 deletions.
  1. +18 −0 upnp/upnpdevice.cpp
  2. +3 −0 upnp/upnpdevice.h
  3. +5 −25 upnp/upnprenderer.cpp
View
@@ -149,3 +149,21 @@ ServiceProxy UPnPDevice::getService(const char *service)
return ServiceProxy ();
}
+
+void UPnPDevice::propagateError(GError *error)
+{
+ QMetaObject::invokeMethod(this, "error",
+ Qt::QueuedConnection,
+ Q_ARG(int, error->code),
+ Q_ARG(QString, QString::fromUtf8(error->message)));
+
+ g_error_free (error);
+}
+
+void UPnPDevice::propagateError(const GError *error)
+{
+ QMetaObject::invokeMethod(this, "error",
+ Qt::QueuedConnection,
+ Q_ARG(int, error->code),
+ Q_ARG(QString, QString::fromUtf8(error->message)));
+}
View
@@ -60,6 +60,9 @@ private Q_SLOTS:
void onDeviceUnavailable(const QString& udn);
protected:
DeviceProxy m_proxy;
+
+ void propagateError(GError *error);
+ void propagateError(const GError *error);
};
#endif // UPNPDEVICE_H
View
@@ -292,11 +292,7 @@ void UPnPRenderer::on_get_position_info(GUPnPServiceProxy *proxy, GUPnPServicePr
NULL);
if (error != 0) {
- QMetaObject::invokeMethod(self, "error",
- Qt::QueuedConnection,
- Q_ARG(int, error->code),
- Q_ARG(QString, QString::fromUtf8(error->message)));
- g_error_free(error);
+ self->propagateError(error);
return;
}
@@ -322,10 +318,7 @@ void UPnPRenderer::on_get_protocol_info(GUPnPServiceProxy *proxy, GUPnPServicePr
}
protocol_info = 0;
- QMetaObject::invokeMethod(self, "error",
- Q_ARG(int, error->code),
- Q_ARG(QString, QString::fromUtf8(error->message)));
- g_error_free(error);
+ self->propagateError(error);
}
self->setProtocolInfo(QString::fromUtf8(protocol_info));
@@ -346,10 +339,7 @@ void UPnPRenderer::on_got_introspection (GUPnPServiceInfo *info,
UPnPRenderer *self = reinterpret_cast<UPnPRenderer*>(user_data);
if (error != 0) {
- QMetaObject::invokeMethod(self, "error",
- Qt::QueuedConnection,
- Q_ARG(int, error->code),
- Q_ARG(QString, QString::fromUtf8(error->message)));
+ self->propagateError(error);
} else {
bool canPause = gupnp_service_introspection_get_action(introspection, "Pause") != NULL;
self->setCanPause(canPause);
@@ -403,12 +393,7 @@ void UPnPRenderer::on_set_av_transport_uri (GUPnPServiceProxy *proxy,
return;
}
- QMetaObject::invokeMethod(call->m_renderer, "error",
- Qt::QueuedConnection,
- Q_ARG(int, error->code),
- Q_ARG(QString, QString::fromUtf8(error->message)));
-
- g_error_free (error);
+ call->m_renderer->propagateError(error);
}
void UPnPRenderer::setAVTransportUri(const QString &uri, const QString &metaData)
@@ -438,12 +423,7 @@ void UPnPRenderer::on_stop (GUPnPServiceProxy *proxy,
&error,
NULL);
if (error != 0) {
- QMetaObject::invokeMethod(call->m_renderer, "error",
- Qt::QueuedConnection,
- Q_ARG(int, error->code),
- Q_ARG(QString, QString::fromUtf8(error->message)));
-
- g_error_free (error);
+ call->m_renderer->propagateError(error);
return;
}

0 comments on commit 960b4a4

Please sign in to comment.