usbuis/imageprintui/src/eventmanager.cpp
changeset 93 2dc695882abd
parent 89 3592750162a5
equal deleted inserted replaced
89:3592750162a5 93:2dc695882abd
     1 /*
       
     2 * Copyright (c) 2006, 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:  Handles DpeEventNotify call with AO
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 
       
    20 #include <e32base.h>
       
    21 #include <dpsdefs.h>
       
    22 #include <dpsparam.h>
       
    23 #include <s32file.h>
       
    24 #include <f32file.h>
       
    25 #include <e32std.h>
       
    26 #include <coemain.h>
       
    27 #include <d32usbc.h>
       
    28 
       
    29 #include "eventmanager.h"
       
    30 #include "imageprintuidebug.h"
       
    31 #include "pictbridge.h"
       
    32 #include "imageprintuiappui.h"
       
    33  
       
    34  
       
    35 // ---------------------------------------------------------------------------
       
    36 //  constructor
       
    37 // ---------------------------------------------------------------------------
       
    38 //
       
    39 CEventManager::CEventManager(CImagePrintUiAppUi* aAppUi, CDpsEngine* aDpsEngine)
       
    40     : CActive(CActive::EPriorityStandard), iAppUi(aAppUi),iDpsEngine(aDpsEngine),
       
    41       iErrorState(EFalse)
       
    42     {
       
    43     CActiveScheduler::Add(this);
       
    44     StartListening();
       
    45     }
       
    46 
       
    47 
       
    48 
       
    49 // ---------------------------------------------------------------------------
       
    50 // 
       
    51 // ---------------------------------------------------------------------------
       
    52 //
       
    53 CEventManager* CEventManager::NewL(CImagePrintUiAppUi* aAppUi, CDpsEngine* aDpsEngine)
       
    54     {
       
    55     CEventManager* self = new( ELeave ) CEventManager(aAppUi, aDpsEngine);
       
    56     return self;
       
    57     }
       
    58 
       
    59 // ---------------------------------------------------------------------------
       
    60 // 
       
    61 // ---------------------------------------------------------------------------
       
    62 //
       
    63 CEventManager::~CEventManager()
       
    64     {
       
    65     Cancel();
       
    66     }
       
    67 
       
    68 // ---------------------------------------------------------------------------
       
    69 // Start listening events
       
    70 // 
       
    71 // ---------------------------------------------------------------------------
       
    72 //
       
    73 void CEventManager::StartListening()
       
    74 	{
       
    75 	FLOG(_L("[IMAGEPRINTUI]\t CEventManager::Start listening"));
       
    76 	iDpsEngine->DpsEventNotify(iEventRequest, iStatus);
       
    77 	SetActive();
       
    78 	}
       
    79  	
       
    80 // ---------------------------------------------------------------------------
       
    81 // Handles situation depends on result after calling DpsEventNotify 
       
    82 // 
       
    83 // ---------------------------------------------------------------------------
       
    84 //
       
    85 void CEventManager::HandleReturnStatusL()
       
    86 	{
       
    87     FLOG(_L("[IMAGEPRINTUI]>>> CEventManager; HandleReturnStatus"));
       
    88     FTRACE(FPrint(_L("[IMAGEPRINTUI]\t CEventManager event value is %d"), iEventRequest.iEvent ));
       
    89     FTRACE(FPrint(_L("[IMAGEPRINTUI]\t CEventManager iPrintStatus is %x"), iEventRequest.iPrinterEvent.iRepParam.iPrintStatus ));
       
    90     FTRACE(FPrint(_L("[IMAGEPRINTUI]\t CEventManager iJobStatus is %x"), iEventRequest.iPrinterEvent.iRepParam.iJobStatus ));
       
    91     FTRACE(FPrint(_L("[IMAGEPRINTUI]\t CEventManager iErrorStatus hex is %x"), iEventRequest.iPrinterEvent.iRepParam.iErrorStatus ));
       
    92     FTRACE(FPrint(_L("[IMAGEPRINTUI]\t CEventManager iJobEndReason is %x"), iEventRequest.iPrinterEvent.iRepParam.iJobEndReason.iMajor ));
       
    93     FTRACE(FPrint(_L("[IMAGEPRINTUI]\t CEventManager iPaperMinor is %x"), iEventRequest.iPrinterEvent.iRepParam.iJobEndReason.iPaperMinor ));
       
    94     FTRACE(FPrint(_L("[IMAGEPRINTUI]\t CEventManager iInkMinor is %x"), iEventRequest.iPrinterEvent.iRepParam.iJobEndReason.iInkMinor ));
       
    95     FTRACE(FPrint(_L("[IMAGEPRINTUI]\t CEventManager iHardMinor is %x"), iEventRequest.iPrinterEvent.iRepParam.iJobEndReason.iHardMinor ));
       
    96     FTRACE(FPrint(_L("[IMAGEPRINTUI]\t CEventManager iFileMinor is %x"), iEventRequest.iPrinterEvent.iRepParam.iJobEndReason.iFileMinor ));
       
    97     FTRACE(FPrint(_L("[IMAGEPRINTUI]\t CEventManager iDisconnectEnable is %d"), iEventRequest.iPrinterEvent.iRepParam.iDisconnectEnable ));
       
    98     FTRACE(FPrint(_L("[IMAGEPRINTUI]\t CEventManager iCapabilityChange is %d"), iEventRequest.iPrinterEvent.iRepParam.iCapabilityChange ));
       
    99     FTRACE(FPrint(_L("[IMAGEPRINTUI]\t CEventManager iNewJobOk is is %d"), iEventRequest.iPrinterEvent.iRepParam.iNewJobOk ));
       
   100     
       
   101     
       
   102 	if(iEventRequest.iEvent == EDpsEvtNotifyJobStatus)	
       
   103 		{
       
   104 		FLOG(_L("[IMAGEPRINTUI]<<< CEventManager; NotifyPrintProgress"));
       
   105 		FTRACE(FPrint(_L("[IMAGEPRINTUI]\t CEventManager  iImagesPrinted is %d"), iEventRequest.iJobEvent.iRepParam.iImagesPrinted ));
       
   106 		FTRACE(FPrint(_L("[IMAGEPRINTUI]\t CEventManager  iProgress is %d"), iEventRequest.iJobEvent.iRepParam.iProgress ));
       
   107 	    iAppUi->NotifyPrintProgress(iEventRequest.iJobEvent.iRepParam.iImagesPrinted, 
       
   108 	                                 iEventRequest.iJobEvent.iRepParam.iProgress);
       
   109 		}
       
   110 		
       
   111 	else if(iEventRequest.iEvent == EDpsEvtNotifyDeviceStatus)
       
   112 		    {		    		    
       
   113 		    FLOG(_L("[IMAGEPRINTUI]<<< CEventManager; HandleReturnStatus, EDpsEvtNotifyDeviceStatus"));
       
   114 		    iAppUi->NotifyPrintStatus(iEventRequest.iPrinterEvent.iRepParam.iPrintStatus);
       
   115 		    
       
   116 		    HandleJobStatusL(iEventRequest.iPrinterEvent.iRepParam.iJobStatus);
       
   117 		    
       
   118 		    HandleErrorStatusL(iEventRequest.iPrinterEvent.iRepParam.iErrorStatus);
       
   119 		    
       
   120 		    if(iEventRequest.iPrinterEvent.iRepParam.iJobEndReason.iMajor == EDpsJobErrorPaper)
       
   121 				{
       
   122 				FLOG(_L("[IMAGEPRINTUI] CEventManager::EDpsJobErrorPaper"));
       
   123 				HandlePaperErrorL(iEventRequest.iPrinterEvent.iRepParam.iJobEndReason.iPaperMinor);
       
   124 				}
       
   125 			else if(iEventRequest.iPrinterEvent.iRepParam.iJobEndReason.iMajor == EDpsJobErrorInk)
       
   126 				{
       
   127 				FLOG(_L("[IMAGEPRINTUI] CEventManager::EDpsJobErrorInk"));
       
   128 				HandleInkErrorL(iEventRequest.iPrinterEvent.iRepParam.iJobEndReason.iInkMinor);
       
   129 				}
       
   130 			else if(iEventRequest.iPrinterEvent.iRepParam.iJobEndReason.iMajor == EDpsJobErrorFile)
       
   131 				{
       
   132 				FLOG(_L("[IMAGEPRINTUI] CEventManager::EDpsJobErrorFile"));
       
   133 				HandleFileErrorL(iEventRequest.iPrinterEvent.iRepParam.iJobEndReason.iFileMinor);
       
   134 				}
       
   135 			else if(iEventRequest.iPrinterEvent.iRepParam.iJobEndReason.iMajor == EDpsJobErrorHardware)
       
   136 				{
       
   137 				FLOG(_L("[IMAGEPRINTUI] CEventManager::EDpsJobErrorHardware"));
       
   138 				HandleHardwareErrorL(iEventRequest.iPrinterEvent.iRepParam.iJobEndReason.iHardMinor);
       
   139 				}			
       
   140 		    
       
   141 		    if(iEventRequest.iPrinterEvent.iRepParam.iNewJobOk)
       
   142 				{
       
   143 				FLOG(_L("[IMAGEPRINTUI] CEventManager::HandleDeviceStatusL, NewJob is OK"));
       
   144 				iAppUi->NotifyEventL(CEventManager::ENewJobOK );
       
   145 		    	}
       
   146 	        //capability change	
       
   147 			else if(iEventRequest.iPrinterEvent.iRepParam.iCapabilityChange)
       
   148 				{
       
   149 				FLOG(_L("[IMAGEPRINTUI] CEventManager::capability change"));
       
   150 				iAppUi->NotifyEventL(CEventManager::ECapabilityChange);
       
   151 				}
       
   152 		    }
       
   153     FLOG(_L("[IMAGEPRINTUI]<<< CEventManager; HandleReturnStatus, next call StartListening"));		    
       
   154 	StartListening();
       
   155 	}
       
   156 
       
   157 // ---------------------------------------------------------------------------
       
   158 // 
       
   159 // ---------------------------------------------------------------------------
       
   160 //
       
   161 void CEventManager::HandleErrorStatusL(TInt aStatus)
       
   162 	{
       
   163 	FLOG(_L("[IMAGEPRINTUI] CEventManager::HandleErrorStatusL"));
       
   164 	if(aStatus  == EDpsErrorStatusOk)
       
   165 		{
       
   166 		FLOG(_L("[IMAGEPRINTUI] CEventManager::HandleDeviceStatusL, EDpsErrorStatusOk"));
       
   167 	    iAppUi->NotifyEventL(CEventManager::ENotErrorState);
       
   168 		}	
       
   169 	else if(aStatus == EDpsErrorStatusFatal)
       
   170 		{
       
   171 		FLOG(_L("[IMAGEPRINTUI] CEventManager::HandleDeviceStatusL, Fatal error"));
       
   172 		iAppUi->NotifyEventL(CEventManager::EErrorState);
       
   173 		
       
   174 		if(iEventRequest.iPrinterEvent.iRepParam.iJobEndReason.iInkMinor == EDpsInkEmpty ||
       
   175 		   iEventRequest.iPrinterEvent.iRepParam.iJobEndReason.iInkMinor == EDpsInkLow ||
       
   176 		   iEventRequest.iPrinterEvent.iRepParam.iJobEndReason.iPaperMinor == EDpsPaperJam )
       
   177 			{
       
   178 			FLOG(_L("[IMAGEPRINTUI] CEventManager Fatal error, don't show note"));
       
   179 			}
       
   180 		else if(iEventRequest.iPrinterEvent.iRepParam.iJobEndReason.iMajor == EDpsJobErrorPaper ||
       
   181     	   iEventRequest.iPrinterEvent.iRepParam.iJobEndReason.iMajor == EDpsJobErrorInk ||
       
   182     	   iEventRequest.iPrinterEvent.iRepParam.iJobEndReason.iMajor == EDpsJobErrorHardware ||
       
   183     	   iEventRequest.iPrinterEvent.iRepParam.iJobEndReason.iMajor == EDpsJobErrorFile )
       
   184 			{
       
   185 			FLOG(_L("[IMAGEPRINTUI] CEventManager error major, don't show note"));
       
   186 			}
       
   187 		 	
       
   188 		else 
       
   189 			{
       
   190 			FLOG(_L("[IMAGEPRINTUI] CEventManager Fatal error, show note"));
       
   191 		    iAppUi->NotifyEventL(EDpsErrorStatusFatal);	
       
   192 			}		
       
   193 		}
       
   194 	else if(aStatus == EDpsErrorStatusWarning)
       
   195 		{
       
   196 		FLOG(_L("[IMAGEPRINTUI] CEventManager::HandleDeviceStatusL, Warning"));
       
   197 		iAppUi->NotifyEventL(CEventManager::EErrorState);
       
   198 				
       
   199 	    if(iEventRequest.iPrinterEvent.iRepParam.iJobEndReason.iMajor == EDpsJobErrorPaper ||
       
   200     	   iEventRequest.iPrinterEvent.iRepParam.iJobEndReason.iMajor == EDpsJobErrorInk ||
       
   201     	   iEventRequest.iPrinterEvent.iRepParam.iJobEndReason.iMajor == EDpsJobErrorHardware ||
       
   202     	   iEventRequest.iPrinterEvent.iRepParam.iJobEndReason.iMajor == EDpsJobErrorFile )
       
   203 			{
       
   204 			FLOG(_L("[IMAGEPRINTUI] CEventManager warning major, don't show note"));
       
   205 			}
       
   206 		else
       
   207 			{
       
   208 			FLOG(_L("[IMAGEPRINTUI] CEventManager warning,  show note"));
       
   209 			iAppUi->NotifyEventL(CEventManager::EWarning);	
       
   210 			}
       
   211 		}	
       
   212 	}
       
   213 	
       
   214 // ---------------------------------------------------------------------------
       
   215 // 
       
   216 // ---------------------------------------------------------------------------
       
   217 //
       
   218 void CEventManager::HandleJobStatusL(TInt aStatus)
       
   219 	{
       
   220 	FLOG(_L("[IMAGEPRINTUI] CEventManager::HandleJobStatusL"));
       
   221 	if( aStatus == EDpsJobStatusEndedOther)
       
   222 		{
       
   223 		FLOG(_L("[IMAGEPRINTUI] CEventManager::HandleDeviceStatusL, User cancel from printer"));
       
   224 		iAppUi->NotifyEventL(EDpsJobStatusEndedOther);
       
   225 		}
       
   226 		
       
   227 	else if( aStatus  == EDpsJobStatusEndedOk)
       
   228 		{
       
   229 		FLOG(_L("[IMAGEPRINTUI] CEventManager::HandleDeviceStatusL, Job ended normally"));
       
   230 		iAppUi->NotifyEventL(EDpsJobStatusEndedOk );
       
   231 		}	
       
   232 	else if( aStatus  == EDpsJobStatusEndedAbortImmediately)
       
   233 		{
       
   234 		FLOG(_L("[IMAGEPRINTUI] CEventManager::HandleDeviceStatusL, User has abort job"));
       
   235 		iAppUi->NotifyEventL(EDpsJobStatusEndedAbortImmediately);
       
   236 		}	
       
   237 	
       
   238 	}
       
   239 // ---------------------------------------------------------------------------
       
   240 // 
       
   241 // ---------------------------------------------------------------------------
       
   242 //
       
   243 void CEventManager::HandleHardwareErrorL(TInt aError)
       
   244 	{
       
   245 	FLOG(_L("[IMAGEPRINTUI] CEventManager::HandleHardwareErrorL"));
       
   246 	 if( aError ==  EDpsHardFatal || aError ==  EDpsHardServiceCall ||
       
   247          aError ==  EDpsHardNotAvailable || aError ==  EDpsHardBusy || 
       
   248          aError ==  EDpsHardLever || aError ==  EDpsHardCoverOpen ||
       
   249          aError ==  EDpsHardNoMarkingHead || aError ==  EDpsHardInkCoverOpen ||
       
   250          aError ==  EDpsHardNoInkCartridge  )
       
   251 		{
       
   252 		FLOG(_L("[IMAGEPRINTUI]\t CEventManager::harware  minor"));
       
   253 		iAppUi->NotifyEventL(CEventManager::EWarning);
       
   254 		}	
       
   255 	else 
       
   256 		{
       
   257 		FLOG(_L("[IMAGEPRINTUI] CEventManager::Hardware major"));
       
   258 		iAppUi->NotifyEventL(CEventManager::EShowError);
       
   259 		} 		
       
   260 	
       
   261 	}
       
   262 
       
   263 // ---------------------------------------------------------------------------
       
   264 // 
       
   265 // ---------------------------------------------------------------------------
       
   266 //
       
   267 void CEventManager::HandleInkErrorL(TInt aError)
       
   268 	{
       
   269 	FLOG(_L("[IMAGEPRINTUI] CEventManager::HandleInkErrorL"));
       
   270 	if(aError == EDpsInkEmpty)
       
   271 	    {
       
   272 		FLOG(_L("[IMAGEPRINTUI] CEventManager::ink empty"));
       
   273 		iAppUi->NotifyEventL(CEventManager::EInkEmpty); 
       
   274 		}
       
   275 	else if(aError == EDpsInkLow )
       
   276 	    {
       
   277 	    FLOG(_L("[IMAGEPRINTUI] CEventManager::ink low"));
       
   278 	    iAppUi->NotifyEventL(EDpsInkLow);	
       
   279 	    }
       
   280 	else if( aError== EDpsInkWaste)	
       
   281 		{
       
   282 		FLOG(_L("[IMAGEPRINTUI] CEventManager::ink general"));
       
   283 		iAppUi->NotifyEventL(CEventManager::EWarning);
       
   284 		}
       
   285 	else 
       
   286 		{
       
   287 		FLOG(_L("[IMAGEPRINTUI] CEventManager ink major,  show note"));
       
   288 	    iAppUi->NotifyEventL(CEventManager::EShowError);	
       
   289 		}
       
   290 	}
       
   291 
       
   292 // ---------------------------------------------------------------------------
       
   293 // 
       
   294 // ---------------------------------------------------------------------------
       
   295 //
       
   296 void CEventManager::HandlePaperErrorL(TInt aError)
       
   297 	{
       
   298 	FLOG(_L("[IMAGEPRINTUI] CEventManager::HandlePaperErrorL"));
       
   299 	
       
   300 	if( aError == EDpsPaperLoad  || aError == EDpsPaperEject ||
       
   301 	    aError == EDpsPaperMedia || aError == EDpsPaperNearlyEmpty ||
       
   302 	    aError == EDpsPaperTypeSizeNoMatch ) 
       
   303 		{
       
   304 		FLOG(_L("[IMAGEPRINTUI]\t CEventManager::paperMinor, show warning"));
       
   305 		iAppUi->NotifyEventL(CEventManager::EWarning);
       
   306 		}
       
   307 	else if( aError == EDpsPaperJam)
       
   308 		{
       
   309 		FLOG(_L("[IMAGEPRINTUI] CEventManager::Paper jam"));
       
   310 		iAppUi->NotifyEventL(EDpsPaperJam);
       
   311 		}
       
   312 	else if( aError == EDpsPaperEmpty)
       
   313 		{
       
   314 		FLOG(_L("[IMAGEPRINTUI] CEventManager::Paper empty"));
       
   315 		iAppUi->NotifyEventL(EDpsPaperEmpty);
       
   316 		}	
       
   317     else
       
   318 		{
       
   319 		FLOG(_L("[IMAGEPRINTUI] CEventManager paper major, show note"));
       
   320 	    iAppUi->NotifyEventL(CEventManager::EShowError);	
       
   321 		}		
       
   322 	}
       
   323 
       
   324 // ---------------------------------------------------------------------------
       
   325 // 
       
   326 // ---------------------------------------------------------------------------
       
   327 //
       
   328 void CEventManager::HandleFileErrorL(TInt aError)
       
   329 	{
       
   330 	FLOG(_L("[IMAGEPRINTUI] CEventManager::HandleFileErrorL"));
       
   331 	
       
   332 	if(aError ==  EDpsFilePrintInfo ||
       
   333        aError ==  EDpsFileDecode  )
       
   334 	    {
       
   335 		FLOG(_L("[IMAGEPRINTUI] CEventManager::file minor"));
       
   336 		iAppUi->NotifyEventL(CEventManager::EWarning);
       
   337 		}	
       
   338 	else
       
   339 		{
       
   340 		FLOG(_L("[IMAGEPRINTUI] CEventManager::file major"));
       
   341 		iAppUi->NotifyEventL(CEventManager::EShowError);
       
   342 		}
       
   343 	}
       
   344 
       
   345 // ---------------------------------------------------------------------------
       
   346 // 
       
   347 // ---------------------------------------------------------------------------
       
   348 //	
       
   349 void CEventManager::RunError()
       
   350     {
       
   351     FLOG(_L("[IMAGEPRINTUI] CEventManager::RunError"));
       
   352     
       
   353     StartListening();
       
   354     if(iStatus.Int() == KErrTimedOut)
       
   355     	{
       
   356     	FLOG(_L("[IMAGEPRINTUI]<<< CEventManager; RunError, timed out"));	
       
   357     	}
       
   358     else if( iStatus.Int() == KErrUsbInterfaceNotReady)	
       
   359 		{
       
   360 		FLOG(_L("[IMAGEPRINTUI] CEventManager::KErrUsbInterfaceNotReady"));
       
   361 		// iAppUi->NotifyEventL(KErrUsbInterfaceNotReady);
       
   362 		}		
       
   363     FTRACE(FPrint(_L("[IMAGEPRINTUI]\t CEventManager::RunError iStatus is is %d"), iStatus.Int() ));
       
   364     // iAppUi->NotifyEventL(CEventManager::ESeriousError);
       
   365     }
       
   366 // ---------------------------------------------------------------------------
       
   367 // 
       
   368 // ---------------------------------------------------------------------------
       
   369 //	
       
   370 void CEventManager::RunL()
       
   371     {
       
   372     FLOG(_L("[IMAGEPRINTUI]\t CEventManager::RunL"));
       
   373     FTRACE(FPrint(_L("[IMAGEPRINTUI]\t CEventManager::RunL iStatus   is %d"), iStatus.Int() ));
       
   374     if (iStatus.Int() == KErrNone)
       
   375 		{
       
   376 		FLOG(_L("[IMAGEPRINTUI]\t CEventManager::RunL no error"));
       
   377 	    HandleReturnStatusL();
       
   378 		}
       
   379 	else
       
   380 		{
       
   381 		FLOG(_L("[IMAGEPRINTUI]\t CEventManager::RunL there is error in iStatus"));
       
   382 		User::LeaveIfError(iStatus.Int());
       
   383 		}
       
   384     }
       
   385 
       
   386 // ---------------------------------------------------------------------------
       
   387 // 
       
   388 // ---------------------------------------------------------------------------
       
   389 //
       
   390 void CEventManager::DoCancel()
       
   391     {
       
   392     FLOG(_L("[IMAGEPRINTUI]>>> CEventManager  DoCancel"));
       
   393     iDpsEngine->CancelDpsEventNotify();
       
   394     FLOG(_L("[IMAGEPRINTUI]>>> CEventManager  DoCancel complete"));
       
   395     }