ImagePrint/ImagePrintEngine/DeviceProtocols/upnpprotocolfw2/inc/cupnpprintingdevice.h
branchRCL_3
changeset 21 d59c248c9d36
parent 0 d11fb78c4374
equal deleted inserted replaced
20:159fc2f68139 21:d59c248c9d36
       
     1 /*
       
     2 * Copyright (c) 2002-2007 Nokia Corporation and/or its subsidiary(-ies).
       
     3 * All rights reserved.
       
     4 * This component and the accompanying materials are made available
       
     5 * under the terms of "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 * Nokia Corporation - initial contribution.
       
    11 *
       
    12 * Contributors:
       
    13 *
       
    14 * Description:  Declares CUPnPPrintingDevice class
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 #ifndef CUPNPPRINTINGDEVICE_H
       
    20 #define CUPNPPRINTINGDEVICE_H
       
    21 
       
    22 #include <fbs.h>
       
    23 #include <upnpmediaserverclient.h>
       
    24 #include <upnpfilesharing.h>
       
    25 #include <data_caging_path_literals.hrh>
       
    26 
       
    27 #include "imageprint.h"
       
    28 #include "mprotprintingdevice.h"
       
    29 #include "cprintercontrolpoint.h"
       
    30 #include "printmessagecodes.h"
       
    31 #include "cupprintercontainer.h"
       
    32 #include "cuplogger.h"
       
    33 #include "upconsts.h"
       
    34 #include "cupprintingjob.h"
       
    35 
       
    36 _LIT8(KFriendlyName, "UPnPProtocol");
       
    37 
       
    38 /// @brief The timeout to wait for first devices to be discovered
       
    39 #define KPrinterDiscoveryTimeout 	TTimeIntervalMicroSeconds32(25000000)
       
    40 
       
    41 /// @brief The timeout to wait for responses during printing 60 seconds
       
    42 #define KPrinterResponseTimeout 	TTimeIntervalMicroSeconds32(60000000)
       
    43 //#define KPrinterResponseTimeout 	TTimeIntervalMicroSeconds32(30000000)
       
    44 
       
    45 /// @brief The timeout to wait for responses during printing
       
    46 #define KPrinterSubmitTimeout 		TTimeIntervalMicroSeconds32(15000000)
       
    47 
       
    48 // @brief The times the timer can expire while printing is processing
       
    49 #define KPendingLimit 5
       
    50 
       
    51 #define	KVersionMajor 0
       
    52 #define	KVersionMinor 0
       
    53 #define	KVersionBuild 1
       
    54 
       
    55 
       
    56 enum TUPnPProtocolState
       
    57 {
       
    58 	EUPnPUninitialized=0,
       
    59 	EUPnPDiscovery,
       
    60 	EUPnPReady,
       
    61 	EUPnPJobReady,
       
    62 	EUPnPSubmittingJob,
       
    63 	EUPnPPrintingStarted,
       
    64 	EUPnPPrinting,
       
    65 	EUPnPPrintingReady,
       
    66 	EUPnPCancelling,
       
    67 	EUPnPCancellingDiscovery
       
    68 };
       
    69 
       
    70 /*
       
    71 * @class 		CUPnPPrintingDevice
       
    72 * @description	Implements the MProtPrintingDevice and MPCPObserver interfaces 
       
    73 *				to integrate Image Print and UPnP stack.
       
    74 *
       
    75 */
       
    76 class CUPnPPrintingDevice : public CBase, public MPCPObserver, public MProtPrintingDevice
       
    77 	{
       
    78 		public:
       
    79 		
       
    80 			/*
       
    81 			* @function		CUPnPPrintingDevice
       
    82 			* @description	C++ constructor
       
    83 			*/
       
    84 			CUPnPPrintingDevice();
       
    85 
       
    86 			/*
       
    87 			* @function		NewProtocolL
       
    88 			* @description	Called from Main.cpp to construct a new MProtPrintingDevice instance
       
    89 			*/
       
    90 			static MProtPrintingDevice* NewL();
       
    91 
       
    92 			/*
       
    93 			* @function		~CUPnPPrintingDevice
       
    94 			* @description	Destructor.
       
    95 			*/
       
    96 			~CUPnPPrintingDevice();
       
    97 			
       
    98 			/*
       
    99 			* @function		DiscoveryTimeoutCBL
       
   100 			* @description	This static callback function is called by iPrinterTimer when the 
       
   101 			*				discovery timer event occurs.
       
   102 			* @param		
       
   103 			* @return		
       
   104 			*/
       
   105 			static TBool DiscoveryTimeoutCBL(TAny *aWho);
       
   106 			
       
   107 			/*
       
   108 			* @function		StatusTimeoutCBL
       
   109 			* @description	This static callback function is called by iPrinterTimer when the 
       
   110 			*				status timer event occurs.
       
   111 			* @param		
       
   112 			* @return		
       
   113 			*/
       
   114 			static TBool StatusTimeoutCBL(TAny *aWho);
       
   115 
       
   116 			/*
       
   117 			* @function		SubmitTimeoutCBL
       
   118 			* @description	This static callback function is called by iPrinterTimer when the 
       
   119 			*				submit timer event occurs.
       
   120 			* @param		TAny
       
   121 			* @return		TInt
       
   122 			*/
       
   123 			static TInt SubmitTimeoutCBL(TAny *aWho);
       
   124 
       
   125 			
       
   126 			
       
   127 
       
   128 			// ===============================
       
   129 			// From MProtPrintingDevice.
       
   130 			// ===============================
       
   131 			// General
       
   132 			virtual void ConstructL(const TDesC& aDLLPath);
       
   133 			virtual TVersion Version();
       
   134 			virtual TUint SupportedProtocols();
       
   135 			// Discovery.
       
   136 			virtual void StartDiscoveryL(MProtDiscoveryObserver& aObserver, TUint aProtocols = 0);
       
   137 			virtual TInt RemoveCachedDeviceL(TInt aDeviceID);
       
   138 			virtual void CancelDiscovery(TBool aDoCallBack = ETrue);
       
   139 			// Print.
       
   140 			virtual TInt CreatePrintJobL(TInt aDeviceID, RPointerArray<TDesC>& aImages, MProtPrintEventObserver& aObserver);
       
   141 			virtual void SubmitPrintJobL();
       
   142 			virtual TInt CancelPrintJob();
       
   143 			virtual TInt ContinuePrintJobL();
       
   144 			virtual TInt GetNumPrintPages();
       
   145 			virtual TInt GetPrintJobStatus();
       
   146 			virtual TInt GetPrinterStatus(TInt aDeviceID);
       
   147 			// Capabilities.
       
   148 			virtual TInt GetDeviceCapabilityIDsL(TInt aDeviceID, RArray<TInt>& aCapabilityIDs);
       
   149 			virtual TInt GetDeviceCapabilityL(TInt aDeviceID, TInt aCapabilityID, TPrintCapability& aCapability);
       
   150 			virtual TInt GetJobSetting(TInt aCapabilityID, TInt& aValue);
       
   151 			virtual TInt SetJobSettingL(TInt aCapabilityID, TInt aValue, TInt& aAffectedCapability);
       
   152 			// Preview.
       
   153 			virtual TInt GetNumPreviewPages();
       
   154 			virtual TInt GetJobTemplateIconL(TInt aTemplateID, TInt& aFsBitmapHandle);
       
   155 			virtual TInt CreatePreviewImage(TInt aPageNumber);
       
   156 
       
   157 			virtual void RegisterIdleObserver(MProtIdleObserver* aObserver);
       
   158 		
       
   159 			virtual void SetNumsOfCopiesL( const RArray<TInt>& aNumsOfCopies, TInt& aErr );
       
   160 
       
   161 			// ===============================
       
   162 			// From MPCPObserver
       
   163 			// ===============================
       
   164 			virtual void CreateJobResponse( CUpnpAction* aAction, TInt aErrorCode );
       
   165 			virtual void CancelJobResponse( CUpnpAction* aAction, TInt aErrorCode );
       
   166 			virtual void GetPrinterAttributesResponse( CUpnpAction* aAction, TInt aErrorCode );
       
   167 			virtual void GetJobAttributesResponse( CUpnpAction* aAction, TInt aErrorCode );
       
   168 			virtual void GetMarginsResponse( CUpnpAction* aAction, TInt aErrorCode );
       
   169 	        virtual void GetMediaListResponse( CUpnpAction* aAction, TInt aErrorCode );
       
   170 			virtual void StateUpdatedResponse( const TDesC8& aPrinterState, 
       
   171                                            const TDesC8& aPrinterStateReasons, 
       
   172                                            const TDesC8& aJobIdList,
       
   173 	                                       const TDesC8& aJobEndState, 
       
   174                                            const TDesC8& aJobMediaSheetsCompleted, 
       
   175                                            const TDesC8& aJobAbortState,
       
   176                                            const TDesC8& aContentCompleteList );
       
   177 			virtual void DeviceDiscoveredL( CUpnpDevice* aDevice );
       
   178 			virtual void DeviceDisappeared( CUpnpDevice* aDevice );
       
   179 			// state events
       
   180 			virtual void PrinterStateUpdated( const TDesC8& aEvent );
       
   181 			virtual void PrinterStateReasonsUpdated( const TDesC8& aEvent );
       
   182 			virtual void JobIdListUpdated( const TDesC8& aEvent );
       
   183 			virtual void JobEndStateUpdated( const TDesC8& aEvent );
       
   184 			virtual void JobMediaSheetsCompletedUpdated( const TDesC8& aEvent );
       
   185 			virtual void ContentCompleteListUpdated( const TDesC8& aEvent );
       
   186 			virtual void JobAbortStateUpdated( const TDesC8& aEvent );
       
   187 
       
   188 		protected:
       
   189 		
       
   190 
       
   191 		private:
       
   192 
       
   193 			/*
       
   194 			* @function 	StartDiscoveryInternalL
       
   195 			* @description	Non-leaving interface for MProtPrintingDevice method StartDiscoveryL
       
   196 			*				for ImagePrint compliance. Informs observer about leaves by call back method.
       
   197 			* @param 		TInt protocol identifier bitmap
       
   198 			*/
       
   199 			void StartDiscoveryInternalL(TUint aProtocol);
       
   200 
       
   201 			/*
       
   202 			* @function 	RestartControlPointL
       
   203 			* @description	Restarts the printer control point
       
   204 			*/
       
   205 			void RestartControlPointL();
       
   206 
       
   207 			/*
       
   208 			* @function 	SendPrinterListL
       
   209 			* @description	Returns the device list to MProtDiscoveryObserver object
       
   210 			* @param		TBool
       
   211 			*/
       
   212 			void SendPrinterListL(TBool aSync = ETrue);
       
   213 
       
   214 			/*
       
   215 			* @function 	DoDiscoveryTimeoutL
       
   216 			* @description	Ends the first device discovery session. This function is called
       
   217 			*				by the static callback function DiscoveryTimeoutCBL.
       
   218 			* @param		TBool aDoCallBack If ETrue then protocol client is notified.
       
   219 			* @return 		TBool
       
   220 			*/
       
   221 			TBool DoDiscoveryTimeoutL(TBool aDoCallBack);
       
   222 
       
   223 			/*
       
   224 			* @function 	DoSubmitTimeoutL
       
   225 			* @description	This function is executed after submit time out expires.
       
   226 			* @return 		TInt
       
   227 			*/
       
   228 			void DoSubmitTimeoutL();
       
   229 
       
   230 			/*
       
   231 			* @function 	SubmitJobToPcpL
       
   232 			* @description	Submits the printing job to PCP
       
   233 			* @param		CDevice& Reference to the printer to be used in printing
       
   234 			* @param		TInt The ID of the printer to be used in printing
       
   235 			*/
       
   236 			void SubmitJobToPcpL(CUpnpDevice& aPrinter, TInt aPrinterID);
       
   237 
       
   238 			/*
       
   239 			* @function 	SubmitJobToPcpL
       
   240 			* @description	Submits the printing job to PCP
       
   241 			* @param		TInt The ID of the printer to be used in printing
       
   242 			*/
       
   243 			void SubmitJobToPcpL(TInt aDeviceID);
       
   244 
       
   245 			/*
       
   246 			* @function 	DoStatusTimeoutL
       
   247 			* @description	Handles time out event in printer communication.
       
   248 			* @return 		TBool
       
   249 			*/
       
   250 			TBool DoStatusTimeoutL();
       
   251 
       
   252 			/*
       
   253 			* @function 	InitJobL
       
   254 			* @description	Initializes the printing jobs to job container
       
   255 			* @param		TInt 			Printer for printing jobs
       
   256 			* @param		RPointerArray	File paths for files to be printed
       
   257 			*/
       
   258 			void InitJobL(TInt aDeviceId, RPointerArray<TDesC>& aImages);
       
   259 
       
   260 			/*
       
   261 			* @function 	StartPrintingL
       
   262 			* @description	Sends the printing jobs to the UPnP Printer Control Point
       
   263 			*/
       
   264 			void StartPrintingL();
       
   265 
       
   266 			/*
       
   267 			* @function 	DoCancelPrinting
       
   268 			* @description	Cancels the ongoing printing job. Returns KErrInvalidSequence if state is not 
       
   269 			*				EUPnPSubmittingJob, EUPnPPrintingStarted or EUPnPPrinting.
       
   270 			* @return 		TInt	System wide error code
       
   271 			*/
       
   272 			TInt DoCancelPrinting();
       
   273 			
       
   274 			/*
       
   275 			* @function 	UpdatePrintingStatus
       
   276 			* @description	Updates the status of printing jobs and informs the printing observer about progress and events
       
   277 			* @param		const TDesC8& aPrinterState
       
   278 			*/
       
   279 			void UpdatePrintingStatus(const TUPnPState aJobState);
       
   280 		
       
   281 			
       
   282 			/*
       
   283 			* @function		FinishPrinting
       
   284 			* @description	Executes the basic operations to be done when printing is done.
       
   285 			*/
       
   286 			void FinishPrinting();
       
   287 
       
   288 			/*
       
   289 			* @function		FinishPrinting
       
   290 			* @description	Overloads FinishPrinting and informs observer about occurred error.
       
   291 			* @param		TInt Symbian wide error code
       
   292 			* @param		TInt ImagePrint specific (error) message code
       
   293 			*/
       
   294 			void FinishPrinting(TInt aErrorCode, TInt aErrorMessage);
       
   295 
       
   296 			/*
       
   297 			* @function		ResetTimer
       
   298 			* @description	Resets the timer and initializes timer related flags.
       
   299 			*/
       
   300 			void ResetTimer();			
       
   301 
       
   302 			/*
       
   303 			* @function		StartTimer
       
   304 			* @description	Starts the timer and resets it first.
       
   305 			* @param		TTimeIntervalMicroSeconds32	Delay for the timer
       
   306 			* @param		TTimeIntervalMicroSeconds32 Interval for timer to expire
       
   307 			* @param		TCallBack					Call back function when timer expires
       
   308 			*/
       
   309 			void StartTimer(TTimeIntervalMicroSeconds32 aDelay,TTimeIntervalMicroSeconds32 anInterval,TCallBack aCallBack);			
       
   310 
       
   311 			/*
       
   312 			* @function		GetPrinter
       
   313 			* @description	Returns a pointer to the current printer.
       
   314 			* @return		CDevice* Current printer or NULL
       
   315 			*/
       
   316 			CUpnpDevice* GetPrinter();
       
   317 			
       
   318 		private:
       
   319 			// @var iPrinterControl		Control point to UPnP
       
   320 			CPrinterControlPoint* iPrinterControl;
       
   321 			
       
   322 			// @var iPrinterContainer	Container for printers
       
   323 			CUPPrinterContainer* iPrinterContainer;
       
   324 			
       
   325 			// @var iPrintingJob		Printing job
       
   326 			CUPPrintingJob* iPrintingJob;
       
   327 			
       
   328 			// @var iPrinterTimer		Array of discovered printers
       
   329 			CPeriodic* iPrinterTimer;
       
   330 			
       
   331 			// @var iPrintFactory		XHTML-print file factory
       
   332 			CUPPrintFactory* iPrintFactory;
       
   333 			
       
   334 			// @var iPrinterState		State information of the object
       
   335 			TUPnPProtocolState iState;
       
   336 
       
   337 			// @var iPrintersFound		Indicates if there are printers found
       
   338 			TBool iPrintersFound;
       
   339 
       
   340 			// @var iStatusTimeout		This variable is set to ETrue when a status time out occurs
       
   341 			TBool iStatusTimeout;
       
   342 
       
   343 			// @var iFbsBitmap			(Dummy) bitmap for icon template
       
   344 			CFbsBitmap* iFbsBitmap;
       
   345 			
       
   346 			// @var iPendingCount		Counter to avoid too long pending while printing
       
   347 			TInt iPendingCount;
       
   348 			
       
   349 			// @var iFriendlyName		In Home network configuration defined name for the device
       
   350 			TBuf8<256> iFriendlyName;
       
   351 			
       
   352 			// @var iTriedReadCacheAndFail   To check that never trying read cache file more than one time, if we don't have it.
       
   353 			TBool iTriedReadCacheAndFail;
       
   354 			
       
   355 	};
       
   356 
       
   357 #endif // CUPNPPRINTINGDEVICE_H
       
   358 
       
   359 //  End of File