[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.22

1.1       ohara       1: /* -*- mode: C; coding: euc-japan -*- */
1.22    ! ohara       2: /* $OpenXM: OpenXM/src/ox_math/serv1.c,v 1.21 2003/02/12 08:28:41 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 */
                     45: #define VERSION     0x15020100
                     46: #define ID_STRING  "2003/02/01"
1.14      ohara      47:
                     48: int main()
                     49: {
                     50:     OXFILE* sv;
                     51:
1.21      ohara      52:     ox_stderr_init(stderr);
1.14      ohara      53:     ml_init();
                     54:     mathcap_init(VERSION, ID_STRING, "ox_math", NULL, NULL);
                     55:
                     56:     sv = oxf_open(3);
                     57:     oxf_determine_byteorder_server(sv);
                     58:     sm(sv);
                     59:     shutdown();
                     60: }
                     61:
1.7       ohara      62: /* a part of stack machine. */
1.13      ohara      63: int sm_receive_ox()
1.1       ohara      64: {
                     65:     int tag;
                     66:     int code;
                     67:
1.13      ohara      68:     tag = receive_ox_tag(stack_oxfp);
                     69:     if (oxf_error(stack_oxfp)) {
                     70:         return 0;
                     71:     }
1.1       ohara      72:     switch(tag) {
                     73:     case OX_DATA:
1.13      ohara      74:         push(receive_cmo(stack_oxfp));
1.1       ohara      75:         break;
                     76:     case OX_COMMAND:
1.13      ohara      77:         code = receive_sm_command(stack_oxfp);
                     78:         sm_run(code);
1.1       ohara      79:         break;
                     80:     default:
1.21      ohara      81:         ox_printf("illeagal OX message(%d)\n", tag);
1.1       ohara      82:         break;
                     83:     }
1.13      ohara      84:     return 1;
1.1       ohara      85: }
                     86:
1.13      ohara      87: int sm(OXFILE *oxfp)
                     88: {
1.21      ohara      89:     int i=0;
1.16      ohara      90:     fd_set fdmask;
1.13      ohara      91:     stack_oxfp = oxfp;
                     92:     stack_extend();
1.21      ohara      93:     sm_siginit();
1.16      ohara      94:
                     95:     FD_ZERO(&fdmask);
                     96:     FD_SET(oxf_fileno(oxfp), &fdmask);
1.15      ohara      97:
1.22    ! ohara      98:     for (i=0; ; i++) {
        !            99:         sm_sigunmask();
1.21      ohara     100:         ox_printf("phase%d: select\n",i);
1.18      ohara     101:         if (select(5, &fdmask, NULL, NULL, NULL) > 0) {
1.21      ohara     102:             sm_sigmask();
                    103:             ox_printf("phase%d: receiving\n",i);
1.16      ohara     104:             sm_receive_ox();
1.21      ohara     105:         }
1.22    ! ohara     106:         sm_sigmask();
1.21      ohara     107:         ox_printf("phase%d: clearing(%d)\n",i,sm_state_interrupting());
                    108:         if (sm_state_interrupting()) {
                    109:             exchange_ox_sync_ball(stack_oxfp);
                    110:             sm_state_clear_interrupting();
1.1       ohara     111:         }
                    112:     }
1.21      ohara     113:     ox_printf("ox_math::socket(%d) is closed.\n", stack_oxfp->fd);
1.1       ohara     114: }

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