From: carl@SOL1.GPS.CALTECH.EDU (Carl J Lydick)
Newsgroups: comp.os.vms
Subject: Symbiont to requeue files
Date: 19 Nov 1992 20:09:25 GMT
Organization: HST Wide Field/Planetary Camera
Reply-To: carl@SOL1.GPS.CALTECH.EDU
NNTP-Posting-Host: sol1.gps.caltech.edu

Another question that comes up from time to time is regarding how to set up a
symbiont that requeues files to another symbiont.  Here's something that does
something along those lines.  It copies the input file, then submits it to
another queue for processing.  Please note that this program does NOT preserve
ownership of the job, so it would be a *BAD* idea to set it up to resubmit jobs
to a batch queue.

The program, as written, takes the device name passed to the output routine and
uses it to determine which queue and which form to use as it resubmits jobs. 
It expects to be initialized with a command of the form:
	$ INIT/QUEUE/ON=formname_queuename/PROCESSOR=this_images_name queue_name
E.g., if you want it to forward jobs to queue TXA5 using form WIDE, you'd
	$ INIT/QUEUE/ON=WIDE_TXA5/PROCESSOR=this_images_name queue_name.
Hope someone finds it useful, at least as a simple example of using the PSM
routines.  By the way, it uses the routine NOTLIB_COPY I posted yesterday, and
copies the files it's working on to SYS$SYSDEVICE:[SPOOL].  The include file
"$psmdef.h" can be derived from the $PSMDEF module of SYS$LIBRARY:LIB.MLB.

#include descrip
#include psmmsgdef
#include "$psmdef.h"
long stat;
#define ckstat(x) if(((stat = x) & 7) != 1) return stat
char queue_name[80], form_name[80];
int queue_name_length, form_name_length;
long seqnum = 0;
char format[80];

modify()
{	long code1 = PSM$K_MAIN_INPUT, ps_main_input();
	long code2 = PSM$K_OUTPUT, ps_output();
	PSM$REPLACE(&code1, ps_main_input);
	PSM$REPLACE(&code2, ps_output);
	PSM$PRINT(0, 0, 0);
}

ps_main_input(long *request_id, long *work_area, long *func, 
	struct dsc$descriptor *funcdesc, long *funcarg)
{	if (*func == PSM$K_OPEN)
 	{	char buffer[256];
		$DESCRIPTOR(out_file, buffer);
		
		sprintf(buffer, format, seqnum++);
		out_file.dsc$w_length = strlen(buffer);
		ckstat(notlib_copy(funcdesc, &out_file));
		ckstat(queue_it(&out_file));
	}
	else if (*func == PSM$K_READ)
		return PSM$_EOF;
	else if (*func == PSM$K_READ)
		return 1;
	else
		return PSM$_FUNNOTSUP;
}

#include jpidef
ps_output(long *request_id, long *work_area, long *func, 
	struct dsc$descriptor *funcdesc, long *funcarg)
{	char *ptr1, *ptr2;
	if (*func == PSM$K_OPEN)
 	{	long iosb[2], pid;
		struct item_code_3
		{	unsigned short buflen, itmcod;
			void *bufadr, *lenadr;
		} itmlst[] =
		{
			{	4,	JPI$_PID,	&pid,	0 },
			{	0,	0,		0,	0 }
		};

		ckstat(SYS$GETJPIW(0, 0, 0, itmlst, iosb, 0, 0));
		ckstat(iosb[0]);
		sprintf(format, "SYS$SYSDEVICE:[SPOOL]%08X.%%08X", pid);
		for(ptr1 = form_name, ptr2 = funcdesc->dsc$a_pointer; 
			((ptr2 - funcdesc->dsc$a_pointer) <
			funcdesc->dsc$w_length) && *ptr2 != '_'; ++ptr2)
			*ptr1++ = *ptr2;
		form_name_length = ptr1 - form_name;
		for(ptr1 = queue_name, ++ptr2;
			(ptr2 - funcdesc->dsc$a_pointer) <
			funcdesc->dsc$w_length; ++ptr2)
			*ptr1++ = *ptr2;
		queue_name_length = ptr1 - queue_name;
	}
	return 1;
}

#include sjcdef
queue_it(struct dsc$descriptor *file)
{	long iosb[2];
	struct item_list_3
	{	unsigned short buflen, itmcod;
		void *bufadr, *lenadr;

	} itmlst1[] =
	{   {	queue_name_length,	SJC$_QUEUE,	queue_name,	0},
	    {file->dsc$w_length,SJC$_FILE_SPECIFICATION,file->dsc$a_pointer,0},
	    {	form_name_length,	SJC$_FORM_NAME,	form_name,	0},
	    {	0,			SJC$_DELETE_FILE,	0,	0},
	    {	0,			0,		0,		0}
	};

	ckstat(SYS$SNDJBCW(0, SJC$_ENTER_FILE, 0, itmlst1, iosb, 0, 0));
	return iosb[0];
}
--------------------------------------------------------------------------------
Carl J Lydick | INTERnet: CARL@SOL1.GPS.CALTECH.EDU | NSI/HEPnet: SOL1::CARL

Disclaimer:  Hey, I understand VAXen and VMS.  That's what I get paid for.  My
understanding of astronomy is purely at the amateur level (or below).  So
unless what I'm saying is directly related to VAX/VMS, don't hold me or my
organization responsible for it.  If it IS related to VAX/VMS, you can try to
hold me responsible for it, but my organization had nothing to do with it.