| version 1.7, 2000/11/27 09:57:10 |
version 1.9, 2003/01/11 11:42:32 |
|
|
| /* -*- mode: C -*- */ |
/* -*- mode: C -*- */ |
| /* $OpenXM: OpenXM/src/ox_toolkit/testclient.c,v 1.6 2000/11/21 07:59:08 ohara Exp $ */ |
/* $OpenXM: OpenXM/src/ox_toolkit/testclient.c,v 1.8 2000/11/28 04:24:12 ohara Exp $ */ |
| |
|
| /* A sample implementation of an OpenXM client with OpenXM C library */ |
/* A sample implementation of an OpenXM client with OpenXM C library */ |
| |
|
| Line 21 int dumpx(OXFILE *oxfp, int n) |
|
| Line 21 int dumpx(OXFILE *oxfp, int n) |
|
| int i; |
int i; |
| int len = oxf_read(buff, 1, n, oxfp); |
int len = oxf_read(buff, 1, n, oxfp); |
| |
|
| fprintf(stderr, "I have read %d byte from socket(%d).\n", len, oxfp->fd); |
fprintf(ox_stderr, "I have read %d byte from socket(%d).\n", len, oxfp->fd); |
| for(i = 0; i < len; i++) { |
for(i = 0; i < len; i++) { |
| fprintf(stderr, "%02x ", buff[i]); |
fprintf(ox_stderr, "%02x ", buff[i]); |
| if (i%20 == 19) { |
if (i%20 == 19) { |
| fprintf(stderr, "\n"); |
fprintf(ox_stderr, "\n"); |
| } |
} |
| } |
} |
| fprintf(stderr, "\n"); |
fprintf(ox_stderr, "\n"); |
| return len; |
return len; |
| } |
} |
| |
|
| Line 47 static int prompt() |
|
| Line 47 static int prompt() |
|
| #define VERSION 0x11121500 |
#define VERSION 0x11121500 |
| #define ID_STRING "v0.11121500" |
#define ID_STRING "v0.11121500" |
| |
|
| mathcap *oxf_mathcap(OXFILE *oxfp) |
|
| { |
|
| if (oxfp->mathcap == NULL) { |
|
| oxfp->mathcap = new_mathcap(); |
|
| } |
|
| return oxfp->mathcap; |
|
| } |
|
| |
|
| cmo_mathcap *oxf_cmo_mathcap(OXFILE *oxfp) |
|
| { |
|
| return mathcap_get(oxf_mathcap(oxfp)); |
|
| } |
|
| |
|
| int test_0() |
int test_0() |
| { |
{ |
| cmo* c = NULL; |
cmo* c = NULL; |
| #ifdef DEBUG |
#ifdef DEBUG |
| fprintf(stderr, "testclient:: calling ox_mathcap().\n"); |
fprintf(ox_stderr, "testclient:: calling ox_mathcap().\n"); |
| c = ox_mathcap(sv); |
c = ox_mathcap(sv); |
| fprintf(stderr, "testclient:: cmo received.(%p)\n", c); |
fprintf(ox_stderr, "testclient:: cmo received.(%p)\n", c); |
| #else |
#else |
| c = (cmo *)ox_mathcap(sv); |
c = (cmo *)ox_mathcap(sv); |
| #endif |
#endif |
| print_cmo(c); |
print_cmo(c); |
| fflush(stderr); |
fflush(ox_stderr); |
| |
|
| mathcap_init(VERSION, ID_STRING, "testclient", NULL, NULL); |
mathcap_init(VERSION, ID_STRING, "testclient", NULL, NULL); |
| send_ox_cmo(sv, oxf_cmo_mathcap(sv)); |
send_ox_cmo(sv, oxf_cmo_mathcap(sv)); |
|
|
| send_ox_command(sv, SM_popCMO); |
send_ox_command(sv, SM_popCMO); |
| receive_ox_tag(sv); |
receive_ox_tag(sv); |
| c = receive_cmo(sv); |
c = receive_cmo(sv); |
| fprintf(stderr, "testclient:: cmo received.\n"); |
fprintf(ox_stderr, "testclient:: cmo received.\n"); |
| print_cmo(c); |
print_cmo(c); |
| } |
} |
| |
|
|
|
| |
|
| mathcap_init(1000, "test!", "testclient", NULL, NULL); |
mathcap_init(1000, "test!", "testclient", NULL, NULL); |
| m = oxf_cmo_mathcap(sv); |
m = oxf_cmo_mathcap(sv); |
| fprintf(stderr, "testclient:: test cmo_mathcap.\n"); |
fprintf(ox_stderr, "testclient:: test cmo_mathcap.\n"); |
| send_ox_cmo(sv, m); |
send_ox_cmo(sv, m); |
| send_ox_command(sv, SM_popCMO); |
send_ox_command(sv, SM_popCMO); |
| receive_ox_tag(sv); |
receive_ox_tag(sv); |
| c = receive_cmo(sv); |
c = receive_cmo(sv); |
| fprintf(stderr, "testclient:: cmo received.(%p)\n", c); |
fprintf(ox_stderr, "testclient:: cmo received.(%p)\n", c); |
| print_cmo(c); |
print_cmo(c); |
| fputc('\n', stderr); |
fputc('\n', ox_stderr); |
| } |
} |
| |
|
| /* Example: |
/* Example: |
| Line 115 int main(int argc, char* argv[]) |
|
| Line 102 int main(int argc, char* argv[]) |
|
| int code; |
int code; |
| char *server = "ox_sm1"; |
char *server = "ox_sm1"; |
| |
|
| setbuf(stderr, NULL); |
ox_stderr_init(NULL); |
| |
setbuf(ox_stderr, NULL); |
| |
|
| if (argc>1) { |
if (argc>1) { |
| server = argv[1]; |
server = argv[1]; |
| } |
} |
| fprintf(stderr, "testclient:: I use %s as an OX server.\n", server); |
fprintf(ox_stderr, "testclient:: I use %s as an OX server.\n", server); |
| /* sv = ox_start("localhost", "ox", server); */ |
/* sv = ox_start("localhost", "ox", server); */ |
| if (sv == NULL) { |
if (sv == NULL) { |
| fprintf(stderr, "testclient:: I cannot connect to servers.\n"); |
fprintf(ox_stderr, "testclient:: I cannot connect to servers.\n"); |
| exit(1); |
exit(1); |
| } |
} |
| |
|
| Line 142 int main(int argc, char* argv[]) |
|
| Line 130 int main(int argc, char* argv[]) |
|
| }else if (code == SM_popCMO || code == SM_popString) { |
}else if (code == SM_popCMO || code == SM_popString) { |
| receive_ox_tag(sv); |
receive_ox_tag(sv); |
| c = receive_cmo(sv); |
c = receive_cmo(sv); |
| fprintf(stderr, "testclient:: cmo received.\n"); |
fprintf(ox_stderr, "testclient:: cmo received.\n"); |
| print_cmo(c); |
print_cmo(c); |
| } |
} |
| } |
} |
| } |
} |
| |
|
| ox_reset(sv); |
ox_reset(sv); |
| fprintf(stderr, "The testclient resets.\n"); |
fprintf(ox_stderr, "The testclient resets.\n"); |
| ox_close(sv); |
ox_close(sv); |
| fprintf(stderr, "The testclient halts.\n"); |
fprintf(ox_stderr, "The testclient halts.\n"); |
| |
|
| return 0; |
return 0; |
| } |
} |