1/* BEGIN LICENSE BLOCK
2 * Version: CMPL 1.1
3 *
4 * The contents of this file are subject to the Cisco-style Mozilla Public
5 * License Version 1.1 (the "License"); you may not use this file except
6 * in compliance with the License.  You may obtain a copy of the License
7 * at www.eclipse-clp.org/license.
8 *
9 * Software distributed under the License is distributed on an "AS IS"
10 * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied.  See
11 * the License for the specific language governing rights and limitations
12 * under the License.
13 *
14 * The Original Code is  The ECLiPSe Constraint Logic Programming System.
15 * The Initial Developer of the Original Code is  Cisco Systems, Inc.
16 * Portions created by the Initial Developer are
17 * Copyright (C) 1994-2006 Cisco Systems, Inc.  All Rights Reserved.
18 *
19 * Contributor(s):
20 *
21 * END LICENSE BLOCK */
22
23/**********************************************************************
24**      System: PDS (Parallel Distributed System)
25**              MPS (Message Passing System)
26**        File: upcalls.c
27**      Author: Kees Schuerman
28** Description: Upcall routines common to the PDS and MPS
29***********************************************************************/
30
31#include "config.h"
32#include <pds.h>	/* PDS Library Interface		      */
33
34#include <sys/types.h>
35#include <signal.h>
36#include <unistd.h>
37#include <stdio.h>
38
39
40/**********************************************************************
41** AMSG Primitives
42***********************************************************************/
43
44/*ARGSUSED*/
45void
46amsg_warn(msg_warn,culprit)
47    amsg_warn_t msg_warn;
48    aport_id_t culprit;
49{
50#ifdef DEBUG_MPS
51    (void) fprintf(stderr,"%d: amsg_warn: %d - culprit: %d ...\n",
52	    	   bport_self(),msg_warn,culprit);
53#endif
54}
55
56
57void
58amsg_error(msg_error,culprit)
59    amsg_error_t msg_error;
60    aport_id_t culprit;
61{
62    (void) fprintf(stderr,"%d: amsg_error: %d - culprit: %d ...\n",
63	           bport_self(),msg_error,culprit);
64}
65
66
67void
68amsg_panic(msg_panic,culprit)
69    amsg_panic_t msg_panic;
70    aport_id_t culprit;
71{
72    (void) fprintf(stderr,"%d: amsg_panic: %d - culprit: %d ...\n",
73	           bport_self(),msg_panic,culprit);
74}
75
76
77
78/**********************************************************************
79** BMSG Primitives
80***********************************************************************/
81
82#define BMSG_RETRIES_MAX         10000
83
84#if defined(__STDC__)
85extern void worker_bport_ack(bport_id_t port_id,
86                             bport_primitive_t port_primitive,
87                             bmsg_ret_t ret);
88extern void worker_bport_notify(bport_id_t port_id,
89                                bport_primitive_t port_primitive);
90#else
91extern void worker_bport_ack();
92extern void worker_bport_notify();
93#endif
94
95
96void
97bport_ack(port_id,port_primitive,ret)
98    bport_id_t port_id;
99    bport_primitive_t port_primitive;
100    bmsg_ret_t ret;
101{
102    if (par_present())
103	worker_bport_ack(port_id,port_primitive,ret);
104}
105
106
107void
108bport_notify(port_id,port_primitive)
109    bport_id_t port_id;
110    bport_primitive_t port_primitive;
111{
112    if (par_present())
113	worker_bport_notify(port_id,port_primitive);
114}
115
116
117/*ARGSUSED*/
118void
119bmem_ack(mem_id,mem_primitive,ret)
120    bmem_id_t mem_id;
121    bmem_primitive_t mem_primitive;
122    bmsg_ret_t ret;
123{
124#ifdef DEBUG_MPS
125    (void) fprintf(stderr,"%d: bmem_ack: mem_id: %d mem_primitive:%d ret: %d\n",
126                   bport_self(),mem_id,mem_primitive,ret);
127#endif
128}
129
130
131/*ARGSUSED*/
132void
133bmem_notify(port_id,mem_primitive,mem_address,mem_data_size)
134    bport_id_t port_id;
135    bmem_primitive_t mem_primitive;
136    bmem_address_t mem_address;
137    bmem_size_t mem_data_size;
138{
139#ifdef DEBUG_MPS
140    (void) fprintf(stderr,"%d: bmem_notify: port_id: %d %d %d %d\n",
141                   bport_self(),port_id,mem_primitive,mem_address,mem_data_size);
142#endif
143}
144
145
146void
147bmsg_warn(msg_warn,culprit)
148    bmsg_warn_t msg_warn;
149    bport_id_t culprit;
150{
151    int retries;
152    bport_t dummy;
153
154    switch (msg_warn) {
155	case BMSG_WEP_PORT :
156	    retries = 0;
157	    if (bport_port(culprit, &dummy) == BMSG_OK)
158	    {
159		while ((bport_close(culprit) != BMSG_NOPORT) &&
160                   (retries++ < BMSG_RETRIES_MAX))
161		    ;
162	    }
163	    break;
164	default :
165#ifdef DEBUG_MPS
166    	    (void) fprintf(stderr,"%d: bmsg_warn: %d - culprit: %d ...\n",
167		           bport_self(),msg_warn,culprit);
168#endif
169	    break;
170    }
171}
172
173
174void
175bmsg_error(msg_error,culprit)
176    bmsg_error_t msg_error;
177    bport_id_t culprit;
178{
179    switch (msg_error) {
180        case BMSG_WEP_PDIED :
181            if (culprit == NSRV_BPORT_ID)
182                (void) fprintf(stderr,"%d: bmsg_error: name server died !\n",
183		               bport_self());
184            else
185                (void) fprintf(stderr,"%d: bmsg_error: bport %d died !\n",
186                               bport_self(),culprit);
187            return;
188        default :
189#ifdef DEBUG_MPS
190    	    (void) fprintf(stderr,"%d: bmsg_error: %d - culprit: %d ...\n",
191		           bport_self(),msg_error,culprit);
192#endif
193            break;
194    }
195}
196
197
198void
199bmsg_panic(msg_panic,culprit)
200    bmsg_panic_t msg_panic;
201    bport_id_t culprit;
202{
203    (void) fprintf(stderr,"%d: bmsg_panic: %d - culprit: %d ...\n",
204	           bport_self(),msg_panic,culprit);
205}
206
207
208void
209bproc_trigger(port)
210    bport_t * port;
211{
212    if (port->bport_id == bport_self())
213    {
214        (void) bmsg_trigger(BMSG_INTRA_DOMAIN);
215    }
216    else if (kill((int) port->bpid, SIGIO) != 0)
217    {
218        (void) fprintf(stderr, "bport %d died\n", (int) port->bport_id);
219    }
220}
221
222
223/**********************************************************************
224** Miscellaneous
225***********************************************************************/
226
227void
228msg_trigger()
229{
230    if (bmsg_ready())
231        (void) bmsg_trigger((BMSG_INTER_DOMAIN | BMSG_INTRA_DOMAIN));
232}
233
234
235