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

1.1       ohara       1: /* -*- mode: C; coding: euc-japan -*- */
1.15    ! ohara       2: /* $OpenXM: OpenXM/src/ox_math/serv1.c,v 1.14 2000/12/03 22:09:34 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.14      ohara      23: /* if in_critical equals to 1 then we do not permit an interrupt. */
1.1       ohara      24: static int flag_sigusr1 = 0;
                     25:
                     26: /* SM_control_reset_connection */
1.15    ! ohara      27: static void handler()
1.1       ohara      28: {
                     29:     fprintf(stderr, "signal received.\n");
1.15    ! ohara      30:     signal(SIGUSR1, handler);
        !            31:     flag_sigusr1++;
1.1       ohara      32: }
                     33:
1.15    ! ohara      34: static int exchange_ox_sync_ball(OXFILE *oxfp)
1.1       ohara      35: {
                     36:     int tag;
1.15    ! ohara      37:     send_ox_tag(oxfp, OX_SYNC_BALL);
        !            38:     while((tag = receive_ox_tag(oxfp)) != OX_SYNC_BALL) {
1.1       ohara      39:         if (tag == OX_DATA) {
1.15    ! ohara      40:             receive_cmo(oxfp);
        !            41:         }else if (tag == OX_COMMAND) {
        !            42:             receive_int32(oxfp);
1.1       ohara      43:         }
                     44:     }
                     45: }
                     46:
1.14      ohara      47: int shutdown()
                     48: {
                     49:     oxf_close(stack_oxfp);
                     50:     ml_exit();
                     51:     exit(0);
                     52: }
                     53:
                     54: #define VERSION 0x11121400
                     55: #define ID_STRING  "2000/11/29"
                     56:
                     57: int main()
                     58: {
                     59:     OXFILE* sv;
                     60:
                     61:     ml_init();
                     62:     mathcap_init(VERSION, ID_STRING, "ox_math", NULL, NULL);
                     63:
1.15    ! ohara      64:     signal(SIGUSR1, handler);
1.14      ohara      65:
                     66:     sv = oxf_open(3);
                     67:     oxf_determine_byteorder_server(sv);
                     68:     sm(sv);
                     69:     shutdown();
                     70: }
                     71:
1.7       ohara      72: /* a part of stack machine. */
1.13      ohara      73: int sm_receive_ox()
1.1       ohara      74: {
                     75:     int tag;
                     76:     int code;
                     77:
1.13      ohara      78:     tag = receive_ox_tag(stack_oxfp);
                     79:     if (oxf_error(stack_oxfp)) {
                     80:         return 0;
                     81:     }
1.1       ohara      82:     switch(tag) {
                     83:     case OX_DATA:
1.13      ohara      84:         push(receive_cmo(stack_oxfp));
1.1       ohara      85:         break;
                     86:     case OX_COMMAND:
1.13      ohara      87:         code = receive_sm_command(stack_oxfp);
                     88:         sm_run(code);
1.1       ohara      89:         break;
                     90:     default:
                     91:         fprintf(stderr, "illeagal message? ox_tag = (%d)\n", tag);
                     92:         break;
                     93:     }
1.13      ohara      94:     return 1;
1.1       ohara      95: }
                     96:
1.13      ohara      97: int sm(OXFILE *oxfp)
                     98: {
1.15    ! ohara      99:        int mask;
1.13      ohara     100:     stack_oxfp = oxfp;
                    101:     stack_extend();
1.15    ! ohara     102:
        !           103:     mask = sigsetmask(sigmask(SIGUSR1));
1.13      ohara     104:     while(sm_receive_ox()) {
1.15    ! ohara     105:         sigsetmask(mask);
        !           106:         usleep(1);
        !           107:         sigsetmask(sigmask(SIGUSR1));
1.1       ohara     108:         if(flag_sigusr1) {
1.15    ! ohara     109:             exchange_ox_sync_ball(oxfp);
1.1       ohara     110:             flag_sigusr1 = 0;
                    111:         }
                    112:     }
1.13      ohara     113:     fprintf(stderr, "SM: socket(%d) is closed.\n", stack_oxfp->fd);
1.1       ohara     114: }

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