DirectPrint/DirectPrintServer/inc/directprintbody.h
changeset 19 2275db202402
parent 11 613a5ff70823
equal deleted inserted replaced
2:acc370d7f2f6 19:2275db202402
       
     1 /*
       
     2 * Copyright (c) 2010 Kanrikogaku Kenkyusho, Ltd.
       
     3 * All rights reserved.
       
     4 * This component and the accompanying materials are made available
       
     5 * under the terms of the License "Eclipse Public License v1.0"
       
     6 * which accompanies this distribution, and is available
       
     7 * at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     8 *
       
     9 * Initial Contributors:
       
    10 * Kanrikogaku Kenkyusho, Ltd. - Initial contribution
       
    11 *
       
    12 * Contributors:
       
    13 *
       
    14 * Description:  Contains the CDirectPrintBody class definition.
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 // Protection against nested includes
       
    20 #ifndef CDIRECTPRINTBODY_H
       
    21 #define CDIRECTPRINTBODY_H
       
    22 
       
    23 // System includes
       
    24 #include <e32base.h>
       
    25 
       
    26 // User includes
       
    27 #include "imageprint.h"
       
    28 #include "directprintprotocolsloader.h"
       
    29 #include "directprintscheduler.h"
       
    30 #include "mprotprintingdevice.h"
       
    31 
       
    32 // Forward declarations
       
    33 class TDpMessage;
       
    34 
       
    35 /**
       
    36  *
       
    37  *	This class is in charge of discoverying devices across the protocols available, of creating
       
    38  *	a print job in the right printer and right protocol, etc. It can be considered a controller. 
       
    39  *	Implements the MProtPrintingDevice observers (MProtDiscoveryObserver, MProtPrintEventObserver) so it can act
       
    40  *	accordingly when the protocols report or need something.
       
    41  */
       
    42 class CDirectPrintBody : public CBase, public MProtDiscoveryObserver, public MProtPrintEventObserver, public MProtIdleObserver
       
    43 	{
       
    44 	public:
       
    45 	
       
    46 		/**
       
    47          *	2-phase constructor
       
    48          *
       
    49          *	@return new object      
       
    50          */
       
    51 		static CDirectPrintBody* NewL();
       
    52 		
       
    53 		/**
       
    54          *	Destructor         
       
    55          */
       
    56 		~CDirectPrintBody();
       
    57 
       
    58 		/**
       
    59          *	Start discovery for one or several protocols
       
    60          *
       
    61          *	@param aObserver observer for notifications about discovery events
       
    62          *	@param aProtocols OR:ed protocol ids
       
    63          *	@return error code     
       
    64          */
       
    65 		TInt StartDiscovery(MPrinterDiscoveryObserver& aObserver, TUint aProtocols = 0);
       
    66 		
       
    67 		/**
       
    68          *	Cancel discovery        
       
    69          */
       
    70 		void CancelDiscovery();
       
    71 		
       
    72 		/**
       
    73          *	Creates print job
       
    74          *
       
    75          *	@param aPrinterID printer id
       
    76          *	@param aImages array of image file names to be printed
       
    77          *	@param aObserver observer for notifications about print job events
       
    78          *	@return error code     
       
    79          */
       
    80 		TInt CreatePrintJobL(TInt aPrinterID, RPointerArray<TDesC>& aImages, MPrintEventObserver& aObserver);
       
    81 		
       
    82 		/**
       
    83          *	Start actual printing of previously created print job
       
    84          */
       
    85 		void SubmitPrintJobL();
       
    86 		
       
    87 		/**
       
    88          *	Cancel print job
       
    89          *
       
    90          *	@return error code      
       
    91          */
       
    92 		TInt CancelPrintJob();
       
    93 		
       
    94 		/**
       
    95          *	Continue print job
       
    96          *
       
    97          *	@return error code      
       
    98          */
       
    99 		TInt ContinuePrintJobL();
       
   100 		
       
   101 		/**
       
   102          *	Print pages amount getter
       
   103          *
       
   104          *	@return amount of print pages with current settings for current print job    
       
   105          */
       
   106 		TInt GetNumPrintPages();
       
   107 		
       
   108 		/**
       
   109          *	Job status getter
       
   110          *
       
   111          *	@return job status code    
       
   112          */
       
   113 		TInt GetJobStatus();
       
   114 		
       
   115 		/**
       
   116          *	Printer status getter
       
   117          *
       
   118          *	@param aPrinterID printer id
       
   119          *	@return printer status code    
       
   120          */
       
   121 		TInt GetPrinterStatus(TInt aPrinterID);
       
   122 		
       
   123 		/**
       
   124          *	Printer capability id getter
       
   125          *
       
   126          *	@param aPrinterID printer id
       
   127          *	@param aCapabilityIDs place holder for capability ids supported by printer
       
   128          *	@return error code    
       
   129          */
       
   130 		TInt GetPrinterCapabilityIDsL(TInt aPrinterID, RArray<TInt>& aCapabilityIDs);
       
   131 		
       
   132 		/**
       
   133          *	Printer capability getter
       
   134          *
       
   135          *	@param aPrinterID printer id
       
   136          *	@param aCapabilityID capability id
       
   137          *	@param aCapability place holder for capability
       
   138          *	@return error code    
       
   139          */
       
   140 		TInt GetPrinterCapabilityL(TInt aPrinterID, TInt aCapabilityID, TDirectPrintCapability& aCapability);
       
   141 		
       
   142 		/**
       
   143          *	Printer setting getter
       
   144          *
       
   145          *	@param aCapabilityID capability id
       
   146          *	@param aValue place holder for capability value
       
   147          *	@return error code    
       
   148          */
       
   149 		TInt GetJobSetting(TInt aCapabilityID, TInt& aValue);
       
   150 		
       
   151 		/**
       
   152          *	Printer setting setter
       
   153          *
       
   154          *	@param aCapabilityID capability id
       
   155          *	@param aValue capability value
       
   156          *	@param aAffectedCapability affected capability id
       
   157          *	@return error code    
       
   158          */
       
   159 		TInt SetJobSettingL(TInt aCapabilityID, TInt aValue, TInt& aAffectedCapability);
       
   160 		
       
   161 		/**
       
   162          *	Preview pages amount getter for current protocol
       
   163          *
       
   164          *	@return preview pages amount      
       
   165          */
       
   166 		TInt GetNumPreviewPages();
       
   167 		
       
   168 		/**
       
   169          *	Template icon getter
       
   170          *
       
   171          *	@param aTemplateID template id
       
   172          *	@param aFbsBitmapHandle place holder for template bitmap handle
       
   173          *	@return error code    
       
   174          */
       
   175 		TInt GetJobTemplateIconL(TInt aTemplateID, TInt& aFbsBitmapHandle);
       
   176 		
       
   177 		/**
       
   178          *Creates a preview image
       
   179          *
       
   180          *	@param aPageNumber Page number to create preview image of
       
   181          *	@return error code    
       
   182          */
       
   183 		TInt CreatePreviewImage(TInt aPageNumber);
       
   184 		
       
   185 		/**
       
   186          *	Remove cached printer
       
   187          *
       
   188          *	@param aPrinterID printer id
       
   189          *	@return error code    
       
   190          */
       
   191 		TInt RemoveCachedPrinterL(TInt aPrinterID);
       
   192 		
       
   193 		/**
       
   194          *	Supported protocols getter
       
   195          *
       
   196          *	@return OR:ed protocol ids      
       
   197          */
       
   198 		TUint SupportedProtocols();
       
   199 
       
   200 		/**
       
   201          *	Register observer for idle events receiving
       
   202          *
       
   203          *	@param aObserver observer      
       
   204          */
       
   205 		void RegisterIdleObserver(MIdleObserver* aObserver);
       
   206 
       
   207 		/**
       
   208          *	Number of copies setter for current print job
       
   209          *
       
   210          *	@param aNumsOfCopies number of copies array
       
   211          *	@param aErr place holder for error code      
       
   212          */
       
   213 		void SetNumsOfCopiesL(const RArray<TInt>& aNumsOfCopies, TInt& aErr);
       
   214 
       
   215 		/**
       
   216          *	Handle session disconnection
       
   217          *
       
   218          *	@param aIdleObserver idle observer object of that session
       
   219          *	@param aDiscoveryObserver discovery observer object of that session     
       
   220          *	@param aEventObserver print job observer object of that session
       
   221          */
       
   222 		void HandleSessionDisconnect( const MIdleObserver* aIdleObserver,
       
   223 									const MPrinterDiscoveryObserver* aDiscoveryObserver,
       
   224 									const MPrintEventObserver* aEventObserver );
       
   225 
       
   226 		/**
       
   227          *	Number of protocols getter
       
   228          *
       
   229          *	@return number of protocols
       
   230          */
       
   231 		TInt ProtocolCount();
       
   232 
       
   233 		/**
       
   234          *	Protocol name getter
       
   235          *
       
   236          *	@param aMessage message completed upon event arrival
       
   237          *	@return error code
       
   238          */
       
   239 		TInt GetProtocolNameL(TDpMessage& aMessage);
       
   240 
       
   241 
       
   242 	private: // from MProtDiscoveryObserver
       
   243 		void FoundDeviceL(TPrinter& aDeviceInfo);
       
   244 		void DiscoveryStatusL(TInt aStatus, TInt aErrorCode, TInt aErrorStringCode);
       
   245 		void RemoveDeviceL(TPrinter& aDeviceInfo);
       
   246 
       
   247 	private: // from MProtPrintEventObserver
       
   248 		void PrintJobProgressEvent(TInt aStatus, TInt aPercent, TInt aJobStateCode);
       
   249 		void PrintJobErrorEvent(TInt aErrorCode, TInt aErrorStringCode);
       
   250 		void PrinterStatusEvent(TInt aErrorCode, TInt aErrorStringCode);
       
   251 		void PreviewImageEvent(TInt aFsBitmapHandle);
       
   252 		void ShowMessageL(TInt aMsgLine1Code, TInt aMsgLine2Code);
       
   253 		TBool AskYesNoQuestionL(TInt aMsgLine1Code, TInt aMsgLine2Code);
       
   254 		const TDesC& AskForInputL(TInt aMsgLine1Code, TInt aMsgLine2Code);
       
   255 
       
   256 	private: // from MProtIdleObserver
       
   257 		void StatusEvent(const TEvent &aEvent, TInt aError, TInt aMsgCode);
       
   258 	
       
   259 	private:
       
   260 		CDirectPrintBody();
       
   261 		void ConstructL();
       
   262 		TInt FindInternalDeviceReference(TInt aExternalDeviceID, TInt& aInternalDeviceID, MProtPrintingDevice*& aProtToUse);
       
   263 		TInt ValidateImagesL(const RPointerArray<HBufC>& aImageList, TInt &aInvalidCount);
       
   264 		CDirectPrintScheduler& ActiveScheduler() const;
       
   265 		void TryNextDiscovery();
       
   266 		static TInt TryNextDiscoveryL(TAny* aObj);
       
   267 		void DoTryNextDiscoveryL();
       
   268 
       
   269 	private:
       
   270 		/// Class loader and manager.
       
   271 		CDirectPrintProtocolsLoader* iClassLoader;
       
   272 		/// Pointer to store the current protocol in use for discovery.
       
   273 		MProtPrintingDevice* iCurrentProtocol;
       
   274 		/// Pointer to store the current protocol in use for creating a print job.
       
   275 		MProtPrintingDevice* iCurrentPrintJobProtocol;
       
   276 		/// DirectPrint Observer.
       
   277 		MPrinterDiscoveryObserver* iPrinterDiscoveryObserver;
       
   278 		/// DirectPrint Observer.
       
   279 		MPrintEventObserver* iPrinterPrintEventObserver;
       
   280 		/// DirectPrint Idle Observer.
       
   281 		MIdleObserver* iPrinterIdleObserver;							
       
   282 		/// Used to store the requested protocols.
       
   283 		TUint iProtocolsRequested;
       
   284 		/// Array of the image filenames to print.
       
   285 		RPointerArray<HBufC> iImageFileNames;
       
   286 		/// Enables async discovery
       
   287 		CIdle* iIdleDiscovery;
       
   288 		
       
   289 		TBool iDiscoveryCancelled;
       
   290 	};
       
   291 
       
   292 #endif // CDIRECTPRINTBODY_H
       
   293 
       
   294 //  End of File