datasourceadaptation/gpsdatasourceadaptation/common/src/cpositionerq.cpp
changeset 36 b47902b73a93
parent 0 9cfd9a3ee49c
equal deleted inserted replaced
35:a2efdd544abf 36:b47902b73a93
       
     1 // Copyright (c) 2008-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 //
       
    15 
       
    16 /**
       
    17  @file
       
    18  @InternalComponent
       
    19 */
       
    20 
       
    21 #include "psylogging.h"
       
    22 #include "cpositionerq.h"
       
    23 #include "psypanic.h"
       
    24 #include "tpositionercall.h"
       
    25 
       
    26 /*
       
    27 * CPositionerQ::NewL
       
    28 * Two-phased constructor.
       
    29 * @param aEnv pointer to the CPositionerEnvironment
       
    30 */
       
    31 CPositionerQ* CPositionerQ::NewL()
       
    32     {
       
    33     CPositionerQ* self = new( ELeave ) CPositionerQ();
       
    34     
       
    35     return self;
       
    36     }
       
    37 
       
    38 /*
       
    39 * CPositionerQ::CPositionerQ
       
    40 * C++ default constructor can NOT contain any code, that
       
    41 * might leave.
       
    42 */
       
    43 CPositionerQ::CPositionerQ()
       
    44     {
       
    45     }
       
    46 
       
    47 /*
       
    48 * CPositionerQ::~CPositionerQ
       
    49 * Destructor.
       
    50 */
       
    51 CPositionerQ::~CPositionerQ()
       
    52     {
       
    53     __ASSERT_DEBUG(iPsyArray.Count() == 0, User::Panic(KAdaptationPanicCategory, EPanicQNotEmpty));
       
    54     
       
    55     iPsyArray.Close();
       
    56     }
       
    57 
       
    58 /**
       
    59 * Registers the PSY instance to the request handler
       
    60 * @param aPSY pointer to the MPositioner
       
    61 */
       
    62 void CPositionerQ::RegisterPSYL(MPositioner* aPSY)
       
    63     {
       
    64     TRACESTRING("CPositionerQ::RegisterPSYL start...")
       
    65     
       
    66     //Register the psy
       
    67     User::LeaveIfError(iPsyArray.Append(aPSY));
       
    68     
       
    69     TRACESTRING("CPositionerQ::RegisterPSYL end")
       
    70     }
       
    71 
       
    72 /**
       
    73 * Unregisters the MPositioner instance
       
    74 * @param aPSY pointer to the MPositioner
       
    75 */
       
    76 void CPositionerQ::UnregisterPSY(MPositioner* aPSY)
       
    77     {
       
    78     TRACESTRING("CPositionerQ::UnregisterPSY start...")
       
    79 
       
    80     TInt index = KErrNotFound;
       
    81     index = Index(*aPSY);
       
    82     
       
    83     if(index!=KErrNotFound)
       
    84         {
       
    85         iPsyArray.Remove(index);
       
    86         }
       
    87         
       
    88     TRACESTRING("CPositionerQ::UnregisterPSY end")
       
    89     }
       
    90 
       
    91 /**
       
    92 * Calles aCall::Call for all MPositioners in the queue
       
    93 * @param TPositionerCall* pointer to the TPositionerCall derived class
       
    94 */
       
    95 void CPositionerQ::PositionerIterator(TPositionerCall& aCall)
       
    96 	{
       
    97 	for(TInt i=0; i < iPsyArray.Count(); ++i)
       
    98 		{
       
    99 		aCall.Call(Positioner(i));
       
   100 		}
       
   101 	}
       
   102 
       
   103 /**
       
   104 * CPositionerQ::IterETrue
       
   105 * Calls aCall::Call for all MPositioners in the queue
       
   106 * @param aCall reference to the TPositionerCall derived function to be called
       
   107 * @return TBool	returns True if the call returns true for any positioner in the queue
       
   108 */
       
   109 TBool CPositionerQ::IterETrue(TRetBoolPositionerCall& aCall)
       
   110 	{
       
   111     TInt count = iPsyArray.Count();
       
   112     for(TInt i=0; i<count; i++)
       
   113         {
       
   114         if(aCall.Call(Positioner(i)))
       
   115             {
       
   116             return ETrue;
       
   117             }
       
   118         }
       
   119     return EFalse;
       
   120 	}
       
   121 
       
   122 /**
       
   123 * CPositionerQ::IterGreatest
       
   124 * 
       
   125 * Calls aCall::Call for all MPositioners in the queue
       
   126 * @param aCall reference to the TPositionerCall derived function to be called
       
   127 * @return TBool	returns the greatest of all the integer values returned from each MPositioner method
       
   128 */
       
   129 TUint CPositionerQ::IterGreatest(TRetTUintPositionerCall& aCall)
       
   130 	{
       
   131     TInt count = iPsyArray.Count();
       
   132     TUint greatest = 0;
       
   133     TUint result = 0;
       
   134     
       
   135     for(TInt i=0; i<count; i++)
       
   136         {
       
   137         result = aCall.Call(Positioner(i));
       
   138         if(result > greatest)
       
   139             {
       
   140             greatest = result;
       
   141             }
       
   142         }
       
   143     return greatest;
       
   144 	}
       
   145 
       
   146 /*
       
   147 * CPositionerQ::Count
       
   148 *
       
   149 * @return count of MPositioner objects in the queue
       
   150 */
       
   151 TUint CPositionerQ::Count()
       
   152 	{
       
   153 	return iPsyArray.Count();
       
   154 	}
       
   155 	
       
   156 TInt CPositionerQ::Index(MPositioner& aPSY)
       
   157     {
       
   158     TInt index = KErrNotFound;
       
   159     TInt count = iPsyArray.Count();
       
   160 
       
   161     for(TInt i=0; i<count; i++)
       
   162         {
       
   163         if(iPsyArray[i] == &aPSY)
       
   164             {
       
   165             index = i;
       
   166             }
       
   167         }
       
   168 	return index;
       
   169 	}    
       
   170 /*
       
   171 * CPositionerQ::Positioner
       
   172 *
       
   173 * @return MPositioner pointer for requested index
       
   174 */
       
   175 MPositioner& CPositionerQ::Positioner(TUint aIndex)
       
   176 	{
       
   177 	return *(iPsyArray[aIndex]);
       
   178 	}
       
   179 	
       
   180 //  End of File
       
   181