home *** CD-ROM | disk | FTP | other *** search
/ CLIX - Fazer Clix Custa Nix / CLIX-CD.cdr / mac / lib / Mac / Processes.xs < prev    next >
Text File  |  1998-04-17  |  8KB  |  320 lines

  1. /* $Header: /home/neeri/MacCVS/MacPerl/perl/ext/Mac/Processes/Processes.xs,v 1.2 1997/11/18 00:53:10 neeri Exp $
  2.  *
  3.  *    Copyright (c) 1996 Matthias Neeracher
  4.  *
  5.  *    You may distribute under the terms of the Perl Artistic License,
  6.  *    as specified in the README file.
  7.  *
  8.  * $Log: Processes.xs,v $
  9.  * Revision 1.2  1997/11/18 00:53:10  neeri
  10.  * MacPerl 5.1.5
  11.  *
  12.  * Revision 1.1  1997/04/07 20:50:30  neeri
  13.  * Synchronized with MacPerl 5.1.4a1
  14.  *
  15.  */
  16.  
  17. #define MAC_CONTEXT
  18.  
  19. #include "EXTERN.h"
  20. #include "perl.h"
  21. #include "XSUB.h"
  22. #include <Types.h>
  23. #include <Memory.h>
  24. #include <Processes.h>
  25. #include <TFileSpec.h>
  26.  
  27. typedef LaunchPBPtr         LaunchParam;
  28. typedef ProcessInfoRecPtr   ProcessInfo;
  29.  
  30. static ProcessInfo NewProcessInfo()
  31. {
  32.     ProcessInfo pi;
  33.     pi = (ProcessInfo) malloc(sizeof(ProcessInfoRec)+sizeof(FSSpec)+36);
  34.     pi->processInfoLength   =   sizeof(ProcessInfoRec);
  35.     pi->processName         =   (StringPtr)((char *)pi+sizeof(ProcessInfoRec));
  36.     pi->processAppSpec      =   (FSSpecPtr)((char *)pi+sizeof(ProcessInfoRec)+36);
  37.     
  38.     return pi;
  39. }
  40.  
  41. MODULE = Mac::Processes PACKAGE = LaunchParam
  42.  
  43. =head2 LaunchParam
  44.  
  45. This Perl hash maps onto the fields of a Launch Parameter Block 
  46. I<(Consult the manual)>.
  47.  
  48. The fields are: 
  49.  
  50.     launchFileFlags
  51.     launchControlFlags
  52.     launchAppSpec
  53.     launchAvailableSize
  54.     launchProcessSN
  55.     launchPreferredSize
  56.     launchMinimumSize
  57.  
  58. =cut
  59.  
  60. STRUCT * LaunchParam
  61.     U16                     launchFileFlags;
  62.     U16                     launchControlFlags;
  63.     FSSpecPtr               launchAppSpec;
  64.     ProcessSerialNumber     launchProcessSN;
  65.     U32                     launchPreferredSize;
  66.     U32                     launchMinimumSize;
  67.     U32                     launchAvailableSize;
  68.  
  69. =item new LaunchParam [ARGUMENTS]
  70.  
  71. Returns LaunchParam.
  72.  
  73.     $launch = 
  74.         new LaunchParam(
  75.             launchAppSpec => "volume:apps:myapp", launchMinimumSize => 32000);
  76.  
  77. =cut
  78. LaunchParam
  79. _new()
  80.     CODE:
  81.     RETVAL = (LaunchParam) malloc(sizeof(LaunchParamBlockRec)+sizeof(FSSpec));
  82.     RETVAL->launchBlockID           =   extendedBlock;
  83.     RETVAL->launchEPBLength         =   extendedBlockLen;
  84.     RETVAL->launchAppSpec           =   (FSSpecPtr)((char *)RETVAL+sizeof(LaunchParamBlockRec));
  85.     RETVAL->launchAppParameters =   nil;
  86.     OUTPUT:
  87.     RETVAL
  88.  
  89. =item DESTROY LPB
  90.  
  91. =cut
  92. void
  93. DESTROY(lpb)
  94.     LaunchParam lpb
  95.     CODE:
  96.     free(lpb);
  97.  
  98.  
  99. MODULE = Mac::Processes PACKAGE = ProcessInfo
  100.  
  101. =head2 ProcessInfo
  102.  
  103. This Perl hash allows access to the C<ProcessInfo> structure.
  104. B<(Consult your manual)>.
  105.  
  106. The field names are: 
  107.  
  108.     processName
  109.     processNumber
  110.     processType
  111.     processSignature
  112.     processSize
  113.     processMode
  114.     processLocation
  115.     processLauncher
  116.     processLaunchDate
  117.     processActiveTime
  118.     processAppSpec
  119.  
  120. =cut
  121.  
  122. STRUCT * ProcessInfo
  123.     Str255              processName;
  124.     ProcessSerialNumber processNumber;
  125.     U32                 processType;
  126.     OSType              processSignature;
  127.     U32                 processMode;
  128.     Ptr                 processLocation;
  129.     U32                 processSize;
  130.     U32                 processFreeMem;
  131.     ProcessSerialNumber processLauncher;
  132.     U32                 processLaunchDate;
  133.     U32                 processActiveTime;
  134.     FSSpecPtr           processAppSpec;
  135.  
  136. =item DESTROY PI
  137.  
  138. =cut
  139. void
  140. DESTROY(pi)
  141.     ProcessInfo pi
  142.     CODE:
  143.     free(pi);
  144.  
  145. MODULE = Mac::Processes PACKAGE = Mac::Processes
  146.  
  147. =head2 Functions
  148.  
  149. =item LaunchApplication LAUNCHPARAMS
  150.  
  151. The LaunchApplication function launches the application from the specified file
  152. and returns the process serial number, preferred partition size, and minimum
  153. partition size if the application is successfully launched.
  154. Returns zero on failure.
  155.  
  156. =cut
  157. MacOSRet
  158. LaunchApplication(LaunchParams)
  159.     LaunchParam LaunchParams
  160.  
  161. =item LaunchDeskAccessory PFILESPEC, PDANAME
  162.  
  163. The LaunchDeskAccessory function searches the resource fork of the file specified
  164. by the pFileSpec parameter for the desk accessory with the 'DRVR' resource name
  165. specified in the pDAName parameter. If the 'DRVR' resource name is found,
  166. LaunchDeskAccessory launches the corresponding desk accessory. If the desk
  167. accessory is already open, it is brought to the front.
  168. Returns zero on failure.
  169.  
  170. =cut
  171. MacOSRet
  172. LaunchDeskAccessory(pFileSpec, pDAName)
  173.     SV *        pFileSpec
  174.     Str255  pDAName
  175.     PREINIT:
  176.     FSSpec  spec;
  177.     FSSpec *    fssp = nil;
  178.     CODE:
  179.     if (SvTRUE(pFileSpec) && Path2FSSpec(SvPV(pFileSpec,na), &spec))
  180.         fssp = &spec;
  181.     RETVAL = LaunchDeskAccessory(fssp, pDAName);
  182.     OUTPUT:
  183.     RETVAL
  184.  
  185. =item GetCurrentProcess
  186.  
  187. The GetCurrentProcess function returns the process serial
  188. number of the process that is currently running, that is, the one currently
  189. accessing the CPU.
  190. Return C<undef> if an error was detected.
  191.  
  192. =cut
  193. ProcessSerialNumber
  194. GetCurrentProcess()
  195.     CODE:
  196.     if (gLastMacOSErr = GetCurrentProcess(&RETVAL)) {
  197.         XSRETURN_UNDEF;
  198.     }
  199.     OUTPUT:
  200.     RETVAL
  201.     
  202. =item GetFrontProcess
  203.  
  204. The GetFrontProcess function returns the process serial
  205. number of the process running in the foreground.
  206. Return C<undef> if an error was detected.
  207.  
  208. =cut
  209. ProcessSerialNumber
  210. GetFrontProcess()
  211.     CODE:
  212.     if (gLastMacOSErr = GetFrontProcess(&RETVAL)) {
  213.         XSRETURN_UNDEF;
  214.     }
  215.     OUTPUT:
  216.     RETVAL
  217.     
  218. =item GetNextProcess PSN
  219.  
  220. Get information about the next process, if any, in the Process Manager’s internal
  221. list of open processes.
  222. Return C<undef> if an error was detected.
  223.  
  224. =cut
  225. ProcessSerialNumber
  226. GetNextProcess(PSN)
  227.     ProcessSerialNumber PSN
  228.     CODE:
  229.     if (gLastMacOSErr = GetNextProcess(&PSN)) {
  230.         XSRETURN_UNDEF;
  231.     } else
  232.         RETVAL = PSN;
  233.     OUTPUT:
  234.     RETVAL
  235.     
  236. =item GetProcessInformation PSN
  237.  
  238. The GetProcessInformation function returns, in a process information record,
  239. information about the specified process. The information returned in the info
  240. parameter includes the application’s name as it appears in the Application menu,
  241. the type and signature of the application, the address of the application
  242. partition, the number of bytes in the application partition, the number of free
  243. bytes in the application heap, the application that launched the application, the
  244. time at which the application was launched, and the location of the application
  245. file.
  246. Return C<undef> if an error was detected.
  247.  
  248. =cut
  249. ProcessInfo
  250. GetProcessInformation(PSN)
  251.     ProcessSerialNumber PSN
  252.     CODE:
  253.     RETVAL = NewProcessInfo();
  254.     if (gLastMacOSErr = GetProcessInformation(&PSN, RETVAL)) {
  255.         free(RETVAL);
  256.         XSRETURN_UNDEF;
  257.     } 
  258.     OUTPUT:
  259.     RETVAL
  260.     
  261. =item SetFrontProcess PSN
  262.  
  263. The SetFrontProcess function schedules the specified process to move to the
  264. foreground. The specified process moves to the foreground after the current
  265. foreground process makes a subsequent call to WaitNextEvent or EventAvail.
  266. Returns zero on failure.
  267.  
  268. =cut
  269. MacOSRet
  270. SetFrontProcess(PSN)
  271.     ProcessSerialNumber &PSN
  272.  
  273. =item WakeUpProcess PSN
  274.  
  275. The WakeUpProcess function makes a process suspended by WaitNextEvent() eligible to
  276. receive CPU time. A process is suspended when the value of the sleep parameter in
  277. the WaitNextEvent() function is not 0 and no events for that process are pending in
  278. the event queue. This process remains suspended until the time specified in the
  279. sleep parameter expires or an event becomes available for that process. You can
  280. use WakeUpProcess to make the process eligible for execution before the time
  281. specified in the sleep parameter expires.
  282. Returns zero on failure.
  283.  
  284. =cut
  285. MacOSRet
  286. WakeUpProcess(PSN)
  287.     ProcessSerialNumber &PSN
  288.  
  289. =item SameProcess PSN1, PSN2
  290.  
  291. The SameProcess function compares two process serial numbers and determines
  292. whether they refer to the same process.
  293. Return C<undef> if an error was detected.
  294.  
  295. =cut
  296. Boolean
  297. SameProcess(PSN1, PSN2)
  298.     ProcessSerialNumber PSN1
  299.     ProcessSerialNumber PSN2
  300.     CODE:
  301.     if (gLastMacOSErr = SameProcess(&PSN1, &PSN2, &RETVAL)) {
  302.         XSRETURN_UNDEF;
  303.     } 
  304.     OUTPUT:
  305.     RETVAL
  306.  
  307. =item ExitToShell
  308.  
  309. This function is not implemented: ExitToShell() unsupported. Use exit.
  310.  
  311. =cut
  312. void
  313. ExitToShell()
  314.     CODE:
  315.     croak("ExitToShell() unsupported. Use exit.");
  316.  
  317. =back
  318.  
  319. =cut
  320.