telephonyserverplugins/common_tsy/test/component/src/cctsyactiveretriever.cpp
changeset 0 3553901f7fa8
equal deleted inserted replaced
-1:000000000000 0:3553901f7fa8
       
     1 // Copyright (c) 2007-2009 Nokia Corporation and/or its subsidiary(-ies).
       
     2 // All rights reserved.
       
     3 // This component and the accompanying materials are made available
       
     4 // under the terms of "Eclipse Public License v1.0"
       
     5 // which accompanies this distribution, and is available
       
     6 // at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     7 //
       
     8 // Initial Contributors:
       
     9 // Nokia Corporation - initial contribution.
       
    10 //
       
    11 // Contributors:
       
    12 //
       
    13 // Description:
       
    14 // Implementation of CFilteringActiveScheduler and CActiveRetriever
       
    15 // 
       
    16 //
       
    17 
       
    18 /**
       
    19  @file 
       
    20 */
       
    21 
       
    22 #include "cctsyactiveretriever.h"
       
    23 
       
    24 
       
    25 TInt CActiveRetriever::iSimultaneousRetrieveRequestsNumber(0);
       
    26 
       
    27 //----------------------------------------------------------------------------
       
    28 // Implementation of CFilteringActiveScheduler
       
    29 //----------------------------------------------------------------------------
       
    30 CFilteringActiveScheduler::~CFilteringActiveScheduler()
       
    31 	{
       
    32 	iRetrievers.Reset();
       
    33 	}
       
    34 
       
    35 //
       
    36 void CFilteringActiveScheduler::AddRetrieverL(CActiveRetriever& aRetriever)
       
    37 	{
       
    38 	iRetrievers.AppendL(&aRetriever);
       
    39 	}
       
    40 
       
    41 //	
       
    42 void CFilteringActiveScheduler::StartScheduler()
       
    43 	{
       
    44 
       
    45 	for (TInt i = 0; i<iRetrievers.Count(); i++)
       
    46 		{
       
    47 		if (iRetrievers[i]->IsActive())
       
    48 			{
       
    49 			// only if there is Active Retriever then actually starts Scheduler
       
    50 			return CActiveScheduler::Start();
       
    51 			}
       
    52 		}
       
    53 	}
       
    54 
       
    55 //
       
    56 void CFilteringActiveScheduler::WaitForAnyRequest()
       
    57 	{
       
    58 	do 	
       
    59 		{
       
    60 		CActiveScheduler::WaitForAnyRequest();
       
    61 		}
       
    62 	while (!IsOneOfMyRequestsComplete()); // WaitForAnyRequest while one of my requests is not complete 
       
    63 	}
       
    64 
       
    65 
       
    66 // check whether thera is any Retriever's request complete
       
    67 TBool CFilteringActiveScheduler::IsOneOfMyRequestsComplete()
       
    68 	{
       
    69 	TBool ret(EFalse);
       
    70 	
       
    71 	for (TInt i = 0; i<iRetrievers.Count() && !ret; i++)
       
    72 		{
       
    73 		if (iRetrievers[i]->IsRequestComplete())
       
    74 			{
       
    75 			ret = ETrue;
       
    76 			iRetrievers[i]->PerformCancelIfNeeded();
       
    77 			}
       
    78 		}
       
    79 	
       
    80 	return ret;
       
    81 	}
       
    82 
       
    83 //----------------------------------------------------------------------------
       
    84 // Implementation of CActiveRetriever
       
    85 //----------------------------------------------------------------------------
       
    86 CActiveRetriever* CActiveRetriever::
       
    87 			NewLC(CAsyncRetrieveVariableLengthBufferV2& aAsynchRetrieveBuffer)
       
    88     {
       
    89 	CActiveRetriever* self =  new (ELeave) CActiveRetriever(aAsynchRetrieveBuffer);
       
    90 	CleanupStack::PushL(self);
       
    91 	return self;		
       
    92     }
       
    93     
       
    94 //
       
    95 CActiveRetriever* CActiveRetriever::
       
    96 			NewL(CAsyncRetrieveVariableLengthBufferV2& aAsynchRetrieveBuffer)
       
    97     {
       
    98 	return new (ELeave) CActiveRetriever(aAsynchRetrieveBuffer);
       
    99     }
       
   100     
       
   101 //
       
   102 CActiveRetriever::CActiveRetriever(CAsyncRetrieveVariableLengthBufferV2& aAsynchRetrieveBuffer) : 
       
   103     CActive(EPriorityStandard),
       
   104     iAsynchRetrieveBuffer(aAsynchRetrieveBuffer),
       
   105     iTestCase(ECaseNotSpecified),
       
   106     iPhase1Passed(EFalse)
       
   107     {
       
   108     CActiveScheduler::Add(this);
       
   109     }
       
   110     
       
   111 //
       
   112 CActiveRetriever::~CActiveRetriever()
       
   113     {
       
   114     Cancel();
       
   115     }
       
   116 //
       
   117 TBool CActiveRetriever::IsRequestComplete()
       
   118 	{
       
   119 	TBool ret(EFalse);
       
   120 	
       
   121 	if ( ( AsynchRetrieveBuffer().IsActive() && 
       
   122 	       AsynchRetrieveBuffer().iStatus!=KRequestPending ) ||
       
   123 	     ( IsActive() && iStatus!=KRequestPending) )
       
   124 		{
       
   125 		ret = ETrue;
       
   126 		}
       
   127 	
       
   128 	return ret;
       
   129 	}
       
   130 
       
   131 //
       
   132 void CActiveRetriever::PerformCancelIfNeeded()
       
   133 	{
       
   134 	if ( AsynchRetrieveBuffer().IsActive() && 
       
   135 	     AsynchRetrieveBuffer().iStatus!=KRequestPending )
       
   136 		{
       
   137 		switch(TestCase())
       
   138 			{
       
   139 			case CActiveRetriever::ECasePhase2Cancel:
       
   140 				if ( ! Phase1Passed() ) // cancel request after passing of 1st phase
       
   141 					{
       
   142 					SetPhase1Passed(ETrue);
       
   143 					break;
       
   144 					}
       
   145 			case CActiveRetriever::ECasePhase1Cancel:
       
   146 				AsynchRetrieveBuffer().Cancel();
       
   147 				SetTestCase(CActiveRetriever::ECaseNotSpecified);
       
   148 				break;
       
   149 			case CActiveRetriever::ECaseNotSpecified:
       
   150 			default:
       
   151 				break;
       
   152 			}
       
   153 		}
       
   154 	}
       
   155 
       
   156 // resets pending requests number, STATIC 
       
   157 TInt CActiveRetriever::ResetRequestsNumber()
       
   158 	{
       
   159 	TInt ret(iSimultaneousRetrieveRequestsNumber); 
       
   160 	iSimultaneousRetrieveRequestsNumber = 0;
       
   161 	return ret;
       
   162 	}
       
   163 //
       
   164 TRequestStatus& CActiveRetriever::Status()
       
   165 	{
       
   166 	return iStatus;
       
   167 	}
       
   168 
       
   169 // AO's request function with test case parameter
       
   170 void CActiveRetriever::Activate(TTestCase aTestCase)
       
   171     {
       
   172     if ( ECaseGeneralCancelCase != aTestCase )
       
   173     	{
       
   174         iTestCase = aTestCase;
       
   175         iSimultaneousRetrieveRequestsNumber++;
       
   176         SetActive();
       
   177     	}
       
   178     else
       
   179     	{
       
   180     	iAsynchRetrieveBuffer.Cancel();
       
   181 	    iTestCase = ECaseNotSpecified;
       
   182     	}
       
   183     }
       
   184     
       
   185 //   
       
   186 void CActiveRetriever::RunL()
       
   187     {
       
   188     DoComplete(); // stops the Scheduler
       
   189     }
       
   190 
       
   191 //
       
   192 void CActiveRetriever::DoCancel()
       
   193     {
       
   194     if (IsActive())
       
   195 	    {
       
   196 	    iAsynchRetrieveBuffer.Cancel();
       
   197 	    DoComplete();
       
   198 	    }
       
   199     }
       
   200     
       
   201 //
       
   202 CActive& CActiveRetriever::AsynchRetrieveBuffer()
       
   203 	{
       
   204 	return iAsynchRetrieveBuffer;
       
   205 	}
       
   206 	
       
   207 //
       
   208 void CActiveRetriever::SetTestCase(CActiveRetriever::TTestCase aCase)
       
   209 	{
       
   210 	iTestCase = aCase;
       
   211 	}
       
   212 
       
   213 //	
       
   214 CActiveRetriever::TTestCase CActiveRetriever::TestCase()
       
   215 	{
       
   216 	return iTestCase;
       
   217 	}
       
   218 
       
   219 //
       
   220 void CActiveRetriever::SetPhase1Passed(TBool aPassed)
       
   221 	{
       
   222 	iPhase1Passed = aPassed;
       
   223 	}
       
   224 
       
   225 //	
       
   226 TBool CActiveRetriever::Phase1Passed()
       
   227 	{
       
   228 	return iPhase1Passed;
       
   229 	}
       
   230 
       
   231 //
       
   232 void CActiveRetriever::DoComplete()
       
   233 	{
       
   234     if (!(--iSimultaneousRetrieveRequestsNumber))
       
   235 	    {
       
   236     	CActiveScheduler::Stop();
       
   237     	}
       
   238 	}