midltests async...
[metze/samba/wip.git] / testprogs / win32 / midltests / midltests.idl
1 #ifndef MIDLTESTS_C_CODE
2
3 /*
4  * For midltests_tcp.exe you may want to
5  * redirect the traffic via rinetd
6  * with a /etc/rinetd.conf like this:
7  *
8  * 172.31.9.1 5032 172.31.9.8 5032
9  * 172.31.9.1 5064 172.31.9.8 5064
10  *
11  * This is useful to watch the traffic with
12  * a network sniffer.
13  */
14 /*
15 cpp_quote("#define LISTEN_IP \"0.0.0.0\"")
16 cpp_quote("#define FORWARD_IP \"127.0.0.1\"")
17 cpp_quote("#define CONNECT_IP \"172.31.9.1\"")
18 */
19
20 /*
21  * With midltests_tcp.exe NDR64 is enforced by default.
22  * For testing it might be needed to allow downgrades
23  * to NDR32. This is needed when you use 'pipe'.
24  */
25 cpp_quote("#define DONOT_FORCE_NDR64 1")
26
27 [
28   uuid("225b9fcb-eb3d-497b-8b0b-591f049a2507"),
29   pointer_default(unique)
30 ]
31 interface midltests
32 {
33         typedef pipe char pipe_char;
34         typedef pipe hyper pipe_hyper;
35         typedef struct {
36                 long l;
37                 short s;
38         } structtype;
39         typedef pipe structtype pipe_structtype;
40
41         struct msg {
42                 long l;
43                 [size_is(l)] char *m;
44         };
45
46         /*
47          * async pipes need to be passed by reference
48          */
49         long midltests_fn(
50                 [out,ref] struct msg *out1,
51                 [out,ref] pipe_structtype *outp,
52                 [in,ref] pipe_structtype *inp,
53                 [in] struct msg in1
54         );
55
56         long midltests_ping( [in] struct msg in1);
57
58 }
59
60 #elif MIDLTESTS_C_CODE
61
62 struct pipe_char_state {
63         const char *name;
64         unsigned long count;
65         unsigned long sleep;
66 };
67
68 void pipe_char_pull(
69             char * _state,
70             unsigned char * buf,
71             unsigned long esize,
72             unsigned long * ecount)
73 {
74         struct pipe_char_state *state = (struct pipe_char_state *)_state;
75
76         printf("pull1:%s: esize[%u] ecount[%u]\n",
77                 state->name, esize, *ecount);
78         *ecount = state->count--;
79         if (*ecount > esize) {
80                 *ecount = esize;
81         }
82         memset(buf, 0xDD, *ecount * sizeof(*buf));
83         printf("pull2:%s: esize[%u] ecount[%u]\n",
84                 state->name, esize, *ecount);
85 }
86
87 void pipe_char_push(
88             char * _state,
89             unsigned char * buf,
90             unsigned long ecount)
91 {
92         struct pipe_char_state *state = (struct pipe_char_state *)_state;
93
94         printf("push:%s: ecount[%u]\n",
95                 state->name, ecount);
96 }
97
98 void pipe_char_alloc(
99             char * _state,
100             unsigned long bsize,
101             unsigned char * * buf,
102             unsigned long * bcount)
103 {
104         struct pipe_char_state *state = (struct pipe_char_state *)_state;
105
106         printf("alloc1:%s: bsize[%u], bcount[%u]\n",
107                 state->name, bsize, *bcount);
108         *bcount = bsize / sizeof(**buf);
109         *buf = malloc(*bcount * sizeof(**buf));
110         printf("alloc2:%s: bsize[%u], bcount[%u]\n",
111                 state->name, bsize, *bcount);
112 }
113
114 struct pipe_hyper_state {
115         const char *name;
116         unsigned long count;
117         unsigned long sleep;
118 };
119
120 void pipe_hyper_pull(
121             char * _state,
122             hyper * buf,
123             unsigned long esize,
124             unsigned long * ecount)
125 {
126         struct pipe_hyper_state *state = (struct pipe_hyper_state *)_state;
127
128         printf("pull1:%s: esize[%u] ecount[%u]\n",
129                 state->name, esize, *ecount);
130         *ecount = state->count--;
131         if (*ecount > esize) {
132                 *ecount = esize;
133         }
134         memset(buf, 0xDD, *ecount * sizeof(*buf));
135         printf("pull2:%s: esize[%u] ecount[%u]\n",
136                 state->name, esize, *ecount);
137 }
138
139 void pipe_hyper_push(
140             char * _state,
141             hyper * buf,
142             unsigned long ecount)
143 {
144         struct pipe_hyper_state *state = (struct pipe_hyper_state *)_state;
145
146         printf("push:%s: ecount[%u]\n",
147                 state->name, ecount);
148 }
149
150 void pipe_hyper_alloc(
151             char * _state,
152             unsigned long bsize,
153             hyper * * buf,
154             unsigned long * bcount)
155 {
156         struct pipe_hyper_state *state = (struct pipe_hyper_state *)_state;
157
158         printf("alloc1:%s: bsize[%u], bcount[%u]\n",
159                 state->name, bsize, *bcount);
160         *bcount = bsize / sizeof(**buf);
161         *buf = malloc(*bcount * sizeof(**buf));
162         printf("alloc2:%s: bsize[%u], bcount[%u]\n",
163                 state->name, bsize, *bcount);
164 }
165 struct pipe_structtype_state {
166         const char *name;
167         unsigned long count;
168         unsigned long sleep;
169 };
170
171 RPC_STATUS pipe_structtype_pull(
172             char * _state,
173             structtype * buf,
174             unsigned long esize,
175             unsigned long * ecount)
176 {
177         struct pipe_structtype_state *state = (struct pipe_structtype_state *)_state;
178
179         printf("pull1:%s: esize[%u] ecount[%u]\n",
180                 state->name, esize, *ecount);
181         *ecount = state->count--;
182         if (*ecount > esize) {
183                 *ecount = esize;
184         }
185         memset(buf, 0xDD, *ecount * sizeof(*buf));
186         printf("pull2:%s: esize[%u] ecount[%u]\n",
187                 state->name, esize, *ecount);
188 }
189
190 RPC_STATUS pipe_structtype_push(
191             char * _state,
192             structtype * buf,
193             unsigned long ecount)
194 {
195         struct pipe_structtype_state *state = (struct pipe_structtype_state *)_state;
196
197         printf("push:%s: ecount[%u]\n",
198                 state->name, ecount);
199 }
200
201 RPC_STATUS pipe_structtype_alloc(
202             char * _state,
203             unsigned long bsize,
204             structtype * * buf,
205             unsigned long * bcount)
206 {
207         struct pipe_structtype_state *state = (struct pipe_structtype_state *)_state;
208
209         printf("alloc1:%s: bsize[%u], bcount[%u]\n",
210                 state->name, bsize, *bcount);
211         *bcount = bsize / sizeof(**buf);
212         *buf = malloc(*bcount * sizeof(**buf));
213         printf("alloc2:%s: bsize[%u], bcount[%u]\n",
214                 state->name, bsize, *bcount);
215 }
216 static void midltests(void)
217 {
218         RPC_ASYNC_STATE aping;
219         RPC_ASYNC_STATE afn;
220         long ret;
221         struct msg out1;
222         unsigned char out1b[3];
223         struct pipe_structtype_state outs;
224         ASYNC_pipe_structtype outp;
225         struct pipe_structtype_state ins;
226         ASYNC_pipe_structtype inp;
227         struct msg in1;
228         unsigned char in1b[3000];
229
230         in1.l = sizeof(in1b);
231         memset(&in1b, 0xAA, sizeof(in1b));
232         in1.m = in1b;
233
234         memset(&outs, 0, sizeof(outs));
235         outs.name = "outp";
236         memset(&outp, 0, sizeof(outp));
237         outp.pull = pipe_structtype_pull;
238         outp.push = pipe_structtype_push;
239         outp.alloc = pipe_structtype_alloc;
240         outp.state = (char *)&outs;
241
242         memset(&ins, 0, sizeof(ins));
243         ins.name = "inp";
244         ins.count = 35;
245         memset(&inp, 0, sizeof(inp));
246         inp.pull = pipe_structtype_pull;
247         inp.push = pipe_structtype_push;
248         inp.alloc = pipe_structtype_alloc;
249         inp.state = (char *)&ins;
250
251         out1.l = sizeof(out1b);
252         memset(&out1b, 0xFF, sizeof(out1b));
253         out1.m = out1b;
254
255         RpcAsyncInitializeHandle(&aping, sizeof(aping));
256         cli_midltests_ping(&aping, in1);
257         while (TRUE) {
258                 RPC_STATUS status;
259                 status = RpcAsyncCompleteCall(&aping, &ret);
260                 if (status != RPC_S_ASYNC_CALL_PENDING) {
261                         break;
262                 }
263                 Sleep(100);
264         }
265         RpcAsyncInitializeHandle(&afn, sizeof(afn));
266         cli_midltests_fn(&afn, &out1, &outp, &inp, in1);
267         while (TRUE) {
268                 RPC_STATUS status;
269                 status = RpcAsyncCompleteCall(&aping, &ret);
270                 if (status != RPC_S_ASYNC_CALL_PENDING) {
271                         break;
272                 }
273                 Sleep(100);
274         }
275 }
276
277 void srv_midltests_fn(
278         PRPC_ASYNC_STATE midltests_fn_AsyncHandle,
279             /* [ref][out] */ struct msg *out1,
280     /* [out] */ ASYNC_pipe_structtype *outp,
281     /* [in] */ ASYNC_pipe_structtype *inp,
282     /* [in] */ struct msg in1)
283 {
284         long ret;
285         structtype inb[2500];
286         unsigned long inb_len = 0;
287         structtype *outb = NULL;
288         unsigned long outb_size = 0;
289         unsigned long outb_len = 0;
290
291         printf("srv_midltests_fn: Start\n");
292         fflush(stdout);
293
294         do {
295                 inp->pull(inp->state, inb, sizeof(inb), &inb_len);
296                 printf("pull inp_len[%u]\n", inb_len);
297                 fflush(stdout);
298         } while (inb_len > 0);
299
300         outb_size = 50;
301         do {
302                 outp->alloc(outp->state, outb_size, &outb, &outb_len);
303                 memset(outb, 0xCC, outb_len * sizeof(*outb));
304                 printf("push outb_len[%u]\n", outb_len);
305                 fflush(stdout);
306                 outp->push(outp->state, outb, outb_len);
307                 //Sleep(1000);
308                 outb_size--;
309         } while (outb_len > 0);
310
311         out1->l = 3;
312         out1->m = (unsigned char *)malloc(out1->l);
313         memset(out1->m, 0xBB, out1->l);
314         printf("srv_midltests_fn: End\n");
315         fflush(stdout);
316         ret = 0x65757254;
317         RpcAsyncCompleteCall(midltests_fn_AsyncHandle, &ret);
318 }
319
320 void srv_midltests_ping(
321         PRPC_ASYNC_STATE midltests_ping_AsyncHandle,
322     /* [in] */ struct msg in1)
323 {
324         long ret;
325         printf("srv_midltests_ping: Start\n");
326         printf("srv_midltests_ping: End\n");
327         ret = 0x65757254;
328         RpcAsyncCompleteCall(midltests_ping_AsyncHandle, &ret);
329 }
330 #endif