1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/xpcom/io/nsIObjectOutputStream.idl Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,97 @@ 1.4 +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ 1.5 +/* This Source Code Form is subject to the terms of the Mozilla Public 1.6 + * License, v. 2.0. If a copy of the MPL was not distributed with this 1.7 + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ 1.8 + 1.9 +#include "nsIBinaryOutputStream.idl" 1.10 + 1.11 +/** 1.12 + * @See nsIObjectInputStream 1.13 + * @See nsIBinaryOutputStream 1.14 + */ 1.15 + 1.16 +[scriptable, uuid(92c898ac-5fde-4b99-87b3-5d486422094b)] 1.17 +interface nsIObjectOutputStream : nsIBinaryOutputStream 1.18 +{ 1.19 + /** 1.20 + * Write the object whose "root" or XPCOM-identity nsISupports is aObject. 1.21 + * The cause for writing this object is a strong or weak reference, so the 1.22 + * aIsStrongRef argument must tell which kind of pointer is being followed 1.23 + * here during serialization. 1.24 + * 1.25 + * If the object has only one strong reference in the serialization and no 1.26 + * weak refs, use writeSingleRefObject. This is a valuable optimization: 1.27 + * it saves space in the stream, and cycles on both ends of the process. 1.28 + * 1.29 + * If the reference being serialized is a pointer to an interface not on 1.30 + * the primary inheritance chain ending in the root nsISupports, you must 1.31 + * call writeCompoundObject instead of this method. 1.32 + */ 1.33 + void writeObject(in nsISupports aObject, in boolean aIsStrongRef); 1.34 + 1.35 + /** 1.36 + * Write an object referenced singly and strongly via its root nsISupports 1.37 + * or a subclass of its root nsISupports. There must not be other refs to 1.38 + * aObject in memory, or in the serialization. 1.39 + */ 1.40 + void writeSingleRefObject(in nsISupports aObject); 1.41 + 1.42 + /** 1.43 + * Write the object referenced by an interface pointer at aObject that 1.44 + * inherits from a non-primary nsISupports, i.e., a reference to one of 1.45 + * the multiply inherited interfaces derived from an nsISupports other 1.46 + * than the root or XPCOM-identity nsISupports; or a reference to an 1.47 + * inner object in the case of true XPCOM aggregation. aIID identifies 1.48 + * this interface. 1.49 + */ 1.50 + void writeCompoundObject(in nsISupports aObject, 1.51 + in nsIIDRef aIID, 1.52 + in boolean aIsStrongRef); 1.53 + 1.54 + void writeID(in nsIDRef aID); 1.55 + 1.56 + /** 1.57 + * Optimized serialization support -- see nsIStreamBufferAccess.idl. 1.58 + */ 1.59 + [notxpcom] charPtr getBuffer(in uint32_t aLength, in uint32_t aAlignMask); 1.60 + [notxpcom] void putBuffer(in charPtr aBuffer, in uint32_t aLength); 1.61 +}; 1.62 + 1.63 +%{C++ 1.64 + 1.65 +inline nsresult 1.66 +NS_WriteOptionalObject(nsIObjectOutputStream* aStream, nsISupports* aObject, 1.67 + bool aIsStrongRef) 1.68 +{ 1.69 + bool nonnull = (aObject != nullptr); 1.70 + nsresult rv = aStream->WriteBoolean(nonnull); 1.71 + if (NS_SUCCEEDED(rv) && nonnull) 1.72 + rv = aStream->WriteObject(aObject, aIsStrongRef); 1.73 + return rv; 1.74 +} 1.75 + 1.76 +inline nsresult 1.77 +NS_WriteOptionalSingleRefObject(nsIObjectOutputStream* aStream, 1.78 + nsISupports* aObject) 1.79 +{ 1.80 + bool nonnull = (aObject != nullptr); 1.81 + nsresult rv = aStream->WriteBoolean(nonnull); 1.82 + if (NS_SUCCEEDED(rv) && nonnull) 1.83 + rv = aStream->WriteSingleRefObject(aObject); 1.84 + return rv; 1.85 +} 1.86 + 1.87 +inline nsresult 1.88 +NS_WriteOptionalCompoundObject(nsIObjectOutputStream* aStream, 1.89 + nsISupports* aObject, 1.90 + const nsIID& aIID, 1.91 + bool aIsStrongRef) 1.92 +{ 1.93 + bool nonnull = (aObject != nullptr); 1.94 + nsresult rv = aStream->WriteBoolean(nonnull); 1.95 + if (NS_SUCCEEDED(rv) && nonnull) 1.96 + rv = aStream->WriteCompoundObject(aObject, aIID, aIsStrongRef); 1.97 + return rv; 1.98 +} 1.99 + 1.100 +%}