ncdengine/engine/src/catalogsconnectionobserver.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 "catalogsconnectionobserver.h"
       
    20 
       
    21 #include "catalogsconstants.h"
       
    22 #include "catalogsengineobserver.h"
       
    23 #include "catalogsdebug.h"
       
    24 
       
    25 CCatalogsConnectionObserver* CCatalogsConnectionObserver::NewL( MCatalogsEngineObserver& aObserver )
       
    26     {
       
    27     DLTRACEIN((""));
       
    28     CCatalogsConnectionObserver* self = new (ELeave) CCatalogsConnectionObserver( aObserver );
       
    29     CleanupStack::PushL( self );
       
    30     self->ConstructL();
       
    31     CleanupStack::Pop( self );
       
    32     return self;
       
    33     }
       
    34 
       
    35 CCatalogsConnectionObserver::~CCatalogsConnectionObserver()
       
    36     {
       
    37     DLTRACEIN((""));
       
    38     Cancel();
       
    39     iConnectionEventProperty.Close();
       
    40     }
       
    41 
       
    42 CCatalogsConnectionObserver::CCatalogsConnectionObserver( MCatalogsEngineObserver& aObserver )
       
    43     : CActive( EPriorityNormal ), iObserver( aObserver )
       
    44     {
       
    45     CActiveScheduler::Add( this );
       
    46     }
       
    47 
       
    48 void CCatalogsConnectionObserver::ConstructL()
       
    49     {
       
    50     DLTRACEIN((""));    
       
    51     
       
    52     // Important: this client side process and the server side process 
       
    53     // must agree what the key is. The current agreement is that the key is
       
    54     // client process SID.
       
    55     TUint key = RProcess().SecureId().iId;    
       
    56     
       
    57     User::LeaveIfError( iConnectionEventProperty.Attach( KCatalogsEnginePropertyCategory, key ) );
       
    58 
       
    59     iConnectionEventProperty.Subscribe( iStatus );
       
    60     SetActive();
       
    61     }
       
    62 
       
    63 void CCatalogsConnectionObserver::RunL()
       
    64     {
       
    65     DLTRACEIN(( "iStatus=%d", iStatus.Int() )); 
       
    66     
       
    67     // On error handling: if in any situation request completes with error,
       
    68     // we stop further processsing. This is non-critical system, and it doesn't
       
    69     // really make sense to build complex error recovery here.
       
    70     //
       
    71     // Note that when RProperty is deleted on the server side, all subscriptions are completed
       
    72     // with KErrNotFound.
       
    73     if ( iStatus.Int() != KErrNone )
       
    74         {
       
    75         return;
       
    76         }
       
    77     
       
    78     // first subscribe, then get value, otherwise we might miss an update.
       
    79     iConnectionEventProperty.Subscribe( iStatus );
       
    80     SetActive();
       
    81     
       
    82     TBool connectionActive;
       
    83     TInt err = iConnectionEventProperty.Get( connectionActive );
       
    84     DLINFO(("err = %d", err));        
       
    85     if ( err == KErrNone )
       
    86         {
       
    87         iObserver.CatalogsConnectionEvent( connectionActive );
       
    88         }
       
    89     else
       
    90         {
       
    91         // Error occured, something is seriously wrong.
       
    92         // Nothing really to do than shut down this subsystem by canceling
       
    93         // request.
       
    94         DLWARNING(("Error occurred while reading connection event property!"));
       
    95         Cancel();
       
    96         }
       
    97     }
       
    98 
       
    99 void CCatalogsConnectionObserver::DoCancel()
       
   100     {
       
   101     DLTRACEIN((""));
       
   102     iConnectionEventProperty.Cancel();
       
   103     }