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): Kees Schuerman, ECRC
20 *
21 * END LICENSE BLOCK */
22/**********************************************************************
23**      System: BMSG
24**        File: bmsg.msg.h
25**      Author: Kees Schuerman
26**      SccsId: "@(#)bmsg.msg.h	1.1 6/28/95"
27** Description: Basic Message Passing Library API
28***********************************************************************/
29
30#ifndef _BMSG_MSG_H_
31#define _BMSG_MSG_H_
32
33
34/*
35** Return Codes
36*/
37
38#define BMSG_OK              PDS_OK             /* success               */
39#define BMSG_NYI             PDS_NYI            /* not yet implemented   */
40#define BMSG_WARN            PDS_WARN           /* general warning       */
41#define BMSG_ERROR           PDS_ERROR          /* general error         */
42#define BMSG_IMPLIM          PDS_IMPLIM         /* implementation limit  */
43#define BMSG_INVAL           PDS_INVAL          /* invalid argument      */
44#define BMSG_NORESOURCES     PDS_NORESOURCES    /* no resources          */
45#define BMSG_NOMEMORY        PDS_NOMEMORY       /* no memory             */
46
47#define BMSG_NOPORT	     (PDS_RET_MAX + 1)  /* no such port          */
48#define BMSG_NOMESSAGE	     (PDS_RET_MAX + 2)  /* no message            */
49#define BMSG_NOID	     (PDS_RET_MAX + 3)  /* no identifiers 	 */
50#define BMSG_POPENED	     (PDS_RET_MAX + 4)  /* port opened	   	 */
51#define BMSG_PBLOCKED        (PDS_RET_MAX + 5)  /* port blocked     	 */
52#define BMSG_PUNBLOCKED      (PDS_RET_MAX + 6)  /* port unblocked        */
53#define BMSG_POPENING	     (PDS_RET_MAX + 7)  /* port opening        	 */
54#define BMSG_PCLOSING	     (PDS_RET_MAX + 8)  /* port closing      	 */
55#define BMSG_PBLOCKING	     (PDS_RET_MAX + 9)  /* port blocking   	 */
56#define BMSG_PUNBLOCKING     (PDS_RET_MAX + 10) /* port unblocking   	 */
57#define BMSG_PDYING          (PDS_RET_MAX + 11) /* port dying        	 */
58#define BMSG_PNOTAVAILABLE   (PDS_RET_MAX + 12) /* port not available	 */
59#define BMSG_PUNREACH        (PDS_RET_MAX + 13) /* port unreachable      */
60
61
62/*
63** Warnings, Errors, Panics
64*/
65
66#define BMSG_WEP_NONE  		0
67#define BMSG_WEP_INCONSISTENCY	1
68#define BMSG_WEP_RESOURCES	2
69#define BMSG_WEP_MEMORY  	3
70#define BMSG_WEP_ID  		4
71#define BMSG_WEP_PORT  		5
72#define BMSG_WEP_PDIED 		6
73
74
75/*
76** Message Passing System Options
77*/
78
79#define BDOMAIN_CREATE		0x01
80#define BPORT_NOTIFICATION	0x02
81#define BMEM_NOTIFICATION	0x04
82
83#define BMSG_ALOG_ON		0x10
84#define BMSG_ALOG_OPEN		0x20
85#define BMSG_ALOG_CLOSE		0x40
86#define BMSG_ALOG_MASTER	0x80
87
88
89/*
90** Message Passing Trigger Options
91*/
92
93#define BMSG_INTER_DOMAIN	0x01
94#define BMSG_INTRA_DOMAIN	0x02
95
96
97/*
98** Option Names
99*/
100
101#define BMSG_INTRA_DOMAIN_TRIGGERING	0x01
102
103
104/*
105** Option Values
106*/
107
108#define BMSG_OFF	0x00
109#define BMSG_ON		0x01
110
111
112/*
113** Message Passing System Events
114*/
115
116#define BEVENT_PORT_OPEN_ACK		0x0001
117#define BEVENT_PORT_OPEN_NOTIFY		0x0002
118#define BEVENT_PORT_CLOSE_ACK		0x0004
119#define BEVENT_PORT_CLOSE_NOTIFY	0x0008
120#define BEVENT_PORT_BLOCK_ACK		0x0010
121#define BEVENT_PORT_BLOCK_NOTIFY	0x0020
122#define BEVENT_PORT_UNBLOCK_ACK		0x0040
123#define BEVENT_PORT_UNBLOCK_NOTIFY	0x0080
124#define BEVENT_MEM_PUT_ACK		0x0100
125#define BEVENT_MEM_PUT_NOTIFY		0x0200
126#define BEVENT_MEM_GET_ACK		0x0400
127#define BEVENT_MEM_GET_NOTIFY		0x0800
128#define BEVENT_MSG			0x1000
129
130
131/*
132** Port Primitives
133*/
134
135#define BPORT_OPEN 		0x01
136#define BPORT_CLOSE		0x02
137#define BPORT_BLOCK     	0x03
138#define BPORT_UNBLOCK     	0x04
139
140
141/*
142** Memory Primitives
143*/
144
145#define BMEM_PUT 		0x05
146#define BMEM_GET 		0x06
147
148
149/*
150** Message Classes                (Message Data Size)
151*/
152
153#define BMSG_SHORT	64	/*     <=   64 bytes */
154#define BMSG_MEDIUM	512 	/*  65 ..  512 bytes */
155#define BMSG_LONG	    	/*      >  512 bytes */
156
157
158/*
159** Message Buffer Scratch Area
160*/
161
162#define BMSG_BUF_SCRATCH_BYTES	(3 * sizeof(void_ptr))
163
164
165
166/*
167** Generic Type Definitions and Associated Message Data Types
168*/
169
170#define BMSG_INTFC	1
171
172typedef pds_size_t bmsg_size_t;
173typedef pds_ret_t bmsg_ret_t;
174
175#define MDT_BMSGSIZE		MDT_SIZE
176#define MDT_BMSGRET		MDT_RET
177
178typedef pds_word_t bport_id_t;
179typedef pds_word_t bdomain_id_t;
180typedef pds_uint16 bport_number_t;
181typedef pds_word_t bpid_t;
182
183#define BPORT_ID_MAX		PDS_HALF_WORD_MAX
184#define BDOMAIN_ID_MAX		PDS_WORD_MAX
185
186#define MDT_BPORTID		MDT_WORD
187#define MDT_BDOMAINID		MDT_WORD
188#define MDT_BPORTNUMBER		MDT_UINT16
189#define MDT_BPID		MDT_WORD
190
191typedef pds_word_t bmem_id_t;
192typedef pds_size_t bmem_size_t;
193typedef pds_double_word_t bmsg_address_t;
194
195#define BMSG_ADDR_OFFSET	PDS_ADDR_OFFSET
196
197#define MDT_BMEMID		MDT_WORD
198#define MDT_BMEMSIZE		MDT_SIZE
199#define MDT_BMSGADDRESS		MDT_ADDRESS
200
201typedef void_ptr bmem_address_t;
202
203#define INET_ADDRESSLEN_MAX 32
204#define BNET_ADDRESSLEN_MAX INET_ADDRESSLEN_MAX
205
206typedef char inet_address_t[INET_ADDRESSLEN_MAX+1];
207typedef inet_address_t bnet_address_t;
208
209extern msg_type_t MDT_INETADDRESS;
210#define MDT_BNETADDRESS	MDT_INETADDRESS
211
212typedef pds_int32 bmsg_bool_t;
213typedef void_ptr bmsg_t;
214
215#define MDT_BMSGBOOL		MDT_INT32
216
217typedef msg_type_t bmsg_type_t;
218typedef msg_type_no_t bmsg_type_no_t;
219typedef msg_intfc_no_t bmsg_intfc_no_t;
220typedef msg_typedef_t bmsg_typedef_t;
221typedef msg_count_t bmsg_count_t;
222typedef msg_data_t bmsg_data_t;
223typedef pds_word_t bmsg_optval_t;
224typedef msg_option_t bmsg_option_t;
225typedef pds_word_t bmsg_optname_t;
226
227
228#define MDT_BMSGTYPE            MDT_MSGTYPE
229#define MDT_BMSGTYPENO          MDT_MSGTYPENO
230#define MDT_BMSGINTFCNO         MDT_MSGINTFCNO
231#define MDT_BMSGTYPEDEF         MDT_MSGTYPEDEF
232#define MDT_BMSGCOUNT           MDT_MSGCOUNT
233#define MDT_BMSGDATA 		MDT_MSGDATA
234#define MDT_BMSGOPTION		MDT_MSGOPTION
235#define MDT_BMSGOPTVAL		MDT_WORD
236#define MDT_BMSGOPTNAME		MDT_WORD
237
238
239#define BMSG_FILENAMELEN_MAX 255
240
241typedef struct {
242    bpid_t bpid;		       /* (local) process identifier	  */
243    bport_id_t bport_id;	       /* port identifier	          */
244    bdomain_id_t bdomain_id;	       /* domain identifier  	          */
245#if WORDS_BIGENDIAN
246    unsigned : PDS_PAD_BITS;           /* pad				  */
247    bmem_address_t bmsg_queue_address; /* address of port's message queue */
248#else /* LITTLE ENDIAN */
249    bmem_address_t bmsg_queue_address; /* address of port's message queue */
250    unsigned : PDS_PAD_BITS;           /* pad				  */
251#endif /* WORDS_BIGENDIAN */
252    bnet_address_t bnet_address;       /* network address	  	  */
253    bport_number_t bport_number;       /* port number             	  */
254} bport_t;
255
256extern msg_type_t MDT_BPORT;
257
258typedef struct {
259    bdomain_id_t bdomain_id;	  /* domain identifier		      */
260    char bdomain_file[BMSG_FILENAMELEN_MAX+1];
261				  /* shared memory backing store file */
262#if WORDS_BIGENDIAN
263    unsigned : PDS_PAD_BITS;      /* pad			      */
264    bmem_address_t bdomain_start; /* shared memory start address      */
265#else /* LITTLE ENDIAN */
266    bmem_address_t bdomain_start; /* shared memory start address      */
267    unsigned : PDS_PAD_BITS;      /* pad			      */
268#endif /* WORDS_BIGENDIAN */
269    bmem_size_t bdomain_size;     /* shared memory size 	      */
270} bdomain_t;
271
272extern msg_type_t MDT_BDOMAIN;
273
274typedef pds_dp_float bmsg_counter_t;
275
276#define MDT_BMSGCOUNTER MDT_DP_FLOAT
277
278typedef struct {
279    bmsg_counter_t sent_short;	 /* # short sized messages sent      */
280    bmsg_counter_t sent_medium;	 /* # medium sized messages sent     */
281    bmsg_counter_t sent_long;	 /* # long sized messages sent       */
282    bmsg_counter_t rcvd_short;	 /* # short sized messages received  */
283    bmsg_counter_t rcvd_medium;	 /* # medium sized messages received */
284    bmsg_counter_t rcvd_long;	 /* # long sized messages received   */
285} bmsg_info_t;
286
287typedef struct {
288    bmsg_counter_t lputs;  	 /* # puts to local memory    	     */
289    bmsg_counter_t lgets;  	 /* # gets from local memory  	     */
290    bmsg_counter_t rputs;	 /* # puts to remote memory   	     */
291    bmsg_counter_t rgets;	 /* # gets from remote memory 	     */
292} bmem_info_t;
293
294typedef struct {
295    bmsg_counter_t lputs;	 /* # puts to local memory	     */
296    bmsg_counter_t lgets;	 /* # gets from local memory	     */
297    bmsg_counter_t rputs;	 /* # puts to remote memory   	     */
298    bmsg_counter_t rgets;	 /* # gets from remote memory 	     */
299    bmsg_counter_t sends;	 /* # messages sent to port 	     */
300    bmsg_counter_t receives;	 /* # messages received from port    */
301} bport_info_t;
302
303extern msg_type_t MDT_BMSGINFO;
304extern msg_type_t MDT_BMEMINFO;
305#define MDT_BPORTINFO	MDT_BMSGINFO
306
307typedef pds_word_t bmem_primitive_t;
308typedef pds_word_t bport_primitive_t;
309
310#define MDT_BMEMPRIMITIVE	MDT_WORD
311#define MDT_BPORTPRIMITIVE	MDT_WORD
312
313typedef pds_word_t bmsg_wep_t;
314typedef bmsg_wep_t bmsg_warn_t;
315typedef bmsg_wep_t bmsg_error_t;
316typedef bmsg_wep_t bmsg_panic_t;
317
318#define MDT_BMSGWEP     MDT_WORD
319#define MDT_BMSGWARN    MDT_BMSGWEP
320#define MDT_BMSGERROR   MDT_BMSGWEP
321#define MDT_BMSGPANIC   MDT_BMSGWEP
322
323typedef struct {
324    pds_uint32 v_minor;
325    pds_uint32 v_major;
326} bmsg_version_t;
327
328extern msg_type_t MDT_BMSGVERSION;
329
330
331
332/*
333** Type System
334*/
335
336#define bmsg_type_define(IntfcNo,TypeNo,TypeDef,MsgType)	\
337	pds_type_define(IntfcNo,TypeNo,TypeDef,MsgType)
338
339#define bmsg_type_size(MsgType,Size,Option)			\
340	pds_type_size(MsgType,Size,Option)
341
342#define bmsg_type_xdr(Xdrs,MsgType,MsgData)			\
343	pds_type_xdr(Xdrs,MsgType,MsgData)
344
345
346
347/*
348** Port Primitives
349*/
350
351extern bport_id_t bport_id_local;
352
353#define bport_self()	bport_id_local
354
355
356#if defined(__STDC__)
357extern bmsg_ret_t bport_familiar(bport_id_t port_id,
358				 bmsg_bool_t * familiar);
359extern bmsg_ret_t bport_port(bport_id_t port_id,
360			     bport_t * port);
361extern bmsg_ret_t bport_open(bport_t * port);
362extern bmsg_ret_t bport_close(bport_id_t port_id);
363extern bmsg_ret_t bport_flush(bport_id_t port_id);
364extern bmsg_ret_t bport_block(bport_id_t port_id);
365extern bmsg_ret_t bport_unblock(bport_id_t port_id);
366extern void bport_ack(bport_id_t port_id,          		/* upcall */
367		      bport_primitive_t port_primitive,
368		      bmsg_ret_t ret);
369extern void bport_notify(bport_id_t port_id,			/* upcall */
370		         bport_primitive_t port_primitive);
371#else /* __STDC__ */
372extern bmsg_ret_t bport_familiar();
373extern bmsg_ret_t bport_port();
374extern bmsg_ret_t bport_open();
375extern bmsg_ret_t bport_close();
376extern bmsg_ret_t bport_flush();
377extern bmsg_ret_t bport_block();
378extern bmsg_ret_t bport_unblock();
379extern void bport_ack();					/* upcall */
380extern void bport_notify();					/* upcall */
381#endif /* __STDC__ */
382
383
384
385/*
386** Message Primitives
387*/
388
389#if defined(__STDC__)
390extern bmsg_ret_t bmsg_alloc(bmsg_size_t size,
391			     bmsg_data_t * * data,
392			     bmsg_t * msg);
393extern bmsg_ret_t bmsg_free(bmsg_t msg);
394extern bmsg_size_t bmsg_size(bmsg_t msg);
395extern bmsg_data_t * bmsg_data(bmsg_t msg);
396extern bmsg_ret_t bmsg_send(bport_id_t port_id,
397			    bmsg_t msg,
398			    bmsg_size_t size);
399extern bmsg_ret_t bmsg_receive(bmsg_t * msg,
400			       bmsg_data_t * * data,
401                               bmsg_size_t * size,
402			       bport_id_t * port_id,
403			       bmsg_bool_t * familiar);
404extern bmsg_ret_t bmsg_peek(bmsg_t * msg,
405			    bmsg_data_t * * data,
406                            bmsg_size_t * size,
407			    bport_id_t * port_id,
408			    bmsg_bool_t * familiar);
409extern void bmsg_notify(void);					/* upcall */
410#else /* __STDC__ */
411extern bmsg_ret_t bmsg_alloc();
412extern bmsg_ret_t bmsg_free();
413extern bmsg_size_t bmsg_size();
414extern bmsg_data_t * bmsg_data();
415extern bmsg_ret_t bmsg_send();
416extern bmsg_ret_t bmsg_receive();
417extern bmsg_ret_t bmsg_peek();
418extern void bmsg_notify();					/* upcall */
419#endif /* __STDC__ */
420
421
422
423/*
424** Memory Primitives
425*/
426
427#if defined(__STDC__)
428extern void bmem_cpy(bmem_address_t mem_dst_address,
429		     bmem_address_t mem_src_address,
430		     bmem_size_t mem_data_size);
431extern bmsg_ret_t bmem_put(bport_id_t port_id,
432			   bmem_id_t * mem_id,
433		           bmem_address_t mem_src_address,
434			   bmem_address_t mem_dst_address,
435			   bmem_size_t mem_data_size);
436extern bmsg_ret_t bmem_get(bport_id_t port_id,
437			   bmem_id_t * mem_id,
438		           bmem_address_t mem_src_address,
439			   bmem_address_t mem_dst_address,
440			   bmem_size_t mem_data_size);
441extern void bmem_ack(bmem_id_t mem_id,       			/* upcall */
442		     bmem_primitive_t mem_primitive,
443		     bmsg_ret_t ret);
444extern void bmem_notify(bport_id_t port_id,                     /* upcall */
445                        bmem_primitive_t mem_primitive,
446                        bmem_address_t mem_address,
447                        bmem_size_t mem_data_size);
448#else /* __STDC__ */
449extern void bmem_cpy();
450extern bmsg_ret_t bmem_put();
451extern bmsg_ret_t bmem_get();
452extern void bmem_ack();				          	/* upcall */
453extern void bmem_notify();                                      /* upcall */
454#endif /* __STDC__ */
455
456
457
458/*
459** Miscellaneous Primitives
460*/
461
462extern int bmsg_initialised;
463extern int bmsg_exited;
464extern int bmsg_exiting;
465extern bdomain_id_t bdomain_id_local;
466
467#define bmsg_ready()	(bmsg_initialised && !bmsg_exited && !bmsg_exiting)
468#define bdomain_self()	bdomain_id_local
469
470#if defined(__STDC__)
471extern bmsg_ret_t bmsg_version(bmsg_version_t * version);
472extern bmsg_ret_t bmsg_init(bport_id_t port_id,
473			    bdomain_t * domain,
474			    bmsg_option_t option);
475extern void bmsg_exit(void);
476extern bmsg_ret_t bmsg_set_option(bmsg_optname_t optname,
477                                  bmsg_optval_t optval);
478extern bmsg_ret_t bmsg_get_option(bmsg_optname_t optname,
479                                  bmsg_optval_t * optval);
480extern bmsg_ret_t bmsg_trigger(bmsg_option_t option);
481extern void bproc_trigger(bport_t * port);		  	/* upcall */
482extern void bmsg_warn(bmsg_warn_t msg_warn,		  	/* upcall */
483		      bport_id_t culprit);
484extern void bmsg_error(bmsg_error_t msg_error,		  	/* upcall */
485		       bport_id_t culprit);
486extern void bmsg_panic(bmsg_panic_t msg_panic,		  	/* upcall */
487		       bport_id_t culprit);
488extern char * bmsg_error_string(bmsg_ret_t bret);
489extern void bmsg_perror(bmsg_ret_t bret,
490			char * s);
491extern bmsg_ret_t bmsg_info(bmsg_info_t * msg_info);
492extern bmsg_ret_t bmem_info(bmem_info_t * mem_info);
493extern bmsg_ret_t bport_info(bport_id_t port_id,
494			     bport_info_t * port_info);
495extern bmsg_ret_t bmem_address(bmsg_address_t msg_address,
496			       bmem_address_t * mem_address);
497extern void bmsg_address(bmem_address_t mem_address,
498			 bmsg_address_t * msg_address);
499#else /* __STDC__ */
500extern bmsg_ret_t bmsg_version();
501extern bmsg_ret_t bmsg_init();
502extern void bmsg_exit();
503extern bmsg_ret_t bmsg_trigger();
504extern void bproc_trigger();		  		  	/* upcall */
505extern void bmsg_warn();				  	/* upcall */
506extern void bmsg_error();		  		  	/* upcall */
507extern void bmsg_panic();				  	/* upcall */
508extern char * bmsg_error_string();
509extern void bmsg_perror();
510extern bmsg_ret_t bmsg_info();
511extern bmsg_ret_t bmem_info();
512extern bmsg_ret_t bport_info();
513extern bmsg_ret_t bmem_address();
514extern void bmsg_address();
515#endif /* __STDC__ */
516
517
518#endif /* _BMSG_MSG_H_ */
519