summaryrefslogtreecommitdiffstats
path: root/testprogs/win32/midltests/todo/midltests-pipe-02.idl
blob: e6be283841967e6667603b6ff51dd1d745a6916f (plain)
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
#ifndef MIDLTESTS_C_CODE

[
  uuid("225b9fcb-eb3d-497b-8b0b-591f049a2507"),
  pointer_default(unique)
]
interface midltests
{
	typedef pipe char pipe_char;

	struct msg {
		long l;
		[size_is(l)] char *m;
	};

	long midltests_fn(
		[out,ref] struct msg *out1,
		[out] pipe_char outp,
		[in] pipe_char inp,
		[in] struct msg in1
	);
}

#elif MIDLTESTS_C_CODE

struct pipe_char_state {
	const char *name;
	unsigned long count;
	unsigned long sleep;
};

void pipe_char_pull(
            char * _state,
            unsigned char * buf,
            unsigned long esize,
            unsigned long * ecount)
{
	struct pipe_char_state *state = (struct pipe_char_state *)_state;

	printf("pull1:%s: esize[%u] ecount[%u]\n",
		state->name, esize, *ecount);
	*ecount = state->count--;
	if (*ecount > esize) {
		*ecount = esize;
	}
	memset(buf, 0xDD, *ecount);
	printf("pull2:%s: esize[%u] ecount[%u]\n",
		state->name, esize, *ecount);
}

void pipe_char_push(
            char * _state,
            unsigned char * buf,
            unsigned long ecount)
{
	struct pipe_char_state *state = (struct pipe_char_state *)_state;

	printf("push:%s: ecount[%u]\n",
		state->name, ecount);
}

void pipe_char_alloc(
            char * _state,
            unsigned long bsize,
            unsigned char * * buf,
            unsigned long * bcount)
{
	struct pipe_char_state *state = (struct pipe_char_state *)_state;

	printf("alloc1:%s: bsize[%u], bcount[%u]\n",
		state->name, bsize, *bcount);
	*bcount = bsize / sizeof(**buf);
	*buf = malloc(*bcount * sizeof(**buf));
	printf("alloc2:%s: bsize[%u], bcount[%u]\n",
		state->name, bsize, *bcount);
}

static void midltests(void)
{
    struct msg out1;
	unsigned char out1b[3];
	struct pipe_char_state outs;
	pipe_char outp;
	struct pipe_char_state ins;
	pipe_char inp;
	struct msg in1;
	unsigned char in1b[3];

	in1.l = sizeof(in1b);
	memset(&in1b, 0xAA, sizeof(in1b));
	in1.m = in1b;

	memset(&outs, 0, sizeof(outs));
	outs.name = "outp";
	memset(&outp, 0, sizeof(outp));
	outp.pull = pipe_char_pull;
	outp.push = pipe_char_push;
	outp.alloc = pipe_char_alloc;
	outp.state = (char *)&outs;

	memset(&ins, 0, sizeof(ins));
	ins.name = "inp";
	ins.count = 1;
	memset(&inp, 0, sizeof(inp));
	inp.pull = pipe_char_pull;
	inp.push = pipe_char_push;
	inp.alloc = pipe_char_alloc;
	inp.state = (char *)&ins;

	out1.l = sizeof(out1b);
	memset(&out1b, 0xFF, sizeof(out1b));
	out1.m = out1b;

	cli_midltests_fn(&out1, outp, inp, in1);
}

long srv_midltests_fn(
	    /* [ref][out] */ struct msg *out1,
    /* [out] */ pipe_char outp,
    /* [in] */ pipe_char inp,
    /* [in] */ struct msg in1)
{
	char inb[500];
	unsigned long inb_len = 0;
	char *outb = NULL;
	unsigned long outb_size = 0;
	unsigned long outb_len = 0; 

	printf("srv_midltests_fn: Start\n");

	do {
		inp.pull(inp.state, inb, sizeof(inb), &inb_len);
		printf("pull inp_len[%u]\n", inb_len);
	} while (inb_len > 0);

	outb_size = 5;
	do {
		outp.alloc(outp.state, outb_size, &outb, &outb_len);
		memset(outb, 0xCC, outb_len);
		outp.push(outp.state, outb, outb_len);
		printf("push outb_len[%u]\n", outb_len);
		//Sleep(1000);
		outb_size--;
	} while (outb_len > 0);

	out1->l = 3;
	out1->m = (unsigned char *)malloc(out1->l);
	memset(out1->m, 0xBB, out1->l);
	printf("srv_midltests_fn: End\n");
	return 0x65757254;
}

#endif