convergedcallengine/csplugin/src/cspcenreplistener.cpp
branchRCL_3
changeset 20 987c9837762f
parent 0 ff3b6d0fd310
equal deleted inserted replaced
19:7d48bed6ce0c 20:987c9837762f
       
     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:  Central Repository listening
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 // INCLUDE FILES
       
    20 #include "cspcenreplistener.h"
       
    21 #include <centralrepository.h>
       
    22 #include "csppanic.pan"
       
    23 #include "mcspcenrepobserver.h"
       
    24 #include "csplogger.h"
       
    25 
       
    26 
       
    27 // -----------------------------------------------------------------------------
       
    28 // CSPCenRepListener::CSPCenRepListener
       
    29 // C++ default constructor can NOT contain any code, that
       
    30 // might leave.
       
    31 // -----------------------------------------------------------------------------
       
    32 //
       
    33 CSPCenRepListener* CSPCenRepListener::NewL(
       
    34         TUid aUid,
       
    35         TUint32 aMonitorSetting,
       
    36         MCSPCenRepObserver* aObserver
       
    37         )
       
    38     {
       
    39     CSPLOGSTRING( CSPINT, "CSPCenRepListener::NewL" )
       
    40     CSPCenRepListener* self = new( ELeave ) 
       
    41         CSPCenRepListener( aUid, aMonitorSetting, aObserver );
       
    42     CleanupStack::PushL( self );
       
    43     self->ConstructL();
       
    44     CleanupStack::Pop();
       
    45     return self;
       
    46     }
       
    47     
       
    48 
       
    49 // Destructor
       
    50 CSPCenRepListener::~CSPCenRepListener()
       
    51     {
       
    52     Cancel();
       
    53     delete iRepository;
       
    54     }
       
    55     
       
    56 
       
    57 // -----------------------------------------------------------------------------
       
    58 // CSPCenRepListener::Get
       
    59 // -----------------------------------------------------------------------------
       
    60 //
       
    61 TInt CSPCenRepListener::Get( TInt& aValue )
       
    62     {
       
    63     return ( iRepository->Get( iMonitorSetting, aValue ) );
       
    64     }
       
    65 
       
    66 
       
    67 // -----------------------------------------------------------------------------
       
    68 // CSPCenRepListener::DoCancel
       
    69 // -----------------------------------------------------------------------------
       
    70 //
       
    71 void CSPCenRepListener::DoCancel()
       
    72     {
       
    73     __ASSERT_DEBUG( iRepository, Panic( ECSPPanicNoRepository ) );
       
    74     iRepository->NotifyCancel( iMonitorSetting );
       
    75     }
       
    76 
       
    77 
       
    78 // -----------------------------------------------------------------------------
       
    79 // CSPCenRepListener::RunError
       
    80 // -----------------------------------------------------------------------------
       
    81 //
       
    82 TInt CSPCenRepListener::RunError(
       
    83         #ifdef _DEBUG
       
    84         TInt aError // Log the leavecode from RunL
       
    85         #else
       
    86         TInt /*aError*/
       
    87         #endif
       
    88         )
       
    89     {
       
    90     #ifdef _DEBUG
       
    91     CSPLOGSTRING2( CSPERROR, "CSPCenRepListener::RunError %d", aError );
       
    92     #endif
       
    93     return ( KErrNone );
       
    94     }
       
    95 
       
    96 
       
    97 // -----------------------------------------------------------------------------
       
    98 // CSPCenRepListener::RunL
       
    99 // -----------------------------------------------------------------------------
       
   100 //
       
   101 void CSPCenRepListener::RunL()
       
   102     {
       
   103     CSPLOGSTRING( CSPINT, "CSPCenRepListener::RunL");
       
   104 
       
   105     // Don't resubmit the request on error
       
   106     // Central repositry completes notifications with id of setting
       
   107     // so check only that value of iStatus is negative
       
   108     User::LeaveIfError( iStatus.Int() < KErrNone ); 
       
   109     SubmitNotifyRequestL();
       
   110 
       
   111     TInt volume;
       
   112     // The loudspeaker volume has changed in repository.
       
   113     // Retrieve the current volume from repository.
       
   114     User::LeaveIfError( Get( volume ) );
       
   115 
       
   116     CSPLOGSTRING2( CSPINT, "CSPCenRepListener::RunL vol %d", volume);
       
   117     iObserver->HandleNotifyCenRepL( iUid, iMonitorSetting, volume ); 
       
   118     }
       
   119 
       
   120 
       
   121 // -----------------------------------------------------------------------------
       
   122 // CSPCenRepListener::CSPCenRepListener
       
   123 // -----------------------------------------------------------------------------
       
   124 //
       
   125 CSPCenRepListener::CSPCenRepListener(
       
   126         TUid aUid,
       
   127         TUint32 aMonitorSetting,
       
   128         MCSPCenRepObserver* aObserver
       
   129         ) : CActive( EPriorityStandard ),
       
   130             iUid( aUid ),
       
   131             iMonitorSetting( aMonitorSetting ),
       
   132             iObserver( aObserver )
       
   133     {
       
   134     CSPLOGSTRING( CSPINT, "CSPCenRepListener::CSPCenRepListener, start");
       
   135     CActiveScheduler::Add( this );
       
   136     
       
   137     CSPLOGSTRING( CSPINT, "CSPCenRepListener::CSPCenRepListener, complete");
       
   138     }
       
   139 
       
   140         
       
   141 // -----------------------------------------------------------------------------
       
   142 // CSPCenRepListener::ConstructL
       
   143 // -----------------------------------------------------------------------------
       
   144 //
       
   145 void CSPCenRepListener::ConstructL()
       
   146     {
       
   147     // Create repository instance
       
   148     iRepository = CRepository::NewL( iUid );
       
   149     // Start monitoring
       
   150     SubmitNotifyRequestL();
       
   151     }
       
   152 
       
   153 
       
   154 // -----------------------------------------------------------------------------
       
   155 // CSPCenRepListener::SubmitNotifyRequestL
       
   156 // -----------------------------------------------------------------------------
       
   157 //
       
   158 void CSPCenRepListener::SubmitNotifyRequestL()
       
   159     {
       
   160     CSPLOGSTRING( CSPINT, "CSPCenRepListener::SubmitNotifyRequestL");
       
   161     __ASSERT_DEBUG( iRepository, Panic( ECSPPanicNoRepository ) );
       
   162     __ASSERT_DEBUG( !IsActive(), Panic( ECSPPanicRepositoryAlreadyActive ) );
       
   163     iRepository->NotifyRequest( iMonitorSetting, iStatus );
       
   164     SetActive();
       
   165     CSPLOGSTRING( CSPINT, "CSPCenRepListener::SubmitNotifyRequestL, complete");
       
   166     }
       
   167 
       
   168     
       
   169 // End of file