ncdengine/engine/src/catalogsserverengine.cpp
changeset 0 ba25891c3a9e
equal deleted inserted replaced
-1:000000000000 0:ba25891c3a9e
       
     1 /*
       
     2 * Copyright (c) 2006 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:  
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 #include <e32property.h>
       
    20 
       
    21 #include "catalogsserverengine.h"
       
    22 #include "catalogssession.h"
       
    23 #include "ncdproviderimpl.h"
       
    24 #include "catalogsdebug.h"
       
    25 #include "catalogsconstants.h"
       
    26 #include "catalogsuids.h"
       
    27 #include "ncdprovidermanager.h"
       
    28 
       
    29 // ======== MEMBER FUNCTIONS ========
       
    30 
       
    31 
       
    32 
       
    33 CCatalogsServerEngine::CCatalogsServerEngine()
       
    34     {
       
    35     }
       
    36 
       
    37 
       
    38 void CCatalogsServerEngine::ConstructL()
       
    39     {
       
    40     DLTRACEIN((""));
       
    41 
       
    42     // Define the Catalogs Engine maintenance lock property, if not already
       
    43     // defined.
       
    44     // Don't use explicit category UID, server SID instead?
       
    45     //  - explicit category UID requires WriteDeviceData cap. Well we have it but anyway.
       
    46 
       
    47     // Security policy
       
    48 //    TSecurityPolicy readPolicy;
       
    49 //    TSecurityPolicy writePolicy;
       
    50     _LIT_SECURITY_POLICY_PASS( readPolicy );
       
    51     _LIT_SECURITY_POLICY_PASS( writePolicy );
       
    52 
       
    53     DLINFO(( "Defining catalogs engine maintenance lock property" ));
       
    54 
       
    55     TInt err = RProperty::Define( 
       
    56         KCatalogsEnginePropertyCategory,
       
    57         KCatalogsEnginePropertyKeyMaintenanceLock,
       
    58         RProperty::EInt,
       
    59         readPolicy,
       
    60         writePolicy );
       
    61 
       
    62     if( err != KErrNone && err != KErrAlreadyExists ) 
       
    63         {
       
    64         DLERROR(( "Maintenance lock property create failed with %d", err ));
       
    65         DLTRACEOUT(( "LEAVE %d", err ));
       
    66         User::Leave( err );
       
    67         }
       
    68 
       
    69     DLINFO(( "Maintenance lock property define returned %d", err ));
       
    70     
       
    71     iProviderManager = CNcdProviderManager::NewL();
       
    72 
       
    73     DLTRACEOUT((""));
       
    74     }
       
    75 
       
    76 CCatalogsServerEngine* CCatalogsServerEngine::NewL()
       
    77     {
       
    78     CCatalogsServerEngine* self = CCatalogsServerEngine::NewLC();
       
    79     CleanupStack::Pop( self );
       
    80     return self;
       
    81     }
       
    82 
       
    83 CCatalogsServerEngine* CCatalogsServerEngine::NewLC()
       
    84     {
       
    85     CCatalogsServerEngine* self = new( ELeave ) CCatalogsServerEngine;
       
    86     CleanupStack::PushL( self );
       
    87     self->ConstructL();
       
    88     return self;
       
    89     }
       
    90 
       
    91 CCatalogsServerEngine::~CCatalogsServerEngine()
       
    92     {
       
    93     DLTRACEIN((""));
       
    94     // Engine is going to be killed and we can free our reference to
       
    95     // the provider
       
    96     delete iProviderManager;
       
    97     DLTRACEOUT((""));
       
    98     }
       
    99 
       
   100 
       
   101 void CCatalogsServerEngine::CreateProviderL(
       
   102     MCatalogsSession& aSession,
       
   103     TInt aProvider,
       
   104     TInt& aHandle,
       
   105     TUint32 aOptions )
       
   106     {
       
   107     DLTRACEIN(( "aProvider=%08x", aProvider ));
       
   108     
       
   109     // Providers, who we know
       
   110     TInt providerUid( KNcdProviderUid ); // only one uid is known at the moment
       
   111 
       
   112     
       
   113     if ( aProvider == providerUid )
       
   114         {
       
   115         TBool created = EFalse;
       
   116         
       
   117         // if created==ETrue, provider's refcount is 1, otherwise it's > 1
       
   118         CNcdProvider& provider = iProviderManager->ProviderL(
       
   119             aSession.Context(), created );        
       
   120         
       
   121         TRAPD( err, 
       
   122             {
       
   123             provider.PrepareSessionL( aSession, aOptions );
       
   124             // AddObjectL increases provider's refcount by 1
       
   125             aHandle = aSession.AddObjectL( &provider );
       
   126             });
       
   127 
       
   128         
       
   129         if ( created ) 
       
   130             {
       
   131             if ( err != KErrNone ) 
       
   132                 {
       
   133                 provider.Close();
       
   134                 }
       
   135             
       
   136             if ( provider.DatabaseClearingStatus() && err == KErrNone ) 
       
   137                 {
       
   138                 DLTRACE(("Databases were cleared, status: %d", 
       
   139                     provider.DatabaseClearingStatus() ));
       
   140                 User::Leave( provider.DatabaseClearingStatus() );
       
   141                 }
       
   142             }
       
   143 
       
   144         User::LeaveIfError( err );
       
   145         }
       
   146     else
       
   147         {
       
   148         DLWARNING(( "Unknown provider" ));        
       
   149         User::Leave( KErrNotFound );
       
   150         }
       
   151     
       
   152     DLTRACEOUT((""));
       
   153     }
       
   154     
       
   155 
       
   156 void CCatalogsServerEngine::HandleSessionRemoval( 
       
   157     MCatalogsSession& aSession )
       
   158     {
       
   159     DLTRACEIN((""));
       
   160     CNcdProvider* provider = iProviderManager->Provider( aSession.Context() );
       
   161     
       
   162     if ( provider )
       
   163         {
       
   164         provider->HandleSessionRemoval( aSession );
       
   165 
       
   166         // Remove provider manager's reference
       
   167         if ( provider->AccessCount() == 1 ) 
       
   168             {
       
   169             DLTRACE(("Last session, deleting provider"));
       
   170             provider->Close();
       
   171             }            
       
   172         }
       
   173      
       
   174     DLTRACEOUT((""));
       
   175     }