home *** CD-ROM | disk | FTP | other *** search
Text File | 1993-06-02 | 6.0 KB | 271 lines | [TEXT/KAHL] |
- /*
- File: Larry.c
-
- Contains: Larry component routines.
-
- Refer to develop Issue 15, "Managing Component Registration",
- for details on this code.
-
- Written by: Gary Woodcock
-
- Copyright: © 1993 by Apple Computer, Inc.
-
- Change History (most recent first):
-
- */
-
- //-----------------------------------------------------------------------
- // Includes
-
- #include "LarryPrivate.h"
-
- #include <Errors.h>
- #include <Memory.h>
- #include <Packages.h>
- #include <SysEqu.h>
- #include <OSUtils.h>
-
- //-----------------------------------------------------------------------
-
- #ifdef BUILD_LINKED
-
- // Use this declaration when we're running linked (for debugging)
- pascal ComponentResult
- LarryDispatcher (ComponentParameters *params, Handle storage)
-
- #else
-
- // Use this declaration when we're a standalone component
- pascal ComponentResult
- main (ComponentParameters *params, Handle storage)
-
- #endif BUILD_LINKED
-
- {
- // This routine is the main dispatcher for the component
-
- ComponentResult result = noErr;
- ComponentFunction larryFunction = nil;
-
- // Did we get a Component Manager request code (< 0)?
- if (params->what < 0)
- {
- switch (params->what)
- {
- case kComponentOpenSelect: // Open request
- {
- larryFunction = _LarryOpen;
- break;
- }
- case kComponentCloseSelect: // Close request
- {
- larryFunction = _LarryClose;
- break;
- }
- case kComponentCanDoSelect: // Can Do request
- {
- result = CallComponentFunction (params,
- (ComponentFunction) _LarryCanDo);
- break;
- }
- case kComponentVersionSelect: // Version request
- {
- result = CallComponentFunction (params,
- (ComponentFunction) _LarryVersion);
- break;
- }
- case kComponentRegisterSelect: // Register request
- {
- result = CallComponentFunction (params,
- (ComponentFunction) _LarryRegister);
- break;
- }
- case kComponentTargetSelect: // Target request not supported
- case kComponentUnregisterSelect: // Unregister request not supported
- default: // Unknown request
- {
- result = badComponentSelector;
- break;
- }
- }
- }
- else // Unknown request
- {
- result = badComponentSelector;
- }
- if (larryFunction != nil)
- {
- result = CallComponentFunctionWithStorage (storage, params, larryFunction);
- }
- return (result);
- }
-
- //-----------------------------------------------------------------------
-
- pascal ComponentResult
- _LarryOpen (Handle storage, ComponentInstance self)
- {
- #pragma unused (storage)
-
- ComponentResult result = noErr;
-
- #ifdef THINK_C
- SetComponentInstanceA5 (self, *(long *) CurrentA5);
- #endif THINK_C
-
- // Can we open another instance?
- if (CountComponentInstances ((Component) self) <= kMaxLarryInstances)
- {
- // Set up our instance storage
- LarryPrivateGlobalsHdl globals = (LarryPrivateGlobalsHdl) NewHandleClear (sizeof (LarryPrivateGlobals));
-
- // Did we get our storage?
- if (globals != nil)
- {
- // Keep a reference to self
- (**globals).self = (Component) self;
-
- // Set storage ref
- SetComponentInstanceStorage (self, (Handle) globals);
- }
- else // NewHandleClear failed
- {
- result = MemError();
- }
- }
- else // No more instances can be opened
- {
- result = -1L; // Return anonymous error
- }
- return (result);
- }
-
- //-----------------------------------------------------------------------
-
- pascal ComponentResult
- _LarryClose (Handle storage, ComponentInstance self)
- {
- LarryPrivateGlobalsHdl globals = (LarryPrivateGlobalsHdl) storage;
- ComponentResult result = noErr;
-
- // Do we have any clean up to do?
- if (globals != nil)
- {
- // Dispose globals
- DisposHandle ((Handle) globals);
- }
- return (result);
- }
-
- //-----------------------------------------------------------------------
-
- pascal ComponentResult
- _LarryCanDo (short selector)
- {
- // Case on the request code
- switch (selector)
- {
- // Component Manager request codes
- case kComponentOpenSelect:
- case kComponentCloseSelect:
- case kComponentCanDoSelect:
- case kComponentVersionSelect:
- case kComponentRegisterSelect:
- {
- return (true);
- }
-
- // Unsupported or unknown request codes
- case kComponentTargetSelect: // Target request not supported
- case kComponentUnregisterSelect: // Unregister request not supported
- default: // Not a request code we recognize
- {
- return (false);
- }
- }
- }
-
- //-----------------------------------------------------------------------
-
- pascal ComponentResult
- _LarryVersion (void)
- {
- // Return the version info
- return (larryInterfaceRev);
- }
-
- //-----------------------------------------------------------------------
-
- pascal ComponentResult
- _LarryRegister (void)
- {
- ComponentDescription theDesc;
- Component moeCompID;
- long dummy;
-
- // Set up component description for Moe
- theDesc.componentType = 'moe ';
- theDesc.componentSubType = kAnyComponentSubType;
- theDesc.componentManufacturer = 'appl';
- theDesc.componentFlags = 0L;
- theDesc.componentFlagsMask = kAnyComponentFlagsMask;
-
- // Try to find Moe
- moeCompID = FindNextComponent (nil, &theDesc);
-
- // If we found Moe, we can register
- if (moeCompID != 0L)
- {
- // Beep twice to let us know Larry's registered
- SysBeep(5);
- SysBeep(5);
-
- // Delay for a sec (just to keep all the components' beeps from
- // running together)
- Delay (60, &dummy);
- }
-
- return ((moeCompID != 0L) ? 0L : 1L);
- }
-
- //-----------------------------------------------------------------------
-
- #ifdef THINK_C
- #ifdef BUILD_LINKED
-
- Component
- RegisterLarry (void)
- {
- ComponentDescription theDesc;
- Handle name;
- Component theComp;
-
- // Set up component description
- theDesc.componentType = 'lary';
- theDesc.componentSubType = kAnyComponentSubType;
- theDesc.componentManufacturer = 'appl';
- theDesc.componentFlags = cmpWantsRegisterMessage;
- theDesc.componentFlagsMask = kAnyComponentFlagsMask;
-
- // Name the component
- PtrToHand ("\pLarry (linked)", &name, 14);
-
- // Register with the component main entry point
- theComp = RegisterComponent (&theDesc, (void *)LarryDispatcher, 0, name, 0, 0);
-
- // Clean up
- if (name != nil)
- {
- DisposHandle (name);
- }
- return (theComp);
- }
-
- #endif BUILD_LINKED
- #endif THINK_C
-
- //-----------------------------------------------------------------------
-
-
-
-