home *** CD-ROM | disk | FTP | other *** search
/ QuickTime 2.0 Beta / Quicktime 2.0 Beta.iso / Programming Stuff / Sample Code / DTS Sample Code / DelegateOnlyComponent ƒ / MyComponent.c < prev    next >
Encoding:
C/C++ Source or Header  |  1994-03-22  |  5.0 KB  |  213 lines  |  [TEXT/KAHL]

  1. /*
  2.     File:        MyComponent.c
  3.     
  4.     Contains:    simple component sample.
  5.  
  6.     Written by:    John Wang
  7.  
  8.     Copyright:    © 1994 by Apple Computer, Inc., all rights reserved.
  9.  
  10.     Change History (most recent first):
  11.  
  12.         <1>        03/22/94    JW        Created.
  13.  
  14.     To Do:
  15.     
  16. */
  17.  
  18. #ifdef THINK_C
  19. #define        applec
  20. #endif
  21.  
  22. #include    <Memory.h>
  23. #include    <Errors.h>
  24. #include    <Components.h>
  25. #include    <Movies.h>
  26. #include    <QuickTimeComponents.h>
  27. #include    <Components.h>
  28. #include    <LowMem.h>
  29.  
  30. #include    "MyComponent.h"
  31. #include    "MyComponentRoutines.h"
  32.  
  33. /* ------------------------------------------------------------------------- */
  34.  
  35. //    Component entry point.
  36.  
  37. pascal ComponentResult main(ComponentParameters *params, char **storage)
  38. {
  39.     PrivateGlobals         **myPrivateGlobals = (PrivateGlobals **) storage;
  40.     long                ret;
  41.     
  42.     if ( kDEBUGME )
  43.         DebugStr("\pIn main()");
  44.     
  45.     if ( params->what < 0 ) { 
  46.         switch ( params->what ) {
  47.             case kComponentOpenSelect:
  48.                 return ( CallComponentFunction(params, (ComponentFunctionUPP) MyOpen) );
  49.     
  50.             case kComponentCloseSelect:
  51.                 return ( CallComponentFunctionWithStorage(storage, params,
  52.                         (ComponentFunctionUPP) MyClose) );
  53.                 
  54.             case kComponentCanDoSelect:
  55.                 ret = CallComponentFunction(params, (ComponentFunctionUPP) MyCanDo);
  56.                 if ( ret == false ) {
  57.                     DebugStr("\pIn kComponentCanDoSelect");
  58.                     if ( (**myPrivateGlobals).delegate ) {
  59.                         ret = DelegateComponentCall(params, (**myPrivateGlobals).delegate);
  60.                     }
  61.                 }
  62.                 return ( ret );
  63.     
  64.             case kComponentVersionSelect: 
  65.                 return ( CallComponentFunction(params, (ComponentFunctionUPP) MyVersion) );
  66.     
  67.             case kComponentRegisterSelect: 
  68.                 return ( CallComponentFunctionWithStorage(storage, params,
  69.                         (ComponentFunctionUPP) MyRegister) );
  70.  
  71.             case kComponentTargetSelect: 
  72.                 return ( CallComponentFunctionWithStorage(storage, params,
  73.                         (ComponentFunctionUPP) MyTarget) );
  74.  
  75.             default:
  76.                 return ( paramErr );
  77.         }
  78.     } else {
  79.         switch ( params->what ) {
  80.             default:
  81.                 if ( (**myPrivateGlobals).delegate ) {
  82.                     //    If base media handler is targeted, then delegate all unimplemented
  83.                     //    calls to the base media handler.
  84.                     long    ret;
  85.                     
  86.                     ret = DelegateComponentCall(params, (**myPrivateGlobals).delegate);
  87.                     return ( ret );
  88.                 } else {
  89.                     //    If base media handler has not been targeted, then return paramErr.
  90.                     return ( paramErr );
  91.                 }
  92.         }
  93.     }
  94. }
  95.  
  96. /* ------------------------------------------------------------------------- */
  97.  
  98. //    Required component calls.
  99.  
  100. pascal ComponentResult MyOpen(ComponentInstance self)
  101. {
  102.     PrivateGlobals             **myPrivateGlobals;
  103.     ComponentInstance        myComp;
  104.     ComponentDescription    searchComp;
  105.     Component                dataHandler;
  106.     
  107.     if ( kDEBUGME )
  108.         DebugStr("\pIn MyOpen()");
  109.         
  110.     myPrivateGlobals = nil;
  111.     searchComp.componentType = 'dhlr';
  112.     searchComp.componentSubType = 'alis';
  113.     searchComp.componentManufacturer = 'appl';
  114.     searchComp.componentFlags = 0x40000000;
  115.     searchComp.componentFlagsMask = 0x40000000;
  116.  
  117.     //    Open base media handler component and target it.
  118.     dataHandler = FindNextComponent(nil, &searchComp);
  119.     if (dataHandler == nil) {
  120.         DebugStr("\pCould not find data handler.");
  121.     }
  122.     if ((myComp = OpenComponent(dataHandler)) == nil) {
  123.         return(componentNotCaptured);
  124.     }
  125.     ComponentSetTarget(myComp, self);
  126.     
  127.     //    Create private variables.
  128.     myPrivateGlobals = (PrivateGlobals **) NewHandleClear(sizeof(PrivateGlobals));
  129.     if ( myPrivateGlobals == nil )
  130.         goto bail;
  131.     
  132.     //    Initialize private variables.
  133.     (**myPrivateGlobals).delegate = myComp;
  134.  
  135.     //    Since we've gotten here, everyt hings ok and we can set up the connection.
  136.     SetComponentInstanceStorage(self, (Handle) myPrivateGlobals);
  137.     return ( noErr );
  138.  
  139. bail:
  140.     if ( myPrivateGlobals )
  141.         DisposeHandle((Handle) myPrivateGlobals);
  142.     return ( memFullErr );
  143. }
  144.  
  145. pascal ComponentResult MyClose(Handle storage, ComponentInstance self)
  146. {
  147.     PrivateGlobals         **myPrivateGlobals = (PrivateGlobals **) storage;
  148.  
  149.     if ( kDEBUGME )
  150.         DebugStr("\pIn MyClose()");
  151.         
  152.     //    Dispose of private variables.
  153.     if ( myPrivateGlobals ) {
  154.         if ((**myPrivateGlobals).delegate) {
  155.             CloseComponent((**myPrivateGlobals).delegate);
  156.             (**myPrivateGlobals).delegate = nil;
  157.         }
  158.         DisposeHandle((Handle) myPrivateGlobals);
  159.     }
  160.     
  161.     return ( noErr );
  162. }
  163.  
  164. pascal ComponentResult MyCanDo(short selector)
  165. {    
  166.     long    ret;
  167.  
  168.     if ( kDEBUGME )
  169.         DebugStr("\pIn MyCanDo()");
  170.     
  171.     switch ( selector ) {
  172.     
  173.         //    Required component calls.
  174.         case kComponentOpenSelect:
  175.         case kComponentCloseSelect:
  176.         case kComponentCanDoSelect:
  177.         case kComponentVersionSelect: 
  178.         case kComponentRegisterSelect: 
  179.         case kComponentTargetSelect: 
  180.  
  181.         //    MyComponent specific calls.
  182.  
  183.         //    Not handled.
  184.         default:
  185.             return ( false );
  186.     }
  187. }
  188.  
  189. pascal ComponentResult MyVersion()
  190. {
  191.     if ( kDEBUGME )
  192.         DebugStr("\pIn MyVersion()");
  193.  
  194.     return ( (kMyComponentSpec<<16) | (kMyComponentVersion) );
  195. }
  196.  
  197. pascal ComponentResult MyRegister()
  198. {
  199.     return ( false );
  200. }
  201.  
  202. pascal ComponentResult MyTarget(Handle storage, ComponentInstance self)
  203. {
  204.     PrivateGlobals         **myPrivateGlobals = (PrivateGlobals **) storage;
  205.  
  206.     if ( kDEBUGME )
  207.         DebugStr("\pIn MyTarget()");
  208.  
  209.     //    From now on, self will be the component instance that targeted us.
  210.     (**myPrivateGlobals).self = self;
  211.     
  212.     return ( noErr );
  213. }