=================================================================== RCS file: /home/cvs/OpenXM/src/ox_math/serv1.c,v retrieving revision 1.1.1.1 retrieving revision 1.12 diff -u -p -r1.1.1.1 -r1.12 --- OpenXM/src/ox_math/serv1.c 1999/10/29 08:06:41 1.1.1.1 +++ OpenXM/src/ox_math/serv1.c 2000/12/03 15:19:23 1.12 @@ -1,24 +1,31 @@ /* -*- mode: C; coding: euc-japan -*- */ -/* $OpenXM$ */ -/* $Id: serv1.c,v 1.1.1.1 1999/10/29 08:06:41 ohara Exp $ */ +/* $OpenXM: OpenXM/src/ox_math/serv1.c,v 1.11 2000/11/28 20:16:03 ohara Exp $ */ +/* + Copyright (C) Katsuyoshi OHARA, 2000. + Portions copyright 1999 Wolfram Research, Inc. + + You must see OpenXM/Copyright/Copyright.generic. + The MathLink Library is licensed from Wolfram Research Inc.. + See OpenXM/Copyright/Copyright.mathlink for detail. +*/ + #include #include #include #include -#include #include -#include "ox.h" +#include #include "serv2.h" -extern MLINK lp; -static int sv_read = 3; -static int sv_write = 4; +static int send_ox_sync_ball(); +static OXFILE *sv; + static int flag_sigusr1 = 0; static int flag_sigusr2 = 0; -/* 1 のとき割り込み禁止 */ +/* if in_critical equals to 1 then we do not permit an interrupt. */ static int in_critical = 0; static int set_critical() @@ -45,7 +52,7 @@ static int handler_reset1() if (!flag_sigusr1) { flag_sigusr1 = 1; if(critical_p()) { - send_ox_sync_ball(sv_write); + send_ox_sync_ball(); already_send_ox_sync_ball = 1; } } @@ -53,47 +60,46 @@ static int handler_reset1() static int handler_kill() { - close(3); - close(4); + oxf_close(sv); exit(1); } -static int send_ox_sync_ball(int fd) +static int send_ox_sync_ball() { fprintf(stderr, "sending a sync_ball.\n"); - send_ox_tag(fd, OX_SYNC_BALL); + send_ox_tag(sv, OX_SYNC_BALL); } -static int exchange_ox_syncball(int fd) +static int exchange_ox_syncball() { int tag; - while((tag = receive_ox_tag(fd)) != OX_SYNC_BALL) { + while((tag = receive_ox_tag(sv)) != OX_SYNC_BALL) { /* skipping a message. */ if (tag == OX_DATA) { - receive_cmo(fd); + receive_cmo(sv); }else { - receive_int32(fd); + receive_int32(sv); } } fprintf(stderr, "received a sync_ball.\n"); } -/* スタックマシン部分 */ -int receive_ox(int fd_read, int fd_write) +/* a part of stack machine. */ +int receive_ox(OXFILE *oxfp) { int tag; int code; - tag = receive_ox_tag(fd_read); + tag = receive_ox_tag(oxfp); switch(tag) { case OX_DATA: - push(receive_cmo(fd_read)); + push(receive_cmo(oxfp)); break; case OX_COMMAND: - code = receive_sm_command(fd_read); + code = receive_sm_command(oxfp); set_critical(); - execute_sm_command(fd_write, code); + execute_sm_command(oxfp, code); unset_critical(); break; default: @@ -104,28 +110,39 @@ int receive_ox(int fd_read, int fd_write) return 0; } +int shutdown() +{ + oxf_close(sv); + ml_exit(); + exit(0); +} + +#define VERSION 0x11121400 +#define ID_STRING "2000/11/29" + int main() { - MATH_init(); - initialize_stack(); + sv = oxf_open(3); + ml_init(); + mathcap_init(VERSION, ID_STRING, "ox_math", NULL, NULL); + signal(SIGUSR1, handler_reset1); signal(SIGKILL, handler_kill); - /* バイトオーダの決定 */ - decideByteOrder2(sv_read, sv_write, 0); + oxf_determine_byteorder_server(sv); while(1) { - receive_ox(sv_read, sv_write); + receive_ox(sv); if(flag_sigusr1) { if (!already_send_ox_sync_ball) { - send_ox_sync_ball(sv_write); + send_ox_sync_ball(); already_send_ox_sync_ball = 1; } - exchange_ox_syncball(sv_read); + exchange_ox_syncball(); flag_sigusr1 = 0; already_send_ox_sync_ball = 0; } } - MATH_exit(); + shutdown(); }