1
1
using System ;
2
2
using System . Collections . Generic ;
3
- using System . Runtime . Remoting . Messaging ;
4
3
using System . Threading ;
5
4
using System . Threading . Tasks ;
6
5
@@ -22,7 +21,7 @@ public class InvokeResult {
22
21
public Value [ ] OutArgs { get ; set ; }
23
22
}
24
23
25
- public class ObjectMirror : Value {
24
+ public class ObjectMirror : Value , IInvocableMethodOwnerMirror {
26
25
TypeMirror type ;
27
26
AppDomainMirror domain ;
28
27
@@ -142,37 +141,43 @@ public long Address {
142
141
}
143
142
}
144
143
145
- public Value InvokeMethod ( ThreadMirror thread , MethodMirror method , IList < Value > arguments ) {
146
- return InvokeMethod ( vm , thread , method , this , arguments , InvokeOptions . None ) ;
144
+ Value IInvocableMethodOwnerMirror . GetThisObject ( ) {
145
+ return this ;
147
146
}
148
147
149
- public Value InvokeMethod ( ThreadMirror thread , MethodMirror method , IList < Value > arguments , InvokeOptions options ) {
150
- return InvokeMethod ( vm , thread , method , this , arguments , options ) ;
148
+ void IInvocableMethodOwnerMirror . ProcessResult ( InvokeResult result )
149
+ {
150
+ }
151
+
152
+ // Public invocation API
153
+
154
+ public static Value InvokeMethod ( IInvocableMethodOwnerMirror mirror , ThreadMirror thread , MethodMirror method , IList < Value > arguments , InvokeOptions options = InvokeOptions . None ) {
155
+ return InvokeMethod ( mirror , mirror . VirtualMachine , thread , method , mirror . GetThisObject ( ) , arguments , options ) ;
151
156
}
152
157
153
158
[ Obsolete ( "Use the overload without the 'vm' argument" ) ]
154
- public IAsyncResult BeginInvokeMethod ( VirtualMachine vm , ThreadMirror thread , MethodMirror method , IList < Value > arguments , InvokeOptions options , AsyncCallback callback , object state ) {
155
- return BeginInvokeMethod ( vm , thread , method , this , arguments , options , callback , state ) ;
159
+ public static IAsyncResult BeginInvokeMethod ( IInvocableMethodOwnerMirror mirror , VirtualMachine vm , ThreadMirror thread , MethodMirror method , IList < Value > arguments , InvokeOptions options , AsyncCallback callback , object state ) {
160
+ return BeginInvokeMethod ( vm , thread , method , mirror . GetThisObject ( ) , arguments , options , callback , state ) ;
156
161
}
157
162
158
- public IAsyncResult BeginInvokeMethod ( ThreadMirror thread , MethodMirror method , IList < Value > arguments , InvokeOptions options , AsyncCallback callback , object state ) {
159
- return BeginInvokeMethod ( vm , thread , method , this , arguments , options , callback , state ) ;
163
+ public static IAsyncResult BeginInvokeMethod ( IInvocableMethodOwnerMirror mirror , ThreadMirror thread , MethodMirror method , IList < Value > arguments , InvokeOptions options , AsyncCallback callback , object state ) {
164
+ return BeginInvokeMethod ( mirror . VirtualMachine , thread , method , mirror . GetThisObject ( ) , arguments , options , callback , state ) ;
160
165
}
161
166
162
- public Value EndInvokeMethod ( IAsyncResult asyncResult ) {
163
- return EndInvokeMethodInternal ( asyncResult ) ;
167
+ public static Value EndInvokeMethod ( IInvocableMethodOwnerMirror mirror , IAsyncResult asyncResult ) {
168
+ return EndInvokeMethodInternal ( mirror , asyncResult ) ;
164
169
}
165
170
166
- public InvokeResult EndInvokeMethodWithResult ( IAsyncResult asyncResult ) {
167
- return ObjectMirror . EndInvokeMethodInternalWithResult ( asyncResult ) ;
171
+ public static InvokeResult EndInvokeMethodWithResult ( IInvocableMethodOwnerMirror mirror , IAsyncResult asyncResult ) {
172
+ return EndInvokeMethodInternalWithResult ( mirror , asyncResult ) ;
168
173
}
169
174
170
- public Task < Value > InvokeMethodAsync ( ThreadMirror thread , MethodMirror method , IList < Value > arguments , InvokeOptions options = InvokeOptions . None ) {
175
+ public static Task < Value > InvokeMethodAsync ( IInvocableMethodOwnerMirror mirror , ThreadMirror thread , MethodMirror method , IList < Value > arguments , InvokeOptions options = InvokeOptions . None ) {
171
176
var tcs = new TaskCompletionSource < Value > ( ) ;
172
- BeginInvokeMethod ( thread , method , arguments , options , iar =>
177
+ BeginInvokeMethod ( mirror , thread , method , arguments , options , iar =>
173
178
{
174
179
try {
175
- tcs . SetResult ( EndInvokeMethod ( iar ) ) ;
180
+ tcs . SetResult ( EndInvokeMethod ( mirror , iar ) ) ;
176
181
} catch ( OperationCanceledException ) {
177
182
tcs . TrySetCanceled ( ) ;
178
183
} catch ( Exception ex ) {
@@ -182,12 +187,12 @@ public Task<Value> InvokeMethodAsync (ThreadMirror thread, MethodMirror method,
182
187
return tcs . Task ;
183
188
}
184
189
185
- public Task < InvokeResult > InvokeMethodAsyncWithResult ( ThreadMirror thread , MethodMirror method , IList < Value > arguments , InvokeOptions options = InvokeOptions . None ) {
190
+ public static Task < InvokeResult > InvokeMethodAsyncWithResult ( IInvocableMethodOwnerMirror mirror , ThreadMirror thread , MethodMirror method , IList < Value > arguments , InvokeOptions options = InvokeOptions . None ) {
186
191
var tcs = new TaskCompletionSource < InvokeResult > ( ) ;
187
- BeginInvokeMethod ( thread , method , arguments , options , iar =>
192
+ BeginInvokeMethod ( mirror , thread , method , arguments , options , iar =>
188
193
{
189
194
try {
190
- tcs . SetResult ( EndInvokeMethodInternalWithResult ( iar ) ) ;
195
+ tcs . SetResult ( EndInvokeMethodInternalWithResult ( mirror , iar ) ) ;
191
196
} catch ( OperationCanceledException ) {
192
197
tcs . TrySetCanceled ( ) ;
193
198
} catch ( Exception ex ) {
@@ -202,11 +207,11 @@ public Task<InvokeResult> InvokeMethodAsyncWithResult (ThreadMirror thread, Meth
202
207
// finished. The callback will be called with a different IAsyncResult that represents one method invocation.
203
208
// From protocol version 2.22.
204
209
//
205
- public IAsyncResult BeginInvokeMultiple ( ThreadMirror thread , MethodMirror [ ] methods , IList < IList < Value > > arguments , InvokeOptions options , AsyncCallback callback , object state ) {
206
- return BeginInvokeMultiple ( vm , thread , methods , this , arguments , options , callback , state ) ;
210
+ public static IAsyncResult BeginInvokeMultiple ( IInvocableMethodOwnerMirror mirror , ThreadMirror thread , MethodMirror [ ] methods , IList < IList < Value > > arguments , InvokeOptions options , AsyncCallback callback , object state ) {
211
+ return BeginInvokeMultiple ( mirror . VirtualMachine , thread , methods , mirror . GetThisObject ( ) , arguments , options , callback , state ) ;
207
212
}
208
213
209
- public void EndInvokeMultiple ( IAsyncResult asyncResult ) {
214
+ public static void EndInvokeMultiple ( IAsyncResult asyncResult ) {
210
215
EndInvokeMultipleInternal ( asyncResult ) ;
211
216
}
212
217
@@ -281,7 +286,7 @@ public void Abort ()
281
286
if ( ID == 0 ) // Ooops
282
287
return ;
283
288
284
- ObjectMirror . AbortInvoke ( VM , Thread , ID ) ;
289
+ AbortInvoke ( VM , Thread , ID ) ;
285
290
}
286
291
}
287
292
@@ -334,7 +339,13 @@ static void InvokeCB (ValueImpl v, ValueImpl exc, ValueImpl out_this, ValueImpl[
334
339
r . Callback . BeginInvoke ( r , null , null ) ;
335
340
}
336
341
337
- internal static InvokeResult EndInvokeMethodInternalWithResult ( IAsyncResult asyncResult ) {
342
+ internal static InvokeResult EndInvokeMethodInternalWithResult ( IInvocableMethodOwnerMirror mirror , IAsyncResult asyncResult ) {
343
+ var result = EndInvokeMethodInternalWithResultImpl ( asyncResult ) ;
344
+ mirror . ProcessResult ( result ) ;
345
+ return result ;
346
+ }
347
+
348
+ internal static InvokeResult EndInvokeMethodInternalWithResultImpl ( IAsyncResult asyncResult ) {
338
349
if ( asyncResult == null )
339
350
throw new ArgumentNullException ( "asyncResult" ) ;
340
351
@@ -368,8 +379,8 @@ internal static InvokeResult EndInvokeMethodInternalWithResult (IAsyncResult asy
368
379
}
369
380
}
370
381
371
- internal static Value EndInvokeMethodInternal ( IAsyncResult asyncResult ) {
372
- InvokeResult res = EndInvokeMethodInternalWithResult ( asyncResult ) ;
382
+ internal static Value EndInvokeMethodInternal ( IInvocableMethodOwnerMirror mirror , IAsyncResult asyncResult ) {
383
+ InvokeResult res = EndInvokeMethodInternalWithResult ( mirror , asyncResult ) ;
373
384
return res . Result ;
374
385
}
375
386
@@ -383,8 +394,8 @@ internal static void EndInvokeMultipleInternal (IAsyncResult asyncResult) {
383
394
r . AsyncWaitHandle . WaitOne ( ) ;
384
395
}
385
396
386
- internal static Value InvokeMethod ( VirtualMachine vm , ThreadMirror thread , MethodMirror method , Value this_obj , IList < Value > arguments , InvokeOptions options ) {
387
- return EndInvokeMethodInternal ( BeginInvokeMethod ( vm , thread , method , this_obj , arguments , options , null , null ) ) ;
397
+ internal static Value InvokeMethod ( IInvocableMethodOwnerMirror mirror , VirtualMachine vm , ThreadMirror thread , MethodMirror method , Value this_obj , IList < Value > arguments , InvokeOptions options ) {
398
+ return EndInvokeMethodInternal ( mirror , BeginInvokeMethod ( vm , thread , method , this_obj , arguments , options , null , null ) ) ;
388
399
}
389
400
390
401
internal static void AbortInvoke ( VirtualMachine vm , ThreadMirror thread , int id )
0 commit comments