predictivesearch/PcsServerClientAPI/src/CPsPropertyHandler.cpp
changeset 0 e686773b3f54
child 12 4ae315f230bc
equal deleted inserted replaced
-1:000000000000 0:e686773b3f54
       
     1 /*
       
     2 * Copyright (c) 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:  This is the client side internal file to handle
       
    15 *                property used in Publish and Subscribe framework.
       
    16 *
       
    17 */
       
    18 
       
    19 //SYSTEM INCLUDES
       
    20 #include <CPsRequestHandler.h>
       
    21 #include <MPsResultsObserver.h>
       
    22 
       
    23 // USER INCLUDES
       
    24 #include "CPsPropertyHandler.h"
       
    25 #include "CPcsDebug.h"
       
    26 
       
    27 // UID used for Publish and Subscribe mechanism
       
    28 // This should be same as the one defined in CPcsAlgorithm.cpp
       
    29 // Server UID3 has to be used for this framework
       
    30 const TUid KCStatus = {0x2000B5B6};
       
    31 
       
    32 // ========================= MEMBER FUNCTIONS ==================================
       
    33 
       
    34 // -----------------------------------------------------------------------------
       
    35 // CPsPropertyHandler::NewL()
       
    36 // Two-phased constructor.
       
    37 // -----------------------------------------------------------------------------
       
    38  CPsPropertyHandler* CPsPropertyHandler::NewL( CPSRequestHandler* aRequestHandler )
       
    39 {
       
    40     PRINT ( _L("Enter CPsPropertyHandler::NewL") );
       
    41     
       
    42     CPsPropertyHandler* self = new ( ELeave ) CPsPropertyHandler(aRequestHandler);
       
    43     CleanupStack::PushL( self );
       
    44     self->ConstructL();
       
    45     CleanupStack::Pop( self );
       
    46     
       
    47     PRINT ( _L("End CPsPropertyHandler::NewL") );
       
    48     
       
    49     return( self ) ;
       
    50 }
       
    51 
       
    52 // -----------------------------------------------------------------------------
       
    53 // CPsPropertyHandler::ConstructL()
       
    54 // Symbian 2nd phase constructor can leave.
       
    55 // -----------------------------------------------------------------------------
       
    56 void CPsPropertyHandler::ConstructL(  )
       
    57 {
       
    58     PRINT ( _L("Enter CPsPropertyHandler::ConstructL") );
       
    59     
       
    60     TInt err = iCacheStatusProperty.Attach(KCStatus, 0 );
       
    61     User::LeaveIfError(err);   
       
    62     
       
    63     // Attach the cache error property
       
    64     err = iCacheErrorProperty.Attach(KCStatus, 1);
       
    65     User::LeaveIfError(err); 
       
    66     
       
    67     iCacheStatusProperty.Subscribe(iStatus);
       
    68     
       
    69     SetActive();
       
    70     
       
    71     PRINT ( _L("End CPsPropertyHandler::ConstructL") );
       
    72 }
       
    73 
       
    74 // -----------------------------------------------------------------------------
       
    75 // CPsPropertyHandler::CPsPropertyHandler()
       
    76 // C++ default constructor can NOT contain any code, that might leave.
       
    77 // -----------------------------------------------------------------------------
       
    78 CPsPropertyHandler::CPsPropertyHandler( CPSRequestHandler* aRequestHandler )
       
    79 : CActive( EPriorityStandard ), 
       
    80   iRequestHandler(aRequestHandler)
       
    81 {
       
    82     PRINT ( _L("Enter CPsPropertyHandler::CPsPropertyHandler") );
       
    83     
       
    84     CActiveScheduler::Add( this );
       
    85     
       
    86     PRINT ( _L("End CPsPropertyHandler::CPsPropertyHandler") );
       
    87 }
       
    88 
       
    89 // -----------------------------------------------------------------------------
       
    90 // CPsPropertyHandler::~CPsPropertyHandler()
       
    91 // Destructor.
       
    92 // -----------------------------------------------------------------------------
       
    93 CPsPropertyHandler::~CPsPropertyHandler()
       
    94 {
       
    95     PRINT ( _L("Enter CPsPropertyHandler::~CPsPropertyHandler") );
       
    96 
       
    97     Cancel(); // Causes call to DoCancel()
       
    98     
       
    99     iCacheStatusProperty.Close();
       
   100 
       
   101 }
       
   102 
       
   103 // -----------------------------------------------------------------------------
       
   104 // CPsPropertyHandler::RunL()
       
   105 // Invoked to handle responses from the server.
       
   106 // -----------------------------------------------------------------------------
       
   107 void CPsPropertyHandler::RunL()
       
   108 {
       
   109 	iCacheStatusProperty.Subscribe(iStatus);
       
   110 	SetActive();
       
   111 	
       
   112 	//Get the value
       
   113 	TCachingStatus status; 
       
   114 	TInt statusValue;
       
   115 	iCacheStatusProperty.Get(statusValue);
       
   116 	status = (TCachingStatus)statusValue;
       
   117 	
       
   118 	TInt cacheError;
       
   119 	iCacheErrorProperty.Get(cacheError);
       
   120 	
       
   121 	if( (status == ECachingComplete) || (status == ECachingCompleteWithErrors))
       
   122 	{
       
   123 		for(TInt i = 0; i < iRequestHandler->iObservers.Count(); i++)
       
   124 			iRequestHandler->iObservers[i]->CachingStatus(status, cacheError);
       
   125 	}
       
   126 }
       
   127 
       
   128 // -----------------------------------------------------------------------------
       
   129 // CPsPropertyHandler::DoCancel()
       
   130 // Cancels any outstanding operation.
       
   131 // -----------------------------------------------------------------------------
       
   132 void CPsPropertyHandler::DoCancel()
       
   133 {
       
   134 	iCacheStatusProperty.Cancel();
       
   135 }
       
   136 
       
   137 // -----------------------------------------------------------------------------
       
   138 // CPsPropertyHandler::GetCachingStatusL()
       
   139 // Returns the caching status fr synchronous request
       
   140 // -----------------------------------------------------------------------------
       
   141 TInt CPsPropertyHandler::GetCachingStatusL(TCachingStatus& aStatus)
       
   142 {
       
   143 	TInt status;
       
   144 	//Get the status from the property
       
   145 	iCacheStatusProperty.Get(status);
       
   146 	
       
   147 	aStatus = (TCachingStatus)status;
       
   148 	
       
   149 	TInt cacheError;
       
   150 	iCacheErrorProperty.Get(cacheError);
       
   151 	
       
   152 	return cacheError;
       
   153 }
       
   154 
       
   155 //END OF FILE