[comp.sys.mac.programmer] Modifying Inits

Ken.Knight@f421.n109.z1.fidonet.org (Ken Knight) (11/07/90)

I am in the process of writing a CDEV/INIT combination. The CDEV will be 
used to select various modules to run (like Pyro! or After Dark) and set 
some general parameters. I'm not quite sure how to pass the information 
to the INIT. My best guess now is that I should store the data in a 
resource in the INIT/CDEV and then call something like OpenResFile() to 
get the newests info and the code for the module to run (each module 
would be stored in its own distinct code-type resource). Is this the 
best way to go? Are there any articles on this or similar subjects 
(modifying the way an INIT runs during the current session)?
 
Thanks,
 
  ** Ken **


--  

   	Ken Knight, Ken.Knight@f421.n109.z1.fidonet.org
   	via The Black Cat's Shack's FidoNet<->Usenet Gateway
	    blkcat.fidonet.org   and   Fidonet 1:109/401

mneerach@iiic.ethz.ch (Matthias Ulrich Neeracher) (11/10/90)

In article <2351.2737EA8E@blkcat.fidonet.org> Ken.Knight@f421.n109.z1.fidonet.org (Ken Knight) writes:
]I am in the process of writing a CDEV/INIT combination. The CDEV will be 
]used to select various modules to run (like Pyro! or After Dark) and set 
]some general parameters. I'm not quite sure how to pass the information 
]to the INIT. [...]
] Are there any articles on this or similar subjects 
](modifying the way an INIT runs during the current session)?

I think this has been discussed several times, so I'll try to summarize:

It is widely agreed that a very good method for new systems is to let the
INIT register a pointer to its parameters with _Gestalt.

For older systems, there is no generally accepted method. Solutions include 
the one you suggested (using resources), installing an IPC device driver,
or storing the data in the heap, preceded by an unique label (Creator of
INIT & your Name & your granma's Social Security Number. This label can then
be found by traversing heap block headers or with a brute force search. I
use in my INITs the latter method because it doesn't make any assumptions 
about the heap block structure. It has worked for me.

Matthias

-----
Matthias Neeracher                                   mneerach@iiic.ethz.ch
   "These days, though, you have to be pretty technical before you can 
    even aspire to crudeness." -- William Gibson, _Johnny Mnemonic_

chaffee@reed.UUCP (Alex Chaffee) (11/10/90)

In <2351.2737EA8E@blkcat.fidonet.org> Ken.Knight@f421.n109.z1.fidonet.org (Ken Knight) writes:

>I am in the process of writing a CDEV/INIT combination. The CDEV will be 
>used to select various modules to run (like Pyro! or After Dark) and set 
>some general parameters. I'm not quite sure how to pass the information 
>to the INIT. My best guess now is that I should store the data in a 
>resource in the INIT/CDEV and then call something like OpenResFile() to 
>get the newests info and the code for the module to run (each module 
>would be stored in its own distinct code-type resource). Is this the 
>best way to go? Are there any articles on this or similar subjects 
>(modifying the way an INIT runs during the current session)?

This is one of those great undocumented problems with no clean solution.
It's basically unsafe to save the data in the init file itself, since users
have a habit of renaming inits and it'd be hard to find your data if you did
that.  So put it in a preferences file in the system folder (or, better yet,
in the preferences folder).  That way both the INIT and the cdev will know
exactly where to find it.

If you don't mind having to reboot each time the information changes, then
all you'd have to do is an OpenResFile on that file (with appropriate error
checking if it's not there).  If you want the changes to be instantly known
to both the INIT and the cdev, there are a number of options, ranging from
having the INIT install a driver which moderates communication to using
Gestalt's "unique ID" feature to (my favorite) having the INIT allocate a
pointer or handle for its data in the system heap at startup, then saving
its address in an 'ADDR' resource in the preferences file, where the cdev
can find it.  Naturally, the block would start with a sanity check, like
your file signature, to catch old 'ADDR' resources if the INIT fails...

Is that perfectly clear? :-)

Isn't there something in the UMPG about this?  If not, there should be...

 - Alex

>   	Ken Knight, Ken.Knight@f421.n109.z1.fidonet.org
>   	via The Black Cat's Shack's FidoNet<->Usenet Gateway
>	    blkcat.fidonet.org   and   Fidonet 1:109/401
-- 
Alex Chaffee
chaffee@reed.{UUCP,BITNET}
Reed College, Portland OR 97202
____________________

mxmora@unix.SRI.COM (Matt Mora) (11/13/90)

In article <15669@reed.UUCP> chaffee@reed.UUCP (Alex Chaffee) writes:
>
>Isn't there something in the UMPG about this?  If not, there should be...

Yes there is on pages 51-53 "INIT-CDEV data exchange". It metions
all the same methods that have been described in this this thread.
Sorry, but there is no "Offical" way except with the new Gestalt stuff.




>Alex Chaffee
>chaffee@reed.{UUCP,BITNET}
>Reed College, Portland OR 97202
>____________________






-- 
___________________________________________________________
Matthew Mora                |   my Mac  Matt_Mora@sri.com
SRI International           |  my unix  mxmora@unix.sri.com
___________________________________________________________

Lewis_P@cc.curtin.edu.au (Peter Lewis) (11/13/90)

In article <15669@reed.UUCP>, chaffee@reed.UUCP (Alex Chaffee) writes:
> In <2351.2737EA8E@blkcat.fidonet.org> Ken.Knight@f421.n109.z1.fidonet.org (Ken Knight) writes:
> 
>> [CDEV/INIT IPC Question]
> 
> This is one of those great undocumented problems with no clean solution.
> It's basically unsafe to save the data in the init file itself, since users
> have a habit of renaming inits and it'd be hard to find your data if you did
> that.  So put it in a preferences file in the system folder (or, better yet,
> in the preferences folder).  That way both the INIT and the cdev will know
> exactly where to find it.

It doesnt matter if the user renames the INIT, both the INIT and the CDEV
have direct access to the resource file (The INIT has a handle to itself
in A0, and the cdev is called with CurResFile set to the file (I think
CurResFile is valid for the INIT as well)).  So as long as you dont mind
waiting til Restart time, this is the best method for communicating between
INIT/CDEV (IMHO).  (Please - not another file in my system folder!!!)

If you wish immediate communication, the only sane way is to use _Gestalt,
but this requires having an current system which many people do not have
yet.  (I wonder what happens if you search thru virtual memory looking
for a signiture?).  On the subject of _Gestalt, I've seen no docs yet
but I understand that there is a call to a mapping from a signiture to
a longInt, and a call to return the longInt given the signiture.  If this
is correct, the two more calls would allow hierarchical information -
SetGestaultX(which_gestault:handle; signiture:longInt; value:longInt);
GetGestaultX(which_gestault:handle; signiture:longInt; var value:longInt);
(So you could create your own Gestaul mapping, and save the handle to them
in the system Gestault mapping).  It seems to me this could be a very
powerful feature.  Does Apple already do something like this?

OK, I've finished my ramblings now, unless no one has mentioned the
CDEV/INIT-IPC package that is I think available on info-mac et al which
is suppose to be very good (but I havent used it yet - its more fun to
recreate the wheel each time :-)

   Peter.

>>   	Ken Knight, Ken.Knight@f421.n109.z1.fidonet.org
>>   	via The Black Cat's Shack's FidoNet<->Usenet Gateway
>>	    blkcat.fidonet.org   and   Fidonet 1:109/401
> -- 
> Alex Chaffee
> chaffee@reed.{UUCP,BITNET}
> Reed College, Portland OR 97202
-- 
Disclaimer:Curtin & I have an agreement:Neither of us listen to either of us.
*-------+---------+---------+---------+---------+---------+---------+-------*
Internet: Lewis_P@cc.curtin.edu.au              I Peter Lewis
ACSnet: Lewis_P@cc.cut.oz.au                    I NCRPDA, Curtin University
Bitnet: Lewis_P%cc.curtin.edu.au@cunyvm.bitnet  I GPO Box U1987
UUCP: uunet!munnari.oz!cc.curtin.edu.au!Lewis_P I Perth, WA, 6001, AUSTRALIA
"!thgir  s'ti  naem  t'nseod  yaw  taht  ti  seod  enoyreve  esuaceb  tsuJ"