| 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 |
|
|---|
| 11 | struct msg {
|
|---|
| 12 | long l;
|
|---|
| 13 | [size_is(l)] char *m;
|
|---|
| 14 | };
|
|---|
| 15 |
|
|---|
| 16 | long midltests_fn(
|
|---|
| 17 | [out,ref] struct msg *out1,
|
|---|
| 18 | [out] pipe_char outp,
|
|---|
| 19 | [in] pipe_char inp,
|
|---|
| 20 | [in] struct msg in1
|
|---|
| 21 | );
|
|---|
| 22 | }
|
|---|
| 23 |
|
|---|
| 24 | #elif MIDLTESTS_C_CODE
|
|---|
| 25 |
|
|---|
| 26 | struct pipe_char_state {
|
|---|
| 27 | const char *name;
|
|---|
| 28 | unsigned long count;
|
|---|
| 29 | unsigned long sleep;
|
|---|
| 30 | };
|
|---|
| 31 |
|
|---|
| 32 | void pipe_char_pull(
|
|---|
| 33 | char * _state,
|
|---|
| 34 | unsigned char * buf,
|
|---|
| 35 | unsigned long esize,
|
|---|
| 36 | unsigned long * ecount)
|
|---|
| 37 | {
|
|---|
| 38 | struct pipe_char_state *state = (struct pipe_char_state *)_state;
|
|---|
| 39 |
|
|---|
| 40 | printf("pull1:%s: esize[%u] ecount[%u]\n",
|
|---|
| 41 | state->name, esize, *ecount);
|
|---|
| 42 | *ecount = state->count--;
|
|---|
| 43 | if (*ecount > esize) {
|
|---|
| 44 | *ecount = esize;
|
|---|
| 45 | }
|
|---|
| 46 | memset(buf, 0xDD, *ecount);
|
|---|
| 47 | printf("pull2:%s: esize[%u] ecount[%u]\n",
|
|---|
| 48 | state->name, esize, *ecount);
|
|---|
| 49 | }
|
|---|
| 50 |
|
|---|
| 51 | void pipe_char_push(
|
|---|
| 52 | char * _state,
|
|---|
| 53 | unsigned char * buf,
|
|---|
| 54 | unsigned long ecount)
|
|---|
| 55 | {
|
|---|
| 56 | struct pipe_char_state *state = (struct pipe_char_state *)_state;
|
|---|
| 57 |
|
|---|
| 58 | printf("push:%s: ecount[%u]\n",
|
|---|
| 59 | state->name, ecount);
|
|---|
| 60 | }
|
|---|
| 61 |
|
|---|
| 62 | void pipe_char_alloc(
|
|---|
| 63 | char * _state,
|
|---|
| 64 | unsigned long bsize,
|
|---|
| 65 | unsigned char * * buf,
|
|---|
| 66 | unsigned long * bcount)
|
|---|
| 67 | {
|
|---|
| 68 | struct pipe_char_state *state = (struct pipe_char_state *)_state;
|
|---|
| 69 |
|
|---|
| 70 | printf("alloc1:%s: bsize[%u], bcount[%u]\n",
|
|---|
| 71 | state->name, bsize, *bcount);
|
|---|
| 72 | *bcount = bsize / sizeof(**buf);
|
|---|
| 73 | *buf = malloc(*bcount * sizeof(**buf));
|
|---|
| 74 | printf("alloc2:%s: bsize[%u], bcount[%u]\n",
|
|---|
| 75 | state->name, bsize, *bcount);
|
|---|
| 76 | }
|
|---|
| 77 |
|
|---|
| 78 | static void midltests(void)
|
|---|
| 79 | {
|
|---|
| 80 | struct msg out1;
|
|---|
| 81 | unsigned char out1b[3];
|
|---|
| 82 | struct pipe_char_state outs;
|
|---|
| 83 | pipe_char outp;
|
|---|
| 84 | struct pipe_char_state ins;
|
|---|
| 85 | pipe_char inp;
|
|---|
| 86 | struct msg in1;
|
|---|
| 87 | unsigned char in1b[3];
|
|---|
| 88 |
|
|---|
| 89 | in1.l = sizeof(in1b);
|
|---|
| 90 | memset(&in1b, 0xAA, sizeof(in1b));
|
|---|
| 91 | in1.m = in1b;
|
|---|
| 92 |
|
|---|
| 93 | memset(&outs, 0, sizeof(outs));
|
|---|
| 94 | outs.name = "outp";
|
|---|
| 95 | memset(&outp, 0, sizeof(outp));
|
|---|
| 96 | outp.pull = pipe_char_pull;
|
|---|
| 97 | outp.push = pipe_char_push;
|
|---|
| 98 | outp.alloc = pipe_char_alloc;
|
|---|
| 99 | outp.state = (char *)&outs;
|
|---|
| 100 |
|
|---|
| 101 | memset(&ins, 0, sizeof(ins));
|
|---|
| 102 | ins.name = "inp";
|
|---|
| 103 | ins.count = 1;
|
|---|
| 104 | memset(&inp, 0, sizeof(inp));
|
|---|
| 105 | inp.pull = pipe_char_pull;
|
|---|
| 106 | inp.push = pipe_char_push;
|
|---|
| 107 | inp.alloc = pipe_char_alloc;
|
|---|
| 108 | inp.state = (char *)&ins;
|
|---|
| 109 |
|
|---|
| 110 | out1.l = sizeof(out1b);
|
|---|
| 111 | memset(&out1b, 0xFF, sizeof(out1b));
|
|---|
| 112 | out1.m = out1b;
|
|---|
| 113 |
|
|---|
| 114 | cli_midltests_fn(&out1, outp, inp, in1);
|
|---|
| 115 | }
|
|---|
| 116 |
|
|---|
| 117 | long srv_midltests_fn(
|
|---|
| 118 | /* [ref][out] */ struct msg *out1,
|
|---|
| 119 | /* [out] */ pipe_char outp,
|
|---|
| 120 | /* [in] */ pipe_char inp,
|
|---|
| 121 | /* [in] */ struct msg in1)
|
|---|
| 122 | {
|
|---|
| 123 | char inb[500];
|
|---|
| 124 | unsigned long inb_len = 0;
|
|---|
| 125 | char *outb = NULL;
|
|---|
| 126 | unsigned long outb_size = 0;
|
|---|
| 127 | unsigned long outb_len = 0;
|
|---|
| 128 |
|
|---|
| 129 | printf("srv_midltests_fn: Start\n");
|
|---|
| 130 |
|
|---|
| 131 | do {
|
|---|
| 132 | inp.pull(inp.state, inb, sizeof(inb), &inb_len);
|
|---|
| 133 | printf("pull inp_len[%u]\n", inb_len);
|
|---|
| 134 | } while (inb_len > 0);
|
|---|
| 135 |
|
|---|
| 136 | outb_size = 5;
|
|---|
| 137 | do {
|
|---|
| 138 | outp.alloc(outp.state, outb_size, &outb, &outb_len);
|
|---|
| 139 | memset(outb, 0xCC, outb_len);
|
|---|
| 140 | outp.push(outp.state, outb, outb_len);
|
|---|
| 141 | printf("push outb_len[%u]\n", outb_len);
|
|---|
| 142 | //Sleep(1000);
|
|---|
| 143 | outb_size--;
|
|---|
| 144 | } while (outb_len > 0);
|
|---|
| 145 |
|
|---|
| 146 | out1->l = 3;
|
|---|
| 147 | out1->m = (unsigned char *)malloc(out1->l);
|
|---|
| 148 | memset(out1->m, 0xBB, out1->l);
|
|---|
| 149 | printf("srv_midltests_fn: End\n");
|
|---|
| 150 | return 0x65757254;
|
|---|
| 151 | }
|
|---|
| 152 |
|
|---|
| 153 | #endif
|
|---|