Boolean PrvIsLibOpen(UInt16 refNum) { Boolean isOpen = false; FlickrGlobals* globals = PrvLockGlobals(refNum); if (NULL != globals) { isOpen = true; PrvUnlockGlobals(globals); } return isOpen; }
Err ZDicFontClose(UInt16 refNum, UInt32 clientContext) { ZDicFontGlobalsType * gP; Int16 openCount; Int16 contextCount; Err err = errNone; gP = PrvLockGlobals(refNum); /* If not open, return */ if (!gP) { /* MUST return zero here to get around a bug in system v1.x that * would cause SysLibRemove to fail. */ return errNone; } /* Destroy the client context (we ignore the return code in this implementation) */ PrvDestroyClientContext(gP, clientContext); /* Decrement our library open count */ gP->openCount--; /* Error check for open count underflow */ ErrFatalDisplayIf(gP->openCount < 0, "ZDicFont open count underflow"); /* Save the new open count and the context count */ openCount = gP->openCount; contextCount = gP->contextCount; PrvUnlockGlobals(gP); /* If open count reached zero, free our library globals */ if ( openCount <= 0 ) { /* Error check to make sure that all client contexts were destroyed */ ErrFatalDisplayIf(contextCount != 0, "not all client contexts were destroyed"); /* Free our library globals */ PrvFreeGlobals(refNum); } else { /* return this error code to inform the caller * that others are still using this library */ err = ZDicFontErrStillOpen; } return err; }
static Boolean PrvIsLibOpen(UInt16 refNum) { ZDicFontGlobalsType * gP; Boolean isOpen = false; gP = PrvLockGlobals(refNum); if ( gP ) { isOpen = true; PrvUnlockGlobals(gP); } return( isOpen ); }
Err ZDicFontOpen(UInt16 refNum, UInt32 *clientContextP) { ZDicFontGlobalsType *gP; Err err = errNone; Int16 originalOpenCount = 0; /* Error-check our parameters */ ErrFatalDisplayIf( clientContextP == NULL, "null context variable pointer"); /* Initialize return variable */ *clientContextP = 0; /* Get library globals */ gP = PrvLockGlobals(refNum); /* Check if already open */ if (!gP) { /* Allocate and initialize our library globals. */ gP = PrvMakeGlobals(refNum); if ( !gP ) err = memErrNotEnoughSpace; } /* If we have globals, create a client context, increment open * count, and unlock our globals */ if ( gP ) { originalOpenCount = gP->openCount; err = PrvCreateClientContext(gP, clientContextP); if ( !err ) gP->openCount++; PrvUnlockGlobals(gP); /* If there was an error creating a client context and there */ /* are no other clients, free our globals */ if ( err && (originalOpenCount == 0) ) PrvFreeGlobals(refNum); } return( err ); }
static ZDicFontGlobalsType * PrvMakeGlobals(UInt16 refNum) { ZDicFontGlobalsType * gP = NULL; MemHandle gH; SysLibTblEntryType * libEntryP; /* Get library globals */ libEntryP = SysLibTblEntry(refNum); ErrFatalDisplayIf(libEntryP == NULL, "invalid ZDicFont refNum"); /* Error check to make sure the globals don't already exist */ ErrFatalDisplayIf(libEntryP->globalsP, "ZDicFont globals already exist"); /* Allocate and initialize our library globals. */ gH = MemHandleNew(sizeof(ZDicFontGlobalsType)); if ( !gH ) return( NULL ); /* Save the handle of our library globals in the system library table */ /* entry so we can later retrieve it using SysLibTblEntry(). */ libEntryP->globalsP = (void*)gH; /* Lock our globals (should not fail) */ gP = PrvLockGlobals(refNum); ErrFatalDisplayIf(gP == NULL, "failed to lock ZDicFont globals"); /* Set the owner of our globals memory chunk to "system" (zero), so it won't get * freed automatically by Memory Manager when the first application to call * ZDicFontOpen exits. This is important if the library is going to stay open * between apps. */ MemPtrSetOwner(gP, 0); /* Initialize our library globals */ MemSet(gP, sizeof(ZDicFontGlobalsType), 0); /* for convenience and debugging, save ref in globals structure */ gP->thisLibRefNum = refNum; /* initial open count */ gP->openCount = 0; /* return a pointer to our *locked* globals */ return( gP ); }
Err FlickrClose(UInt16 refNum) { FlickrGlobals * gP; Int16 openCount; Err err = errNone; DMSG("FlickrClose() enter\n"); gP = PrvLockGlobals(refNum); /* If not open, return */ if (!gP) { /* MUST return zero here to get around a bug in system v1.x that * would cause SysLibRemove to fail. */ return errNone; } /* Decrement our library open count */ gP->openCount--; /* Error check for open count underflow */ ErrFatalDisplayIf(gP->openCount < 0, "InfoMan Flickr Uploader open count underflow"); /* Save the new open count and the context count */ openCount = gP->openCount; PrvUnlockGlobals(gP); /* If open count reached zero, free our library globals */ if ( openCount <= 0 ) { /* Free our library globals */ PrvFreeGlobals(refNum); } else { /* return this error code to inform the caller * that others are still using this library */ err = flickrErrStillOpen; } DMSG("FlickrClose() exit\n"); return err; }
Err FlickrOpen(UInt16 refNum) { FlickrGlobals *gP; Err err = errNone; Int16 originalOpenCount = 0; DMSG("FlickrOpen() enter\n"); /* Get library globals */ gP = PrvLockGlobals(refNum); /* Check if already open */ if (!gP) { /* Allocate and initialize our library globals. */ gP = PrvMakeGlobals(refNum); if ( !gP ) err = memErrNotEnoughSpace; } /* If we have globals, create a client context, increment open * count, and unlock our globals */ if ( gP ) { originalOpenCount = gP->openCount; if ( !err ) gP->openCount++; PrvUnlockGlobals(gP); /* If there was an error creating a client context and there */ /* are no other clients, free our globals */ if ( err && (originalOpenCount == 0) ) PrvFreeGlobals(refNum); } DMSG("FlickrOpen() exit\n"); return err; }