File: AsyncCalls.cs

package info (click to toggle)
mono-reference-assemblies 3.12.1%2Bdfsg-2
  • links: PTS, VCS
  • area: main
  • in suites: stretch
  • size: 604,240 kB
  • ctags: 625,505
  • sloc: cs: 3,967,741; xml: 2,793,081; ansic: 418,042; java: 60,435; sh: 14,833; makefile: 11,576; sql: 7,956; perl: 1,467; cpp: 1,446; yacc: 1,203; python: 598; asm: 422; sed: 16; php: 1
file content (190 lines) | stat: -rw-r--r-- 7,373 bytes parent folder | download | duplicates (15)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
//
// MonoTests.Remoting.AsyncCalls.cs
//
// Author: Lluis Sanchez Gual (lluis@ximian.com)
//
// 2003 (C) Copyright, Ximian, Inc.
//

using System;
using System.Collections;
using System.Threading;
using NUnit.Framework;
using System.Text;
using System.Runtime.InteropServices;

namespace MonoTests.Remoting
{
	public abstract class AsyncCallTest : BaseCallTest
	{
		public override InstanceSurrogate GetInstanceSurrogate () { return new AsyncInstanceSurrogate (); }
		public override AbstractSurrogate GetAbstractSurrogate () { return new AsyncAbstractSurrogate (); }
		public override InterfaceSurrogate GetInterfaceSurrogate () { return new AsyncInterfaceSurrogate (); }

		public static void DoWork ()
		{
			for (int n=0; n<10; n++)
				Thread.Sleep (1);
		}
	}

	public delegate int DelegateSimple ();
	public delegate string DelegatePrimitiveParams (int a, uint b, char c, string d);
	public delegate string DelegatePrimitiveParamsInOut (ref int a1, out int a2, ref float b1, out float b2, int filler, ref char c1, out char c2, ref string d1, out string d2);
	public delegate Complex DelegateComplexParams (ArrayList a, Complex b, string c);
	public delegate Complex DelegateComplexParamsInOut (ref ArrayList a, out Complex b, byte[] bytes, StringBuilder sb, string c);
	public delegate void DelegateProcessContextData ();

	public class AsyncInstanceSurrogate : InstanceSurrogate
	{
		public override int Simple ()
		{
			DelegateSimple de = new DelegateSimple (RemoteObject.Simple);
			IAsyncResult ar = de.BeginInvoke (null,null);
			AsyncCallTest.DoWork ();
			return de.EndInvoke (ar);
		}

		public override string PrimitiveParams (int a, uint b, char c, string d)
		{
			DelegatePrimitiveParams de = new DelegatePrimitiveParams (RemoteObject.PrimitiveParams);
			IAsyncResult ar = de.BeginInvoke (a,b,c,d,null,null);
			AsyncCallTest.DoWork ();
			return de.EndInvoke (ar);
		}

		public override string PrimitiveParamsInOut (ref int a1, out int a2, ref float b1, out float b2, int filler, ref char c1, out char c2, ref string d1, out string d2)
		{
			DelegatePrimitiveParamsInOut de = new DelegatePrimitiveParamsInOut (RemoteObject.PrimitiveParamsInOut);
			IAsyncResult ar = de.BeginInvoke (ref a1, out a2, ref b1, out b2, filler, ref c1, out c2, ref d1, out d2, null,null);
			AsyncCallTest.DoWork ();
			return de.EndInvoke (ref a1, out a2, ref b1, out b2, ref c1, out c2, ref d1, out d2, ar);
		}

		public override Complex ComplexParams (ArrayList a, Complex b, string c)
		{
			DelegateComplexParams de = new DelegateComplexParams (RemoteObject.ComplexParams);
			IAsyncResult ar = de.BeginInvoke (a,b,c,null,null);
			AsyncCallTest.DoWork ();
			return de.EndInvoke (ar);
		}

		public override Complex ComplexParamsInOut (ref ArrayList a, out Complex b, [In,Out] byte[] bytes, StringBuilder sb, string c)
		{
			DelegateComplexParamsInOut de = new DelegateComplexParamsInOut (RemoteObject.ComplexParamsInOut);
			IAsyncResult ar = de.BeginInvoke (ref a, out b, bytes, sb, c, null,null);
			AsyncCallTest.DoWork ();
			return de.EndInvoke (ref a, out b, ar);
		}

		public override void ProcessContextData ()
		{
			DelegateProcessContextData de = new DelegateProcessContextData (RemoteObject.ProcessContextData);
			IAsyncResult ar = de.BeginInvoke (null,null);
			AsyncCallTest.DoWork ();
			de.EndInvoke (ar);
		}
	}

	public class AsyncAbstractSurrogate : AbstractSurrogate
	{
		public override int Simple ()
		{
			DelegateSimple de = new DelegateSimple (RemoteObject.Simple);
			IAsyncResult ar = de.BeginInvoke (null,null);
			AsyncCallTest.DoWork ();
			return de.EndInvoke (ar);
		}

		public override string PrimitiveParams (int a, uint b, char c, string d)
		{
			DelegatePrimitiveParams de = new DelegatePrimitiveParams (RemoteObject.PrimitiveParams);
			IAsyncResult ar = de.BeginInvoke (a,b,c,d,null,null);
			AsyncCallTest.DoWork ();
			return de.EndInvoke (ar);
		}

		public override string PrimitiveParamsInOut (ref int a1, out int a2, ref float b1, out float b2, int filler, ref char c1, out char c2, ref string d1, out string d2)
		{
			DelegatePrimitiveParamsInOut de = new DelegatePrimitiveParamsInOut (RemoteObject.PrimitiveParamsInOut);
			IAsyncResult ar = de.BeginInvoke (ref a1, out a2, ref b1, out b2, filler, ref c1, out c2, ref d1, out d2, null,null);
			AsyncCallTest.DoWork ();
			return de.EndInvoke (ref a1, out a2, ref b1, out b2, ref c1, out c2, ref d1, out d2, ar);
		}

		public override Complex ComplexParams (ArrayList a, Complex b, string c)
		{
			DelegateComplexParams de = new DelegateComplexParams (RemoteObject.ComplexParams);
			IAsyncResult ar = de.BeginInvoke (a,b,c,null,null);
			AsyncCallTest.DoWork ();
			return de.EndInvoke (ar);
		}

		public override Complex ComplexParamsInOut (ref ArrayList a, out Complex b, [In,Out] byte[] bytes, StringBuilder sb, string c)
		{
			DelegateComplexParamsInOut de = new DelegateComplexParamsInOut (RemoteObject.ComplexParamsInOut);
			IAsyncResult ar = de.BeginInvoke (ref a, out b, bytes, sb, c, null,null);
			AsyncCallTest.DoWork ();
			return de.EndInvoke (ref a, out b, ar);
		}

		public override void ProcessContextData ()
		{
			DelegateProcessContextData de = new DelegateProcessContextData (RemoteObject.ProcessContextData);
			IAsyncResult ar = de.BeginInvoke (null,null);
			AsyncCallTest.DoWork ();
			de.EndInvoke (ar);
		}
	}

	public class AsyncInterfaceSurrogate : InterfaceSurrogate
	{
		public override int Simple ()
		{
			DelegateSimple de = new DelegateSimple (RemoteObject.Simple);
			IAsyncResult ar = de.BeginInvoke (null,null);
			AsyncCallTest.DoWork ();
			return de.EndInvoke (ar);
		}

		public override string PrimitiveParams (int a, uint b, char c, string d)
		{
			DelegatePrimitiveParams de = new DelegatePrimitiveParams (RemoteObject.PrimitiveParams);
			IAsyncResult ar = de.BeginInvoke (a,b,c,d,null,null);
			AsyncCallTest.DoWork ();
			return de.EndInvoke (ar);
		}

		public override string PrimitiveParamsInOut (ref int a1, out int a2, ref float b1, out float b2, int filler, ref char c1, out char c2, ref string d1, out string d2)
		{
			DelegatePrimitiveParamsInOut de = new DelegatePrimitiveParamsInOut (RemoteObject.PrimitiveParamsInOut);
			IAsyncResult ar = de.BeginInvoke (ref a1, out a2, ref b1, out b2, filler, ref c1, out c2, ref d1, out d2, null,null);
			AsyncCallTest.DoWork ();
			return de.EndInvoke (ref a1, out a2, ref b1, out b2, ref c1, out c2, ref d1, out d2, ar);
		}

		public override Complex ComplexParams (ArrayList a, Complex b, string c)
		{
			DelegateComplexParams de = new DelegateComplexParams (RemoteObject.ComplexParams);
			IAsyncResult ar = de.BeginInvoke (a,b,c,null,null);
			AsyncCallTest.DoWork ();
			return de.EndInvoke (ar);
		}

		public override Complex ComplexParamsInOut (ref ArrayList a, out Complex b, [In,Out] byte[] bytes, StringBuilder sb, string c)
		{
			DelegateComplexParamsInOut de = new DelegateComplexParamsInOut (RemoteObject.ComplexParamsInOut);
			IAsyncResult ar = de.BeginInvoke (ref a, out b, bytes, sb, c, null,null);
			AsyncCallTest.DoWork ();
			return de.EndInvoke (ref a, out b, ar);
		}

		public override void ProcessContextData ()
		{
			DelegateProcessContextData de = new DelegateProcessContextData (RemoteObject.ProcessContextData);
			IAsyncResult ar = de.BeginInvoke (null,null);
			AsyncCallTest.DoWork ();
			de.EndInvoke (ar);
		}
	}
}