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

  1. /* $Header: /home/neeri/MacCVS/MacPerl/perl/ext/Mac/Components/Components.xs,v 1.2 1997/11/18 00:52:09 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: Components.xs,v $
  9.  * Revision 1.2  1997/11/18 00:52:09  neeri
  10.  * MacPerl 5.1.5
  11.  *
  12.  * Revision 1.1  1997/04/07 20:49:14  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 <Components.h>
  25.  
  26. static ComponentDescription * MakeComponentDesc(
  27.     SV *                componentType,
  28.     SV *                componentSubType,
  29.     SV *                componentManufacturer,
  30.     unsigned long   componentFlags,
  31.     unsigned long   componentFlagsMask)
  32. {
  33.     static ComponentDescription desc;
  34.     
  35.     if (SvTRUE(componentType))
  36.         desc.componentType = *(OSType *)SvPV(componentType, na);
  37.     else 
  38.         desc.componentType = 0;
  39.     if (SvTRUE(componentSubType))
  40.         desc.componentSubType = *(OSType *)SvPV(componentSubType, na);
  41.     else 
  42.         desc.componentSubType = 0;
  43.     if (SvTRUE(componentManufacturer))
  44.         desc.componentManufacturer = *(OSType *)SvPV(componentManufacturer, na);
  45.     else 
  46.         desc.componentManufacturer = 0;
  47.     desc.componentFlags     = componentFlags;
  48.     desc.componentFlagsMask = componentFlagsMask;
  49.     
  50.     return &desc;
  51. }
  52.  
  53. static SV * MakeOSSV(OSType type)
  54. {
  55.     return type ? newSVpv((char *) &type, 4) : newSVpv("", 0);
  56. }
  57.  
  58. MODULE = Mac::Components    PACKAGE = Mac::Components
  59.  
  60. =head1 EXTENSION
  61.  
  62. Mac::Components - Extension description
  63.  
  64. =head2 Mac::Components
  65.  
  66. =item RegisterComponentResource TR, GLOBAL
  67.  
  68. The RegisterComponentResource function makes a component available for use by
  69. applications (or other clients). Once the Component Manager has registered a
  70. component, applications can find and open the component using the standard
  71. Component Manager routines. You provide information identifying the component and
  72. specifying its capabilities. The Component Manager returns a component identifier
  73. that uniquely identifies the component to the system.
  74.  
  75. =cut
  76. Component
  77. RegisterComponentResource(tr, global)
  78.     Handle  tr 
  79.     short       global
  80.     CODE:
  81.     RETVAL = RegisterComponentResource((ComponentResourceHandle) tr, global);
  82.     OUTPUT:
  83.     RETVAL
  84.  
  85. =item UnregisterComponent ACOMPONENT
  86.  
  87. The UnregisterComponent function removes a component from the Component Manager’s
  88. registration list. Most components are registered at startup and remain
  89. registered until the computer is shut down. However, you may want to provide some
  90. services temporarily. In that case you dispose of the component that provides the
  91. temporary service by using this function.
  92. Returns zero on failure.
  93.  
  94. =cut
  95. MacOSRet
  96. UnregisterComponent(aComponent)
  97.     Component aComponent
  98.  
  99. =item FindNextComponent ACOMPONENT, [COMPONENTTYPE, [COMPONENTSUBTYPE, [COMPONENTMANUFACTURER, [COMPONENTFLAGS, [COMPONENTFLAGSMASK]]]]]
  100.  
  101. The FindNextComponent function returns the component identifier of a component
  102. that meets the search criteria. FindNextComponent returns a function result of 0
  103. when there are no more matching components. 
  104.  
  105. =cut
  106. Component
  107. FindNextComponent(aComponent, componentType = &sv_undef, componentSubType = &sv_undef, componentManufacturer = &sv_undef, componentFlags = 0, componentFlagsMask = 0)
  108.     Component       aComponent
  109.     SV *                componentType
  110.     SV *                componentSubType
  111.     SV *                componentManufacturer
  112.     unsigned long   componentFlags
  113.     unsigned long   componentFlagsMask
  114.     CODE:
  115.     RETVAL = 
  116.         FindNextComponent(
  117.             aComponent, 
  118.             MakeComponentDesc(componentType, componentSubType, componentManufacturer, componentFlags, componentFlagsMask));
  119.     OUTPUT:
  120.     RETVAL
  121.  
  122. =item CountComponents [COMPONENTTYPE, [COMPONENTSUBTYPE, [COMPONENTMANUFACTURER, [COMPONENTFLAGS, [COMPONENTFLAGSMASK]]]]]
  123.  
  124. The CountComponents function returns a long integer containing the number of
  125. components that meet the specified search criteria.
  126.  
  127. =cut
  128. long
  129. CountComponents(componentType = &sv_undef, componentSubType = &sv_undef, componentManufacturer = &sv_undef, componentFlags = 0, componentFlagsMask = 0)
  130.     SV *                componentType
  131.     SV *                componentSubType
  132.     SV *                componentManufacturer
  133.     unsigned long   componentFlags
  134.     unsigned long   componentFlagsMask
  135.     CODE:
  136.     RETVAL = 
  137.         CountComponents(
  138.             MakeComponentDesc(componentType, componentSubType, componentManufacturer, componentFlags, componentFlagsMask));
  139.     OUTPUT:
  140.     RETVAL
  141.  
  142. =item GetComponentInfo ACOMPONENT
  143.  
  144. The GetComponentInfo function returns information about the specified component.
  145.  
  146.     ($info, $name, $mask, $flags, $manufacturer, $subtype, $type) =
  147.         GetComponentInfo($Component);
  148.  
  149. =cut
  150. void
  151. GetComponentInfo(aComponent)
  152.     Component   aComponent
  153.     PREINIT:
  154.     ComponentDescription    desc;
  155.     Handle                  name;
  156.     Handle                  info;
  157.     PPCODE:
  158.     name = NewEmptyHandle();
  159.     info = NewEmptyHandle();
  160.     gLastMacOSErr = GetComponentInfo(aComponent, &desc, name, info, nil);
  161.     HLock(name);
  162.     HLock(info);
  163.     if (!gLastMacOSErr) 
  164.         if (GIMME != G_ARRAY) {
  165.             XS_XPUSH(Str255, (StringPtr)*name);
  166.         } else {
  167.             XPUSHs(sv_2mortal(MakeOSSV(desc.componentType)));
  168.             XPUSHs(sv_2mortal(MakeOSSV(desc.componentSubType)));
  169.             XPUSHs(sv_2mortal(MakeOSSV(desc.componentManufacturer)));
  170.             XPUSHs(sv_2mortal(newSViv(desc.componentFlags)));
  171.             XPUSHs(sv_2mortal(newSViv(desc.componentFlagsMask)));
  172.             XS_XPUSH(Str255, (StringPtr)*name);
  173.             XS_XPUSH(Str255, (StringPtr)*info);
  174.         }
  175.     DisposeHandle(name);
  176.     DisposeHandle(info);
  177.  
  178. =item GetComponentListModSeed
  179.  
  180. The GetComponentListModSeed function allows you to determine if the list of
  181. registered components has changed. This function returns the value of the
  182. component registration seed number.
  183.  
  184. =cut
  185. long 
  186. GetComponentListModSeed()
  187.  
  188. =item OpenComponent ACOMPONENT
  189.  
  190. The OpenComponent function allows your application to gain access to the services
  191. provided by a component. Your application must open a component before it can
  192. call any component functions. You specify the component with a component
  193. identifier that your application previously obtained from the FindNextComponent
  194. function.
  195. Returns ComponentInstance.
  196.  
  197. =cut
  198. ComponentInstance
  199. OpenComponent(aComponent)
  200.     Component aComponent
  201.  
  202. =item CloseComponent ACOMPONENTINSTANCE
  203.  
  204. The CloseComponent function terminates your application’s access to the services
  205. provided by a component. Your application specifies the connection to be closed
  206. with the component instance returned by the OpenComponent() or OpenDefaultComponent()
  207. function.
  208. Returns zero on failure.
  209.  
  210. =cut
  211. MacOSRet
  212. CloseComponent(aComponentInstance)
  213.     ComponentInstance   aComponentInstance
  214.  
  215. =item GetComponentInstanceError ACOMPONENTINSTANCE
  216.  
  217. The GetComponentInstanceError function returns the last error generated by a
  218. specific connection to a component.
  219. Returns zero on failure.
  220.  
  221. =cut
  222. MacOSRet
  223. GetComponentInstanceError(aComponentInstance)
  224.     ComponentInstance   aComponentInstance
  225.  
  226. =item ComponentFunctionImplemented CI, FTNNUMBER
  227.  
  228. The ComponentFunctionImplemented function allows you to determine whether a
  229. component supports a specified request. Your application can use this function to
  230. determine a component’s capabilities. 
  231. Returns 1 if supported.
  232.  
  233. =cut
  234. long
  235. ComponentFunctionImplemented(ci, ftnNumber)
  236.     ComponentInstance ci
  237.     short               ftnNumber
  238.  
  239. =item GetComponentVersion CI
  240.  
  241. The GetComponentVersion function returns a component’s version number
  242. as a coded integer.
  243.  
  244. =cut
  245. long
  246. GetComponentVersion(ci)
  247.     ComponentInstance   ci
  248.  
  249. =item SetDefaultComponent ACOMPONENT, FLAGS
  250.  
  251. The SetDefaultComponent function allows your component to change the search order
  252. for registered components. You specify a component that is to be placed at the
  253. front of the search chain, along with control information that governs the
  254. reordering operation. The order of the search chain influences which component
  255. the Component Manager selects in response to an application’s use of the
  256. OpenDefaultComponent() and FindNextComponent() functions.
  257. Returns zero on failure.
  258.  
  259. =cut
  260. MacOSRet
  261. SetDefaultComponent(aComponent, flags)
  262.     Component   aComponent
  263.     short       flags
  264.  
  265. =item OpenDefaultComponent COMPONENTTYPE, [COMPONENTSUBTYPE]
  266.  
  267. The OpenDefaultComponent function allows your application to gain access to the
  268. services provided by a component. Your application must open a component before
  269. it can call any component functions. You specify the component type and subtype
  270. values of the component to open. The Component Manager searches for a component
  271. that meets those criteria. If you want to exert more control over the selection
  272. process, you can use the FindNextComponent() and OpenComponent() functions.
  273. Returns ComponentInstance.
  274.  
  275. =cut
  276. ComponentInstance
  277. OpenDefaultComponent(componentType, componentSubType = 0)
  278.     OSType componentType
  279.     OSType componentSubType
  280.  
  281. =item RegisterComponentResourceFile RESREFNUM, GLOBAL
  282.  
  283. The RegisterComponentResourceFile function registers all component resources in
  284. the given resource file according to the flags specified in the global parameter.
  285. Returns an integer value.
  286.  
  287. =cut
  288. long 
  289. RegisterComponentResourceFile(resRefNum, global)
  290.     short resRefNum
  291.     short global
  292.     CLEANUP:
  293.     if (RETVAL < 0) {
  294.         gLastMacOSErr = (short) RETVAL;
  295.         XSRETURN_UNDEF;
  296.     }
  297.  
  298.