Annotation of OpenXM/src/ox_toolkit/sample2.c, Revision 1.8
1.1 ohara 1: /* -*- mode: C -*- */
1.8 ! ohara 2: /* $OpenXM: OpenXM/src/ox_toolkit/sample2.c,v 1.7 2003/03/30 08:05:23 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.8 ! ohara 14:
! 15: OXFILE* ox_start(char* host, char* prog1, char* prog2);
1.1 ohara 16:
1.3 ohara 17: void explain_cmo(cmo *);
1.1 ohara 18:
1.3 ohara 19: void explain_cmo_list(cmo_list *c)
1.1 ohara 20: {
1.3 ohara 21: int len=list_length(c);
22: int i=0;
23: printf("{");
24: for(i=0; i<len; i++) {
25: explain_cmo(list_nth(c, i));
26: printf(", ");
27: }
28: printf("}");
1.1 ohara 29: }
30:
1.3 ohara 31: void explain_cmo_int32(cmo_int32 *c)
1.1 ohara 32: {
1.3 ohara 33: printf("%d", c->i);
1.1 ohara 34: }
35:
1.3 ohara 36: void explain_cmo_string(cmo_string *c)
1.1 ohara 37: {
1.3 ohara 38: printf("%s", c->s);
1.1 ohara 39: }
40:
1.3 ohara 41: void explain_cmo_zz(cmo_zz *c)
1.1 ohara 42: {
1.3 ohara 43: printf("%s", new_string_set_cmo((cmo *)c));
1.1 ohara 44: }
45:
1.3 ohara 46: void explain_cmo(cmo *c)
1.1 ohara 47: {
1.3 ohara 48: switch(c->tag) {
49: case CMO_LIST:
50: explain_cmo_list((cmo_list *)c);
51: break;
52: case CMO_INT32:
53: explain_cmo_int32((cmo_int32 *)c);
54: break;
55: case CMO_STRING:
56: explain_cmo_string((cmo_string *)c);
57: break;
58: case CMO_ZZ:
59: explain_cmo_zz((cmo_zz *)c);
60: break;
61: default:
62: printf("cmo");
63: }
1.1 ohara 64: }
65:
66: int main()
67: {
1.3 ohara 68: OXFILE *s;
69: cmo_list *c;
70: cmo *d;
1.1 ohara 71:
1.5 ohara 72: ox_stderr_init(stderr);
1.3 ohara 73: /* starting an OpenXM server */
1.1 ohara 74: s = ox_start("localhost", "ox", "ox_sm1");
75:
1.3 ohara 76: /* making a list. */
77: c = list_appendl(new_cmo_list(),
78: (cmo *)new_cmo_int32(10000),
79: (cmo *)new_cmo_string("Hello"),
80: (cmo *)new_cmo_zz_set_string("3141592653289793238462643383279"),
81: NULL);
82:
83: ox_push_cmo(s, (cmo *)c);
84: ox_push_cmd(s, SM_popCMO);
85:
86: /* The following equals to ox_get(s) */
87: receive_ox_tag(s);
88: d = receive_cmo(s);
89: explain_cmo(d);
90: printf("\n");
1.1 ohara 91:
92: ox_close(s);
93: return 0;
94: }
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>