[comp.sys.mac.programmer] Time Manager questions

resnick@cogsci.uiuc.edu (Pete Resnick) (12/11/90)

There are some things that are very unclear in Inside Mac IV, chap 32 on
the Time Manager. I was hoping someone could clear these up:

1. Nowhere does it say what the declaration of the task should look
like. I am assuming it should be declare as a pascal routine (I am using
THINK C), but what parameters and what else will I need?

2. RmvTime claims that it only can return noErr. What if I pass it
a TMTask that I have not queued? Will this return noErr, and whatever
it returns, will this cause any problems?

Thanks,
pr
--
Pete Resnick             (...so what is a mojo, and why would one be rising?)
Graduate assistant - Philosophy Department, Gregory Hall, UIUC
System manager - Cognitive Science Group, Beckman Institute, UIUC
Internet/ARPAnet/EDUnet  : resnick@cogsci.uiuc.edu
BITNET (if no other way) : FREE0285@UIUCVMD

AS01MEF@VM.TCS.TULANE.EDU (Jeff E Mandel MD MS) (12/12/90)

In article <1990Dec11.072536.13494@ux1.cso.uiuc.edu> resnick@cogsci.uiuc.edu
(Pete Resnick) writes:
>There are some things that are very unclear in Inside Mac IV, chap 32 on
>the Time Manager. I was hoping someone could clear these up:
>
>1. Nowhere does it say what the declaration of the task should look
>like. I am assuming it should be declare as a pascal routine (I am using
>THINK C), but what parameters and what else will I need?
>

How to do Time Manager tasks from C
By Jeff E Mandel MD MS
Asst Professor of Anesthesiology
Tulane University School of Medicine
New Orleans, LA
AS01MEF@VM.TCS.TULANE.EDU
"I work at an institution which steadfastly refuses to allow me to use my
name as my email address. How could anyone suspect I speak for them?"

Since I periodically answer these sort of questions, I thought this would help.
This is MPW C code, excerpted from working code I wrote several years ago, and
probably will not compile as written without a small amount of work. It should
help get you started. 

#include	<memory.h>
#include	<Timer.h>

/*
	A proc to recover the time task pointer and return it as a function result
*/

myTMTaskPtr GetTmTaskRec () = 0x2009;			/* MOVE.L	A1,D0 */

/*
	define a structure which includes a time manager task entry and a pointer for
global
	storage passing
*/

typedef struct {
	TMTask				theTask;
	myGlobalPtrType		myGlobalsPtr;
}	myTMTask, *myTMTaskPtr;


/*
	The time manager proc. Note that it expects no arguments, but the pointer to
the
	task queue entry is in register A1. Since we cannot depend on the state of A5,
we
	use the Task queue entry to hold a pointer to our "global" storage, i.e. any
variables
	we want to share between our program and the time manager proc.
*/

void OneSecondTimer ()
{
	myTMTaskPtr 	theTaskPtr;
	myGlobalPtrType	myGlobalPtr;

	theTaskPtr=GetTmTaskRec();
	myGlobalPtr=theTaskPtr->myGlobalsPtr;
	
	[Useful stuff goes here]
	
	return;
}

void main()
{
	void OneSecondTimer();
	myGlobalPtrType myGlobalPtr;
	myTMTaskPtr	OneSecondTask;

/*
   Set up Time manager task for a one second timer. If you want this to
   recur, need to call PrimeTime each time.
*/

	OneSecondTask=(myTMTaskPtr) NewPtrClear(sizeof(myTMTask));
	OneSecondTask->myGlobalsPtr=myGlobalPtr;
	OneSecondTask->theTask.tmAddr=(TimerProcPtr)OneSecondTimer;
	InsTime((TMTaskPtr)OneSecondTask);
	PrimeTime((TMTaskPtr)OneSecondTask, (long) 1000);

	return;
}

>2. RmvTime claims that it only can return noErr. What if I pass it
>a TMTask that I have not queued? Will this return noErr, and whatever
>it returns, will this cause any problems?
>

I am almost certain that RmvTime with a nonzero TmTask that
is not queued crashes the system (at least through system 6.0), but as Apple
has
revised the Time Manager, this may no longer be so. Unless you LIKE trouble, I
would avoid it.