mmsharing/livecommsui/lcui/tsrc/mustester/Stubs/mceclientstub/src/mcesession.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 
       
    19 #include "mcesession.h"
       
    20 //#include "mceinsession.h"
       
    21 #include "mcemanager.h"
       
    22 #include "mcestreambundle.h"
       
    23 #include "mcemediastream.h"
       
    24 #include "mceinsessionobserver.h"
       
    25 #include "mcesessionobserver.h"
       
    26 #include "mcestreamobserver.h"
       
    27 #include "mcertpobserver.h"
       
    28 #include "mcetransactiondatacontainer.h"
       
    29 #include "mussessionsimulator.h"
       
    30 
       
    31 
       
    32 // ============================ MEMBER FUNCTIONS ===============================
       
    33 
       
    34 
       
    35 // -----------------------------------------------------------------------------
       
    36 // CMceSession::~CMceSession
       
    37 // -----------------------------------------------------------------------------
       
    38 //
       
    39 EXPORT_C CMceSession::~CMceSession()
       
    40     {
       
    41     delete iHeaders;
       
    42     delete iSessionSDPLines;
       
    43     
       
    44     delete iOriginator;
       
    45     delete iRecipient;
       
    46     iMediaStreams.ResetAndDestroy();
       
    47     iBundles.ResetAndDestroy();
       
    48     
       
    49     }
       
    50 
       
    51 
       
    52 // -----------------------------------------------------------------------------
       
    53 // CMceSession::State
       
    54 // -----------------------------------------------------------------------------
       
    55 //
       
    56 EXPORT_C CMceSession::TState CMceSession::State() const
       
    57     {
       
    58     return iState;
       
    59     }
       
    60 
       
    61 
       
    62 // -----------------------------------------------------------------------------
       
    63 // CMceSession::ConnectionActive
       
    64 // -----------------------------------------------------------------------------
       
    65 //
       
    66 EXPORT_C TBool CMceSession::ConnectionActive() const
       
    67     {
       
    68     return iIsConnectionActive;
       
    69     }
       
    70 
       
    71 
       
    72 // -----------------------------------------------------------------------------
       
    73 // CMceSession::RemoveStreamL
       
    74 // -----------------------------------------------------------------------------
       
    75 //
       
    76 EXPORT_C void CMceSession::RemoveStreamL( CMceMediaStream& aMediaStream )
       
    77     {
       
    78     for ( TInt i = 0; i < iMediaStreams.Count(); ++i )
       
    79         {
       
    80         if ( &aMediaStream == iMediaStreams[i] )
       
    81             {
       
    82             delete iMediaStreams[i];
       
    83             iMediaStreams.Remove( i );
       
    84             return;
       
    85             }
       
    86         }
       
    87     
       
    88     User::Leave( KErrNotFound );
       
    89     }
       
    90     
       
    91 
       
    92 // -----------------------------------------------------------------------------
       
    93 // CMceSession::AddStreamL
       
    94 // -----------------------------------------------------------------------------
       
    95 //
       
    96 EXPORT_C void CMceSession::AddStreamL( CMceMediaStream* aMediaStream )
       
    97     {
       
    98     User::LeaveIfError( iMediaStreams.Find( aMediaStream ) != KErrNotFound ? 
       
    99                                             KErrArgument : KErrNone );
       
   100     
       
   101     aMediaStream->InitializeL( *this ); // Initialize before taking ownership
       
   102     
       
   103     iMediaStreams.AppendL( aMediaStream );
       
   104     
       
   105     }
       
   106 
       
   107 
       
   108 // -----------------------------------------------------------------------------
       
   109 // CMceSession::UpdateL
       
   110 // -----------------------------------------------------------------------------
       
   111 //
       
   112 EXPORT_C void CMceSession::UpdateL(
       
   113              TUint32 aTimeout,
       
   114              CDesC8Array* aHeaders, 
       
   115              HBufC8* aContentType,
       
   116              HBufC8* aContent,
       
   117              CDesC8Array* aContentHeaders ) 
       
   118     {
       
   119     User::LeaveIfError( iState != EIdle ? KErrNone : KErrNotReady );
       
   120     User::LeaveIfError( 
       
   121         ( aContentType && aContent ) || 
       
   122        !( aContentType || aContent || aContentHeaders ) ? 
       
   123         KErrNone : KErrArgument );
       
   124     
       
   125     // Leave if in incoming state givem too small timeout value
       
   126     User::LeaveIfError( !( aTimeout > 0 && State() == CMceSession::EIncoming ) ||
       
   127         aTimeout <= SessionTimer() ? KErrNone : KErrArgument );
       
   128     
       
   129     InitializeL(); 
       
   130     
       
   131     iTimeout = aTimeout;
       
   132     
       
   133     delete iHeaders; 
       
   134     iHeaders = aHeaders;
       
   135     delete aContentType;
       
   136     delete aContentHeaders;
       
   137     
       
   138     if ( iState == EIncoming )
       
   139         {
       
   140         iState = EReserving;
       
   141         RestartSimulator();
       
   142         }
       
   143     else
       
   144         {
       
   145         iState = EOffering;
       
   146         }
       
   147     }
       
   148 
       
   149 // -----------------------------------------------------------------------------
       
   150 // CMceSession::InitializeL
       
   151 // -----------------------------------------------------------------------------
       
   152 //
       
   153 /*
       
   154 void CMceSession::InitializeL()
       
   155     {
       
   156     for(int i=0; i<iMediaStreams.Count();i++)
       
   157         {
       
   158         iMediaStreams[i]->InitializeL( *this );
       
   159         }
       
   160     }
       
   161   */  
       
   162 
       
   163 
       
   164 // -----------------------------------------------------------------------------
       
   165 // CMceSession::TerminateL
       
   166 // -----------------------------------------------------------------------------
       
   167 //
       
   168 EXPORT_C void CMceSession::TerminateL( CDesC8Array* aHeaders,
       
   169 					                   HBufC8* aContentType,
       
   170 					                   HBufC8* aContent ) 
       
   171     {
       
   172     __ASSERT_ALWAYS( iState != CMceSession::EIdle, User::Leave( KErrNotReady ) );
       
   173     
       
   174     delete iHeaders;
       
   175     iHeaders = aHeaders;
       
   176     delete aContentType;
       
   177     delete aContent;
       
   178     
       
   179    	iState = CMceSession::ETerminating;
       
   180    	RestartSimulator();
       
   181    
       
   182    	
       
   183     }
       
   184 
       
   185 
       
   186 // -----------------------------------------------------------------------------
       
   187 // CMceSession::Streams
       
   188 // -----------------------------------------------------------------------------
       
   189 //
       
   190 EXPORT_C const RPointerArray<CMceMediaStream>& CMceSession::Streams() const
       
   191     {
       
   192     return iMediaStreams;
       
   193     }
       
   194 
       
   195 
       
   196 // -----------------------------------------------------------------------------
       
   197 // CMceSession::Recipient
       
   198 // -----------------------------------------------------------------------------
       
   199 //
       
   200 EXPORT_C const TDesC8& CMceSession::Recipient() const
       
   201     {
       
   202     return *iRecipient;
       
   203     }
       
   204 
       
   205 // -----------------------------------------------------------------------------
       
   206 // CMceSession::Originator
       
   207 // -----------------------------------------------------------------------------
       
   208 //
       
   209 EXPORT_C const TDesC8& CMceSession::Originator() const
       
   210     {
       
   211     return *iOriginator;
       
   212     }
       
   213 
       
   214 // -----------------------------------------------------------------------------
       
   215 //
       
   216 // -----------------------------------------------------------------------------
       
   217 //
       
   218 EXPORT_C void CMceSession::SetSessionSDPLinesL( CDesC8Array* aSessionSDPLines )
       
   219     {
       
   220     delete iSessionSDPLines;
       
   221     iSessionSDPLines = aSessionSDPLines;
       
   222     }
       
   223 
       
   224 // -----------------------------------------------------------------------------
       
   225 //
       
   226 // -----------------------------------------------------------------------------
       
   227 //
       
   228 EXPORT_C MDesC8Array* CMceSession::SessionSDPLinesL()
       
   229     {
       
   230     if ( iSessionSDPLines )
       
   231         {
       
   232         CDesC8Array* array = new ( ELeave ) CDesC8ArrayFlat( 1 );
       
   233         CleanupStack::PushL( array );
       
   234         for ( TInt i = 0; i < iSessionSDPLines->Count(); ++i )
       
   235             {
       
   236             array->AppendL( iSessionSDPLines->MdcaPoint(i) );
       
   237             }
       
   238         CleanupStack::Pop( array );
       
   239         return array;
       
   240         }
       
   241         
       
   242     return NULL;
       
   243     }
       
   244 
       
   245 // -----------------------------------------------------------------------------
       
   246 //
       
   247 // -----------------------------------------------------------------------------
       
   248 //
       
   249 EXPORT_C TUint32 CMceSession::SessionTimer() const
       
   250     {
       
   251     return iTimeout;
       
   252     }
       
   253 
       
   254 // -----------------------------------------------------------------------------
       
   255 // CMceSession::AddBundleL
       
   256 // -----------------------------------------------------------------------------
       
   257 //
       
   258 EXPORT_C void CMceSession::AddBundleL( CMceStreamBundle* aBundle )
       
   259     {
       
   260     iBundles.AppendL( aBundle );
       
   261     }
       
   262 
       
   263 // -----------------------------------------------------------------------------
       
   264 // CMceSession::RemoveBundleL
       
   265 // -----------------------------------------------------------------------------
       
   266 //
       
   267 EXPORT_C void CMceSession::RemoveBundleL( CMceStreamBundle& aBundle )
       
   268     {
       
   269     TInt index = iBundles.Find( &aBundle );
       
   270     User::LeaveIfError( index );
       
   271     iBundles.Remove( index );
       
   272     }
       
   273 
       
   274 // -----------------------------------------------------------------------------
       
   275 // CMceSession::Bundles
       
   276 // -----------------------------------------------------------------------------
       
   277 //
       
   278 EXPORT_C const RPointerArray< CMceStreamBundle >& CMceSession::Bundles() const
       
   279     {
       
   280     return iBundles;
       
   281     }
       
   282 
       
   283 // -----------------------------------------------------------------------------
       
   284 // CMceSession::GetModifierL
       
   285 // -----------------------------------------------------------------------------
       
   286 //
       
   287 EXPORT_C void CMceSession::GetModifierL( TMceSessionModifier aModifier,
       
   288                                          TUint& aValue ) const
       
   289     {
       
   290     if ( aModifier == KMcePreconditions )
       
   291         {
       
   292         if ( iForceInternetSignaling )
       
   293             {
       
   294             aValue = KMcePreconditionsNotUsed;
       
   295             }
       
   296         else
       
   297             {
       
   298             aValue = KMcePreconditionsSupported;
       
   299             }
       
   300         return;
       
   301         }
       
   302     User::Leave( KErrNotFound );
       
   303     }
       
   304     
       
   305 // -----------------------------------------------------------------------------
       
   306 // CMceSession::SetModifierL
       
   307 // -----------------------------------------------------------------------------
       
   308 //
       
   309 EXPORT_C void CMceSession::SetModifierL( TMceSessionModifier aModifier, 
       
   310                                          TUint aValue )        
       
   311     {
       
   312     if ( aModifier == KMcePreconditions )
       
   313         {
       
   314         if ( aValue == KMcePreconditionsNotUsed )
       
   315             {
       
   316             iForceInternetSignaling = ETrue;
       
   317             }
       
   318         else
       
   319             {
       
   320             iForceInternetSignaling = EFalse;
       
   321             }
       
   322         return;
       
   323         }
       
   324     else if ( aModifier == KMce100Rel )
       
   325         {
       
   326         if ( aValue >= 0 && aValue <= 2 )
       
   327             {
       
   328             i100RelUsage = aValue;
       
   329             return;
       
   330             }
       
   331         }
       
   332     User::LeaveIfError( KErrNotSupported );
       
   333     }
       
   334 
       
   335 // -----------------------------------------------------------------------------
       
   336 // CMceSession::Profile
       
   337 // -----------------------------------------------------------------------------
       
   338 //
       
   339 EXPORT_C TUint32 CMceSession::Profile() const
       
   340     {
       
   341     return iProfileId;
       
   342     }
       
   343 
       
   344 // -----------------------------------------------------------------------------
       
   345 // CMceSession::CMceSession
       
   346 // -----------------------------------------------------------------------------
       
   347 //
       
   348 CMceSession::CMceSession( CMceManager* aManager, TUint32 aProfileId )
       
   349  : iProfileId( aProfileId ),
       
   350    iManager( aManager ),
       
   351    iState( CMceSession::EIdle),
       
   352    iIsConnectionActive( ETrue ),
       
   353    iForceInternetSignaling( EFalse ),
       
   354    i100RelUsage( 1 ), // MCE default
       
   355    iFailWithCode( KErrNone ),
       
   356    iReasonPhrase( KNullDesC8() ),
       
   357    iReasonCode( 0 )
       
   358     {
       
   359     }
       
   360 
       
   361 
       
   362 // -----------------------------------------------------------------------------
       
   363 // CMceSession::Manager
       
   364 // -----------------------------------------------------------------------------
       
   365 //
       
   366 CMceManager& CMceSession::Manager() const
       
   367     {
       
   368     return *iManager;
       
   369     }
       
   370     
       
   371 
       
   372 // -----------------------------------------------------------------------------
       
   373 // CMceSession::ConstructL
       
   374 // -----------------------------------------------------------------------------
       
   375 //
       
   376 void CMceSession::ConstructL()
       
   377     {
       
   378     
       
   379     }
       
   380 
       
   381 // -----------------------------------------------------------------------------
       
   382 // CMceSession::InitializeL
       
   383 // -----------------------------------------------------------------------------
       
   384 //
       
   385 void CMceSession::InitializeL()
       
   386     {
       
   387     for (int i=0; i<iMediaStreams.Count();i++)
       
   388         {
       
   389         iMediaStreams[i]->InitializeL( *this );
       
   390         }
       
   391     
       
   392     /*    
       
   393     for(int i=0; i<iBundles.Count();i++)
       
   394         {
       
   395         iBundles[i]->InitializeL( *this );
       
   396         }
       
   397     */
       
   398     }
       
   399     
       
   400 
       
   401 // -----------------------------------------------------------------------------
       
   402 // CMceSession::RestartSimulator
       
   403 // -----------------------------------------------------------------------------
       
   404 //
       
   405 void CMceSession::RestartSimulator()
       
   406     {
       
   407     if( iManager->iSessionSimulator->IsRunning())
       
   408         {
       
   409         iManager->iSessionSimulator->Stop();
       
   410         }
       
   411     iManager->iSessionSimulator->StartL();    
       
   412     }
       
   413