/*
 *	udc.h -- user-defined channel handling structures (all the code actually in sched.c)
 *	Copyright (C) 2001, 2002 Fred Barnes <frmb2@ukc.ac.uk>
 *
 *	This program is free software; you can redistribute it and/or modify
 *	it under the terms of the GNU General Public License as published by
 *	the Free Software Foundation; either version 2 of the License, or
 *	(at your option) any later version.
 *
 *	This program is distributed in the hope that it will be useful,
 *	but WITHOUT ANY WARRANTY; without even the implied warranty of
 *	MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *	GNU General Public License for more details.
 *
 *	You should have received a copy of the GNU General Public License
 *	along with this program; if not, write to the Free Software
 *	Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
 */

#ifndef __UDC_H
#define __UDC_H

#define UDC_NONE 0x00
#define UDC_BLOCKING_INPUT 0x01		/* inputs use bsyscalls */
#define UDC_BLOCKING_OUTPUT 0x02	/* outputs use bsyscalls */
#define UDC_BLOCKING 0x03		/* both */
#define UDC_BLOCKING_ALT 0x04		/* flags that extra synchronisation is needed */

/* frmb 01/03/02: removed #ifdef-age for MOBILEs, user-progs include this, breaks stuff if they don't define MOBILES! */
typedef struct tag_ext_chan_t {
	void *chanword;							/* used by occam! */
	unsigned int chantype;						/* used by occam! */
	void *chanbxalt;						/* used by occam! */
	void *chansync;							/* used by occam! */

	unsigned int magic;						/* place UDC_MAGIC here */
	int flags;							/* UDC_... */

	int (*chan_verify)(struct tag_ext_chan_t *, unsigned int);
	int (*chan_read)(struct tag_ext_chan_t *, char *, int);
	int (*chan_write)(struct tag_ext_chan_t *, char *, int);
	int (*chan_alt_enable)(struct tag_ext_chan_t *);
	int (*chan_alt_disable)(struct tag_ext_chan_t *);
	int (*chan_min)(struct tag_ext_chan_t *, void **);
	int (*chan_mout)(struct tag_ext_chan_t *, void **);
	int (*chan_min64)(struct tag_ext_chan_t *, unsigned long long *);
	int (*chan_mout64)(struct tag_ext_chan_t *, unsigned long long *);
	int (*chan_minn)(struct tag_ext_chan_t *, unsigned int *, int);
	int (*chan_moutn)(struct tag_ext_chan_t *, unsigned int *, int);

	void *userptr;							/* user pointer */
} ext_chan_t;

#define UDC_MAGIC 0xbeeff00d

/* these can be called from the functions provided by the user */
extern ext_chan_t *ccsp_udc_alloc_extchan (int);
extern void ccsp_udc_free_extchan (ext_chan_t *);
extern void ccsp_udc_resume_process (ext_chan_t *);
extern void ccsp_udc_start_alter (ext_chan_t *, void (*)(void *, int *), void *);
extern int ccsp_udc_kill_alter (ext_chan_t *);

/* these are some magic values for "chantype", so the C world can get some type information */
/* mental note: watch for changes in occ21's typehash() */
#define UDC_CHANTYPE_INT		0x0de4423d		/* CHAN OF INT */
#define UDC_CHANTYPE_BYTE		0x0de44213		/* CHAN OF BYTE */
#define UDC_CHANTYPE_BOOL		0x0de44211		/* CHAN OF BOOL */
#define UDC_CHANTYPE_INT_C_BYTE		0x1bd4def9		/* CHAN OF INT::[]BYTE */
#define UDC_CHANTYPE_P_INT		0xffcea249		/* CHAN OF PROTOCOL (INT) */
#define UDC_CHANTYPE_P_BYTE		0xffcea267		/* CHAN OF PROTOCOL (BYTE) */
#define UDC_CHANTYPE_P_BOOL		0xffcea265		/* CHAN OF PROTOCOL (BOOL) */
#define UDC_CHANTYPE_P_INT_C_BYTE	0xe9c1474d		/* CHAN OF PROTOCOL (INT::[]BYTE) */

#endif	/* !__UDC_H */

