home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #31 / NN_1992_31.iso / spool / comp / sys / mac / programm / 20489 < prev    next >
Encoding:
Internet Message Format  |  1992-12-31  |  6.1 KB

  1. Path: sparky!uunet!spool.mu.edu!olivea!apple!goofy!mumbo.apple.com!gallant.apple.com!apple.com!radcliff
  2. From: radcliff@apple.com (Dave Radcliffe)
  3. Newsgroups: comp.sys.mac.programmer
  4. Subject: Re: Gestalt Selectors in APPL
  5. Message-ID: <1992Dec31.223051.15882@gallant.apple.com>
  6. Date: 31 Dec 92 22:30:51 GMT
  7. References: <BzqC31.FAM@world.std.com>
  8. Sender: news@gallant.apple.com
  9. Organization: Apple Computer
  10. Lines: 142
  11.  
  12. In article <BzqC31.FAM@world.std.com>, zobkiw@world.std.com (Joe Zobkiw) writes:
  13. > I need an application to install a gestalt selector. 
  14. > I know I need to load it into the System Heap but I 
  15. > have a few questions and comments.
  16. > 1) Can I perform a "6-byte-xdef" type trick on this 
  17. > code? I'm not sure I can since even if I mark the 
  18. > 6-byte resource as sysHeap the code it points to is 
  19. > still in my application heap.
  20. > 2) If I place my Gestalt selector function in a separate 
  21. > CODE resource, can I mark that resource as sysHeap and 
  22. > have it work properly? This would be WITHOUT any 6-byte 
  23. > tricks.
  24. > 3) How can I remove the Gestalt selector once the app 
  25. > quits? Will
  26. >     err = ReplaceGestalt(selector, nil, &oldGestaltFunction);
  27. > work or will this cause the System to jump to location 0 
  28. > the next time someone calls my selector?
  29. > What's the easiest way? Thanks in advance! :)
  30. > Joe Zobkiw
  31.  
  32. There is glue code on the January Developer CD that, assuming all you want your 
  33. Gestalt function to do is return a value, solves all your problems.  It is
  34. called GestaltValue.  The ReadMe file is pasted below:
  35.  
  36. GestaltValue Read Me
  37. ) Copyright 1992 Apple Computer, Inc.
  38. All rights reserved
  39. ------------------------------------
  40. This document describes the GestaltValue functionality as implemented in 
  41. GestaltValue.o.  Interfaces to GestaltValue are provided in 
  42. GestaltValue.h and GestaltValue.p.
  43.  
  44. GestaltValue is a set of routines, implemented as glue, that extend and 
  45. enhance existing Gestalt functionality.  For a complete description of 
  46. Gestalt, refer to Chapter 3 of Inside Macintosh VI. 
  47.  
  48. Rationale
  49.  
  50. Existing Gestalt functionality allows developers to put Gestalt to use in 
  51. their own applications by registering a Gestalt selector using the 
  52. NewGestalt or ReplaceGestalt calls, and providing a function which can 
  53. return the appropriate response.
  54.  
  55. While this is a powerful feature of Gestalt, in practice, it is difficult 
  56. to take advantage of for a number of reasons:
  57.  
  58. 1) The supplied function must entirely reside in the system heap.
  59.  
  60. 2) The function should be reentrant and not move memory because Gestalt 
  61. (and therefore the function) may be called at interrupt time.
  62.  
  63. 3) The function must effectively remain resident until restart.  This is 
  64. a problem for applications which may come and go multiple times.
  65.  
  66. 4) Since the purpose of the function is to return a response value, the 
  67. function must know how to locate, or otherwise manage that value.
  68.  
  69. All of this means a lot of work just to allow code to retrieve the response 
  70. value via Gestalt.
  71.  
  72. GestaltValue addresses all these issues.  It is built to deal with the most 
  73. common case, simply returning a 32-bit value.  It safely implements and 
  74. installs a single common, shared gestalt function and reports back values
  75. via the existing Gestalt mechanism.  This gestalt function gets installed 
  76. the first time the glue gets invoked.  Subsequent calls to the glue 
  77. (either from the same application, or a different one) cooperate with 
  78. the gestalt function to maintain a table of selectors and values for the 
  79. function to report.
  80.  
  81. GestaltValue will eventually be implemented as a standard system trap, in 
  82. which case, the glue will simply call the trap.  Although currently provided
  83. as a standalone object file, GestaltValue will eventually be rolled into 
  84. development libraries; watch for it in a development system near you.
  85.  
  86. All three GestaltValue functions defined below can move memory, so they 
  87. cannot be called at interrupt time.  But the shared gestalt function that 
  88. GestaltValue installs in the system heap is reentrant and does not move 
  89. memory (i.e., it satisfies criteria (2) above), so any values registered 
  90. via this mechanism can be safely retrieved at interrupt time via the 
  91. standard Gestalt mechanism.
  92.  
  93. Interface
  94.  
  95. Pascal:
  96.  
  97. FUNCTION NewGestaltValue(selector: OSType;newValue: LONGINT): OSErr;
  98. FUNCTION ReplaceGestaltValue(selector: OSType;replacementValue: LONGINT): OSErr;
  99. FUNCTION DeleteGestaltValue(selector: OSType): OSErr;
  100.  
  101. C:
  102.  
  103. pascal OSErr NewGestaltValue (OSType selector, long newValue);
  104. pascal OSErr ReplaceGestaltValue (OSType selector, long replacementValue);
  105. pascal OSErr DeleteGestaltValue (OSType selector);
  106.  
  107. NewGestaltValue and ReplaceGestaltValue are analogous to NewGestalt and 
  108. ReplaceGestalt.  They take a standard 4 character OSType value and a new
  109. or replacement value.  ReplaceGestaltValue has no parameter analogous 
  110. to the oldGestaltFunction parameter of ReplaceGestalt.  If you desire 
  111. saving the previous value, you should call Gestalt for that selector 
  112. before calling ReplaceGestaltValue.
  113.  
  114. The usual restrictions on the selector parameter still apply.  Apple 
  115. recommends you use your four-character creator sequence for your selector.  
  116. All lowercase letter and nonalphabetic ASCII sequences are reserved for Apple.
  117.  
  118. DeleteGestaltValue makes a Gestalt value unknown to Gestalt.  Subsequent
  119. calls to Gestalt for that selector will return gestaltUndefSelectorErr.
  120.  
  121. Return values
  122.  
  123. GestaltValue requires that the _Gestalt trap be implemented.  You will get 
  124. unimpErr (-4) if _Gestalt is unavailable.
  125.  
  126. NewGestaltValue returns gestaltDupSelectorErr (-5552) if you attempt to add 
  127. a new value for an existing selector.  You should use ReplaceGestaltValue 
  128. instead.
  129.  
  130. ReplaceGestaltValue returns gestaltUndefSelectorErr (-5551) if you attempt 
  131. to replace a non-existent selector.  You should use NewGestaltValue instead.
  132.  
  133. Both NewGestaltValue and ReplaceGestalt value may return memory errors if 
  134. they cannot allocate sufficient room in the system heap for their code and 
  135. data.
  136.  
  137. DeleteGestaltValue returns gestaltUndefSelectorErr if you attempt to delete 
  138. a selector unknown to GestaltValue (such as a pre-defined gestalt selector 
  139. such as 'fpu ').
  140. ----
  141. I hope this helps.  Have fun,
  142.  
  143. Dave Radcliffe
  144. Apple Computer
  145. MacDTS
  146.