
/* cift9-c.c -- CIF test 9, C part */

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <sys/time.h>
#include <unistd.h>

#include "cifccsp.h"

/*
 * note: the current organisation of channel-types has
 * the reference-count in the first word, followed by the
 * declared channels in order.  also relies on gcc allocating
 * the structure in the order given..
 */

struct chantype_LINK;

typedef struct chantype_LINK {
	int refcount;
#ifdef CHANTYPEDESC
	unsigned int *typedesc;
	void *ihook;
#endif
	Channel in;
	Channel out;
} ct_LINK;


void my_process (Process *me, ct_LINK *link_cli)
{
	int i, v;

	for (i=0; i<5; i++) {
		ChanOutInt (&(link_cli->in), i);
		ChanInInt (&(link_cli->out), &v);

		EXTERNAL_CALLN (fprintf, stderr, "got: %d\n", v);
	}

	return;
}


/* allocates process and returns address to occam world */
void real_cift9_init (int *raddr, ct_LINK *link_cli)
{
	Process *p = ProcAlloc (my_process, 65536, 1, link_cli);

	*raddr = (int)p;
	return;
}

/* frees memory used by a process -- lets hope it's finished :) */
void real_cift9_free (int addr)
{
	Process *p = (Process *)addr;

	ProcAllocClean (p);
	return;
}

void _cift9_init (int *ws) { real_cift9_init ((int *)(ws[0]), (ct_LINK *)(ws[1])); }
void _cift9_free (int *ws) { real_cift9_free ((int)(ws[0])); }

