~gnomefreak/firefox-extensions/firegpg.ubuntu

« back to all changes in this revision

Viewing changes to FireGPGCall/ipc/src/.svn/text-base/nsPipeTransport.h.svn-base

  • Committer: John Vivirito
  • Date: 2008-08-12 11:47:33 UTC
  • Revision ID: gnomefreak@ubuntu.com-20080812114733-hn73tjxi26ylibrf
* import of upstream source version 0.5.1

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
 * The contents of this file are subject to the Mozilla Public
 
3
 * License Version 1.1 (the "MPL"); you may not use this file
 
4
 * except in compliance with the MPL. You may obtain a copy of
 
5
 * the MPL at http://www.mozilla.org/MPL/
 
6
 * 
 
7
 * Software distributed under the MPL is distributed on an "AS
 
8
 * IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
 
9
 * implied. See the MPL for the specific language governing
 
10
 * rights and limitations under the MPL.
 
11
 * 
 
12
 * The Original Code is protoZilla.
 
13
 * 
 
14
 * The Initial Developer of the Original Code is Ramalingam Saravanan.
 
15
 * Portions created by Ramalingam Saravanan <svn@xmlterm.org> are
 
16
 * Copyright (C) 2000 Ramalingam Saravanan. All Rights Reserved.
 
17
 * 
 
18
 * Contributor(s):
 
19
 * 
 
20
 * Alternatively, the contents of this file may be used under the
 
21
 * terms of the GNU General Public License (the "GPL"), in which case
 
22
 * the provisions of the GPL are applicable instead of
 
23
 * those above. If you wish to allow use of your version of this
 
24
 * file only under the terms of the GPL and not to allow
 
25
 * others to use your version of this file under the MPL, indicate
 
26
 * your decision by deleting the provisions above and replace them
 
27
 * with the notice and other provisions required by the GPL.
 
28
 * If you do not delete the provisions above, a recipient
 
29
 * may use your version of this file under either the MPL or the
 
30
 * GPL.
 
31
 */
 
32
 
 
33
#ifndef nsPipeTransport_h__
 
34
#define nsPipeTransport_h__
 
35
 
 
36
#include "nspr.h"
 
37
#include "IPCProcess.h"
 
38
 
 
39
#include "nsIPipeTransport.h"
 
40
#include "nsIPipeListener.h"
 
41
#include "nsIRunnable.h"
 
42
#include "nsIEventQueueService.h"
 
43
#include "nsIInterfaceRequestor.h"
 
44
#include "nsITransport.h"
 
45
#include "nsIChannel.h"
 
46
#include "nsIPipe.h"
 
47
#include "nsIFile.h"
 
48
#include "nsIThread.h"
 
49
#include "nsILoadGroup.h"
 
50
#include "nsCOMPtr.h"
 
51
#include "nsString.h"
 
52
#include "nsIStreamListener.h"
 
53
#include "nsIInputStream.h"
 
54
#include "nsIOutputStream.h"
 
55
 
 
56
#ifdef MOZILLA_VERSION
 
57
#include "nsIAsyncInputStream.h"
 
58
#include "nsIAsyncOutputStream.h"
 
59
#else
 
60
// Mods for Mozilla version prior to 1.3b
 
61
#include "nsIObservableInputStream.h"
 
62
#include "nsIObservableOutputStream.h"
 
63
#endif
 
64
 
 
65
#define NS_PIPE_TRANSPORT_DEFAULT_SEGMENT_SIZE   (2*1024)
 
66
#define NS_PIPE_TRANSPORT_DEFAULT_BUFFER_SIZE    (8*1024)
 
67
#define NS_PIPE_TRANSPORT_DEFAULT_HEADERS_SIZE   (4*1024)
 
68
 
 
69
class nsStdoutPoller;
 
70
 
 
71
class nsPipeTransport : public nsIPipeTransport,
 
72
                        public nsIPipeTransportListener,
 
73
                        public nsIOutputStream,
 
74
                        public nsIStreamListener,
 
75
#ifdef MOZILLA_VERSION
 
76
                        public nsIInputStreamCallback,
 
77
                        public nsIOutputStreamCallback
 
78
#else
 
79
// Mods for Mozilla version prior to 1.3b
 
80
                        public nsIInputStreamObserver,
 
81
                        public nsIOutputStreamObserver
 
82
#endif
 
83
 
 
84
{
 
85
public:
 
86
    NS_DECL_ISUPPORTS
 
87
    NS_DECL_NSIPIPETRANSPORT
 
88
    NS_DECL_NSIPIPETRANSPORTHEADERS
 
89
    NS_DECL_NSIPIPETRANSPORTLISTENER
 
90
    NS_DECL_NSIREQUEST
 
91
    NS_DECL_NSIREQUESTOBSERVER
 
92
    NS_DECL_NSIOUTPUTSTREAM
 
93
    NS_DECL_NSISTREAMLISTENER
 
94
 
 
95
#ifdef MOZILLA_VERSION
 
96
    NS_DECL_NSIINPUTSTREAMCALLBACK
 
97
    NS_DECL_NSIOUTPUTSTREAMCALLBACK
 
98
#else
 
99
    // Mods for Mozilla version prior to 1.3b
 
100
    NS_DECL_NSIINPUTSTREAMOBSERVER
 
101
    NS_DECL_NSIOUTPUTSTREAMOBSERVER
 
102
#endif
 
103
 
 
104
    // nsPipeTransport methods:
 
105
    nsPipeTransport();
 
106
    // Always make the destructor virtual: 
 
107
    virtual ~nsPipeTransport();
 
108
 
 
109
    nsresult Finalize(PRBool destructor);
 
110
 
 
111
    void KillProcess(void);
 
112
 
 
113
    // Define a Create method to be used with a factory:
 
114
    static NS_METHOD
 
115
    Create(nsISupports* aOuter, const nsIID& aIID, void* *aResult);
 
116
    
 
117
    enum PipeState {
 
118
      PIPE_NOT_YET_OPENED,
 
119
      PIPE_OPEN,
 
120
      PIPE_CLOSED
 
121
    };
 
122
 
 
123
    enum StreamState {
 
124
      STREAM_NOT_YET_OPENED,
 
125
      STREAM_ASYNC_OPEN,
 
126
      STREAM_SYNC_OPEN,
 
127
      STREAM_CLOSED
 
128
    };
 
129
 
 
130
protected:
 
131
    PRBool                              mFinalized;
 
132
    PRBool                              mNoProxy;
 
133
    PRBool                              mStartedRequest;
 
134
    PRMonitor*                          mMonitor;
 
135
 
 
136
    PipeState                           mPipeState;
 
137
    StreamState                         mStdoutStream;
 
138
    nsresult                            mCancelStatus;
 
139
 
 
140
    nsLoadFlags                         mLoadFlags;
 
141
    PRUint32                            mNotificationFlags;
 
142
 
 
143
    nsCString                           mExecutable;
 
144
    nsCString                           mCommand;
 
145
    nsCString                           mKillString;
 
146
 
 
147
    IPCProcess*                         mProcess;
 
148
    PRIntervalTime                      mKillWaitInterval;
 
149
    PRInt32                             mExitCode;
 
150
 
 
151
    PRUint32                            mBufferSegmentSize;
 
152
    PRUint32                            mBufferMaxSize;
 
153
    PRUint32                            mHeadersMaxSize;
 
154
 
 
155
    nsCString                           mExecBuf;
 
156
 
 
157
    IPCFileDesc*                        mStdinWrite;
 
158
    
 
159
    // Owning refs
 
160
    nsCOMPtr<nsIPipeTransportPoller>    mStdoutPoller;
 
161
    nsCOMPtr<nsIPipeListener>           mConsole;
 
162
    nsCOMPtr<nsIPipeTransportHeaders>   mHeaderProcessor;
 
163
 
 
164
    nsCOMPtr<nsIInputStream>            mInputStream;
 
165
    nsCOMPtr<nsIOutputStream>           mOutputStream;
 
166
 
 
167
    nsCOMPtr<nsIStreamListener>         mListener;
 
168
    nsCOMPtr<nsISupports>               mContext;
 
169
    nsCOMPtr<nsILoadGroup>              mLoadGroup;
 
170
};
 
171
 
 
172
// Helper class to handle polling of STDOUT pipe
 
173
class nsStdoutPoller : public nsIPipeTransportPoller,
 
174
                       public nsIRunnable
 
175
{
 
176
public:
 
177
    NS_DECL_ISUPPORTS
 
178
    NS_DECL_NSIPIPETRANSPORTPOLLER
 
179
    NS_DECL_NSIRUNNABLE
 
180
 
 
181
    nsStdoutPoller();
 
182
    virtual ~nsStdoutPoller();
 
183
 
 
184
    nsresult Init(IPCFileDesc*            aStdoutRead,
 
185
                  IPCFileDesc*            aStderrRead,
 
186
                  PRIntervalTime          aTimeoutInterval,
 
187
                  nsIPipeListener*        aConsole);
 
188
 
 
189
    nsresult Finalize(PRBool destructor);
 
190
 
 
191
    PRBool IsInterrupted(void);
 
192
 
 
193
    nsresult GetPolledFD(PRFileDesc*& aFileDesc);
 
194
 
 
195
    nsresult HeaderSearch(const char* buf, PRUint32 count,
 
196
                          PRUint32 *headerOffset);
 
197
protected:
 
198
    PRBool                              mFinalized;
 
199
 
 
200
    PRLock*                             mLock;
 
201
    PRBool                              mInterrupted;
 
202
    PRBool                              mLoggingEnabled;
 
203
    PRBool                              mJoinableThread;
 
204
 
 
205
    PRIntervalTime                      mTimeoutInterval;
 
206
 
 
207
    nsCString                           mHeadersBuf;
 
208
    PRUint32                            mHeadersBufSize;
 
209
    PRUint32                            mHeadersLastNewline;
 
210
    PRBool                              mRequestStarted;
 
211
    PRInt32                             mContentLength;
 
212
 
 
213
    IPCFileDesc*                        mStdoutRead;
 
214
    IPCFileDesc*                        mStderrRead;
 
215
 
 
216
    PRInt32                             mPollCount;
 
217
    PRFileDesc*                         mPollableEvent;
 
218
    PRPollDesc*                         mPollFD;
 
219
 
 
220
    // Owning refs
 
221
    nsCOMPtr<nsIThread>                 mStdoutThread;
 
222
    nsCOMPtr<nsIOutputStream>           mOutputStream;
 
223
    nsCOMPtr<nsIPipeTransportListener>  mProxyPipeListener;
 
224
    nsCOMPtr<nsIPipeListener>           mConsole;
 
225
};
 
226
 
 
227
// Helper class to handle write to pipe
 
228
class nsStdinWriter : public nsIPipeTransportWriter,
 
229
                      public nsIRunnable
 
230
{
 
231
public:
 
232
    NS_DECL_ISUPPORTS
 
233
    NS_DECL_NSIPIPETRANSPORTWRITER
 
234
    NS_DECL_NSIRUNNABLE
 
235
 
 
236
    nsStdinWriter();
 
237
    virtual ~nsStdinWriter();
 
238
 
 
239
protected:
 
240
    nsCOMPtr<nsIInputStream> mInputStream;
 
241
    PRUint32                 mCount;
 
242
    IPCFileDesc*             mPipe;
 
243
    PRBool                   mCloseAfterWrite;
 
244
};
 
245
 
 
246
#endif // nsPipeTransport_h__