version 1.2, 2000/03/10 12:24:40 |
version 1.4, 2003/01/11 11:42:32 |
|
|
/* -*- mode: C -*- */ |
/* -*- mode: C -*- */ |
/* $OpenXM: OpenXM/src/ox_toolkit/sample2.c,v 1.1 1999/12/16 06:55:07 ohara Exp $ */ |
/* $OpenXM: OpenXM/src/ox_toolkit/sample2.c,v 1.3 2000/10/10 05:23:21 ohara Exp $ */ |
|
|
/* |
/* |
This program explains how to get |
This program explains how to get |
|
|
#include <unistd.h> |
#include <unistd.h> |
#include "ox_toolkit.h" |
#include "ox_toolkit.h" |
|
|
int explain_cmo(cmo *); |
void explain_cmo(cmo *); |
|
|
int explain_cmo_list(cmo_list *c) |
void explain_cmo_list(cmo_list *c) |
{ |
{ |
int len=length_cmo_list(c); |
int len=list_length(c); |
int i=0; |
int i=0; |
printf("{"); |
printf("{"); |
for(i=0; i<len; i++) { |
for(i=0; i<len; i++) { |
explain_cmo(nth_cmo_list(c, i)); |
explain_cmo(list_nth(c, i)); |
printf(", "); |
printf(", "); |
} |
} |
printf("}"); |
printf("}"); |
} |
} |
|
|
int explain_cmo_int32(cmo_int32 *c) |
void explain_cmo_int32(cmo_int32 *c) |
{ |
{ |
printf("%d", c->i); |
printf("%d", c->i); |
} |
} |
|
|
int explain_cmo_string(cmo_string *c) |
void explain_cmo_string(cmo_string *c) |
{ |
{ |
printf("%s", c->s); |
printf("%s", c->s); |
} |
} |
|
|
int explain_cmo_zz(cmo_zz *c) |
void explain_cmo_zz(cmo_zz *c) |
{ |
{ |
printf("%s", new_string_set_cmo((cmo *)c)); |
printf("%s", new_string_set_cmo((cmo *)c)); |
} |
} |
|
|
int explain_cmo(cmo *c) |
void explain_cmo(cmo *c) |
{ |
{ |
switch(c->tag) { |
switch(c->tag) { |
case CMO_LIST: |
case CMO_LIST: |
explain_cmo_list((cmo_list *)c); |
explain_cmo_list((cmo_list *)c); |
break; |
break; |
case CMO_INT32: |
case CMO_INT32: |
explain_cmo_int32((cmo_int32 *)c); |
explain_cmo_int32((cmo_int32 *)c); |
break; |
break; |
case CMO_STRING: |
case CMO_STRING: |
explain_cmo_string((cmo_string *)c); |
explain_cmo_string((cmo_string *)c); |
break; |
break; |
case CMO_ZZ: |
case CMO_ZZ: |
explain_cmo_zz((cmo_zz *)c); |
explain_cmo_zz((cmo_zz *)c); |
break; |
break; |
default: |
default: |
printf("cmo"); |
printf("cmo"); |
} |
} |
} |
} |
|
|
int main() |
int main() |
{ |
{ |
ox_file_t s; |
OXFILE *s; |
cmo_list *c; |
cmo_list *c; |
cmo *d; |
cmo *d; |
int len; |
|
int i; |
|
|
|
/* starting an OpenXM server */ |
ox_stderr_init(NULL); |
|
/* starting an OpenXM server */ |
s = ox_start("localhost", "ox", "ox_sm1"); |
s = ox_start("localhost", "ox", "ox_sm1"); |
|
|
/* making a list. */ |
/* making a list. */ |
c = new_cmo_list(); |
c = list_appendl(new_cmo_list(), |
append_cmo_list(c, (cmo *)new_cmo_int32(10000)); |
(cmo *)new_cmo_int32(10000), |
append_cmo_list(c, (cmo *)new_cmo_string("Hello")); |
(cmo *)new_cmo_string("Hello"), |
append_cmo_list(c, (cmo *)new_cmo_zz_set_string("3141592653289793238462643383279")); |
(cmo *)new_cmo_zz_set_string("3141592653289793238462643383279"), |
|
NULL); |
|
|
/* The following equals to ox_push_cmo(s, (cmo *)c) */ |
ox_push_cmo(s, (cmo *)c); |
send_ox_tag(s->stream, OX_DATA); |
ox_push_cmd(s, SM_popCMO); |
send_cmo(s->stream, (cmo *)c); |
|
|
|
/* The following equals to ox_push_cmd(s, SM_popCMO) */ |
/* The following equals to ox_get(s) */ |
send_ox_tag(s->stream, OX_COMMAND); |
receive_ox_tag(s); |
send_int32(s->stream, SM_popCMO); |
d = receive_cmo(s); |
|
explain_cmo(d); |
/* The following equals to ox_get(s) */ |
printf("\n"); |
receive_ox_tag(s->stream); |
|
d = receive_cmo(s->stream); |
|
explain_cmo(d); |
|
printf("\n"); |
|
|
|
ox_close(s); |
ox_close(s); |
return 0; |
return 0; |