[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.3

1.1       ohara       1: /* -*- mode: C -*- */
1.3     ! ohara       2: /* $OpenXM: OpenXM/src/ox_toolkit/sample2.c,v 1.2 2000/03/10 12:24:40 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.3     ! ohara      70:     /* starting an OpenXM server */
1.1       ohara      71:     s = ox_start("localhost", "ox", "ox_sm1");
                     72:
1.3     ! ohara      73:     /* making a list. */
        !            74:     c = list_appendl(new_cmo_list(),
        !            75:                      (cmo *)new_cmo_int32(10000),
        !            76:                      (cmo *)new_cmo_string("Hello"),
        !            77:                      (cmo *)new_cmo_zz_set_string("3141592653289793238462643383279"),
        !            78:                      NULL);
        !            79:
        !            80:     ox_push_cmo(s, (cmo *)c);
        !            81:     ox_push_cmd(s, SM_popCMO);
        !            82:
        !            83:     /* The following equals to ox_get(s) */
        !            84:     receive_ox_tag(s);
        !            85:     d = receive_cmo(s);
        !            86:     explain_cmo(d);
        !            87:     printf("\n");
1.1       ohara      88:
                     89:     ox_close(s);
                     90:     return 0;
                     91: }

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