Back to index

enigmail  1.4.3
nsIPCBuffer.h
Go to the documentation of this file.
00001 /* ***** BEGIN LICENSE BLOCK *****
00002  * Version: MPL 1.1/GPL 2.0/LGPL 2.1
00003  *
00004  * The contents of this file are subject to the Mozilla Public
00005  * License Version 1.1 (the "MPL"); you may not use this file
00006  * except in compliance with the MPL. You may obtain a copy of
00007  * the MPL at http://www.mozilla.org/MPL/
00008  *
00009  * Software distributed under the MPL is distributed on an "AS
00010  * IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
00011  * implied. See the MPL for the specific language governing
00012  * rights and limitations under the MPL.
00013  *
00014  * The Original Code is protoZilla.
00015  *
00016  * The Initial Developer of the Original Code is Ramalingam Saravanan.
00017  * Portions created by Ramalingam Saravanan <svn@xmlterm.org> are
00018  * Copyright (C) 2000 Ramalingam Saravanan. All Rights Reserved.
00019  *
00020  * Contributor(s):
00021  * Patrick Brunschwig <patrick@mozilla-enigmail.org>
00022  *
00023  * Alternatively, the contents of this file may be used under the terms of
00024  * either the GNU General Public License Version 2 or later (the "GPL"), or
00025  * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
00026  * in which case the provisions of the GPL or the LGPL are applicable instead
00027  * of those above. If you wish to allow use of your version of this file only
00028  * under the terms of either the GPL or the LGPL, and not to allow others to
00029  * use your version of this file under the terms of the MPL, indicate your
00030  * decision by deleting the provisions above and replace them with the notice
00031  * and other provisions required by the GPL or the LGPL. If you do not delete
00032  * the provisions above, a recipient may use your version of this file under
00033  * the terms of any one of the MPL, the GPL or the LGPL.
00034  * ***** END LICENSE BLOCK ***** */
00035 
00036 
00037 #ifndef nsIPCBuffer_h__
00038 #define nsIPCBuffer_h__
00039 
00040 #include "nspr.h"
00041 
00042 #include "nsIIPCBuffer.h"
00043 #include "nsIInputStream.h"
00044 #include "nsIFileStreams.h"
00045 #include "nsIRunnable.h"
00046 #include "nsIThread.h"
00047 #include "nsCOMPtr.h"
00048 #include "nsStringGlue.h"
00049 #include "mozilla/Mutex.h"
00050 
00051 #ifdef XP_WIN_IPC
00052 // Windows
00053 #define IPCFileDesc void
00054 #define IPC_NULL_HANDLE NULL
00055 #define IPC_Read IPC_ReadWin32
00056 #define IPC_Close IPC_CloseWin32
00057 
00058 #else
00059 
00060 // not Windows
00061 #define IPCFileDesc PRFileDesc
00062 #define IPC_NULL_HANDLE nsnull
00063 #define IPC_Read PR_Read
00064 #define IPC_Close PR_Close
00065 
00066 #endif
00067 
00068 // Implementation class for nsIIPCBuffer
00069 class nsIPCBuffer : public nsIIPCBuffer,
00070                     public nsIInputStream,
00071                     public nsIRunnable
00072 {
00073 public:
00074     NS_DECL_ISUPPORTS
00075     NS_DECL_NSIREQUESTOBSERVER
00076     NS_DECL_NSISTREAMLISTENER
00077     NS_DECL_NSIPIPELISTENER
00078     NS_DECL_NSIIPCBUFFER
00079     NS_DECL_NSIINPUTSTREAM
00080     NS_DECL_NSIRUNNABLE
00081 
00082     nsIPCBuffer();
00083     virtual ~nsIPCBuffer();
00084 
00085     // Define a Create method to be used with a factory:
00086     static NS_METHOD
00087     Create(nsISupports *aOuter, REFNSIID aIID, void **aResult);
00088 
00089 protected:
00090     nsresult Finalize(IPCBool destructor);
00091     nsresult Init();
00092 
00093     nsresult CreateTempFile();
00094     nsresult CloseTempOutStream();
00095     nsresult WriteTempOutStream(const char* buf, PRUint32 count);
00096     nsresult OpenTempInStream();
00097     nsresult CloseTempInStream();
00098     nsresult RemoveTempFile();
00099 
00100     IPCBool                              mFinalized;
00101     IPCBool                              mInitialized;
00102     IPCBool                              mThreadJoined;
00103     IPCBool                              mOverflowed;
00104     IPCBool                              mOverflowFile;
00105 
00106     IPCBool                              mRequestStarted;
00107     IPCBool                              mRequestStopped;
00108 
00109     mozilla::Mutex                      mLock;
00110 
00111     PRInt32                             mMaxBytes;
00112     PRUint32                            mByteCount;
00113     PRUint32                            mStreamOffset;
00114 
00115     nsCString                           mByteBuf;
00116 
00117     IPCFileDesc*                        mPipeWrite;
00118     IPCFileDesc*                        mPipeRead;
00119 
00120     nsCOMPtr<nsIFile>                   mTempFile;
00121     nsCOMPtr<nsIFileOutputStream>       mTempOutStream;
00122     nsCOMPtr<nsIFileInputStream>        mTempInStream;
00123 
00124     // Owning refs
00125     nsCOMPtr<nsIThread>                 mPipeThread;
00126     nsCOMPtr<nsIRequestObserver>        mObserver;
00127     nsCOMPtr<nsISupports>               mObserverContext;
00128 
00129     NS_IMETHODIMP GetFileDesc(IPCFileDesc **_retval);
00130 };
00131 
00132 #endif // nsIPCBuffer_h__