vtengines/videoteleng/Src/Session/CVtEngSessionHandler.cpp
changeset 0 ed9695c8bcbe
equal deleted inserted replaced
-1:000000000000 0:ed9695c8bcbe
       
     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:  Session handler.
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 
       
    20 // INCLUDE FILES
       
    21 #include    "CVtEngSessionHandler.h"
       
    22 #include    "CVtEngOperation.h"
       
    23 #include    "CVtEngStateManager.h"
       
    24 #include 	"cvtengincomingcallmonitor.h"
       
    25 #include    "vtengcommands.h"
       
    26 #include    "CVtEngOperation.h"
       
    27 #include    "CVtCtlFactory.h"
       
    28 #include    "MVtCtlCallControl.h"
       
    29 #include    "CVtEngSettings.h"
       
    30 #include    "VtEngUtils.h"
       
    31 #include    "VtCtlTypes.h" // for TVtCtlCSSessionInfoV1 
       
    32 #include    "cvtlogger.h"
       
    33 
       
    34 // ============================ MEMBER FUNCTIONS ===============================
       
    35 
       
    36 // -----------------------------------------------------------------------------
       
    37 // CVtEngSessionHandler::CVtEngSessionHandler
       
    38 // C++ default constructor can NOT contain any code, that
       
    39 // might leave.
       
    40 // -----------------------------------------------------------------------------
       
    41 //
       
    42 CVtEngSessionHandler::CVtEngSessionHandler() 
       
    43     : CActive( CActive::EPriorityStandard ), iIncomingCallMonitor(NULL)
       
    44     {
       
    45     CActiveScheduler::Add( this );
       
    46     }
       
    47 
       
    48 // -----------------------------------------------------------------------------
       
    49 // CVtEngSessionHandler::ConstructL
       
    50 // Symbian 2nd phase constructor can leave.
       
    51 // -----------------------------------------------------------------------------
       
    52 //
       
    53 void CVtEngSessionHandler::ConstructL()
       
    54     {
       
    55     SetActive();
       
    56     TRequestStatus* status = &iStatus;
       
    57     User::RequestComplete( status, KErrNone );
       
    58     StartIncomingCallMonitorL();
       
    59     }
       
    60 
       
    61 // -----------------------------------------------------------------------------
       
    62 // CVtEngSessionHandler::NewL
       
    63 // Two-phased constructor.
       
    64 // -----------------------------------------------------------------------------
       
    65 //
       
    66 CVtEngSessionHandler* CVtEngSessionHandler::NewL(  )
       
    67     {
       
    68     CVtEngSessionHandler* self = new( ELeave ) 
       
    69         CVtEngSessionHandler( );
       
    70     
       
    71     CleanupStack::PushL( self );
       
    72     self->ConstructL();
       
    73     CleanupStack::Pop();
       
    74 
       
    75     return self;
       
    76     }
       
    77 
       
    78     
       
    79 // -----------------------------------------------------------------------------
       
    80 // CVtEngSessionHandler::~CVtEngSessionHandler
       
    81 // Destructor
       
    82 // 
       
    83 // -----------------------------------------------------------------------------
       
    84 //
       
    85 CVtEngSessionHandler::~CVtEngSessionHandler()
       
    86     {
       
    87     __VTPRINTENTER( "SH.~" )
       
    88     Cancel();
       
    89     Uninitialize();
       
    90     delete iIncomingCallMonitor;
       
    91     __VTPRINTEXIT( "SH.~" )
       
    92     }
       
    93 
       
    94 // -----------------------------------------------------------------------------
       
    95 // CVtEngSessionHandler::HandleL
       
    96 // Performs session request.
       
    97 // 
       
    98 // -----------------------------------------------------------------------------
       
    99 //
       
   100 void CVtEngSessionHandler::HandleL( 
       
   101     CVtEngOperation& /*aOperation*/ )
       
   102     {
       
   103     __VTPRINT( DEBUG_SESSION, "SH.HandleL leave not supported" )
       
   104     User::Leave( KErrNotSupported );
       
   105     }
       
   106 
       
   107 // -----------------------------------------------------------------------------
       
   108 // CVtEngSessionHandler::State
       
   109 // Returns session state
       
   110 // 
       
   111 // -----------------------------------------------------------------------------
       
   112 //
       
   113 MVtEngSessionInfo::TSessionState CVtEngSessionHandler::State( 
       
   114     TBool aForcedRefresh ) const
       
   115     {
       
   116     CVtEngStateManager* states = CVtEngUtility::StateManager();
       
   117     if ( aForcedRefresh )
       
   118         {
       
   119         states->Update();
       
   120         }
       
   121     return states->SessionState();
       
   122     }
       
   123 
       
   124 // -----------------------------------------------------------------------------
       
   125 // CVtEngSessionHandler::GetDirection
       
   126 // Returns direction.
       
   127 // 
       
   128 // -----------------------------------------------------------------------------
       
   129 //
       
   130 TInt CVtEngSessionHandler::GetDirection( 
       
   131     TDirection& aDirection ) const
       
   132     {
       
   133     __VTPRINTENTER( "SH.GetDirection" )
       
   134     if ( !iSessionControl )
       
   135         {
       
   136         __VTPRINTEXITR( "SH.GetDirection err=%d", KErrNotFound )
       
   137         return KErrNotFound;
       
   138         }
       
   139 
       
   140     TVtCtlCSSessionInfoV1 info;
       
   141     TPckg<TVtCtlCSSessionInfoV1> pckg( info );
       
   142     TRAPD( err, iSessionControl->GetSessionInfoL( KActiveSessionId, pckg ) );
       
   143     if ( err == KErrNone )
       
   144         {
       
   145         switch ( info.iDirection )
       
   146             {
       
   147             case MVtCtlCallControl::EDirectionMobileOriginated:
       
   148                 aDirection = EDirectionMO;
       
   149                 break;
       
   150             case MVtCtlCallControl::DirectionMobileTerminated:
       
   151                 aDirection = EDirectionMT;
       
   152                 break;
       
   153             default:
       
   154                 aDirection = EDirectionNone;
       
   155                 break;
       
   156             }
       
   157         }
       
   158     __VTPRINT2( DEBUG_SESSION, "SH.direction dir=%d", aDirection )
       
   159     __VTPRINTEXITR( "SH.GetDirection err=%d", err )
       
   160     return err;
       
   161     }
       
   162 
       
   163 // -----------------------------------------------------------------------------
       
   164 // CVtEngSessionHandler::GetDuration
       
   165 // Returns session duration.
       
   166 // 
       
   167 // -----------------------------------------------------------------------------
       
   168 //
       
   169 TInt CVtEngSessionHandler::GetDuration( 
       
   170     TDuration& aDuration,
       
   171     TBool& aEnabled ) const
       
   172     {
       
   173     if ( !iSessionControl )
       
   174         {
       
   175         return KErrNotFound;
       
   176         }
       
   177 
       
   178     TVtCtlDuration duration;
       
   179     TInt err ( iSessionControl->GetDuration( KActiveSessionId, duration ) );
       
   180     if ( err == KErrNone )
       
   181         {
       
   182         aDuration = duration;
       
   183         const CVtEngSettings& settings = CVtEngUtility::Settings();
       
   184         aEnabled = settings.Config().iCallTimerOn;
       
   185         }
       
   186     return err;
       
   187     }
       
   188 
       
   189 // -----------------------------------------------------------------------------
       
   190 // CVtEngSessionHandler::GetCLI
       
   191 // 
       
   192 // 
       
   193 // -----------------------------------------------------------------------------
       
   194 //
       
   195 TInt CVtEngSessionHandler::GetCLI( TCLI& aCLI ) const
       
   196     {
       
   197     const CVtEngSettings& settings = CVtEngUtility::Settings();
       
   198     const TBool isValid = settings.GetCLI( aCLI);
       
   199     TInt res = KErrNone;
       
   200     if ( !isValid )
       
   201         {
       
   202         res = KErrNotReady;    
       
   203         }
       
   204     return res;
       
   205     }
       
   206 
       
   207 
       
   208 // -----------------------------------------------------------------------------
       
   209 // CVtEngSessionHandler::HandleVtSessionEventL
       
   210 // 
       
   211 // 
       
   212 // -----------------------------------------------------------------------------
       
   213 //
       
   214 void CVtEngSessionHandler::HandleVtSessionEventL( 
       
   215     TVtCtlEvent aEvent,
       
   216     TAny* /*aParams*/ )
       
   217     {
       
   218     if ( aEvent == KVtCtlEventSessionStatusChanged )
       
   219         {
       
   220         CVtEngStateManager* states = CVtEngUtility::StateManager();
       
   221         states->Update( );
       
   222         }
       
   223     }
       
   224 
       
   225 // -----------------------------------------------------------------------------
       
   226 // CVtEngSessionHandler::InitializeL
       
   227 // 
       
   228 // 
       
   229 // -----------------------------------------------------------------------------
       
   230 //
       
   231 void CVtEngSessionHandler::InitializeL()
       
   232     {
       
   233     __VTPRINTENTER( "SH.Initilialize" )
       
   234     if ( iSessionControl )
       
   235         {
       
   236         // already initialized
       
   237         __VTPRINTEXIT( "SH.Initilialize" )
       
   238         return;
       
   239         }
       
   240     TInt err = iLib.Load( KVtCtlLibraryName() );
       
   241     CleanupClosePushL( iLib );
       
   242     if ( err == KErrNone )
       
   243         {
       
   244         TLibraryFunction func = iLib.Lookup( 1 );
       
   245         iFactory = reinterpret_cast<CVtCtlFactory*>( func() );
       
   246         iSessionControl = iFactory->CreateCallControlL( *this );
       
   247         
       
   248         // Update state
       
   249         CVtEngStateManager* states = CVtEngUtility::StateManager();
       
   250         states->Update();
       
   251         }    
       
   252     CleanupStack::Pop(); // lib
       
   253     __VTPRINTEXIT( "SH.Initilialize" )
       
   254     }
       
   255 
       
   256 // -----------------------------------------------------------------------------
       
   257 // CVtEngSessionHandler::Uninitialize
       
   258 // 
       
   259 // 
       
   260 // -----------------------------------------------------------------------------
       
   261 //
       
   262 void CVtEngSessionHandler::Uninitialize()
       
   263     {
       
   264     if ( iFactory )
       
   265         {
       
   266         iFactory->Delete( iSessionControl );
       
   267         delete iFactory;
       
   268         iFactory = NULL;
       
   269         iSessionControl = NULL;
       
   270         }
       
   271     iLib.Close();
       
   272     }
       
   273 
       
   274 // -----------------------------------------------------------------------------
       
   275 // CVtEngSessionHandler::RealState
       
   276 // 
       
   277 // 
       
   278 // -----------------------------------------------------------------------------
       
   279 //
       
   280 MVtCtlCallControl::TVtCtlState CVtEngSessionHandler::RealState() const
       
   281     {
       
   282     MVtCtlCallControl::TVtCtlState state( MVtCtlCallControl::EUnknown );
       
   283     if ( iSessionControl )
       
   284         {
       
   285         state = iSessionControl->GetSessionState( KActiveSessionId );
       
   286         __VTPRINT2( DEBUG_SESSION, "SH.realState=%d", state )
       
   287         }
       
   288     return state;
       
   289     }
       
   290 // -----------------------------------------------------------------------------
       
   291 // CVtEngSessionHandler::RunL
       
   292 // 
       
   293 // 
       
   294 // -----------------------------------------------------------------------------
       
   295 //
       
   296 void CVtEngSessionHandler::RunL()
       
   297     {
       
   298     InitializeL();
       
   299     }
       
   300 
       
   301 // -----------------------------------------------------------------------------
       
   302 // CVtEngSessionHandler::DoCancel
       
   303 // 
       
   304 // 
       
   305 // -----------------------------------------------------------------------------
       
   306 //
       
   307 void CVtEngSessionHandler::DoCancel()
       
   308     {
       
   309     // nothing here
       
   310     }
       
   311 
       
   312 // -----------------------------------------------------------------------------
       
   313 // CVtEngSessionHandler::StartIncomingCallMonitorL
       
   314 // 
       
   315 // 
       
   316 // -----------------------------------------------------------------------------
       
   317 //
       
   318 void CVtEngSessionHandler::StartIncomingCallMonitorL()
       
   319     {
       
   320     iIncomingCallMonitor = CVtEngIncomingCallMonitor::NewL();
       
   321     }
       
   322 
       
   323 //  End of File