📄 xprint.c
字号:
}/****************************************************************************** * * Context functions: Init, Set, Destroy, FreeContext * AllocateContextPrivateIndex, AllocateContextPrivate * and supporting functions. * * Init creates a context, creates a XpClientRec for the calling * client, and stores the contextPtr in the client's devPrivates. * * Set creates a XpClientRec for the calling client, and stores the * contextPtr in the client's devPrivates unless the context is None. * If the context is None, then the client's connection association * with any context is removed. * * Destroy frees any and all XpClientRecs associated with the context, * frees the context itself, and removes the contextPtr from any * relevant client devPrivates. * * FreeContext is called by FreeResource to free up a context. * ******************************************************************************//* * CreateContext creates and initializes the memory for the context itself. * The driver's CreateContext function * is then called. */static intProcXpCreateContext(client) ClientPtr client;{ REQUEST(xPrintCreateContextReq); XpScreenPtr pPrintScreen; WindowPtr pRoot; char *printerName, *driverName; XpContextPtr pContext; XpClientPtr pNewPrintClient; int result = Success; XpDriverPtr pDriver; REQUEST_AT_LEAST_SIZE(xPrintCreateContextReq); LEGAL_NEW_RESOURCE(stuff->contextID, client); /* * Check to see if the printer name is valid. */ if((pRoot = XpDiValidatePrinter(stuff + 1, stuff->printerNameLen)) == (WindowPtr)NULL) return BadMatch; pPrintScreen = XpScreens[pRoot->drawable.pScreen->myNum]; /* * Allocate and add the context resource. */ if((pContext = (XpContextPtr) xalloc(totalContextSize)) == (XpContextPtr) NULL) return BadAlloc; InitContextPrivates(pContext); if(AddResource(stuff->contextID, RTcontext, (pointer) pContext) != TRUE) { xfree(pContext); return BadAlloc; } pContext->contextID = stuff->contextID; pContext->clientHead = (XpClientPtr)NULL; pContext->screenNum = pRoot->drawable.pScreen->myNum; pContext->state = 0; pContext->clientSlept = (ClientPtr)NULL; pContext->imageRes = 0; pContext->funcs.DestroyContext = (int (*)())NULL; pContext->funcs.StartJob = (int (*)())NULL; pContext->funcs.EndJob = (int (*)())NULL; pContext->funcs.StartDoc = (int (*)())NULL; pContext->funcs.EndDoc = (int (*)())NULL; pContext->funcs.StartPage = (int (*)())NULL; pContext->funcs.EndPage = (int (*)())NULL; pContext->funcs.PutDocumentData = (int (*)())NULL; pContext->funcs.GetDocumentData = (int (*)())NULL; pContext->funcs.GetAttributes = (char * (*)())NULL; pContext->funcs.GetOneAttribute = (char * (*)())NULL; pContext->funcs.SetAttributes = (int (*)())NULL; pContext->funcs.AugmentAttributes = (int (*)())NULL; pContext->funcs.GetMediumDimensions = (int (*)())NULL; pContext->funcs.GetReproducibleArea = (int (*)())NULL; pContext->funcs.SetImageResolution = (int (*)())NULL; if((pContext->printerName = (char *)xalloc(stuff->printerNameLen + 1)) == (char *)NULL) { /* Freeing the context also causes the XpClients to be freed. */ FreeResource(stuff->contextID, RT_NONE); return BadAlloc; } strncpy(pContext->printerName, (char *)(stuff + 1), stuff->printerNameLen); pContext->printerName[stuff->printerNameLen] = (char)'\0'; driverName = XpDiGetDriverName(pRoot->drawable.pScreen->myNum, pContext->printerName); for(pDriver = pPrintScreen->drivers; pDriver != (XpDriverPtr)NULL; pDriver = pDriver->next) { if(!strcmp(driverName, pDriver->name)) { if(pDriver->CreateContext != (Bool (*)())NULL) pDriver->CreateContext(pContext); else return BadImplementation; break; } } if (client->noClientException != Success) return client->noClientException; else return result;}/* * SetContext creates the calling client's contextClient resource, * and stashes the contextID in the client's devPrivate. */static intProcXpSetContext(client) ClientPtr client;{ REQUEST(xPrintSetContextReq); XpContextPtr pContext; XpClientPtr pPrintClient; int result = Success; REQUEST_AT_LEAST_SIZE(xPrintSetContextReq); if((pContext = client->devPrivates[XpClientPrivateIndex].ptr) != (pointer)NULL) { /* * Erase this client's knowledge of its old context, if any. */ if((pPrintClient = FindClient(pContext, client)) != (XpClientPtr)NULL) { XpUnsetFontResFunc(client); if(pPrintClient->eventMask == 0) FreeXpClient(pPrintClient, TRUE); } client->devPrivates[XpClientPrivateIndex].ptr = (pointer)NULL; } if(stuff->printContext == None) return Success; /* * Check to see that the supplied XID is really a valid print context * in this server. */ if((pContext =(XpContextPtr)SecurityLookupIDByType(client, stuff->printContext, RTcontext, SecurityWriteAccess)) == (XpContextPtr)NULL) { client->errorValue = stuff->printContext; return XpErrorBase+XPBadContext; } if((pPrintClient = AcquireClient(pContext, client)) == (XpClientPtr)NULL) return BadAlloc; client->devPrivates[XpClientPrivateIndex].ptr = pContext; XpSetFontResFunc(client); if (client->noClientException != Success) return client->noClientException; else return result;}XpContextPtrXpGetPrintContext(client) ClientPtr client;{ return (client->devPrivates[XpClientPrivateIndex].ptr);}static intProcXpGetContext(client) ClientPtr client;{ REQUEST(xPrintGetContextReq); xPrintGetContextReply rep; XpContextPtr pContext; XpClientPtr pNewPrintClient; int result = Success; register int n; register long l; REQUEST_SIZE_MATCH(xPrintGetContextReq); if((pContext = client->devPrivates[XpClientPrivateIndex].ptr) == (pointer)NULL) rep.printContext = None; else rep.printContext = pContext->contextID; rep.type = X_Reply; rep.length = 0; rep.sequenceNumber = client->sequence; if (client->swapped) { swaps(&rep.sequenceNumber, n); swapl(&rep.length, l); swapl(&rep.printContext, l); } WriteToClient(client, sz_xPrintGetContextReply, (char *)&rep); return client->noClientException;}/* * DestroyContext frees the context associated with the calling client. * It operates by freeing the context resource ID, thus causing XpFreeContext * to be called. */static intProcXpDestroyContext(client) ClientPtr client;{ REQUEST(xPrintDestroyContextReq); XpContextPtr pContext; XpClientPtr pXpClient; ClientPtr curClient; REQUEST_SIZE_MATCH(xPrintDestroyContextReq); if((pContext =(XpContextPtr)SecurityLookupIDByType(client, stuff->printContext, RTcontext, SecurityDestroyAccess)) == (XpContextPtr)NULL) { client->errorValue = stuff->printContext; return XpErrorBase+XPBadContext; } XpUnsetFontResFunc(client); FreeResource(pContext->contextID, RT_NONE); return Success;}static intProcXpGetContextScreen(client) ClientPtr client;{ REQUEST(xPrintGetContextScreenReq); xPrintGetContextScreenReply rep; XpContextPtr pContext; int n; long l; if((pContext =(XpContextPtr)SecurityLookupIDByType(client, stuff->printContext, RTcontext, SecurityReadAccess)) == (XpContextPtr)NULL) return XpErrorBase+XPBadContext; rep.type = X_Reply; rep.sequenceNumber = client->sequence; rep.length = 0; rep.rootWindow = WindowTable[pContext->screenNum]->drawable.id; if (client->swapped) { swaps(&rep.sequenceNumber, n); swapl(&rep.length, l); swapl(&rep.rootWindow, l); } WriteToClient(client, sz_xPrintGetContextScreenReply, (char *)&rep); return client->noClientException;}/* * XpFreeContext is the routine called by dix:FreeResource when a context * resource ID is freed. * It checks to see if there's a partial job pending on the context, and * if so it calls the appropriate End procs with the cancel flag set. * It calls the driver's DestroyContext routine to allow the driver to clean * up any context-related memory or state. * It calls FreeXpClient to free all the * associated XpClientRecs and to set all the client->devPrivates to NULL. * It frees the printer name string, and frees the context * itself. */static intXpFreeContext(data, id) pointer data; XID id;{ XpContextPtr pContext = (XpContextPtr)data; /* Clean up any pending job on this context */ if(pContext->state != 0) { if(pContext->state & PAGE_STARTED) { WindowPtr pWin = (WindowPtr )LookupIDByType( pContext->pageWin, RT_WINDOW); XpPagePtr pPage = (XpPagePtr)LookupIDByType( pContext->pageWin, RTpage); pContext->funcs.EndPage(pContext, pWin, TRUE); SendXpNotify(pContext, XPEndPageNotify, TRUE); pContext->state &= ~PAGE_STARTED; if(pPage) pPage->context = (XpContextPtr)NULL; } if((pContext->state & DOC_RAW_STARTED) || (pContext->state & DOC_COOKED_STARTED)) { pContext->funcs.EndDoc(pContext, TRUE); SendXpNotify(pContext, XPEndDocNotify, TRUE); pContext->state &= ~DOC_RAW_STARTED; pContext->state &= ~DOC_COOKED_STARTED; } if(pContext->funcs.EndJob != (int (*)())NULL) { pContext->funcs.EndJob(pContext, TRUE); SendXpNotify(pContext, XPEndJobNotify, TRUE); pContext->state &= ~JOB_STARTED; pContext->state &= ~GET_DOC_DATA_STARTED; } } /* * Tell the driver we're destroying the context * This allows the driver to free and ContextPrivate data */ if(pContext->funcs.DestroyContext != (int (*)())NULL) pContext->funcs.DestroyContext(pContext); /* Free up all the XpClientRecs */ while(pContext->clientHead != (XpClientPtr)NULL) { FreeXpClient(pContext->clientHead, TRUE); } xfree(pContext->printerName); xfree(pContext); return Success; /* ??? */}/* * XpFreeClient is the routine called by dix:FreeResource when a RTclient * is freed. It simply calls the FreeXpClient routine to do the work. */static intXpFreeClient(data, id) pointer data; XID id;{ FreeXpClient((XpClientPtr)data, FALSE); return Success;}/* * FreeXpClient * frees the ClientRec passed in, and sets the client->devPrivates to NULL * if the client->devPrivates points to the same context as the XpClient. * Called from XpFreeContext(from FreeResource), and * XpFreeClient. The boolean freeResource specifies whether or not to call * FreeResource for the XpClientRec's XID. We should free it except if we're * called from XpFreeClient (which is itself called from FreeResource for the * XpClientRec's XID). */static voidFreeXpClient(pXpClient, freeResource) XpClientPtr pXpClient; Bool freeResource;{ XpClientPtr pCurrent, pPrev; XpContextPtr pContext = pXpClient->context; /* * If we're freeing the clientRec associated with the context tied * to the client's devPrivates, then we need to clear the devPrivates. */ if(pXpClient->client->devPrivates[XpClientPrivateIndex].ptr == pXpClient->context) { pXpClient->client->devPrivates[XpClientPrivateIndex].ptr = (pointer)NULL; } for(pPrev = (XpClientPtr)NULL, pCurrent = pContext->clientHead; pCurrent != (XpClientPtr)NULL; pCurrent = pCurrent->pNext) { if(pCurrent == pXpClient) { if(freeResource == TRUE) FreeResource (pCurrent->contextClientID, RTclient); if (pPrev != (XpClientPtr)NULL) pPrev->pNext = pCurrent->pNext; else pContext->clientHead = pCurrent->pNext; xfree (pCurrent); break; } pPrev = pCurrent; }}/* * CreateXpClient takes a ClientPtr and returns a pointer to a * XpClientRec which it allocates. It also initializes the Rec, * including adding a resource on behalf of the client to enable the * freeing of the Rec when the client's connection is closed. */static XpClientPtrCreateXpClient(client) ClientPtr client;{ XpClientPtr pNewPrintClient; XID clientResource; if((pNewPrintClient = (XpClientPtr)xalloc(sizeof(XpClientRec))) == (XpClientPtr)NULL) return (XpClientPtr)NULL; clientResource = FakeClientID(client->index); if(!AddResource(clientResource, RTclient, (pointer)pNewPrintClient)) { xfree (pNewPrintClient); return (XpClientPtr)NULL; } pNewPrintClient->pNext = (XpClientPtr)NULL; pNewPrintClient->client = client; pNewPrintClient->context = (XpContextPtr)NULL; pNewPrintClient->eventMask = 0; pNewPrintClient->contextClientID = clientResource; return pNewPrintClient;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -