harvester/client/src/harvesterclientao.cpp
changeset 43 c5e73110f733
parent 36 aa5a574040a4
child 48 1389872e7c51
equal deleted inserted replaced
40:910a23996aa0 43:c5e73110f733
    15 *
    15 *
    16 */
    16 */
    17 
    17 
    18 
    18 
    19 #include "harvesterclientao.h"
    19 #include "harvesterclientao.h"
       
    20 #include "harvesternotificationqueue.h"
    20 #include "harvestercommon.h"
    21 #include "harvestercommon.h"
    21 #include "harvesterlog.h"
    22 #include "harvesterlog.h"
    22 #include "mdsutils.h"
    23 #include "mdsutils.h"
    23 #include "OstTraceDefinitions.h"
    24 #include "OstTraceDefinitions.h"
    24 #ifdef OST_TRACE_COMPILER_IN_USE
    25 #ifdef OST_TRACE_COMPILER_IN_USE
    28 
    29 
    29 // ---------------------------------------------------------------------------
    30 // ---------------------------------------------------------------------------
    30 // NewL
    31 // NewL
    31 // ---------------------------------------------------------------------------
    32 // ---------------------------------------------------------------------------
    32 //
    33 //
    33 CHarvesterClientAO* CHarvesterClientAO::NewL( RHarvesterClient& aHarvesterClient )
    34 CHarvesterClientAO* CHarvesterClientAO::NewL( RHarvesterClient& aHarvesterClient, 
       
    35         CHarvesterNotificationQueue* aNotificationQueue )
    34 	{
    36 	{
    35     WRITELOG( "CHarvesterClientAO::NewL()" );
    37     WRITELOG( "CHarvesterClientAO::NewL()" );
    36     OstTrace0( TRACE_NORMAL, CHARVESTERCLIENTAO_NEWL, "CHarvesterClientAO::NewL" );
    38     OstTrace0( TRACE_NORMAL, CHARVESTERCLIENTAO_NEWL, "CHarvesterClientAO::NewL" );
    37     
    39     
    38 	CHarvesterClientAO* self = new (ELeave) CHarvesterClientAO( aHarvesterClient );
    40 	CHarvesterClientAO* self = new (ELeave) CHarvesterClientAO( aHarvesterClient, aNotificationQueue );
    39 	CleanupStack::PushL( self );
    41 	CleanupStack::PushL( self );
    40 	self->ConstructL();
    42 	self->ConstructL();
    41 	CleanupStack::Pop( self );
    43 	CleanupStack::Pop( self );
    42 	return self;
    44 	return self;
    43 	}
    45 	}
    50 	{   
    52 	{   
    51     OstTrace0( TRACE_NORMAL, CHARVESTERCLIENTAO_CHARVESTERCLIENTAO, "CHarvesterClientAO::~CHarvesterClientAO" );
    53     OstTrace0( TRACE_NORMAL, CHARVESTERCLIENTAO_CHARVESTERCLIENTAO, "CHarvesterClientAO::~CHarvesterClientAO" );
    52     
    54     
    53     WRITELOG( "CHarvesterClientAO::~CHarvesterClientAO()" );
    55     WRITELOG( "CHarvesterClientAO::~CHarvesterClientAO()" );
    54     Cancel();
    56     Cancel();
       
    57     
       
    58     delete iURI;
       
    59     iURI = NULL;
    55  	}
    60  	}
    56 
    61 
    57 // ---------------------------------------------------------------------------
    62 // ---------------------------------------------------------------------------
    58 // CHarvesterClientAO
    63 // CHarvesterClientAO
    59 // First-phase C++ constructor
    64 // First-phase C++ constructor
    60 // ---------------------------------------------------------------------------
    65 // ---------------------------------------------------------------------------
    61 //
    66 //
    62 CHarvesterClientAO::CHarvesterClientAO( RHarvesterClient& aHarvesterClient )
    67 CHarvesterClientAO::CHarvesterClientAO( RHarvesterClient& aHarvesterClient, 
       
    68         CHarvesterNotificationQueue* aNotificationQueue )
    63     : CActive( CActive::EPriorityStandard ), 
    69     : CActive( CActive::EPriorityStandard ), 
    64     iObserver( NULL ),
    70     iObserver( NULL ),
    65     iHarvesterClient( aHarvesterClient )
    71     iHarvesterClient( aHarvesterClient ),
       
    72     iNotificationQueue( aNotificationQueue ),
       
    73     iURI( NULL ),
       
    74     iRequestComplete( EFalse )
    66   	{
    75   	{
    67     OstTrace0( TRACE_NORMAL, DUP1_CHARVESTERCLIENTAO_CHARVESTERCLIENTAO, "CHarvesterClientAO::CHarvesterClientAO" );
    76     OstTrace0( TRACE_NORMAL, DUP1_CHARVESTERCLIENTAO_CHARVESTERCLIENTAO, "CHarvesterClientAO::CHarvesterClientAO" );
    68     
    77     
    69     WRITELOG( "CHarvesterClientAO::CHarvesterClientAO()" );
    78     WRITELOG( "CHarvesterClientAO::CHarvesterClientAO()" );
    70 	}
    79 	}
    92 	
   101 	
    93 	iObserver = aObserver;
   102 	iObserver = aObserver;
    94 	}
   103 	}
    95 
   104 
    96 // ---------------------------------------------------------------------------
   105 // ---------------------------------------------------------------------------
    97 // RemoveObserver
       
    98 // ---------------------------------------------------------------------------
       
    99 //	
       
   100 void CHarvesterClientAO::RemoveObserver( MHarvestObserver* aObserver )
       
   101 	{
       
   102 	WRITELOG( "CHarvesterClientAO::RemoveObserver()" );
       
   103 	OstTrace0( TRACE_NORMAL, CHARVESTERCLIENTAO_REMOVEOBSERVER, "CHarvesterClientAO::RemoveObserver" );
       
   104 	
       
   105 	if ( aObserver == iObserver )
       
   106 		{
       
   107 		if ( iObserver )
       
   108 			{
       
   109 			WRITELOG( "CHarvesterClientAO::RemoveObserver() - deleting observer" );
       
   110 			iObserver = NULL;
       
   111 			}
       
   112 		}
       
   113 	}
       
   114 
       
   115 // ---------------------------------------------------------------------------
       
   116 // DoCancel
   106 // DoCancel
   117 // ---------------------------------------------------------------------------
   107 // ---------------------------------------------------------------------------
   118 //
   108 //
   119 void CHarvesterClientAO::DoCancel()
   109 void CHarvesterClientAO::DoCancel()
   120 	{
   110 	{
   121 	WRITELOG( "CHarvesterClientAO::DoCancel()" );
   111 	WRITELOG( "CHarvesterClientAO::DoCancel()" );
   122 	OstTrace0( TRACE_NORMAL, CHARVESTERCLIENTAO_DOCANCEL, "CHarvesterClientAO::DoCancel" );
   112 	OstTrace0( TRACE_NORMAL, CHARVESTERCLIENTAO_DOCANCEL, "CHarvesterClientAO::DoCancel" );
   123 	
   113 	iRequestComplete = ETrue;
   124 	}
   114 	}
   125 	
   115 	
   126 // ---------------------------------------------------------------------------
   116 // ---------------------------------------------------------------------------
   127 // Active
   117 // Active
   128 // ---------------------------------------------------------------------------
   118 // ---------------------------------------------------------------------------
   129 //
   119 //
   130 void CHarvesterClientAO::Active()
   120 void CHarvesterClientAO::Active( TDesC& aUri )
   131 	{	
   121 	{	
   132 	if (!IsActive())
   122     WRITELOG( "CHarvesterClientAO::Active()");
   133 		{
   123     if( iObserver && !IsActive() )
   134 		iHarvesterClient.RegisterHarvestComplete(iURI, iStatus);
   124         {
   135 		SetActive();
   125         delete iURI;
   136 		}
   126         iURI = NULL;
       
   127         iURI = aUri.Alloc();
       
   128         if( iURI )
       
   129             {
       
   130             TPtr16 uri( iURI->Des() );
       
   131             iHarvesterClient.RegisterHarvestComplete( uri, iStatus );
       
   132             SetActive();            
       
   133             }
       
   134         else if( iObserver )
       
   135             {
       
   136             iObserver->HarvestingComplete( aUri, KErrCompletion );
       
   137             iRequestComplete = ETrue;
       
   138             }
       
   139         }
   137 	}
   140 	}
   138 
   141 
   139 // ---------------------------------------------------------------------------
   142 // ---------------------------------------------------------------------------
   140 // RunL
   143 // RunL
   141 // ---------------------------------------------------------------------------
   144 // ---------------------------------------------------------------------------
   142 //
   145 //
   143 void CHarvesterClientAO::RunL()
   146 void CHarvesterClientAO::RunL()
   144 	{
   147 	{
   145 	WRITELOG( "CHarvesterClientAO::RunL()" );
   148 	WRITELOG( "CHarvesterClientAO::RunL()" );
   146 	OstTrace0( TRACE_NORMAL, CHARVESTERCLIENTAO_RUNL, "CHarvesterClientAO::RunL" );
   149 	OstTrace0( TRACE_NORMAL, CHARVESTERCLIENTAO_RUNL, "CHarvesterClientAO::RunL" );
       
   150 
       
   151 	iNotificationQueue->Cleanup( EFalse );
   147 	
   152 	
   148 
       
   149 	const TInt status = iStatus.Int();
   153 	const TInt status = iStatus.Int();
   150 	
   154 	
   151     if ( status < KErrNone )
   155     if ( status < KErrNone )
   152         {
   156         {
   153         WRITELOG1( "CHarvesterClientAO::RunL() - Error occured while harvesting, error:%d", status );
   157         WRITELOG1( "CHarvesterClientAO::RunL() - Error occured while harvesting, error:%d", status );
   154         }
   158         }
   155 
   159 
   156 	// Callback to client process
   160 	// Callback to client process
   157 	if ( iObserver )
   161 	if ( iObserver && iURI )
   158 		{
   162 		{
   159 		WRITELOG( "CHarvesterClientAO::RunL() - ECompleteRequest - calling callback" );
   163 		WRITELOG( "CHarvesterClientAO::RunL() - Request complete - calling callback" );
   160 		iObserver->HarvestingComplete( iURI, status );
   164 		TPtrC16 uri( iURI->Des() );
       
   165 		iObserver->HarvestingComplete( uri, status );
   161 		}
   166 		}
   162 	
   167 	
   163 	// if the request was not canceled or server is not terminated, Activating AO again
   168     delete iURI;
   164 	if ( status != KErrCancel && status != KErrServerTerminated )
   169     iURI = NULL;
   165 		{
   170 	iRequestComplete = ETrue;
   166 		Active();
       
   167 		}
       
   168 	}
   171 	}
   169 	
   172 	
   170 // ---------------------------------------------------------------------------
   173 // ---------------------------------------------------------------------------
   171 // RunError
   174 // RunError
   172 // ---------------------------------------------------------------------------
   175 // ---------------------------------------------------------------------------
   177 TInt CHarvesterClientAO::RunError( TInt )
   180 TInt CHarvesterClientAO::RunError( TInt )
   178 #endif
   181 #endif
   179     {
   182     {
   180     WRITELOG1( "CHarvesterClientAO::RunError(), errorcode: %d", aError );
   183     WRITELOG1( "CHarvesterClientAO::RunError(), errorcode: %d", aError );
   181     
   184     
       
   185     iNotificationQueue->Cleanup( EFalse );
       
   186     iRequestComplete = ETrue;
       
   187     
   182     return KErrNone;
   188     return KErrNone;
   183     }
   189     }
       
   190 
       
   191 // ---------------------------------------------------------------------------
       
   192 // RequestComplete
       
   193 // ---------------------------------------------------------------------------
       
   194 //  
       
   195 TBool CHarvesterClientAO::RequestComplete()
       
   196     {
       
   197     return iRequestComplete;
       
   198     }
       
   199