Annotation of OpenXM/src/ox_math/serv1.c, Revision 1.11
1.1 ohara 1: /* -*- mode: C; coding: euc-japan -*- */
1.11 ! ohara 2: /* $OpenXM: OpenXM/src/ox_math/serv1.c,v 1.10 2000/10/10 19:58:30 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.1 ohara 19: #include "serv2.h"
20:
1.10 ohara 21: static int send_ox_sync_ball();
1.2 ohara 22:
1.10 ohara 23: static OXFILE *sv;
1.1 ohara 24:
25: static int flag_sigusr1 = 0;
26: static int flag_sigusr2 = 0;
27:
1.7 ohara 28: /* if in_critical equals to 1 then we do not permit an interrupt. */
1.1 ohara 29: static int in_critical = 0;
30:
31: static int set_critical()
32: {
33: in_critical = 1;
34: }
35:
36: static int unset_critical()
37: {
38: in_critical = 0;
39: }
40:
41: static int critical_p() {
42: return in_critical;
43: }
44:
45: static int already_send_ox_sync_ball = 0;
46:
47: /* SM_control_reset_connection */
48: static int handler_reset1()
49: {
50: fprintf(stderr, "signal received.\n");
51: signal(SIGUSR1, handler_reset1);
52: if (!flag_sigusr1) {
53: flag_sigusr1 = 1;
54: if(critical_p()) {
1.10 ohara 55: send_ox_sync_ball();
1.1 ohara 56: already_send_ox_sync_ball = 1;
57: }
58: }
59: }
60:
61: static int handler_kill()
62: {
1.10 ohara 63: oxf_close(sv);
1.1 ohara 64: exit(1);
65: }
66:
1.10 ohara 67: static int send_ox_sync_ball()
1.1 ohara 68: {
69: fprintf(stderr, "sending a sync_ball.\n");
1.10 ohara 70: send_ox_tag(sv, OX_SYNC_BALL);
1.1 ohara 71: }
72:
1.10 ohara 73: static int exchange_ox_syncball()
1.1 ohara 74: {
75: int tag;
76:
1.10 ohara 77: while((tag = receive_ox_tag(sv)) != OX_SYNC_BALL) {
1.1 ohara 78: /* skipping a message. */
79: if (tag == OX_DATA) {
1.10 ohara 80: receive_cmo(sv);
1.1 ohara 81: }else {
1.10 ohara 82: receive_int32(sv);
1.1 ohara 83: }
84: }
85: fprintf(stderr, "received a sync_ball.\n");
86: }
87:
1.7 ohara 88: /* a part of stack machine. */
1.10 ohara 89: int receive_ox(OXFILE *oxfp)
1.1 ohara 90: {
91: int tag;
92: int code;
93:
1.10 ohara 94: tag = receive_ox_tag(oxfp);
1.1 ohara 95: switch(tag) {
96: case OX_DATA:
1.10 ohara 97: push(receive_cmo(oxfp));
1.1 ohara 98: break;
99: case OX_COMMAND:
1.10 ohara 100: code = receive_sm_command(oxfp);
1.1 ohara 101: set_critical();
1.10 ohara 102: execute_sm_command(oxfp, code);
1.1 ohara 103: unset_critical();
104: break;
105: default:
106: fprintf(stderr, "illeagal message? ox_tag = (%d)\n", tag);
107: return -1;
108: break;
109: }
110: return 0;
111: }
112:
1.4 ohara 113: int shutdown()
114: {
1.10 ohara 115: oxf_close(sv);
1.6 ohara 116: ml_exit();
117: exit(0);
1.4 ohara 118: }
119:
1.11 ! ohara 120: #define VERSION 0x11121400
! 121: #define ID_STRING "2000/11/29"
! 122:
1.1 ohara 123: int main()
124: {
1.10 ohara 125: sv = oxf_open(3);
126:
1.6 ohara 127: ml_init();
1.1 ohara 128: initialize_stack();
1.11 ! ohara 129: mathcap_init(VERSION, ID_STRING, "ox_math", NULL, NULL);
1.1 ohara 130:
131: signal(SIGUSR1, handler_reset1);
132: signal(SIGKILL, handler_kill);
133:
1.10 ohara 134: oxf_determine_byteorder_server(sv);
1.1 ohara 135:
136: while(1) {
1.10 ohara 137: receive_ox(sv);
1.1 ohara 138: if(flag_sigusr1) {
139: if (!already_send_ox_sync_ball) {
1.10 ohara 140: send_ox_sync_ball();
1.1 ohara 141: already_send_ox_sync_ball = 1;
142: }
1.10 ohara 143: exchange_ox_syncball();
1.1 ohara 144: flag_sigusr1 = 0;
145: already_send_ox_sync_ball = 0;
146: }
147: }
1.4 ohara 148: shutdown();
1.1 ohara 149: }
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>