Introduce the new UnknownProperty and PropertyReadOnly errors
authorThiago Macieira <thiago.macieira@intel.com>
Thu, 29 Mar 2012 14:11:51 +0000 (11:11 -0300)
committerQt by Nokia <qt-info@nokia.com>
Sun, 15 Apr 2012 22:07:49 +0000 (00:07 +0200)
Those error codes have been standardised for years but we haven't used
them until now.

Task-number: QTBUG-23274
Change-Id: Iebc9ded949f363281a4d43fd9d29a284f2e2df08
Reviewed-by: Jason McDonald <jason.mcdonald@nokia.com>
Reviewed-by: Lorn Potter <lorn.potter@nokia.com>
src/dbus/qdbuserror.cpp
src/dbus/qdbuserror.h
src/dbus/qdbusinternalfilters.cpp

index 9b21ade..b81d8a6 100644 (file)
@@ -94,6 +94,8 @@ org.freedesktop.DBus.Error.TimedOut
 org.freedesktop.DBus.Error.InvalidSignature
 org.freedesktop.DBus.Error.UnknownInterface
 org.freedesktop.DBus.Error.UnknownObject
+org.freedesktop.DBus.Error.UnknownProperty
+org.freedesktop.DBus.Error.PropertyReadOnly
 org.qtproject.QtDBus.Error.InternalError
 org.qtproject.QtDBus.Error.InvalidService
 org.qtproject.QtDBus.Error.InvalidObjectPath
@@ -123,6 +125,8 @@ static const char errorMessages_string[] =
     "org.freedesktop.DBus.Error.InvalidSignature\0"
     "org.freedesktop.DBus.Error.UnknownInterface\0"
     "org.freedesktop.DBus.Error.UnknownObject\0"
+    "org.freedesktop.DBus.Error.UnknownProperty\0"
+    "org.freedesktop.DBus.Error.PropertyReadOnly\0"
     "org.qtproject.QtDBus.Error.InternalError\0"
     "org.qtproject.QtDBus.Error.InvalidService\0"
     "org.qtproject.QtDBus.Error.InvalidObjectPath\0"
@@ -133,8 +137,8 @@ static const char errorMessages_string[] =
 static const int errorMessages_indices[] = {
     0,    6,   40,   76,  118,  153,  191,  231,
     273,  313,  349,  384,  421,  461,  501,  540,
-    581,  617,  661,  705,  746,  787,  829,  874,
-    918,   -1
+    581,  617,  661,  705,  746,  789,  833,  874,
+    916,  961, 1005,   -1
 };
 
 static const int errorMessages_count = sizeof errorMessages_indices /
@@ -230,6 +234,10 @@ static inline QDBusError::ErrorType get(const char *name)
                                 (\c org.freedesktop.DBus.Error.UnknownInterface)
     \value UnknownObject        The object path points to an object that does not exist
                                 (\c org.freedesktop.DBus.Error.UnknownObject)
+    \value UnknownProperty      The property does not exist in this interface
+                                (\c org.freedesktop.DBus.Error.UnknownProperty)
+    \value PropertyReadOnly     The property set failed because the property is read-only
+                                (\c org.freedesktop.DBus.Error.PropertyReadOnly)
 
     \value InternalError        An internal error occurred
 
index a79e66c..a6b3c9a 100644 (file)
@@ -81,6 +81,8 @@ public:
         InvalidSignature,
         UnknownInterface,
         UnknownObject,
+        UnknownProperty,
+        PropertyReadOnly,
         InternalError,
         InvalidService,
         InvalidObjectPath,
index 28d43c8..e498531 100644 (file)
@@ -197,7 +197,7 @@ static inline QDBusMessage interfaceNotFoundError(const QDBusMessage &msg, const
 static inline QDBusMessage
 propertyNotFoundError(const QDBusMessage &msg, const QString &interface_name, const QByteArray &property_name)
 {
-    return msg.createErrorReply(QDBusError::InvalidArgs,
+    return msg.createErrorReply(QDBusError::UnknownProperty,
                                 QString::fromLatin1("Property %1%2%3 was not found in object %4")
                                 .arg(interface_name,
                                      QString::fromLatin1(interface_name.isEmpty() ? "" : "."),
@@ -277,6 +277,7 @@ enum PropertyWriteResult {
     PropertyWriteSuccess = 0,
     PropertyNotFound,
     PropertyTypeMismatch,
+    PropertyReadOnly,
     PropertyWriteFailed
 };
 
@@ -292,6 +293,12 @@ static QDBusMessage propertyWriteReply(const QDBusMessage &msg, const QString &i
                                     .arg(interface_name,
                                          QString::fromLatin1(interface_name.isEmpty() ? "" : "."),
                                          QString::fromLatin1(property_name)));
+    case PropertyReadOnly:
+        return msg.createErrorReply(QDBusError::PropertyReadOnly,
+                                    QString::fromLatin1("Property %1%2%3 is read-only")
+                                    .arg(interface_name,
+                                         QString::fromLatin1(interface_name.isEmpty() ? "" : "."),
+                                         QString::fromLatin1(property_name)));
     case PropertyWriteFailed:
         return msg.createErrorReply(QDBusError::InternalError,
                                     QString::fromLatin1("Internal error"));
@@ -315,6 +322,10 @@ static int writeProperty(QObject *obj, const QByteArray &property_name, QVariant
 
     QMetaProperty mp = mo->property(pidx);
 
+    // check if this property is writable
+    if (!mp.isWritable())
+        return PropertyReadOnly;
+
     // check if this property is exported
     bool isScriptable = mp.isScriptable();
     if (!(propFlags & QDBusConnection::ExportScriptableProperties) && isScriptable)