midltests/todo: add some random idl files I had tested month ago
[metze/samba/wip.git] / testprogs / win32 / midltests / todo / midltests-pipe-03-hyper.idl
1 #ifndef MIDLTESTS_C_CODE
2
3 [
4   uuid("225b9fcb-eb3d-497b-8b0b-591f049a2507"),
5   pointer_default(unique)
6 ]
7 interface midltests
8 {
9         typedef pipe char pipe_char;
10         typedef pipe hyper pipe_hyper;
11
12         struct msg {
13                 long l;
14                 [size_is(l)] char *m;
15         };
16
17         long midltests_fn(
18                 [out,ref] struct msg *out1,
19                 [out] pipe_hyper outp,
20                 [in] pipe_hyper inp,
21                 [in] struct msg in1
22         );
23 }
24
25 #elif MIDLTESTS_C_CODE
26 \r
27 struct pipe_char_state {\r
28         const char *name;\r
29         unsigned long count;\r
30         unsigned long sleep;\r
31 };\r
32 \r
33 void pipe_char_pull(\r
34             char * _state,\r
35             unsigned char * buf,\r
36             unsigned long esize,\r
37             unsigned long * ecount)\r
38 {\r
39         struct pipe_char_state *state = (struct pipe_char_state *)_state;\r
40 \r
41         printf("pull1:%s: esize[%u] ecount[%u]\n",\r
42                 state->name, esize, *ecount);\r
43         *ecount = state->count--;\r
44         if (*ecount > esize) {\r
45                 *ecount = esize;\r
46         }\r
47         memset(buf, 0xDD, *ecount * sizeof(*buf));
48         printf("pull2:%s: esize[%u] ecount[%u]\n",\r
49                 state->name, esize, *ecount);\r
50 }\r
51 \r
52 void pipe_char_push(\r
53             char * _state,\r
54             unsigned char * buf,\r
55             unsigned long ecount)\r
56 {\r
57         struct pipe_char_state *state = (struct pipe_char_state *)_state;\r
58 \r
59         printf("push:%s: ecount[%u]\n",\r
60                 state->name, ecount);\r
61 }\r
62 \r
63 void pipe_char_alloc(\r
64             char * _state,\r
65             unsigned long bsize,\r
66             unsigned char * * buf,\r
67             unsigned long * bcount)\r
68 {\r
69         struct pipe_char_state *state = (struct pipe_char_state *)_state;\r
70 \r
71         printf("alloc1:%s: bsize[%u], bcount[%u]\n",\r
72                 state->name, bsize, *bcount);\r
73         *bcount = bsize / sizeof(**buf);\r
74         *buf = malloc(*bcount * sizeof(**buf));\r
75         printf("alloc2:%s: bsize[%u], bcount[%u]\n",\r
76                 state->name, bsize, *bcount);\r
77 }\r
78
79 struct pipe_hyper_state {
80         const char *name;
81         unsigned long count;
82         unsigned long sleep;
83 };
84
85 void pipe_hyper_pull(
86             char * _state,
87             hyper * buf,
88             unsigned long esize,
89             unsigned long * ecount)
90 {
91         struct pipe_hyper_state *state = (struct pipe_hyper_state *)_state;
92
93         printf("pull1:%s: esize[%u] ecount[%u]\n",
94                 state->name, esize, *ecount);
95         *ecount = state->count--;
96         if (*ecount > esize) {
97                 *ecount = esize;
98         }
99         memset(buf, 0xDD, *ecount * sizeof(*buf));
100         printf("pull2:%s: esize[%u] ecount[%u]\n",
101                 state->name, esize, *ecount);
102 }
103
104 void pipe_hyper_push(
105             char * _state,
106             hyper * buf,
107             unsigned long ecount)
108 {
109         struct pipe_hyper_state *state = (struct pipe_hyper_state *)_state;
110
111         printf("push:%s: ecount[%u]\n",
112                 state->name, ecount);
113 }
114
115 void pipe_hyper_alloc(
116             char * _state,
117             unsigned long bsize,
118             hyper * * buf,
119             unsigned long * bcount)
120 {
121         struct pipe_hyper_state *state = (struct pipe_hyper_state *)_state;
122
123         printf("alloc1:%s: bsize[%u], bcount[%u]\n",
124                 state->name, bsize, *bcount);
125         *bcount = bsize / sizeof(**buf);
126         *buf = malloc(*bcount * sizeof(**buf));
127         printf("alloc2:%s: bsize[%u], bcount[%u]\n",
128                 state->name, bsize, *bcount);
129 }
130 static void midltests(void)
131 {
132         struct msg out1;
133         unsigned char out1b[3];
134         struct pipe_hyper_state outs;
135         pipe_hyper outp;
136         struct pipe_hyper_state ins;
137         pipe_hyper inp;
138         struct msg in1;
139         unsigned char in1b[3];
140
141         in1.l = sizeof(in1b);
142         memset(&in1b, 0xAA, sizeof(in1b));
143         in1.m = in1b;
144
145         memset(&outs, 0, sizeof(outs));
146         outs.name = "outp";
147         memset(&outp, 0, sizeof(outp));
148         outp.pull = pipe_hyper_pull;
149         outp.push = pipe_hyper_push;
150         outp.alloc = pipe_hyper_alloc;
151         outp.state = (char *)&outs;
152
153         memset(&ins, 0, sizeof(ins));
154         ins.name = "inp";
155         ins.count = 1;
156         memset(&inp, 0, sizeof(inp));
157         inp.pull = pipe_hyper_pull;
158         inp.push = pipe_hyper_push;
159         inp.alloc = pipe_hyper_alloc;
160         inp.state = (char *)&ins;
161
162         out1.l = sizeof(out1b);
163         memset(&out1b, 0xFF, sizeof(out1b));
164         out1.m = out1b;
165
166         cli_midltests_fn(&out1, outp, inp, in1);
167 }
168
169 long srv_midltests_fn(
170             /* [ref][out] */ struct msg *out1,\r
171     /* [out] */ pipe_hyper outp,
172     /* [in] */ pipe_hyper inp,
173     /* [in] */ struct msg in1)
174 {
175         hyper inb[500];
176         unsigned long inb_len = 0;
177         hyper *outb = NULL;
178         unsigned long outb_size = 0;
179         unsigned long outb_len = 0; 
180
181         printf("srv_midltests_fn: Start\n");
182
183         do {
184                 inp.pull(inp.state, inb, sizeof(inb), &inb_len);
185                 printf("pull inp_len[%u]\n", inb_len);
186         } while (inb_len > 0);
187
188         outb_size = 5;
189         do {
190                 outp.alloc(outp.state, outb_size, &outb, &outb_len);
191                 memset(outb, 0xCC, outb_len * sizeof(*outb));
192                 outp.push(outp.state, outb, outb_len);
193                 printf("push outb_len[%u]\n", outb_len);
194                 //Sleep(1000);
195                 outb_size--;
196         } while (outb_len > 0);
197
198         out1->l = 3;
199         out1->m = (unsigned char *)malloc(out1->l);
200         memset(out1->m, 0xBB, out1->l);
201         printf("srv_midltests_fn: End\n");
202         return 0x65757254;
203 }
204
205 #endif