📄 printerfactory.cpp
字号:
/*****************************************************************************\ Copyright (c) 2002 - 2002, Hewlett-Packard Co. All rights reserved. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: 1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. 2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. 3. Neither the name of Hewlett-Packard nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission. THIS SOFTWARE IS PROVIDED BY THE AUTHOR "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PATENT INFRINGEMENT; PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.\*****************************************************************************/// PrinterFactory.cpp - Morpheus component code base#include "header.h"#include <string.h>#include "printerfactory.h"APDK_BEGIN_NAMESPACEPrinterFactory* PrinterFactory::s_Instance = NULL; // enforce the singletonPrinterFactory::ProxyListElement* PrinterFactory::s_ProxyList = NULL;unsigned int PrinterFactory::s_uFamilyCount = 0;unsigned int PrinterFactory::s_uPrinterCount = 0;extern void HP_strcat(char* str1, const char* str2);//PrinterFactory//! Constructor for PrinterFactory/*!******************************************************************************/PrinterFactory::PrinterFactory(){ TRACE("PF::PF\n"); // the static factory is coming on-line, do what you need here. TRACE("PF - static factory construction complete\n");} //PrinterFactory//~PrinterFactory//! Destructor for PrinterFactory/*!******************************************************************************/PrinterFactory::~PrinterFactory(){ TRACE("PF::~PF - static factory destructing\n"); ProxyListElement* t_ListEntry; while (s_ProxyList) { TRACE(" - deleting %s from factory list\n", s_ProxyList->printerProxyElement->GetFamilyName()); t_ListEntry = s_ProxyList; s_ProxyList = t_ListEntry->next; delete t_ListEntry; } s_Instance = NULL; // factory is gone TRACE("finished PF::~PF\n");} //~PrinterFactory//Register//! Register proxy classes for printer families/*!This method is used by the constuctor of the PrinterProxy subclasses toregister themselves with the factory. They call Register(this) to passthemselves to the factory.******************************************************************************/void PrinterFactory::Register( const PrinterProxy* thePrinterProxy //!< [in]pointer to the PrinterProxy){ // use the first registration of a printer proxy to force the instantiation // of the only PrinterFactory if (s_Instance == NULL) { TRACE("PF::Register - asking for new factory\n"); // create the singleton s_Instance = new PrinterFactory; } TRACE("PF::Register\n"); // we know we'll need an entry in the list so create it first ProxyListElement* t_ListEntry = new(ProxyListElement); if (t_ListEntry == NULL) { // we have a problem - the driver is not running yet // the RTL is registering these static printer proxy servers and // the main code hasn't started yet. return; } // this list works so simply because we don't care about the order // and we always insert the next entry before the current head. t_ListEntry->printerProxyElement = thePrinterProxy; t_ListEntry->next = s_ProxyList; s_ProxyList = t_ListEntry; s_uFamilyCount++; s_uPrinterCount += thePrinterProxy->GetModelCount(); TRACE("PF::Register %s registered with PrinterFactory\n", thePrinterProxy->GetFamilyName()); TRACE("Printers supported by class are:\n"); MODEL_HANDLE myHandle = thePrinterProxy->StartModelNameEnum(); const char* printerName; while ((printerName = thePrinterProxy->GetNextModelName(myHandle))) { TRACE(" %s\n", printerName); }} //Register//UnRegister//! UnRegister proxy classes for printer families/*!PrinterProxy subclasses use this to unregister themselves with their destuctorexecutes.******************************************************************************/void PrinterFactory::UnRegister( const PrinterProxy* thePrinterProxy //!< [in]pointer to the PrinterProxy to unregister){ // use the first registration of a printer proxy to force the instantiation // of the only PrinterFactory if (s_Instance == NULL) { TRACE("Unregistering a PrinterProxy when factory does not exist\n"); return; } TRACE("PF::UnRegister %s\n", thePrinterProxy->GetFamilyName()); if (s_ProxyList == NULL) { TRACE("PF::UnRegister - Printer Factory printer list is empty!\n"); } ProxyListElement* prevListEntry = NULL; ProxyListElement* t_ListEntry = s_ProxyList; bool bFound = false; while ((t_ListEntry) && (!bFound)) { if (t_ListEntry->printerProxyElement == thePrinterProxy) { TRACE("We found the matching proxy by address\n"); bFound = true; if (prevListEntry != NULL) //somewhere in list { prevListEntry->next = t_ListEntry->next; } else // at head of list { s_ProxyList = t_ListEntry->next; } delete t_ListEntry; s_uFamilyCount--; s_uPrinterCount -= thePrinterProxy->GetModelCount(); } prevListEntry = t_ListEntry; t_ListEntry = t_ListEntry->next; } TRACE("PF::UnRegister removed %s from PrinterFactory\n", thePrinterProxy->GetFamilyName()); TRACE("PF::UnRegister - factory now supports %d families and %d printers\n", s_uFamilyCount, s_uPrinterCount); if (s_ProxyList == NULL) { TRACE("PF::UnRegister asking for deletion of empty Factory\n"); delete PrinterFactory::GetInstance(); }} //UnRegister//GetNextFamilyName//! return the next familiy name that is in the factory/*!Move to the next family in the factory and then return the name of that family.This moved to the next family first!FAMILY_HANDLE is changed to the next family. If there are no more families inthe factory then FAMILY_HANDLE will be NULL.\returnname of the next family in the factory<br>NULL if there are no more families in the factory******************************************************************************/const char* PrinterFactory::GetNextFamilyName( FAMILY_HANDLE& theFamilyHandle //!< [in][out]handle to the current family) const{ TRACE("PF::GetNextFamilyName()\n"); if (nextFamily(theFamilyHandle)) { return getPrinterProxy(theFamilyHandle)->GetFamilyName(); } else { return NULL; }} //GetNextFamilyName//GetFamilyName//! return the family namne that supports the printer/*!\returnthe name of the family that supports the printer name passed in. May be NULLif there is no family in the factory that supports the printer name.******************************************************************************/const char* PrinterFactory::GetFamilyName( const char* thePrinterName //!< [in] name of the printer model) const{ const char* szFamilyName = NULL; FAMILY_HANDLE myFamilyHandle = FindDevIdMatch(thePrinterName); if (myFamilyHandle) { szFamilyName = getPrinterProxy(myFamilyHandle)->GetFamilyName(); } return szFamilyName;} //GetFamilyName//NextModel//! return the next model name for the current family that is in the factory/*!MODEL_HANDLE is updated durint this processes\returnName of the next model that this family supports. Will be NULL at the end ofthe model list.******************************************************************************/const char* PrinterFactory::GetNextModelName( FAMILY_HANDLE theFamilyHandle, //!< [in] handle to the current family MODEL_HANDLE& theModelHandle //!< [in][out] handle to the current model) const{ TRACE("PF::GetNextModelName()\n"); const char* szModelName = NULL; if (theFamilyHandle == NULL) { theModelHandle = NULL; } else
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -