[BACK]Return to serv1.c CVS log [TXT][DIR] Up to [local] / OpenXM / src / ox_math

Annotation of OpenXM/src/ox_math/serv1.c, Revision 1.23

1.1       ohara       1: /* -*- mode: C; coding: euc-japan -*- */
1.23    ! ohara       2: /* $OpenXM: OpenXM/src/ox_math/serv1.c,v 1.22 2003/02/13 01:29:38 ohara Exp $ */
1.8       ohara       3:
                      4: /*
                      5:    Copyright (C) Katsuyoshi OHARA, 2000.
                      6:    Portions copyright 1999 Wolfram Research, Inc.
                      7:
                      8:    You must see OpenXM/Copyright/Copyright.generic.
                      9:    The MathLink Library is licensed from Wolfram Research Inc..
                     10:    See OpenXM/Copyright/Copyright.mathlink for detail.
                     11: */
1.1       ohara      12:
                     13: #include <stdio.h>
                     14: #include <stdlib.h>
                     15: #include <unistd.h>
                     16: #include <signal.h>
                     17: #include <mathlink.h>
1.9       ohara      18: #include <ox_toolkit.h>
1.13      ohara      19: #include "sm.h"
1.1       ohara      20:
1.13      ohara      21: extern OXFILE *stack_oxfp;
1.1       ohara      22:
1.15      ohara      23: static int exchange_ox_sync_ball(OXFILE *oxfp)
1.1       ohara      24: {
                     25:     int tag;
1.22      ohara      26:        ox_printf("exchanging OX_SYNC_BALL\n");
1.15      ohara      27:     send_ox_tag(oxfp, OX_SYNC_BALL);
                     28:     while((tag = receive_ox_tag(oxfp)) != OX_SYNC_BALL) {
1.1       ohara      29:         if (tag == OX_DATA) {
1.15      ohara      30:             receive_cmo(oxfp);
                     31:         }else if (tag == OX_COMMAND) {
                     32:             receive_int32(oxfp);
1.1       ohara      33:         }
                     34:     }
                     35: }
                     36:
1.14      ohara      37: int shutdown()
                     38: {
                     39:     oxf_close(stack_oxfp);
                     40:     ml_exit();
                     41:     exit(0);
                     42: }
                     43:
1.21      ohara      44: /* (Heisei)15/02/01 */
1.23    ! ohara      45: #define VERSION  "2003/02/01"
1.14      ohara      46:
                     47: int main()
                     48: {
                     49:     OXFILE* sv;
                     50:
1.21      ohara      51:     ox_stderr_init(stderr);
1.14      ohara      52:     ml_init();
1.23    ! ohara      53:     mathcap_init(VERSION, "ox_math");
1.14      ohara      54:
                     55:     sv = oxf_open(3);
                     56:     oxf_determine_byteorder_server(sv);
                     57:     sm(sv);
                     58:     shutdown();
                     59: }
                     60:
1.7       ohara      61: /* a part of stack machine. */
1.13      ohara      62: int sm_receive_ox()
1.1       ohara      63: {
                     64:     int tag;
                     65:     int code;
                     66:
1.13      ohara      67:     tag = receive_ox_tag(stack_oxfp);
                     68:     if (oxf_error(stack_oxfp)) {
                     69:         return 0;
                     70:     }
1.1       ohara      71:     switch(tag) {
                     72:     case OX_DATA:
1.13      ohara      73:         push(receive_cmo(stack_oxfp));
1.1       ohara      74:         break;
                     75:     case OX_COMMAND:
1.13      ohara      76:         code = receive_sm_command(stack_oxfp);
                     77:         sm_run(code);
1.1       ohara      78:         break;
                     79:     default:
1.21      ohara      80:         ox_printf("illeagal OX message(%d)\n", tag);
1.1       ohara      81:         break;
                     82:     }
1.13      ohara      83:     return 1;
1.1       ohara      84: }
                     85:
1.13      ohara      86: int sm(OXFILE *oxfp)
                     87: {
1.21      ohara      88:     int i=0;
1.16      ohara      89:     fd_set fdmask;
1.13      ohara      90:     stack_oxfp = oxfp;
                     91:     stack_extend();
1.21      ohara      92:     sm_siginit();
1.16      ohara      93:
                     94:     FD_ZERO(&fdmask);
                     95:     FD_SET(oxf_fileno(oxfp), &fdmask);
1.15      ohara      96:
1.22      ohara      97:     for (i=0; ; i++) {
                     98:         sm_sigunmask();
1.21      ohara      99:         ox_printf("phase%d: select\n",i);
1.18      ohara     100:         if (select(5, &fdmask, NULL, NULL, NULL) > 0) {
1.21      ohara     101:             sm_sigmask();
                    102:             ox_printf("phase%d: receiving\n",i);
1.16      ohara     103:             sm_receive_ox();
1.21      ohara     104:         }
1.22      ohara     105:         sm_sigmask();
1.21      ohara     106:         ox_printf("phase%d: clearing(%d)\n",i,sm_state_interrupting());
                    107:         if (sm_state_interrupting()) {
                    108:             exchange_ox_sync_ball(stack_oxfp);
                    109:             sm_state_clear_interrupting();
1.1       ohara     110:         }
                    111:     }
1.21      ohara     112:     ox_printf("ox_math::socket(%d) is closed.\n", stack_oxfp->fd);
1.1       ohara     113: }

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