Annotation of OpenXM/src/ox_toolkit/testclient.c, Revision 1.2
1.1 ohara 1: /* -*- mode: C -*- */
1.2 ! takayama 2: /* $OpenXM: OpenXM/src/ox_toolkit/testclient.c,v 1.1 1999/12/15 05:21:25 ohara Exp $ */
1.1 ohara 3:
4: /* A sample implementation of an OpenXM client with OpenXM C library */
5:
6: #include <stdio.h>
7: #include <stdlib.h>
8: #include <unistd.h>
9: #include <string.h>
10: #include <errno.h>
11: #include <fcntl.h>
12: #include "ox.h"
13:
14: ox_file_t sv;
15:
16: int dumpx(int fd, int n)
17: {
18: unsigned char buff[2048];
19: int i;
20: int len = read(fd, buff, n);
21:
22: fprintf(stderr, "I have read %d byte from socket.\n", len);
23: for(i = 0; i < len; i++) {
24: fprintf(stderr, "%02x ", buff[i]);
25: if (i%20 == 19) {
26: fprintf(stderr, "\n");
27: }
28: }
29: fprintf(stderr, "\n");
30: return len;
31: }
32:
33: #define VERSION 0x11121500
34: #define ID_STRING "testclient version 0.11121500"
35:
36: int prompt()
37: {
38: printf("> ");
39: }
40:
41: int test_0()
42: {
43: cmo* c = NULL;
44: #ifdef DEBUG
45: fprintf(stderr, "testclient:: calling ox_mathcap().\n");
46: c = ox_mathcap(sv);
47: fprintf(stderr, "testclient:: cmo received.(%p)\n", c);
48: #else
49: c = ox_mathcap(sv);
50: #endif
51: print_cmo(c);
52: fflush(stderr);
53: send_ox_cmo(sv->stream, make_mathcap_object(VERSION, ID_STRING));
54:
55: ox_reset(sv);
56: send_ox_cmo(sv->stream, new_cmo_string("N[ArcTan[1]]"));
57: send_ox_command(sv->stream, SM_executeStringByLocalParser);
58: send_ox_command(sv->stream, SM_popCMO);
59: receive_ox_tag(sv->stream);
60: c = receive_cmo(sv->stream);
61: fprintf(stderr, "testclient:: cmo received.\n");
62: print_cmo(c);
63: }
64:
65: int test_1()
66: {
67: cmo *c = NULL;
68: cmo *m = make_mathcap_object(1000, "test!");
69: fprintf(stderr, "testclient:: test cmo_mathcap.\n");
70: send_ox_cmo(sv->stream, m);
71: send_ox_command(sv->stream, SM_popCMO);
72: receive_ox_tag(sv->stream);
73: c = receive_cmo(sv->stream);
74: fprintf(stderr, "testclient:: cmo received.(%p)\n", c);
75: print_cmo(c);
76: fputc('\n', stderr);
77: }
1.2 ! takayama 78:
! 79: /* Example:
! 80: testclient
! 81: >(OX_DATA,(CMO_INT32,123))
! 82: >(OX_COMMAND,(SM_popCMO))
! 83: */
1.1 ohara 84:
85: int main(int argc, char* argv[])
86: {
87: ox* m = NULL;
88: cmo* c = NULL;
89: int code;
90: char *server = "ox_sm1";
91:
92: setbuf(stderr, NULL);
93:
94: if (argc>1) {
95: server = argv[1];
96: }
97: fprintf(stderr, "testclient:: I use %s as an OX server.\n", server);
98: sv = ox_start("localhost", "ox", server);
99: if (sv == NULL) {
100: fprintf(stderr, "testclient:: I cannot connect to servers.\n");
101: exit(1);
102: }
103:
104: if (strcmp(server, "ox_math")==0) {
105: test_1();
106: }
107:
108: while(prompt(), (m = parse()) != NULL) {
109: send_ox(sv->stream, m);
110: if (m->tag == OX_COMMAND) {
111: code = ((ox_command *)m)->command;
112: if (code >= 1024) {
113: break;
114: }else if (code == SM_popCMO || code == SM_popString) {
115: receive_ox_tag(sv->stream);
116: c = receive_cmo(sv->stream);
117: fprintf(stderr, "testclient:: cmo received.\n");
118: print_cmo(c);
119: }
120: }
121: }
122:
123: ox_reset(sv);
124: fprintf(stderr, "The testclient resets.\n");
125: ox_close(sv);
126: fprintf(stderr, "The testclient halts.\n");
127:
128: return 0;
129: }
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>