[xpcom] Implement support for sending complex types in arrays
authorKalle Vahlman <kalle.vahlman@movial.com>
Tue, 21 Apr 2009 10:49:34 +0000 (13:49 +0300)
committerKalle Vahlman <kalle.vahlman@movial.com>
Tue, 21 Apr 2009 10:50:23 +0000 (13:50 +0300)
xpcom-dbusservice/DBusMarshaling.cpp

index d3e87039fd2c292ced646f4e222413fa356d635a..c95a41d39b1d07bd93368e34af3ddbf2c457f2cc 100644 (file)
@@ -549,12 +549,45 @@ addVariantToIter(JSContext* cx, nsIVariant *aVariant, DBusMessageIter *aIter, DB
                         SET_INT(16)
                         SET_INT(32)
                         SET_INT(64)
+                        case nsIDataType::VTYPE_INTERFACE_IS:
+                        {
+                            nsISupports **data = (nsISupports **)data_ptr;
+
+                            // We might have array of variants
+                            nsCOMPtr<nsIVariant> data_variant =
+                                do_QueryInterface(data[i]);
+
+                            if (data_variant) {
+                                variant->SetFromVariant(data_variant);
+                                break;
+                            }
+
+                            // We might have a wrapped JS obect in the variant
+                            // eg. dicts
+                            nsCOMPtr<nsIXPConnectWrappedJS> wrapped =
+                                do_QueryInterface(data[i]);
+
+                            if (!wrapped)
+                                break;
+
+                            JSObject *js_obj = nsnull;
+                            if (!NS_SUCCEEDED(wrapped->GetJSObject(&js_obj)))
+                                break;
+
+                            jsval js_obj_as_value = OBJECT_TO_JSVAL(js_obj);
+                            addJSValueToIter(cx, &js_obj_as_value,
+                                             &arrayIter, &aChildSigIter);
+                            break;
+                        }
                         default:
                             BDBLOG(("*** No conversion from %i to %c\n", type, dbustype));
                             break;
                     }
 
-                    addVariantToIter(cx, variant, &arrayIter, &aChildSigIter);
+                    PRUint16 vtype = 0;
+                    variant->GetDataType(&vtype);
+                    if (vtype != nsIDataType::VTYPE_EMPTY)
+                        addVariantToIter(cx, variant, &arrayIter, &aChildSigIter);
                 }
 
                 dbus_message_iter_close_container(aIter, &arrayIter);
@@ -866,10 +899,9 @@ addJSValueToIter(JSContext *cx, jsval *aValue, DBusMessageIter *aIter, DBusSigna
         }
         case DBUS_TYPE_ARRAY:
         {
-            if (JSVAL_IS_OBJECT(*aValue) && JS_IsArrayObject(cx, JSVAL_TO_OBJECT(*aValue)))
-            {
-                // Arrays are simply converted to variants and pushed to the
-                // variant code path
+            if (JSVAL_IS_OBJECT(*aValue)) {
+                // Arrays and dicts are simply converted to variants and pushed
+                // to the variant code path
                 nsresult rv;
                 nsCOMPtr<nsIXPConnect> xpc(do_GetService(nsIXPConnect::GetCID(), &rv));
                 if(NS_FAILED(rv))