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