mmsharing/livecommsui/lcui/tsrc/mustester/Stubs/mceclientstub/src/mussessionsimulator.cpp
branchRCL_3
changeset 33 bc78a40cd63c
parent 32 73a1feb507fb
child 35 6c57ef9392d2
equal deleted inserted replaced
32:73a1feb507fb 33:bc78a40cd63c
     1 /*
       
     2 * Copyright (c) 2005 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 #include <e32base.h>
       
    19 #include <e32property.h>
       
    20 #include <MceTransactionDataContainer.h>
       
    21 #include <MceSession.h>
       
    22 #include <MceInSession.h>
       
    23 #include <MceOutSession.h>
       
    24 #include "mceinsessionobserver.h"
       
    25 #include "mcesessionobserver.h"
       
    26 #include "mussessionsimulator.h"
       
    27 #include "muslogger.h"
       
    28 #include <musmanagercommon.h>
       
    29 #include "mussessionproperties.h"
       
    30 
       
    31 
       
    32 
       
    33 TInt KDuration = 60*1;
       
    34 
       
    35 // ============================ MEMBER FUNCTIONS ===============================
       
    36 
       
    37 
       
    38 // -----------------------------------------------------------------------------
       
    39 // CMceManager::NewL
       
    40 // -----------------------------------------------------------------------------
       
    41 //
       
    42 CMusTestSessionSimulator* CMusTestSessionSimulator::NewL(  CMceManager& aManager)
       
    43     {
       
    44     
       
    45     CMusTestSessionSimulator* self = 
       
    46         new (ELeave) CMusTestSessionSimulator( aManager );
       
    47     CleanupStack::PushL( self );
       
    48     self->ConstructL( );
       
    49     CleanupStack::Pop( self );
       
    50     return self;
       
    51     }
       
    52 
       
    53 // -----------------------------------------------------------------------------
       
    54 // CMceManager::~CMceManager
       
    55 // -----------------------------------------------------------------------------
       
    56 //
       
    57 
       
    58 CMusTestSessionSimulator::CMusTestSessionSimulator( CMceManager& aManager )
       
    59     :iManager(aManager)
       
    60     {
       
    61     
       
    62     }
       
    63 
       
    64 // -----------------------------------------------------------------------------
       
    65 // CMceManager::~CMceManager
       
    66 // -----------------------------------------------------------------------------
       
    67 //
       
    68 void CMusTestSessionSimulator::ConstructL(  )
       
    69     {
       
    70     iTimer = CMusTestTimer::NewL(CActive::EPriorityStandard, *this);
       
    71     SimulateReceiveSession();
       
    72     StartL();
       
    73     }
       
    74 
       
    75 // -----------------------------------------------------------------------------
       
    76 // Callback implementation when the timer activity happens in the CMusTestTimer class
       
    77 // -----------------------------------------------------------------------------
       
    78 //
       
    79 void CMusTestSessionSimulator::StartL()
       
    80     {
       
    81     TTimeIntervalMicroSeconds32 someInterVal(KDuration); //you can call After/At/Inactivity depending on what you want to do
       
    82     iTimer->After(someInterVal);
       
    83     }
       
    84 
       
    85 // -----------------------------------------------------------------------------
       
    86 // Callback implementation when the timer activity happens in the CMusTestTimer class
       
    87 // -----------------------------------------------------------------------------
       
    88 //
       
    89 TBool CMusTestSessionSimulator::IsRunning()
       
    90     {
       
    91     return iTimer->IsActive();
       
    92     }
       
    93 
       
    94 // -----------------------------------------------------------------------------
       
    95 // Callback implementation when the timer activity happens in the CMusTestTimer class
       
    96 // -----------------------------------------------------------------------------
       
    97 //
       
    98 void CMusTestSessionSimulator::Stop(  )
       
    99     {
       
   100     iTimer->Cancel();
       
   101     }
       
   102 
       
   103 // -----------------------------------------------------------------------------
       
   104 // Callback implementation when the timer activity happens in the CMusTestTimer class
       
   105 // -----------------------------------------------------------------------------
       
   106 //
       
   107 void CMusTestSessionSimulator::TimerExpired(TAny* aTimer,TInt aError)
       
   108     {
       
   109     if(aError == KErrNone)
       
   110       {
       
   111       // Timer successfully completed, handle it
       
   112       CMusTestTimer* timer = (CMusTestTimer*)aTimer;
       
   113       MUS_LOG("CMusTestSessionSimulator TimerExipired Change the state")
       
   114       StateChangeL();
       
   115       if( (iManager.iSessions[0]->iState == CMceSession::EEstablished )||
       
   116           ( iManager.iSessions[0]->iState == CMceSession::EIncoming )
       
   117         )
       
   118           {
       
   119           timer->Cancel();          
       
   120           }
       
   121       else
       
   122           {
       
   123           TTimeIntervalSeconds seconds(KDuration);
       
   124           timer->Inactivity(seconds); //Notify inactivity after 10 seconds
       
   125           }
       
   126       }
       
   127     }
       
   128 
       
   129 // -----------------------------------------------------------------------------
       
   130 // Simulates Receive Session
       
   131 // -----------------------------------------------------------------------------
       
   132 //
       
   133 void CMusTestSessionSimulator::SimulateReceiveSession()
       
   134     {
       
   135     MUS_LOG("CMusTestSessionSimulator::SimulateReceiveSession ->")
       
   136     TInt usecase;
       
   137     TInt err = RProperty::Get( NMusSessionApi::KCategoryUid, NMusSessionApi::KUseCase, usecase);  
       
   138     if( err == KErrNone )
       
   139         {        
       
   140         if( usecase == MultimediaSharing::EMusReceive || usecase == MultimediaSharing::EMusReceiveTwoWayVideo )
       
   141             {
       
   142             MUS_LOG("CMusTestSessionSimulator::SimulateReceiveSession receive session ")
       
   143             CMceInSession* inSession = CMceInSession::NewL();       
       
   144             inSession->iState = CMceSession::EIncoming;
       
   145             iManager.iSessions.AppendL( inSession );
       
   146             ibIncoming = ETrue;
       
   147             }
       
   148         else
       
   149             {
       
   150             ibIncoming = EFalse;
       
   151             }
       
   152         }
       
   153     else
       
   154         {
       
   155         MUS_LOG1("CMusTestSessionSimulator::SimulateReceiveSession err = %d ",err)
       
   156         }
       
   157     MUS_LOG("CMusTestSessionSimulator::SimulateReceiveSession <-")
       
   158     }
       
   159 // -----------------------------------------------------------------------------
       
   160 // CMceManager::~CMceManager
       
   161 // -----------------------------------------------------------------------------
       
   162 //
       
   163 void CMusTestSessionSimulator::StateChangeL()
       
   164     {
       
   165     MUS_LOG("CMusTestSessionSimulator::StateChangeL ->")
       
   166     TMceTransactionDataContainer* container = new TMceTransactionDataContainer();
       
   167     HBufC8* resonPharase = _L8("OK").AllocL(); ;
       
   168     TInt statusCode = 200;
       
   169     switch( iManager.iSessions[0]->iState )
       
   170         {        
       
   171         case CMceSession::EIdle : // offering
       
   172             statusCode = 180;
       
   173             delete resonPharase;
       
   174             resonPharase = _L8("Ringing").AllocL();    
       
   175             iManager.iSessions[0]->iState = CMceSession::EOffering;
       
   176             MUS_LOG("CMusTestSessionSimulator Session state : Offering 180")
       
   177             break;
       
   178         case CMceSession::EOffering : // estabilished
       
   179         case CMceSession::EAnswering : // estabilished
       
   180             delete resonPharase;
       
   181             resonPharase = _L8("OK").AllocL();    
       
   182             iManager.iSessions[0]->iState = CMceSession::EEstablished;
       
   183             MUS_LOG("CMusTestSessionSimulator Session state : Answering")
       
   184             break;
       
   185         case CMceSession::EEstablished : // estabilished
       
   186             delete resonPharase;
       
   187             resonPharase = _L8("OK").AllocL();
       
   188             MUS_LOG("CMusTestSessionSimulator Session state : Estabilished")
       
   189             break;
       
   190         case CMceSession::ETerminating : // estabilished            
       
   191             delete resonPharase;
       
   192             resonPharase = _L8("OK").AllocL();    
       
   193             iManager.iSessions[0]->iState = CMceSession::ETerminated;
       
   194             MUS_LOG("CMusTestSessionSimulator Session state : Terminated")
       
   195             break;
       
   196         case CMceSession::EIncoming : // estabilished            
       
   197             // handled down
       
   198             break;
       
   199         case CMceSession::EProceeding : // estabilished 
       
   200             iManager.iSessions[0]->iState = CMceSession::EAnswering;
       
   201             MUS_LOG("CMusTestSessionSimulator Session state : Proceeding");
       
   202             break;
       
   203         case CMceSession::EReserving : // estabilished     
       
   204             iManager.iSessions[0]->iState = CMceSession::EProceeding;       
       
   205             MUS_LOG("CMusTestSessionSimulator Session state : Reserving")
       
   206         default:
       
   207             break;
       
   208         }
       
   209     if( iManager.iSessions[0]->iState == CMceSession::EIncoming )
       
   210         {       
       
   211         MUS_LOG("CMusTestSessionSimulator Session state : Incoming") 
       
   212         if( iManager.iSessionObserver && container ) 
       
   213             {
       
   214             CMceInSession* session = ( CMceInSession* ) iManager.iSessions[0];
       
   215             if( session )
       
   216                 {
       
   217                 MUS_LOG("CMusTestSessionSimulator Calling InComingSession")            
       
   218                 iManager.iInSessionObserver->IncomingSession( session , container );     
       
   219                 iManager.iSessions[0]->iState = CMceSession::EReserving; 
       
   220                 }
       
   221             }
       
   222         else
       
   223             {
       
   224             MUS_LOG("CMusTestSessionSimulator insessionobserver empty ")
       
   225             }
       
   226         }
       
   227     else
       
   228         {
       
   229         MUS_LOG("CMusTestSessionSimulator Session state : Inform Session state") 
       
   230         container->SetStatusCode(statusCode);
       
   231         container->SetReasonPhrase( resonPharase ); 
       
   232         if( iManager.iSessionObserver && container ) 
       
   233             {
       
   234             MUS_LOG("CMusTestSessionSimulator Calling SessionStateChanged")
       
   235             if( iManager.iSessions.Count() > 0 )
       
   236                 {
       
   237                 CMceSession* session = iManager.iSessions[0];
       
   238                 if( session )
       
   239                     {
       
   240                     iManager.iSessionObserver->SessionStateChanged( *session ,container);
       
   241                     }
       
   242                 else
       
   243                     {
       
   244                     MUS_LOG("CMusTestSessionSimulator session empty ")
       
   245                     }
       
   246                 }
       
   247             else
       
   248                 {
       
   249                 MUS_LOG("CMusTestSessionSimulator No Session found ")            
       
   250                 }
       
   251             }
       
   252          else
       
   253             {
       
   254             MUS_LOG("CMusTestSessionSimulator Invalid pointer")
       
   255             }
       
   256         }
       
   257     delete container;
       
   258     MUS_LOG("CMusTestSessionSimulator::StateChangeL <-")
       
   259     }
       
   260 
       
   261 // -----------------------------------------------------------------------------
       
   262 // CMceManager::~CMceManager
       
   263 // -----------------------------------------------------------------------------
       
   264 //
       
   265 EXPORT_C CMusTestSessionSimulator::~CMusTestSessionSimulator()
       
   266     {
       
   267     Stop();
       
   268     delete iTimer;
       
   269     }
       
   270 
       
   271 //--------------------------------------------------------------------------------    
       
   272 // Timer implementation
       
   273 //--------------------------------------------------------------------------------
       
   274 //
       
   275 CMusTestTimer::CMusTestTimer(const TInt aPriority,MTimerNotify& aNotify)
       
   276 :CActive(aPriority),iNotify(aNotify)
       
   277 {
       
   278 }
       
   279  
       
   280 CMusTestTimer::~CMusTestTimer()
       
   281 {   
       
   282     Cancel();
       
   283     iTimer.Close();
       
   284 }
       
   285  
       
   286 CMusTestTimer* CMusTestTimer::NewL(const TInt aPriority,MTimerNotify& aNotify)
       
   287 {
       
   288     CMusTestTimer* me = new (ELeave) CMusTestTimer(aPriority,aNotify);
       
   289     CleanupStack::PushL(me);
       
   290     me->ConstructL();
       
   291     CleanupStack::Pop();
       
   292     return me;
       
   293 }
       
   294  
       
   295 void CMusTestTimer::ConstructL(void)
       
   296 {
       
   297     CActiveScheduler::Add(this);
       
   298     iTimer.CreateLocal();
       
   299 }
       
   300  
       
   301 void CMusTestTimer::After(TTimeIntervalMicroSeconds32 aInterval)
       
   302 {
       
   303     Cancel();
       
   304     iTimer.After(iStatus,aInterval);
       
   305     SetActive();
       
   306 }
       
   307  
       
   308 void CMusTestTimer::At(const TTime& aTime)
       
   309 {
       
   310     Cancel();
       
   311     iTimer.At(iStatus,aTime);
       
   312     SetActive();
       
   313 }
       
   314  
       
   315 void CMusTestTimer::Inactivity(TTimeIntervalSeconds aSeconds)
       
   316 {
       
   317     Cancel();
       
   318     iTimer.Inactivity(iStatus,aSeconds);
       
   319     SetActive();
       
   320 }
       
   321  
       
   322 void CMusTestTimer::DoCancel()
       
   323 {
       
   324     iTimer.Cancel();
       
   325 }
       
   326  
       
   327 void CMusTestTimer::RunL()
       
   328 {
       
   329     iNotify.TimerExpired(this,iStatus.Int());
       
   330 }