locationcentre/lcserver/src/lcserverengine.cpp
branchRCL_3
changeset 9 4721bd00d3da
parent 8 3a25f69541ff
child 11 e15b7f06eba6
equal deleted inserted replaced
8:3a25f69541ff 9:4721bd00d3da
     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:  Location Centre Server Engine Object.
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 // SYSTEM INCLUDES
       
    20 #include <s32mem.h>
       
    21 #include <e32std.h>
       
    22 
       
    23 // USER INCLUDES
       
    24 #include "lcserverengine.h"
       
    25 #include "lcregistry.h"
       
    26 #include "lcserverengineobserver.h"
       
    27 #include "lcserverinterface.h"
       
    28 #include "lcdebug.h"
       
    29 
       
    30 // CONSTANT DEFINTIONS
       
    31 const TUint32 KUidMaxValue = 0xFFFFFFFF;
       
    32 
       
    33 // ----- Member funtions for CLcServerEngine ---------------------------------
       
    34 
       
    35 // ---------------------------------------------------------------------------
       
    36 // CLcServerEngine::CLcServerEngine
       
    37 // ---------------------------------------------------------------------------
       
    38 //
       
    39 CLcServerEngine::CLcServerEngine( MLcServerEngineObserver&    aObserver )
       
    40     :iObserver( aObserver )
       
    41     {
       
    42     // C++ Default constructor. No allocations or functions which can Leave
       
    43     // should be called from here.
       
    44     }
       
    45          
       
    46 // ---------------------------------------------------------------------------
       
    47 // CLcServerEngine::~CLcServerEngine
       
    48 // ---------------------------------------------------------------------------
       
    49 //
       
    50 CLcServerEngine::~CLcServerEngine()
       
    51     {
       
    52     // C++ Destructor. Free all resources associated with this class.
       
    53     
       
    54     // Complete any outstanding messages if they exist and free all the
       
    55     // associated resources
       
    56     while ( iMessageArray.Count())
       
    57         {
       
    58         // Extract the IPC message handle from the Array
       
    59         RMessage2* message = iMessageArray[0];
       
    60         iMessageArray.Remove( 0 );
       
    61         
       
    62         // Service the Request.
       
    63         message->Complete( KErrServerTerminated );
       
    64         
       
    65         // Free the message structure
       
    66         delete message;
       
    67         }    
       
    68     iMessageArray.ResetAndDestroy();
       
    69     iMessageArray.Close();
       
    70     
       
    71     // Delete the Location Centre Registry
       
    72     delete iRegistry;
       
    73     }
       
    74         
       
    75 // ---------------------------------------------------------------------------
       
    76 // CLcServerEngine* CLcServerEngine::NewL
       
    77 // ---------------------------------------------------------------------------
       
    78 //
       
    79 CLcServerEngine* CLcServerEngine::NewL( MLcServerEngineObserver&    aObserver )
       
    80     {
       
    81     CLcServerEngine* self = NewLC( aObserver );
       
    82     CleanupStack::Pop( self );
       
    83     return self;         
       
    84     }
       
    85 
       
    86 // ---------------------------------------------------------------------------
       
    87 // CLcServerEngine* CLcServerEngine::NewLC
       
    88 // ---------------------------------------------------------------------------
       
    89 //
       
    90 CLcServerEngine* CLcServerEngine::NewLC( MLcServerEngineObserver&    aObserver )
       
    91     { 
       
    92     // Symbian Two phased constructor. Leaves the object on the Clean-up
       
    93     // stack.
       
    94     CLcServerEngine* self = new ( ELeave )CLcServerEngine( aObserver );
       
    95     CleanupStack::PushL( self );
       
    96     self->ConstructL();
       
    97     return self;         
       
    98     }
       
    99 
       
   100 // ---------------------------------------------------------------------------
       
   101 // void CLcServerEngine::ConstructL
       
   102 // ---------------------------------------------------------------------------
       
   103 //
       
   104 void CLcServerEngine::ConstructL()
       
   105     {
       
   106     // Create the Location Centre Registry
       
   107     iRegistry = CLcRegistry::NewL( *this );
       
   108       
       
   109     }
       
   110 
       
   111 // ---------------------------------------------------------------------------
       
   112 // void CLcServerEngine::ConstructL
       
   113 // ---------------------------------------------------------------------------
       
   114 //
       
   115 void CLcServerEngine::DoServiceL( const RMessage2&      aMessage )
       
   116     {
       
   117     // We cannot store the reference to the RMessage2 object passed but
       
   118     // need to create a new instance and copy the contents for all
       
   119     // furture purposes
       
   120     RMessage2* message = new RMessage2;
       
   121     *message = aMessage;
       
   122     
       
   123     // Append the message to the Queue. All messages will be serviced later
       
   124     // in a generic manner.
       
   125     User::LeaveIfError( iMessageArray.Append( message ));
       
   126         
       
   127     if ( !iRegistryUnderUpdate )
       
   128         {
       
   129         // The registry is consistent. So the message can be handled immediately.
       
   130         ServiceRequests();
       
   131         }
       
   132     }
       
   133 
       
   134 // ---------------------------------------------------------------------------
       
   135 // void CLcServerEngine::RegistryUnderUpdation
       
   136 // ---------------------------------------------------------------------------
       
   137 //
       
   138 void CLcServerEngine::RegistryUnderUpdation()
       
   139     {
       
   140     DEBUG( "+ CLcServerEngine::RegistryUnderUpdation")
       
   141     
       
   142     // Set the Registry update flag. This would prevent the Engine from
       
   143     // performing any operation until the updation completes.
       
   144     iRegistryUnderUpdate = ETrue;
       
   145     
       
   146     DEBUG( "- CLcServerEngine::RegistryUnderUpdation")
       
   147     }
       
   148 
       
   149 // ---------------------------------------------------------------------------
       
   150 // void CLcServerEngine::RegistryUpdated
       
   151 // ---------------------------------------------------------------------------
       
   152 //
       
   153 void CLcServerEngine::RegistryUpdated()
       
   154     {
       
   155     DEBUG( "+ CLcServerEngine::RegistryUpdated")
       
   156         
       
   157     // Reset the Registry Update flag. Now the Registry is consistent and
       
   158     // the Engine can service any requestsy
       
   159     iRegistryUnderUpdate = EFalse;
       
   160     
       
   161     // Serve all the outstanding Location Requests.
       
   162     ServiceRequests();
       
   163     
       
   164     // Notify the Engine Observer about the changes to the Registry.
       
   165     iObserver.LcRegistryUpdated();
       
   166     
       
   167     DEBUG( "- CLcServerEngine::RegistryUpdated")    
       
   168     }
       
   169     
       
   170 // ---------------------------------------------------------------------------
       
   171 // void CLcServerEngine::ServiceRequests
       
   172 // ---------------------------------------------------------------------------
       
   173 //
       
   174 void CLcServerEngine::ServiceRequests()
       
   175     {                       
       
   176     // Service all outstanding LC requests.
       
   177     while ( iMessageArray.Count())
       
   178         {
       
   179         // Extract the IPC message handle from the Array
       
   180         RMessage2* message = iMessageArray[0];
       
   181         iMessageArray.Remove( 0 );
       
   182         
       
   183         // Service the Request.
       
   184         TRAPD( error, ServiceRequestL(*message));
       
   185         
       
   186         DEBUG1( "ServiceRequest Error %d", error ) 
       
   187             
       
   188         // Complete the request with the error code.
       
   189         message->Complete( error );
       
   190                             
       
   191         // Free the message structure
       
   192         delete message;
       
   193         }   
       
   194     }
       
   195 
       
   196 // ---------------------------------------------------------------------------
       
   197 // void CLcServerEngine::ServiceRequestL
       
   198 // ---------------------------------------------------------------------------
       
   199 //
       
   200 void CLcServerEngine::ServiceRequestL( RMessage2&      aMessage )
       
   201     {
       
   202     // Set the Current requestor's SID
       
   203     iCurrentRequestorSid = aMessage.SecureId();
       
   204        
       
   205     switch( aMessage.Function())
       
   206         {
       
   207         case ELcFilteredAppsBufferLength:
       
   208         case ELcFilteredApps:
       
   209             {
       
   210             // Getting the Application buffer length and Getting the list of applications
       
   211             // have similar functionality. Only the last portion of the code changes.
       
   212             // Hence, both the requests will be handled similarly with the necessary
       
   213             // differentiation at the end. 
       
   214            
       
   215             // Create the package buffer for obtaining the filter conditions
       
   216             TPckgBuf< TLcLocationAppFilter > filterBuf;
       
   217              
       
   218             // Read the filter contents
       
   219             User::LeaveIfError( aMessage.Read( 0, filterBuf ));
       
   220             
       
   221             RLcIpcAppInfoArray appArray;
       
   222             CleanupClosePushL( appArray );
       
   223 
       
   224             // Filter Location based Applications based on the Filter
       
   225             // conditions
       
   226             GetFilteredAppsL( filterBuf(), appArray );
       
   227             
       
   228             // Now for the differentiation
       
   229             if ( aMessage.Function() == ELcFilteredAppsBufferLength )
       
   230                 {
       
   231                 // Write the Length Value into a buffer
       
   232                 CBufFlat* lengthBuffer = CBufFlat::NewL( sizeof( TUint32 ));
       
   233                 CleanupStack::PushL( lengthBuffer );
       
   234                 RBufWriteStream lengthWrite( *lengthBuffer, 0 );
       
   235                 CleanupClosePushL( lengthWrite );
       
   236                 lengthWrite.WriteInt32L( appArray.BufferLength());
       
   237                 CleanupStack::PopAndDestroy(); // lengthWrite
       
   238                 
       
   239                 // Write the Buffer back to the IPC message                
       
   240                 TPtr8    ptr( lengthBuffer->Ptr(0));
       
   241                 User::LeaveIfError( aMessage.Write( 1, ptr ));
       
   242                 
       
   243                 // Pop and destroy the length buffer
       
   244                 CleanupStack::PopAndDestroy( lengthBuffer );                    
       
   245                 }
       
   246             else
       
   247                 {
       
   248                 // Create the buffer for packing the Application Information
       
   249                 // structures and pack the contents into this buffer
       
   250                 CBufFlat* buffer = CBufFlat::NewL( appArray.BufferLength() );
       
   251                 CleanupStack::PushL( buffer );
       
   252                 RBufWriteStream writeStream( *buffer, 0 );
       
   253                 CleanupClosePushL( writeStream );                
       
   254                 appArray.ExternalizeL( writeStream );
       
   255                 CleanupStack::PopAndDestroy(); // writeStream
       
   256                 
       
   257                 // Write the buffer back to the IPC message.
       
   258                 TPtr8    ptr( buffer->Ptr(0));
       
   259                 User::LeaveIfError( aMessage.Write( 1, ptr ));
       
   260                 
       
   261                 // Pop and destroy the app buffer              
       
   262                 CleanupStack::PopAndDestroy( buffer );                    
       
   263                 }
       
   264             
       
   265             // Reset and Destroy the Contents of the Application info
       
   266             // array
       
   267             CleanupStack::PopAndDestroy( &appArray );
       
   268             break;
       
   269             }
       
   270         case ELcSpecifiedAppsBufferLength:
       
   271         case ELcSpecifiedApps:
       
   272             {
       
   273             // Getting the Application buffer length and Getting the list of applications
       
   274             // have similar functionality. Only the last portion of the code changes.
       
   275             // Hence, both the requets will be handled similarly with the necessary
       
   276             // differentiation at the end. 
       
   277                             
       
   278             // Obtain the array of Applications which need to be used for
       
   279             // filtering.              
       
   280             
       
   281             // Read the Descriptor from the IPC arguments
       
   282             TInt desLength = aMessage.GetDesLength( 0 );          
       
   283             // Allocate the id Array buffer    
       
   284             CBufFlat* idArrayBuf = CBufFlat::NewL( desLength );
       
   285             CleanupStack::PushL( idArrayBuf );
       
   286             idArrayBuf->ResizeL( desLength );
       
   287             
       
   288             TPtr8   idArrayPtr( idArrayBuf->Ptr(0));
       
   289             
       
   290             // Now read the descriptor finally
       
   291             User::LeaveIfError( aMessage.Read( 0, idArrayPtr ));
       
   292             
       
   293             // Create a Read buffer stream to read the App Ids    
       
   294             RBufReadStream  appReadStream( *idArrayBuf, 0 );
       
   295             CleanupClosePushL( appReadStream );
       
   296             
       
   297             RLcIpcAppIdArray    idArray;
       
   298             CleanupStack::PushL( TCleanupItem( RLcIpcAppIdArray::ResetAndDestroyIdArray, &idArray ));  
       
   299                             
       
   300             // Internalize the structure to obtain the Actual list of Ids    
       
   301             idArray.InternalizeL( appReadStream );  
       
   302              
       
   303              
       
   304             RLcIpcAppInfoArray appArray;
       
   305             CleanupClosePushL( appArray );
       
   306                
       
   307             // Read the second paramte to determine whether the list specified needs to be
       
   308             // included or excluded
       
   309             TBool   includeFlag = aMessage.Int1();
       
   310             if ( includeFlag )
       
   311                 {
       
   312                 GetSpecifiedAppsL( idArray, appArray );
       
   313                 }
       
   314             else
       
   315                 {
       
   316                 GetWithoutSpecifiedAppsL( idArray, appArray );
       
   317                 }
       
   318             
       
   319             if ( aMessage.Function() == ELcSpecifiedAppsBufferLength )
       
   320                 {
       
   321                 // Write the Length Value into a buffer
       
   322                 CBufFlat* lengthBuffer = CBufFlat::NewL( sizeof( TUint32 ));
       
   323                 CleanupStack::PushL( lengthBuffer );             
       
   324                 
       
   325                 RBufWriteStream lengthWrite( *lengthBuffer, 0 );
       
   326                 CleanupClosePushL( lengthWrite );                
       
   327                 lengthWrite.WriteInt32L( appArray.BufferLength());
       
   328                 CleanupStack::PopAndDestroy(); // lengthWrite
       
   329                 
       
   330                 // Write the Buffer back to the IPC message                
       
   331                 TPtr8    ptr( lengthBuffer->Ptr(0));
       
   332                 User::Leave( aMessage.Write( 2, ptr ));
       
   333                 
       
   334                 // Pop and destroy the Length buffer              
       
   335                 CleanupStack::PopAndDestroy( lengthBuffer );                    
       
   336                 }
       
   337             else
       
   338                 {
       
   339                 // Create the buffer for packing the Application Information
       
   340                 // structures and pack the contents into this buffer
       
   341                 CBufFlat* buffer = CBufFlat::NewL( appArray.BufferLength() );
       
   342                 CleanupStack::PushL( buffer );
       
   343                                 
       
   344                 RBufWriteStream writeStream( *buffer, 0 );
       
   345                 CleanupClosePushL( writeStream );                
       
   346                 appArray.ExternalizeL( writeStream );
       
   347                 CleanupStack::PopAndDestroy(); // writeStream
       
   348                 
       
   349                 // Write the buffer back to the IPC message.
       
   350                 TPtr8    ptr( buffer->Ptr(0));
       
   351                 User::Leave( aMessage.Write( 2, ptr ));
       
   352                 
       
   353                 // Pop and destroy the app buffer                  
       
   354                 CleanupStack::PopAndDestroy( buffer ); 
       
   355                 }
       
   356             
       
   357             // We can also destroy the App id array buffer and Read streams
       
   358             CleanupStack::PopAndDestroy( 4, idArrayBuf );
       
   359             
       
   360             break;
       
   361             }
       
   362         case ELcAppInfoLength:
       
   363             {
       
   364             DEBUG( "+ CLcServerEngine::ServiceRequestL, ELcAppInfoLength ") 
       
   365                
       
   366             // Read the Descriptor from the IPC arguments
       
   367             TInt desLength = aMessage.GetDesLength( 0 );
       
   368                                  
       
   369             // Obtain the Application Identifier
       
   370             HBufC* identifier = HBufC::NewLC( desLength );
       
   371             TPtr des(identifier->Des());
       
   372             aMessage.Read( 0, des );
       
   373             
       
   374             // Obtain the Location based Application for this identifer
       
   375             CLcBasicAppInfo* appInfo = NULL;
       
   376             User::LeaveIfError( iRegistry->GetApplicationInfo( *identifier, appInfo ));
       
   377             
       
   378             // Pack the Length field into the Second argument
       
   379             CBufFlat* lengthBuffer = CBufFlat::NewL( sizeof( TUint32 ));
       
   380             CleanupStack::PushL( lengthBuffer );                                       
       
   381                                         
       
   382             RBufWriteStream lengthWrite( *lengthBuffer, 0 );
       
   383             CleanupClosePushL( lengthWrite );                
       
   384             lengthWrite.WriteInt32L(  appInfo->BufferLength());
       
   385             CleanupStack::PopAndDestroy(); // lengthWrite
       
   386             
       
   387             // Write the Buffer back to the IPC message                
       
   388             TPtr8    ptr( lengthBuffer->Ptr(0));
       
   389             User::LeaveIfError( aMessage.Write( 1, ptr ));
       
   390             
       
   391             // Pop and destroy the Length buffer             
       
   392             CleanupStack::PopAndDestroy( 2, identifier );
       
   393             
       
   394             DEBUG( "- CLcServerEngine::ServiceRequestL, ELcAppInfoLength ") 
       
   395                         
       
   396             break;               
       
   397             }
       
   398         case ELcAppInfo:
       
   399             {
       
   400             DEBUG( "+ CLcServerEngine::ServiceRequestL, ELcAppInfo ") 
       
   401             
       
   402             // Read the Descriptor from the IPC arguments
       
   403             TInt desLength = aMessage.GetDesLength( 0 );
       
   404                 
       
   405             // Obtain the Application Identifier
       
   406             HBufC* identifier = HBufC::NewLC( desLength );
       
   407             TPtr des(identifier->Des());
       
   408             aMessage.Read(0, des);
       
   409                         
       
   410             // Obtain the Location based Application for this identifer
       
   411             CLcBasicAppInfo* appInfo = NULL;
       
   412             User::LeaveIfError( iRegistry->GetApplicationInfo( *identifier, appInfo ));
       
   413             
       
   414             // Create the buffer for packing the Application Information
       
   415             // structure and pack the contents into this buffer
       
   416             CBufFlat* buffer = CBufFlat::NewL( appInfo->BufferLength());
       
   417             CleanupStack::PushL( buffer );
       
   418             
       
   419             RBufWriteStream writeStream( *buffer, 0 );
       
   420             CleanupClosePushL( writeStream );                
       
   421             appInfo->ExternalizeL( writeStream );
       
   422             CleanupStack::PopAndDestroy(); // writeStream
       
   423             
       
   424             // Write the buffer back to the IPC message.
       
   425             TPtr8    ptr( buffer->Ptr(0));
       
   426             User::LeaveIfError( aMessage.Write( 1, ptr ));
       
   427             
       
   428             // Pop and destroy the App info buffer                  
       
   429             CleanupStack::PopAndDestroy( 2, identifier );
       
   430             
       
   431             DEBUG( "- CLcServerEngine::ServiceRequestL, ELcAppInfo ") 
       
   432                                       
       
   433             break;
       
   434             }
       
   435         default:
       
   436             {
       
   437             DEBUG( "CLcServerEngine::ServiceRequestL, KErrNotSupported ") 
       
   438             User::Leave( KErrNotSupported );
       
   439             break;
       
   440             }
       
   441         }       
       
   442     }
       
   443     
       
   444 // ---------------------------------------------------------------------------
       
   445 // void CLcServerEngine::GetFilteredApps
       
   446 // ---------------------------------------------------------------------------
       
   447 //
       
   448 void CLcServerEngine::GetFilteredAppsL( 
       
   449         TLcLocationAppFilter&         aAppFilter,             
       
   450         RLcIpcAppInfoArray&           aFilteredAppArray )
       
   451     {
       
   452     DEBUG( "+ CLcServerEngine::GetFilteredAppsL")  
       
   453         
       
   454     // Obtain the current list of Location based Applications from the
       
   455     // Location Centre registry. Incase, the application satisfies the 
       
   456     // filter conditions, then the application is appended to the list.
       
   457     
       
   458     RPointerArray<CLcAppInfo> appInfoArray;
       
   459     User::LeaveIfError( iRegistry->GetAllRegisteredAppsList( appInfoArray ));
       
   460     
       
   461     TInt count = appInfoArray.Count();
       
   462     
       
   463     // Parse through the array list for each item
       
   464     for ( TInt i = 0; i < count; i++ )
       
   465         {
       
   466         // Obtain the element at the position 'i'
       
   467         CLcAppInfo* element = appInfoArray[i];
       
   468         
       
   469         if ( element->ApplicationType() == ELcNativeApplication &&
       
   470         	 IsSameSID( element->ApplicationData()))
       
   471         	{
       
   472         	continue;
       
   473         	}
       
   474         	
       
   475         // Check for the filtering conditions. Here we can check for the System
       
   476         // filters and Application filters simultaneously. The code seems
       
   477         // pretty lengthy owing to many accessor methods but retained it here
       
   478         // instead of using too many local variables.
       
   479         if ( Compare( aAppFilter.SystemCharacteristics(),
       
   480                       element->SystemCharacteristics(),
       
   481                       aAppFilter.SysCharFilterConfiguration()) &&
       
   482              Compare( aAppFilter.ApplicationCharacteristics(),
       
   483                       element->ApplicationCharacteristics(),
       
   484                       aAppFilter.AppCharFilterConfiguration()))
       
   485             {
       
   486             // The filter characteristics have matched. So append the element
       
   487             // to the Array
       
   488             
       
   489             // Ignoring the Append error. Incase there is an error then the
       
   490             // element would not be appened.                
       
   491             User::LeaveIfError( aFilteredAppArray.Append( element ));          
       
   492             }
       
   493         }
       
   494     appInfoArray.Reset();
       
   495     appInfoArray.Close();
       
   496     
       
   497     DEBUG1( "App Count : %d", aFilteredAppArray.Count())
       
   498     DEBUG( "- CLcServerEngine::GetFilteredAppsL")    
       
   499     }        
       
   500 
       
   501 // ---------------------------------------------------------------------------
       
   502 // void CLcServerEngine::GetSpecifiedAppsL
       
   503 // ---------------------------------------------------------------------------
       
   504 //
       
   505 void CLcServerEngine::GetSpecifiedAppsL( 
       
   506         RLcIpcAppIdArray&             aSpecifedApps,             
       
   507         RLcIpcAppInfoArray&           aSpecifiedAppArray )
       
   508     {
       
   509     // Obtain the current list of Location based Applications from the
       
   510     // Location Centre registry. Incase, the application satisfies the 
       
   511     // filter conditions, then the application is appended to the list.
       
   512     RPointerArray<CLcAppInfo> appInfoArray;
       
   513 	User::LeaveIfError( iRegistry->GetAllRegisteredAppsList( appInfoArray ));
       
   514     TInt count = appInfoArray.Count();
       
   515         
       
   516     // Parse through the array list for each item
       
   517     for ( TInt i = 0; i < count; i++ )
       
   518         {
       
   519         // Obtain the element at the position 'i'
       
   520         CLcAppInfo* element = appInfoArray[i];
       
   521         
       
   522         if ( element->ApplicationType() == ELcNativeApplication &&
       
   523         	 IsSameSID( element->ApplicationData()))
       
   524         	{
       
   525         	continue;
       
   526         	}
       
   527         	        
       
   528         // Check for the filtering conditions
       
   529         for ( TInt j = 0; j < aSpecifedApps.Count(); j++ )
       
   530             {
       
   531             // Obtain the current identifier
       
   532             HBufC*  identifier = aSpecifedApps[j];
       
   533             
       
   534             // Check if the current App info's id is the same as this identifer
       
   535             // If Yes, then append it and go to the next element.
       
   536             if ( !identifier->Des().Compare( element->Id()))
       
   537                 {            
       
   538                 // Ignoring the Append error. Incase there is an error then the
       
   539                 // element would not be appened.                
       
   540                 User::LeaveIfError( aSpecifiedAppArray.Append( element ));
       
   541                 }
       
   542             }
       
   543         // Small optimization check to see if the number of elements that have
       
   544         // been added are equal to the the number of elements in the App id
       
   545         // array. If yes, we can stop the checking.
       
   546         if ( aSpecifiedAppArray.Count() == aSpecifedApps.Count() )
       
   547             {
       
   548             break;
       
   549             }
       
   550         }
       
   551     appInfoArray.Reset();
       
   552     appInfoArray.Close();           
       
   553     }        
       
   554 
       
   555 // ---------------------------------------------------------------------------
       
   556 // void CLcServerEngine::GetWithoutSpecifiedAppsL
       
   557 // ---------------------------------------------------------------------------
       
   558 //       
       
   559 void CLcServerEngine::GetWithoutSpecifiedAppsL( 
       
   560         RLcIpcAppIdArray&             aSpecifedApps,            
       
   561         RLcIpcAppInfoArray&           aSpecifiedAppArray )
       
   562     {
       
   563     // Obtain the current list of Location based Applications from the
       
   564     // Location Centre registry. Incase, the application satisfies the 
       
   565     // filter conditions, then the application is appended to the list.
       
   566     
       
   567     RPointerArray<CLcAppInfo> appInfoArray;
       
   568 	User::LeaveIfError( iRegistry->GetAllRegisteredAppsList( appInfoArray ));
       
   569     TInt count = appInfoArray.Count();
       
   570     
       
   571     // Parse through the array list for each item
       
   572     for ( TInt i = 0; i < appInfoArray.Count(); i++ )
       
   573         {
       
   574         // Obtain the element at the position 'i'
       
   575         CLcAppInfo* element = appInfoArray[i];
       
   576    
       
   577         if ( element->ApplicationType() == ELcNativeApplication &&
       
   578         	 IsSameSID( element->ApplicationData()))
       
   579         	{
       
   580         	continue;
       
   581         	}
       
   582         	   
       
   583         // Boolean flag to check whether an element exists or not.
       
   584         TBool append = ETrue;
       
   585                     
       
   586         // Check for the filtering conditions
       
   587         for ( TInt j = 0; j < aSpecifedApps.Count(); j++ )
       
   588             {
       
   589             // Obtain the current identifier
       
   590             HBufC*  identifier = aSpecifedApps[j];
       
   591             
       
   592             // Check if the current App info's id is the same as this identifer
       
   593             // If Yes, then append it and go to the next element.
       
   594             if ( !identifier->Des().Compare( element->Id()))
       
   595                 {            
       
   596                 // Incase, the element being compared in the list is requested
       
   597                 // then set the flag and break the switch
       
   598                 append = EFalse;
       
   599                 break;
       
   600                 }
       
   601             }
       
   602            
       
   603         if ( append )
       
   604             {
       
   605             // Ignoring the Append error. Incase there is an error then the
       
   606             // element would not be appened.                
       
   607             User::LeaveIfError( aSpecifiedAppArray.Append( element ));            
       
   608             }
       
   609         }
       
   610     appInfoArray.Reset();
       
   611     appInfoArray.Close();            
       
   612     }                     
       
   613 
       
   614 // ---------------------------------------------------------------------------
       
   615 // void CLcServerEngine::Compare
       
   616 // ---------------------------------------------------------------------------
       
   617 // 
       
   618 TBool  CLcServerEngine::Compare( TUint32         aFilter,
       
   619                                  TUint32         aFiltertoCompare,   
       
   620                                  TInt            aFilterConfig )
       
   621     {
       
   622     // Here,
       
   623     // aFilter          - Filter passed by the Client Application
       
   624     // aFiltertoCompare - Filter of the Location based Application
       
   625     
       
   626     // If no filter configurations are set then there will be no need to
       
   627     // proceed with checking. The Locaiton based Application must always be
       
   628     // included. Hence, return True.
       
   629     if ( !aFilter )
       
   630         {
       
   631         return ETrue;
       
   632         }
       
   633     
       
   634     // Proceed for the Actual checking.
       
   635     
       
   636     // Set the default value to EFalse to enable pessimistic match.
       
   637     TBool ret = EFalse;
       
   638         
       
   639     switch( aFilterConfig )
       
   640         {
       
   641         case TLcLocationAppFilter::EFilterStrict:
       
   642             {
       
   643             // Strict Filtering needs to be applied. So here we just have to
       
   644             // compare the values and then return True only if there is an
       
   645             // exact match
       
   646             if ( aFilter == aFiltertoCompare )
       
   647                 {
       
   648                 ret = ETrue;
       
   649                 }
       
   650             break;
       
   651             }
       
   652         case TLcLocationAppFilter::EFilterInclusive:
       
   653             {
       
   654             // The Location based Application must have all the characteristics
       
   655             // passed by the Client application. It can have any additonal
       
   656             // characteristic too.
       
   657             if (( aFilter & aFiltertoCompare ) == aFilter )
       
   658                 {
       
   659                 ret = ETrue;
       
   660                 }
       
   661             break;
       
   662             }
       
   663         case TLcLocationAppFilter::EFilterExclusive:
       
   664             {
       
   665             // The filtering should be such that there should be no match
       
   666             // between the requested character set and the one specified for the
       
   667             // Location based Application.
       
   668             if ( !( aFilter & aFiltertoCompare ))
       
   669                 {
       
   670                 ret = ETrue;
       
   671                 }
       
   672             break;
       
   673             }
       
   674         default:
       
   675             {
       
   676             break;
       
   677             }      
       
   678         }
       
   679     return ret;
       
   680     }
       
   681 
       
   682 // ---------------------------------------------------------------------------
       
   683 // TBool CLcServerEngine::IsSameSID
       
   684 // ---------------------------------------------------------------------------
       
   685 // 
       
   686 TBool CLcServerEngine::IsSameSID( const TDesC&		aAppSid )
       
   687 	{
       
   688     // Since the request is for a Native S60 application, the Identifer
       
   689     // contains an UID. Obtain it using Lexer
       
   690     TLex lexer( aAppSid );
       
   691     TUint32 uidValue;
       
   692     
       
   693     if ( lexer.BoundedVal( uidValue, EHex, KUidMaxValue ) || 
       
   694     	 uidValue != iCurrentRequestorSid )
       
   695     	{
       
   696     	return EFalse;
       
   697     	}
       
   698 	else
       
   699 		{
       
   700 		return ETrue;
       
   701 		}
       
   702 	}
       
   703 	
       
   704 // End of File