ImagePrint/ImagePrintEngine/ImagePrintServer/src/server/cserveridleguard.cpp
branchRCL_3
changeset 21 d59c248c9d36
parent 0 d11fb78c4374
equal deleted inserted replaced
20:159fc2f68139 21:d59c248c9d36
       
     1 /*
       
     2 * Copyright (c) 2004-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:  
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 #include "cserveridleguard.h"
       
    20 #include "cimageprintbody.h"
       
    21 #include "tidleevent.h"
       
    22 #include "clog.h"
       
    23 #include "tmessagewrp2.h"
       
    24 
       
    25 CServerIdleGuard* CServerIdleGuard::NewL( CImagePrintBody& aEngine )
       
    26     {	
       
    27 	CServerIdleGuard* self = new ( ELeave ) CServerIdleGuard( aEngine );
       
    28     CleanupStack::PushL( self );
       
    29     self->ConstructL();
       
    30 	CleanupStack::Pop();    // self
       
    31     return self;
       
    32     }
       
    33 
       
    34 CServerIdleGuard::CServerIdleGuard( CImagePrintBody& aEngine ) : iEngine( aEngine ),
       
    35 														iRequestActive( EFalse )
       
    36     {
       
    37     }
       
    38 
       
    39 CServerIdleGuard::~CServerIdleGuard()
       
    40     { 
       
    41     LOG("CServerIdleGuard::~CServerIdleGuard begin");
       
    42     iBuffer.Close();
       
    43     LOG("CServerIdleGuard::~CServerIdleGuard end");  
       
    44     }
       
    45 
       
    46 void CServerIdleGuard::ConstructL()
       
    47     {
       
    48     }
       
    49 
       
    50 void CServerIdleGuard::StatusEvent( const TEvent &aEvent, TInt aError, TInt aMsgCode )
       
    51 	{
       
    52 	LOG("CServerIdleGuard::StatusEvent begin");		
       
    53 	LOG1("CServerIdleGuard::StatusEvent aError: %d", aError);
       
    54 	LOG1("CServerIdleGuard::StatusEvent aMsgCode: %d", aMsgCode);	
       
    55 	LOG1("CServerIdleGuard::StatusEvent aEvent.iProtocol: %d", aEvent.iProtocol);
       
    56 	LOG1("CServerIdleGuard::StatusEvent aEvent.iSeverity: %d", aEvent.iSeverity);
       
    57 	LOG1("CServerIdleGuard::StatusEvent aEvent.iEventType: %d", aEvent.iEventType);				
       
    58 	TRAPD( err, DoStatusEventL( aEvent, aError, aMsgCode ) );					
       
    59 	LOG1("CServerIdleGuard::StatusEvent DoStatusEventL's TRAP err: %d", err);					
       
    60 	Process( err );
       
    61 	LOG("CServerIdleGuard::StatusEvent end");
       
    62 	}
       
    63 		
       
    64 void CServerIdleGuard::Guard( TMessageWrp2& aMessage )
       
    65 	{
       
    66 	LOG("CServerIdleGuard::Guard begin");
       
    67 	if( iMessage ) iMessage->SetDisposable( ETrue );			
       
    68 	iMessage = &aMessage;			
       
    69 	iRequestActive = ETrue;
       
    70 	iEngine.RegisterIdleObserver( this );
       
    71 	if( iBuffer.Count() )
       
    72 		{
       
    73 		LOG("CServerIdleGuard::Guard before Process");
       
    74 		Process();
       
    75 		LOG("CServerIdleGuard::Guard after Process");	
       
    76 		}
       
    77 	LOG("CServerIdleGuard::Guard end");	
       
    78 	}
       
    79 	
       
    80 void CServerIdleGuard::Stop()
       
    81 	{
       
    82 	LOG("CServerIdleGuard::Stop begin");		
       
    83 	if( iRequestActive )
       
    84 		{
       
    85 		LOG("CServerIdleGuard::Stop cancelling...");
       
    86 		iMessage->Complete( KErrCancel );
       
    87 		iRequestActive = EFalse;
       
    88 		}
       
    89 	iEngine.RegisterIdleObserver( NULL );		
       
    90 	LOG("CServerIdleGuard::Stop end");
       
    91 	}	
       
    92 		
       
    93 void CServerIdleGuard::DoStatusEventL( const TEvent &aEvent, TInt aError, TInt aMsgCode )
       
    94 	{
       
    95 	LOG("CServerIdleGuard::DoStatusEventL begin");
       
    96 	TIdleGuardData data;
       
    97 	data.iEvent = aEvent;
       
    98 	data.iError = aError;
       
    99 	data.iMsgCode = aMsgCode;
       
   100 	User::LeaveIfError( iBuffer.Append( data ) );
       
   101 	LOG("CServerIdleGuard::DoStatusEventL end");				
       
   102 	}
       
   103 		
       
   104 void CServerIdleGuard::Process( TInt aErr )
       
   105 	{
       
   106 	LOG("CServerIdleGuard::Process begin");
       
   107 	if( aErr )
       
   108 		{
       
   109 		LOG1("CServerIdleGuard::Process aErr: %d", aErr);
       
   110 		iMessage->Complete( aErr );
       
   111 		iRequestActive = EFalse;
       
   112 		}
       
   113 	else
       
   114 		{
       
   115 		LOG("CServerIdleGuard::Process calling DoProcessL");
       
   116 		TRAPD( err, DoProcessL() );
       
   117 		LOG1("CServerIdleGuard::Process DoProcessL's TRAP err: %d", err);
       
   118 		if( err )
       
   119 			{
       
   120 			iMessage->Complete( err );
       
   121 			iRequestActive = EFalse;
       
   122 			}	
       
   123 		}
       
   124 	LOG("CServerIdleGuard::Process end");	
       
   125 	}
       
   126 
       
   127 void CServerIdleGuard::DoProcessL()
       
   128 	{
       
   129 	LOG("CServerIdleGuard::DoProcessL begin");
       
   130 	if( iBuffer.Count() && iRequestActive )
       
   131 		{
       
   132 		LOG("CServerIdleGuard::DoProcessL step 1");																
       
   133 		TPtr8 ptr(reinterpret_cast<TUint8*>(&(iBuffer[0])), sizeof(iBuffer[0]), sizeof(iBuffer[0]));
       
   134 		LOG("CServerIdleGuard::DoProcessL step 2");
       
   135 		iMessage->WriteL( 0, ptr );
       
   136 		LOG("CServerIdleGuard::DoProcessL step 3");				
       
   137 		iMessage->Complete( KErrNone );
       
   138 		LOG("CServerIdleGuard::DoProcessL step 4");
       
   139 		iRequestActive = EFalse;
       
   140 		LOG("CServerIdleGuard::DoProcessL step 5");
       
   141 		iBuffer.Remove( 0 );
       
   142 		LOG("CServerIdleGuard::DoProcessL step 6");
       
   143 		}
       
   144 	LOG("CServerIdleGuard::DoProcessL end");	
       
   145 	}
       
   146 
       
   147 //  End of File