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

1.1       ohara       1: /* -*- mode: C; coding: euc-japan -*- */
1.21    ! ohara       2: /* $OpenXM: OpenXM/src/ox_math/serv1.c,v 1.20 2003/01/13 12:04:53 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.15      ohara      26:     send_ox_tag(oxfp, OX_SYNC_BALL);
                     27:     while((tag = receive_ox_tag(oxfp)) != OX_SYNC_BALL) {
1.1       ohara      28:         if (tag == OX_DATA) {
1.15      ohara      29:             receive_cmo(oxfp);
                     30:         }else if (tag == OX_COMMAND) {
                     31:             receive_int32(oxfp);
1.1       ohara      32:         }
                     33:     }
                     34: }
                     35:
1.14      ohara      36: int shutdown()
                     37: {
                     38:     oxf_close(stack_oxfp);
                     39:     ml_exit();
                     40:     exit(0);
                     41: }
                     42:
1.21    ! ohara      43: /* (Heisei)15/02/01 */
        !            44: #define VERSION     0x15020100
        !            45: #define ID_STRING  "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();
                     53:     mathcap_init(VERSION, ID_STRING, "ox_math", NULL, NULL);
                     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.16      ohara      97:     while(1) {
1.21    ! ohara      98:         ox_printf("phase%d: select\n",i);
1.18      ohara      99:         if (select(5, &fdmask, NULL, NULL, NULL) > 0) {
1.21    ! ohara     100:             sm_sigmask();
        !           101:             ox_printf("phase%d: receiving\n",i);
1.16      ohara     102:             sm_receive_ox();
1.21    ! ohara     103:             sm_sigunmask();  /* unmasked. */
        !           104:         }
        !           105:         ox_printf("phase%d: clearing(%d)\n",i,sm_state_interrupting());
        !           106:         if (sm_state_interrupting()) {
        !           107:             exchange_ox_sync_ball(stack_oxfp);
        !           108:             sm_state_clear_interrupting();
1.1       ohara     109:         }
1.21    ! ohara     110:         i++;
1.1       ohara     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>