Retired Document
Important: This sample code may not represent best practices for current development. The project may use deprecated symbols and illustrate technologies and techniques that are no longer recommended.
sources/clientUAMGlue.c
// |
// Apple Macintosh Developer Technical Support |
// Written by: Vinnie Moscaritolo |
// |
// Copyright (work in progress) Apple Computer, Inc All rights reserved. |
// |
// You may incorporate this sample code into your applications without |
// restriction, though the sample code has been provided "AS IS" and the |
// responsibility for its operation is 100% yours. However, what you are |
// not permitted to do is to redistribute the source as "DSC Sample Code" |
// after having made changes. If you're going to re-distribute the source, |
// we require that you make it clear in the source that the code was |
// descended from Apple Sample Code, but that you've made changes. |
// |
//------------------------------------------------------------------------------------ |
#pragma mark Includes |
//------------------------------------------------------------------------------------ |
#include <stdio.h> |
#include <String.h> |
#include <Errors.h> |
#include <A4Stuff.h> |
#include <Dialogs.h> |
#include <Resources.h> |
#include <CodeFragments.h> |
#include <MixedMode.h> |
#include <RegisterFileLibs.h> |
#include "ClientUAM.h" |
// --------------------------------------------------------------------------- |
#pragma mark local Prototypes |
// --------------------------------------------------------------------------- |
typedef pascal OSStatus (*UAMCallProcPtr) (UAMArgs *theArgs); |
pascal OSStatus main (UAMArgs *theArgs); |
OSErr MAKEFSSPECFROMREFNUM (short theRefNum, FSSpec *theFileSpec); |
UniversalProcPtr mainAddr = nil; |
CFragConnectionID connID = nil; |
// --------------------------------------------------------------------------- |
pascal OSStatus main(UAMArgs *theArgs) |
// --------------------------------------------------------------------------- |
{ |
OSStatus ErrNo = noErr; |
Str255 errorMessage; |
SInt16 itemHit; |
FSSpec theFileSpec; |
ProcPtr codePtr; |
EnterCodeResource(); |
// first time through |
if(mainAddr == nil) { |
ErrNo = MAKEFSSPECFROMREFNUM( CurResFile(), &theFileSpec); |
if (ErrNo != noErr){ |
DebugStr("\pError Could't make fsspec , HUH\n"); |
goto Error; |
} |
ErrNo = RegisterFileLibs (&theFileSpec ); |
if ((ErrNo != noErr ) && (ErrNo != cfragDupRegistrationErr)) |
{ |
DebugStr("\pError Could't make RegisterFileLibs\n"); |
goto Error; |
} |
// Activate the PGPUAM ppc module |
ErrNo = GetSharedLibrary("\pPGPUAM.PPC", |
kPowerPCCFragArch, |
kReferenceCFrag, |
&connID, |
&(Ptr)codePtr, |
errorMessage); |
if (ErrNo != noErr){ |
DebugStr("\pError Could't load PGPUAM\n"); |
goto Error; |
} |
if (codePtr == nil) { |
DebugStr("\pError PGPUAM mainAddr == nil\n"); |
CloseConnection(&connID); |
ErrNo = -1; //kOutOfMemoryErr |
goto Error; |
} |
mainAddr = NewRoutineDescriptorTrap(codePtr, kUAMCallProcInfo,kPowerPCISA); |
} |
ErrNo = ((UAMCallProcPtr)mainAddr) (theArgs); |
if((mainAddr != nil) |
&& ( (theArgs->command == kUAMClose) |
|| ((theArgs->command == kUAMOpen) && (ErrNo != noErr)))) |
{ |
DisposeRoutineDescriptor(mainAddr); |
CloseConnection(&connID); |
mainAddr = nil; |
} |
ExitCodeResource(); |
return ErrNo; |
Error: |
// handle error |
StandardAlert(kAlertStopAlert,"\pPGPUAM Failed to load",nil, nil , &itemHit); |
ExitCodeResource(); |
return ErrNo; |
} |
/* |
** MakeFSSpecFromRefNum - make an FSSpec from an open path's file |
** reference number |
** |
*/ |
OSErr MAKEFSSPECFROMREFNUM(short theRefNum, FSSpec *theFileSpec) |
{ |
FCBPBRec theFCBInfo; |
OSErr theError; |
/* Use PBGetFCBInfo to get the relevant information */ |
theFCBInfo.ioNamePtr = theFileSpec->name; |
theFCBInfo.ioVRefNum = 0; |
theFCBInfo.ioRefNum = theRefNum; |
theFCBInfo.ioFCBIndx = 0; |
theError = PBGetFCBInfoSync(&theFCBInfo); |
if( theError == noErr ){ |
theFileSpec->vRefNum = theFCBInfo.ioFCBVRefNum; |
theFileSpec->parID = theFCBInfo.ioFCBParID; |
} |
return(theError); |
} /* MakeFSSpecFromRefNum */ |
Copyright © 2003 Apple Computer, Inc. All Rights Reserved. Terms of Use | Privacy Policy | Updated: 2003-07-22