Back to index

lightning-sunbird  0.9+nobinonly
nsIStreamBufferAccess.idl
Go to the documentation of this file.
00001 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
00002 /* ***** BEGIN LICENSE BLOCK *****
00003  * Version: MPL 1.1/GPL 2.0/LGPL 2.1
00004  *
00005  * The contents of this file are subject to the Mozilla Public License Version
00006  * 1.1 (the "License"); you may not use this file except in compliance with
00007  * the License. You may obtain a copy of the License at
00008  * http://www.mozilla.org/MPL/
00009  *
00010  * Software distributed under the License is distributed on an "AS IS" basis,
00011  * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
00012  * for the specific language governing rights and limitations under the
00013  * License.
00014  *
00015  * The Original Code is Mozilla FastLoad code.
00016  *
00017  * The Initial Developer of the Original Code is
00018  * Netscape Communications Corporation.
00019  * Portions created by the Initial Developer are Copyright (C) 2001
00020  * the Initial Developer. All Rights Reserved.
00021  *
00022  * Contributor(s):
00023  *   Brendan Eich <brendan@mozilla.org> (original author)
00024  *
00025  * Alternatively, the contents of this file may be used under the terms of
00026  * either of the GNU General Public License Version 2 or later (the "GPL"),
00027  * or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
00028  * in which case the provisions of the GPL or the LGPL are applicable instead
00029  * of those above. If you wish to allow use of your version of this file only
00030  * under the terms of either the GPL or the LGPL, and not to allow others to
00031  * use your version of this file under the terms of the MPL, indicate your
00032  * decision by deleting the provisions above and replace them with the notice
00033  * and other provisions required by the GPL or the LGPL. If you do not delete
00034  * the provisions above, a recipient may use your version of this file under
00035  * the terms of any one of the MPL, the GPL or the LGPL.
00036  *
00037  * ***** END LICENSE BLOCK ***** */
00038 
00039 #include "nsISupports.idl"
00040 #include "nsrootidl.idl"
00041 
00051 [uuid(ac923b72-ac87-4892-ac7a-ca385d429435)]
00052 interface nsIStreamBufferAccess : nsISupports
00053 {
00081     [notxpcom] charPtr getBuffer(in PRUint32 aLength, in PRUint32 aAlignMask);
00082 
00096     [notxpcom] void putBuffer(in charPtr aBuffer, in PRUint32 aLength);
00097 
00103     void disableBuffering();
00104     void enableBuffering();
00105 
00109     readonly attribute nsISupports unbufferedStream;
00110 };
00111 
00112 %{C++
00113 
00114 // Swap macros, used to convert to/from canonical (big-endian) format
00115 #if defined IS_LITTLE_ENDIAN
00116 
00117 # define NS_SWAP16(x) ((((x) & 0xff) << 8) | (((x) >> 8) & 0xff))
00118 # define NS_SWAP32(x) ((NS_SWAP16((x) & 0xffff) << 16) | (NS_SWAP16((x) >> 16)))
00119 
00120 // We want to avoid casting to 32-bit types if possible, since that violates
00121 // aliasing rules (a standard compiler may assume that pointers of two types
00122 // do not address overlapping storage).
00123 //
00124 // XXX What if we have a compiler that follows aliasing rules strictly but
00125 // doesn't have a 64-bit int type?
00126 //
00127 // XXXbe shouldn't NSPR's LL_INIT work for non-constant arguments in all cases?
00128 
00129 # if defined HAVE_LONG_LONG
00130 #  if PR_BYTES_PER_LONG == 8
00131 #   define ULL_(x)     x ## UL
00132 #  elif (defined WIN32 || defined WIN16) && !defined __GNUC__
00133 #   define ULL_(x)     ((uint64) x ## i64)
00134 #  else
00135 #   define ULL_(x)     x ## ULL
00136 #  endif
00137 
00138 #  define NS_SWAP64(x) ((((x)    & ULL_(0xff00000000000000))    >> 56) |      \
00139                         (((x)    & ULL_(0x00ff000000000000))    >> 40) |      \
00140                         (((x)    & ULL_(0x0000ff0000000000))    >> 24) |      \
00141                         (((x)    & ULL_(0x000000ff00000000))    >> 8)  |      \
00142                         (((x)    & ULL_(0x00000000ff000000))    << 8)  |      \
00143                         (((x)    & ULL_(0x0000000000ff0000))    << 24) |      \
00144                         (((x)    & ULL_(0x000000000000ff00))    << 40) |      \
00145                         (((x) /* & ULL_(0x00000000000000ff) */) << 56))
00146 # else
00147 #  define NS_SWAP64(x) LL_INIT((((x).lo /* & 0xff000000ul */) >> 24) |        \
00148                                (((x).lo    & 0x00ff0000ul)    >> 8)  |        \
00149                                (((x).lo    & 0x0000ff00ul)    << 8)  |        \
00150                                (((x).lo /* & 0x000000fful */) << 24),         \
00151                                (((x).hi /* & 0xff000000ul */) >> 24) |        \
00152                                (((x).hi    & 0x00ff0000ul)    >> 8)  |        \
00153                                (((x).hi    & 0x0000ff00ul)    << 8)  |        \
00154                                (((x).hi /* & 0x000000fful */) << 24))
00155 # endif
00156 
00157 #elif defined IS_BIG_ENDIAN
00158 
00159 # define NS_SWAP16(x) (x)
00160 # define NS_SWAP32(x) (x)
00161 # define NS_SWAP64(x) (x)
00162 
00163 #else
00164 
00165 # error "Unknown byte order"
00166 
00167 #endif
00168 
00174 #define NS_GET_BUFFER(sba,n,a)  ((sba)->GetBuffer(n, a))
00175 #define NS_PUT_BUFFER(sba,p,n)  ((sba)->PutBuffer(p, n))
00176 
00177 #define NS_GET8(p)              (*(PRUint8*)(p))
00178 #define NS_GET16(p)             NS_SWAP16(*(PRUint16*)(p))
00179 #define NS_GET32(p)             NS_SWAP32(*(PRUint32*)(p))
00180 #define NS_GET64(p)             NS_SWAP64(*(PRUint64*)(p))
00181 #define NS_GET_FLOAT(p)         ((float)NS_SWAP32(*(PRUint32*)(p)))
00182 #define NS_GET_DOUBLE(p)        ((double)NS_SWAP64(*(PRUint64*)(p)))
00183 
00184 #define NS_PUT8(p,x)            (*(PRUint8*)(p) = (x))
00185 #define NS_PUT16(p,x)           (*(PRUint16*)(p) = NS_SWAP16(x))
00186 #define NS_PUT32(p,x)           (*(PRUint32*)(p) = NS_SWAP32(x))
00187 #define NS_PUT64(p,x)           (*(PRUint64*)(p) = NS_SWAP64(x))
00188 #define NS_PUT_FLOAT(p,x)       (*(PRUint32*)(p) = NS_SWAP32(*(PRUint32*)&(x)))
00189 #define NS_PUT_DOUBLE(p,x)      (*(PRUint64*)(p) = NS_SWAP64(*(PRUint64*)&(x)))
00190 
00191 %}