1
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2
/* ***** BEGIN LICENSE BLOCK *****
3
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
5
* The contents of this file are subject to the Mozilla Public License Version
6
* 1.1 (the "License"); you may not use this file except in compliance with
7
* the License. You may obtain a copy of the License at
8
* http://www.mozilla.org/MPL/
10
* Software distributed under the License is distributed on an "AS IS" basis,
11
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
12
* for the specific language governing rights and limitations under the
15
* The Original Code is mozilla.org code.
17
* The Initial Developer of the Original Code is
18
* Netscape Communications Corporation.
19
* Portions created by the Initial Developer are Copyright (C) 1998
20
* the Initial Developer. All Rights Reserved.
24
* Alternatively, the contents of this file may be used under the terms of
25
* either of the GNU General Public License Version 2 or later (the "GPL"),
26
* or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
27
* in which case the provisions of the GPL or the LGPL are applicable instead
28
* of those above. If you wish to allow use of your version of this file only
29
* under the terms of either the GPL or the LGPL, and not to allow others to
30
* use your version of this file under the terms of the MPL, indicate your
31
* decision by deleting the provisions above and replace them with the notice
32
* and other provisions required by the GPL or the LGPL. If you do not delete
33
* the provisions above, a recipient may use your version of this file under
34
* the terms of any one of the MPL, the GPL or the LGPL.
36
* ***** END LICENSE BLOCK ***** */
38
#ifndef __nsProxyEvent_h_
39
#define __nsProxyEvent_h_
42
#include "nsAutoPtr.h"
44
#include "nsISupports.h"
45
#include "nsIFactory.h"
47
#include "nsIEventQueueService.h"
48
#include "nsIEventQueue.h"
54
class nsProxyObjectCallInfo;
56
#define PROXY_SYNC 0x0001 // acts just like a function call.
57
#define PROXY_ASYNC 0x0002 // fire and forget. This will return immediately and you will lose all return information.
58
#define PROXY_ALWAYS 0x0004 // ignore check to see if the eventQ is on the same thread as the caller, and alway return a proxied object.
60
//#define AUTOPROXIFICATION
62
// WARNING about PROXY_ASYNC:
64
// If the calling thread goes away, any function which accesses the calling stack
71
// ... thread goes away ...
75
// *x = 0; <----- You will blow up here.
78
// So what gets saved?
80
// You can safely pass base types by value. You can also pass interface pointers.
81
// I will make sure that the interface pointers are addrefed while they are being
82
// proxied. You can also pass string and wstring. These I will copy and free.
84
// I do **NOT** copy arrays or strings with size. If you are using these either
85
// change your interface, or contact me about this feature request.
93
nsProxyObject(nsIEventQueue *destQueue, PRInt32 proxyType, nsISupports *realObject);
94
nsProxyObject(nsIEventQueue *destQueue, PRInt32 proxyType, const nsCID &aClass, nsISupports *aDelegate, const nsIID &aIID);
101
nsresult Post( PRUint32 methodIndex,
102
nsXPTMethodInfo * info,
103
nsXPTCMiniVariant * params,
104
nsIInterfaceInfo * interfaceInfo);
106
nsresult PostAndWait(nsProxyObjectCallInfo *proxyInfo);
107
nsISupports* GetRealObject() const { return mRealObject; }
108
nsIEventQueue* GetQueue() const { return mDestQueue; }
109
PRInt32 GetProxyType() const { return mProxyType; }
111
friend class nsProxyEventObject;
114
nsAutoRefCnt mRefCnt;
118
nsCOMPtr<nsIEventQueue> mDestQueue; /* destination queue */
120
nsCOMPtr<nsISupports> mRealObject; /* the non-proxy object that this event is referring to.
121
This is a strong ref. */
122
nsCOMPtr<nsIEventQueueService> mEventQService;
124
nsresult convertMiniVariantToVariant(nsXPTMethodInfo * methodInfo,
125
nsXPTCMiniVariant * params,
126
nsXPTCVariant **fullParam,
132
class nsProxyObjectCallInfo
136
nsProxyObjectCallInfo(nsProxyObject* owner,
137
nsXPTMethodInfo *methodInfo,
138
PRUint32 methodIndex,
139
nsXPTCVariant* parameterList,
140
PRUint32 parameterCount,
143
~nsProxyObjectCallInfo();
145
PRUint32 GetMethodIndex() const { return mMethodIndex; }
146
nsXPTCVariant* GetParameterList() const { return mParameterList; }
147
PRUint32 GetParameterCount() const { return mParameterCount; }
148
PLEvent* GetPLEvent() const { return mEvent; }
149
nsresult GetResult() const { return mResult; }
150
nsProxyObject* GetProxyObject() const { return mOwner; }
152
PRBool GetCompleted();
154
void PostCompleted();
156
void SetResult(nsresult rv) {mResult = rv; }
158
nsIEventQueue* GetCallersQueue();
159
void SetCallersQueue(nsIEventQueue* queue);
163
nsresult mResult; /* this is the return result of the called function */
164
nsXPTMethodInfo *mMethodInfo;
165
PRUint32 mMethodIndex; /* which method to be called? */
166
nsXPTCVariant *mParameterList; /* marshalled in parameter buffer */
167
PRUint32 mParameterCount; /* number of params */
168
PLEvent *mEvent; /* the current plevent */
169
PRInt32 mCompleted; /* is true when the method has been called. */
171
nsCOMPtr<nsIEventQueue> mCallersEventQ; /* this is the eventQ that we must post a message back to
172
when we are done invoking the method (only PROXY_SYNC).
175
nsRefPtr<nsProxyObject> mOwner; /* this is the strong referenced nsProxyObject */
177
void RefCountInInterfacePointers(PRBool addRef);
178
void CopyStrings(PRBool copy);