Annotation of OpenXM/src/ox_toolkit/sample2.c, Revision 1.2
1.1 ohara 1: /* -*- mode: C -*- */
1.2 ! ohara 2: /* $OpenXM: OpenXM/src/ox_toolkit/sample2.c,v 1.1 1999/12/16 06:55:07 ohara Exp $ */
1.1 ohara 3:
4: /*
5: This program explains how to get
6: int, char *, and so on from the received data
7: by using low-level functions of OpenXM C library.
8: */
9:
10: #include <stdio.h>
11: #include <stdlib.h>
12: #include <unistd.h>
1.2 ! ohara 13: #include "ox_toolkit.h"
1.1 ohara 14:
15: int explain_cmo(cmo *);
16:
17: int explain_cmo_list(cmo_list *c)
18: {
19: int len=length_cmo_list(c);
20: int i=0;
21: printf("{");
22: for(i=0; i<len; i++) {
23: explain_cmo(nth_cmo_list(c, i));
24: printf(", ");
25: }
26: printf("}");
27: }
28:
29: int explain_cmo_int32(cmo_int32 *c)
30: {
31: printf("%d", c->i);
32: }
33:
34: int explain_cmo_string(cmo_string *c)
35: {
36: printf("%s", c->s);
37: }
38:
39: int explain_cmo_zz(cmo_zz *c)
40: {
41: printf("%s", new_string_set_cmo((cmo *)c));
42: }
43:
44: int explain_cmo(cmo *c)
45: {
46: switch(c->tag) {
47: case CMO_LIST:
48: explain_cmo_list((cmo_list *)c);
49: break;
50: case CMO_INT32:
51: explain_cmo_int32((cmo_int32 *)c);
52: break;
53: case CMO_STRING:
54: explain_cmo_string((cmo_string *)c);
55: break;
56: case CMO_ZZ:
57: explain_cmo_zz((cmo_zz *)c);
58: break;
59: default:
60: printf("cmo");
61: }
62: }
63:
64: int main()
65: {
66: ox_file_t s;
67: cmo_list *c;
68: cmo *d;
69: int len;
70: int i;
71:
72: /* starting an OpenXM server */
73: s = ox_start("localhost", "ox", "ox_sm1");
74:
75: /* making a list. */
76: c = new_cmo_list();
77: append_cmo_list(c, (cmo *)new_cmo_int32(10000));
78: append_cmo_list(c, (cmo *)new_cmo_string("Hello"));
79: append_cmo_list(c, (cmo *)new_cmo_zz_set_string("3141592653289793238462643383279"));
80:
81: /* The following equals to ox_push_cmo(s, (cmo *)c) */
82: send_ox_tag(s->stream, OX_DATA);
83: send_cmo(s->stream, (cmo *)c);
84:
85: /* The following equals to ox_push_cmd(s, SM_popCMO) */
86: send_ox_tag(s->stream, OX_COMMAND);
87: send_int32(s->stream, SM_popCMO);
88:
89: /* The following equals to ox_get(s) */
90: receive_ox_tag(s->stream);
91: d = receive_cmo(s->stream);
92: explain_cmo(d);
93: printf("\n");
94:
95: ox_close(s);
96: return 0;
97: }
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>