[BACK]Return to sample2.c CVS log [TXT][DIR] Up to [local] / OpenXM / src / ox_toolkit

Annotation of OpenXM/src/ox_toolkit/sample2.c, Revision 1.4

1.1       ohara       1: /* -*- mode: C -*- */
1.4     ! ohara       2: /* $OpenXM: OpenXM/src/ox_toolkit/sample2.c,v 1.3 2000/10/10 05:23:21 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:
1.3       ohara      15: void explain_cmo(cmo *);
1.1       ohara      16:
1.3       ohara      17: void explain_cmo_list(cmo_list *c)
1.1       ohara      18: {
1.3       ohara      19:     int len=list_length(c);
                     20:     int i=0;
                     21:     printf("{");
                     22:     for(i=0; i<len; i++) {
                     23:         explain_cmo(list_nth(c, i));
                     24:         printf(", ");
                     25:     }
                     26:     printf("}");
1.1       ohara      27: }
                     28:
1.3       ohara      29: void explain_cmo_int32(cmo_int32 *c)
1.1       ohara      30: {
1.3       ohara      31:     printf("%d", c->i);
1.1       ohara      32: }
                     33:
1.3       ohara      34: void explain_cmo_string(cmo_string *c)
1.1       ohara      35: {
1.3       ohara      36:     printf("%s", c->s);
1.1       ohara      37: }
                     38:
1.3       ohara      39: void explain_cmo_zz(cmo_zz *c)
1.1       ohara      40: {
1.3       ohara      41:     printf("%s", new_string_set_cmo((cmo *)c));
1.1       ohara      42: }
                     43:
1.3       ohara      44: void explain_cmo(cmo *c)
1.1       ohara      45: {
1.3       ohara      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:     }
1.1       ohara      62: }
                     63:
                     64: int main()
                     65: {
1.3       ohara      66:     OXFILE *s;
                     67:     cmo_list *c;
                     68:     cmo *d;
1.1       ohara      69:
1.4     ! ohara      70:        ox_stderr_init(NULL);
1.3       ohara      71:     /* starting an OpenXM server */
1.1       ohara      72:     s = ox_start("localhost", "ox", "ox_sm1");
                     73:
1.3       ohara      74:     /* making a list. */
                     75:     c = list_appendl(new_cmo_list(),
                     76:                      (cmo *)new_cmo_int32(10000),
                     77:                      (cmo *)new_cmo_string("Hello"),
                     78:                      (cmo *)new_cmo_zz_set_string("3141592653289793238462643383279"),
                     79:                      NULL);
                     80:
                     81:     ox_push_cmo(s, (cmo *)c);
                     82:     ox_push_cmd(s, SM_popCMO);
                     83:
                     84:     /* The following equals to ox_get(s) */
                     85:     receive_ox_tag(s);
                     86:     d = receive_cmo(s);
                     87:     explain_cmo(d);
                     88:     printf("\n");
1.1       ohara      89:
                     90:     ox_close(s);
                     91:     return 0;
                     92: }

FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>