
/* cift8-c.c -- CIF test 8, 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"

void my_process (Process *me, Channel *in, Channel *out)
{
	int i;
	void *dynarray[2];
	void *da2[2];

	for (i=0; i<5; i++) {
		int size;

		ChanMIn64 (in, dynarray);
		size = (int)(dynarray[1]);

		da2[0] = DMemAlloc (size + 4);
		da2[1] = (void *)(size + 4);

		memcpy (da2[0], dynarray[0], size);
		memcpy (da2[0] + size, " :) ", 4);

		ChanMOut64 (out, da2);

		DMemFree (dynarray[0]);
	}

	return;
}


/* allocates process and returns address to occam world */
void real_cift8_init (int *raddr, Channel *in, Channel *out)
{
	Process *p = ProcAlloc (my_process, 65536, 2, in, out);

	*raddr = (int)p;
	return;
}

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

	ProcAllocClean (p);
	return;
}

void _cift8_init (int *ws) { real_cift8_init ((int *)(ws[0]), (Channel *)(ws[1]), (Channel *)(ws[2])); }
void _cift8_free (int *ws) { real_cift8_free ((int)(ws[0])); }

