upnp/upnpstack/upnpconnmanager/src/upnpconnmanagersession.cpp
changeset 0 f5a58ecadc66
equal deleted inserted replaced
-1:000000000000 0:f5a58ecadc66
       
     1 /** @file
       
     2 * Copyright (c) 2005-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:  Defines the CUpnpConnManagerSession class
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 // INCLUDE FILES
       
    20 #include "upnpconnmanagersession.h"
       
    21 #include "upnpconnmanagerengine.h"
       
    22 #include "upnpconnmanager.h"
       
    23 #include <upnpsymbianserverbase.h>
       
    24 
       
    25 #define KLogFile _L("UPnPConnManager.txt")
       
    26 #include "upnpcustomlog.h"
       
    27 
       
    28 // ================= MEMBER FUNCTIONS =======================
       
    29 // -----------------------------------------------------------------------------
       
    30 // CUpnpConnManagerSession::NewL
       
    31 // Two-phased constructor.
       
    32 // -----------------------------------------------------------------------------
       
    33 //
       
    34 CUpnpConnManagerSession* CUpnpConnManagerSession::NewL(
       
    35     CUpnpConnManagerEngine& aEngine )
       
    36     {
       
    37     LOG_FUNC_NAME;
       
    38     CUpnpConnManagerSession* self =
       
    39         CUpnpConnManagerSession::NewLC( aEngine );
       
    40     CleanupStack::Pop( self ) ;
       
    41     return self ;
       
    42     }
       
    43 
       
    44 // -----------------------------------------------------------------------------
       
    45 // CUpnpConnManagerSession::NewLC
       
    46 // Two-phased constructor.
       
    47 // -----------------------------------------------------------------------------
       
    48 //
       
    49 CUpnpConnManagerSession* CUpnpConnManagerSession::NewLC(
       
    50     CUpnpConnManagerEngine& aEngine )
       
    51     {
       
    52     LOG_FUNC_NAME;
       
    53     CUpnpConnManagerSession* self =
       
    54         new( ELeave ) CUpnpConnManagerSession( aEngine );
       
    55     CleanupStack::PushL( self );
       
    56     return self ;
       
    57     }
       
    58 
       
    59 // -----------------------------------------------------------------------------
       
    60 // CUpnpConnManagerSession::CUpnpConnManagerSession
       
    61 // C++ default constructor can NOT contain any code, that
       
    62 // might leave.
       
    63 // -----------------------------------------------------------------------------
       
    64 //
       
    65 CUpnpConnManagerSession::CUpnpConnManagerSession( CUpnpConnManagerEngine& aEngine )
       
    66         : CSession2(),
       
    67         iConnEngine( aEngine ),
       
    68         iLastEvent( EUnknownEvent )
       
    69     {
       
    70 #ifdef _DEBUG
       
    71     TInt reqsInStart = RThread().RequestCount();
       
    72     TInt processHandlesInStart;
       
    73     TInt threadHandlesInStart;
       
    74     RThread().HandleCount( processHandlesInStart, threadHandlesInStart );
       
    75     LOGS1( "reqsInStart: %d", reqsInStart);
       
    76     LOGS1( "processHandlesInStart: %d", processHandlesInStart );
       
    77     LOGS1( "threadHandlesInStart: %d", threadHandlesInStart );
       
    78 #endif // _DEBUG
       
    79     }
       
    80 
       
    81 // -----------------------------------------------------------------------------
       
    82 // CUpnpConnManagerSession::~CUpnpConnManagerSession
       
    83 // Destructor.
       
    84 // -----------------------------------------------------------------------------
       
    85 //
       
    86 CUpnpConnManagerSession::~CUpnpConnManagerSession()
       
    87     {
       
    88     LOG_FUNC_NAME;
       
    89     
       
    90     iConnEngine.CheckAndCloseConnection( this );
       
    91     }
       
    92 
       
    93 // -----------------------------------------------------------------------------
       
    94 // CUpnpConnManagerSession::ServiceL
       
    95 // Handle client requests.
       
    96 // -----------------------------------------------------------------------------
       
    97 //
       
    98 void CUpnpConnManagerSession::ServiceL( const RMessage2& aMessage )
       
    99     {
       
   100     LOG_FUNC_NAME;
       
   101     TInt err;
       
   102     switch ( aMessage.Function() )
       
   103         {
       
   104         case EEnsureStartRConnection:
       
   105             {
       
   106             err = EventEnsureStartRConnectionL( aMessage );
       
   107             aMessage.Complete( err );
       
   108             break;
       
   109             }
       
   110         case EIsRConnectionStarted:
       
   111             {
       
   112             EventIsRConnectionStartedL( aMessage );
       
   113             aMessage.Complete( KErrNone );
       
   114             break;
       
   115             }
       
   116         case EEventSubscribe:
       
   117             {
       
   118             // subscribe to: 1) wlan lost or 2) address change
       
   119             EventSubscribeToNetworkEventL( aMessage );
       
   120             break;
       
   121             }
       
   122         case ECancelEventSubscribe:
       
   123             {
       
   124             EventCancelSubscribeToNetworkEvent();
       
   125             aMessage.Complete( KErrNone );
       
   126             break;
       
   127             }    
       
   128         case ECmActiveIap:
       
   129             {
       
   130             EventActiveIapL( aMessage );
       
   131             aMessage.Complete( KErrNone );
       
   132             break;
       
   133             }  
       
   134         case ECmGetAddress:
       
   135             {
       
   136             EventLocalAddressL( aMessage );
       
   137             aMessage.Complete( KErrNone );
       
   138             break;
       
   139             }
       
   140             
       
   141         default:
       
   142             PanicClient( aMessage, CUpnpSymbianServerBase::EBadRequest );
       
   143             break;
       
   144         }
       
   145     }
       
   146 
       
   147 // -----------------------------------------------------------------------------
       
   148 // CUpnpConnManagerSession::PanicClient
       
   149 // Panic client.
       
   150 // -----------------------------------------------------------------------------
       
   151 //
       
   152 void CUpnpConnManagerSession::PanicClient( const RMessage2& aMessage, TInt aPanic ) const
       
   153     {
       
   154     LOG_FUNC_NAME;
       
   155     static_cast<const CUpnpSymbianServerBase*>( Server() )->PanicClient( aMessage, aPanic );
       
   156     }
       
   157 
       
   158 // -----------------------------------------------------------------------------
       
   159 // CUpnpConnManagerSession::EventEnsureStartRConnectionL
       
   160 // Device list change.
       
   161 // -----------------------------------------------------------------------------
       
   162 //
       
   163 TInt CUpnpConnManagerSession::EventEnsureStartRConnectionL( const RMessage2& aMessage )
       
   164     {
       
   165     LOG_FUNC_NAME;
       
   166 
       
   167     TInt accessPoint;
       
   168     TInt result = iConnEngine.EnsureStart( accessPoint );
       
   169     TPtr8 ptr( reinterpret_cast<TUint8*>( &accessPoint ), sizeof( TInt ), sizeof( TInt ) );
       
   170     aMessage.WriteL( 0, ptr );
       
   171     
       
   172     iSessionUseConnection = ETrue;
       
   173     
       
   174     return result;
       
   175     }
       
   176 
       
   177 // -----------------------------------------------------------------------------
       
   178 // CUpnpConnManagerSession::EventIsRConnectionStartedL
       
   179 // Checks if connection is started
       
   180 // -----------------------------------------------------------------------------
       
   181 //
       
   182 void CUpnpConnManagerSession::EventIsRConnectionStartedL( const RMessage2& aMessage )
       
   183     {
       
   184     LOG_FUNC_NAME;
       
   185 
       
   186     TBool result = iConnEngine.IsStarted();
       
   187     TPtr8 ptr( reinterpret_cast<TUint8*>( &result ), sizeof( TBool ),
       
   188                sizeof( TBool ) );
       
   189     aMessage.WriteL( 0, ptr );
       
   190     }
       
   191     
       
   192 // -----------------------------------------------------------------------------
       
   193 // CUpnpConnManagerSession::EventSubscribeToNetworkEventL
       
   194 // Subscribes to Wlan lost event
       
   195 // -----------------------------------------------------------------------------
       
   196 //
       
   197 void CUpnpConnManagerSession::EventSubscribeToNetworkEventL( const RMessage2& aMessage )
       
   198     {
       
   199     LOG_FUNC_NAME;
       
   200     if ( !iSubscriberMessage.IsNull() )
       
   201         {
       
   202         aMessage.Complete( KErrServerBusy );
       
   203         return;
       
   204         }
       
   205     else 
       
   206         {
       
   207         iSubscriberMessage = aMessage;
       
   208         }    
       
   209         
       
   210     switch( iLastEvent.Type() )
       
   211         {
       
   212         case EWlanLostEvent: 
       
   213                 WLanLostCompleteL();
       
   214             break;
       
   215         case EAddressChangeEvent: 
       
   216                 AddressChangeCompleteL();
       
   217             break;
       
   218         default: 
       
   219             break;
       
   220         }
       
   221     }
       
   222 
       
   223 // -----------------------------------------------------------------------------
       
   224 // CUpnpConnManagerSession::EventCancelSubscribeToNetworkEvent
       
   225 // Cancel subscription
       
   226 // -----------------------------------------------------------------------------
       
   227 //
       
   228 void CUpnpConnManagerSession::EventCancelSubscribeToNetworkEvent()
       
   229     {
       
   230     LOG_FUNC_NAME;
       
   231     CancelSubscription();
       
   232     }
       
   233 
       
   234 // -----------------------------------------------------------------------------
       
   235 // CUpnpConnManagerSession::EventActiveIap
       
   236 // Returns active Iap.
       
   237 // -----------------------------------------------------------------------------
       
   238 //
       
   239 void CUpnpConnManagerSession::EventActiveIapL( const RMessage2 &aMessage )
       
   240     {
       
   241     LOG_FUNC_NAME;
       
   242 
       
   243     TInt iap = iConnEngine.ActiveIap();
       
   244     TPtr8 ptr( reinterpret_cast<TUint8*>( &iap ), sizeof( TInt ), sizeof( TInt ) );
       
   245 
       
   246     aMessage.WriteL( 0, ptr );
       
   247     }
       
   248 
       
   249 // -----------------------------------------------------------------------------
       
   250 // CUpnpConnManagerSession::EventLocalAddressL
       
   251 // Returns local address
       
   252 // -----------------------------------------------------------------------------
       
   253 //
       
   254 void CUpnpConnManagerSession::EventLocalAddressL( const RMessage2 &aMessage )
       
   255     {
       
   256     LOG_FUNC_NAME;
       
   257 
       
   258     TInetAddr localAddress = iConnEngine.LocalAddress();
       
   259     TPtr8 ptr( reinterpret_cast<TUint8*>( &localAddress ), 
       
   260                sizeof( TInetAddr ), 
       
   261                sizeof( TInetAddr ) );
       
   262 
       
   263     aMessage.WriteL( 0, ptr );       
       
   264     }
       
   265 
       
   266 // -----------------------------------------------------------------------------
       
   267 // CUpnpConnManagerSession::CancelSubscription
       
   268 // Cancel subscription
       
   269 // -----------------------------------------------------------------------------
       
   270 //
       
   271 void CUpnpConnManagerSession::CancelSubscription()
       
   272     {
       
   273     if ( !iSubscriberMessage.IsNull() )
       
   274         {
       
   275         iSubscriberMessage.Complete( KErrCancel );
       
   276         }
       
   277     iLastEvent.SetType( EUnknownEvent );    
       
   278     }
       
   279     
       
   280 // -----------------------------------------------------------------------------
       
   281 // CUpnpConnManagerSession::WLanLostOccured
       
   282 // Ends subscription with Wlan lost code
       
   283 // -----------------------------------------------------------------------------
       
   284 //
       
   285 void CUpnpConnManagerSession::WLanLostOccuredL()
       
   286     {
       
   287     iLastEvent.SetType( EWlanLostEvent );
       
   288     if ( !iSubscriberMessage.IsNull() )
       
   289         {
       
   290         WLanLostCompleteL();
       
   291         }    
       
   292     }
       
   293 
       
   294 // -----------------------------------------------------------------------------
       
   295 // CUpnpConnManagerSession::WLanLostComplete
       
   296 // Notify client about WLan lost event
       
   297 // -----------------------------------------------------------------------------
       
   298 //
       
   299 void CUpnpConnManagerSession::WLanLostCompleteL()
       
   300     {
       
   301     TPtr8 ptr( reinterpret_cast<TUint8*>( &iLastEvent ),
       
   302                sizeof( TUpnpConnectionManagerNetworkEvent ),
       
   303                sizeof( TUpnpConnectionManagerNetworkEvent ) );
       
   304                
       
   305     iSubscriberMessage.WriteL( KNetworkEventSlot, ptr );
       
   306     iSubscriberMessage.Complete( KErrNone );
       
   307     iLastEvent.SetType( EUnknownEvent );
       
   308     }
       
   309 
       
   310 // -----------------------------------------------------------------------------
       
   311 // CUpnpConnManagerSession::AddressChangeOccuredL
       
   312 // Ends subscription with address change code
       
   313 // -----------------------------------------------------------------------------
       
   314 //
       
   315 void CUpnpConnManagerSession::AddressChangeOccuredL( TInetAddr& aAddr )
       
   316     {
       
   317     iLastEvent.SetType( EAddressChangeEvent );
       
   318     iLastEvent.SetAddress( aAddr );
       
   319         
       
   320     if ( !iSubscriberMessage.IsNull() )
       
   321         {
       
   322         AddressChangeCompleteL();
       
   323         }    
       
   324     }
       
   325 
       
   326 // -----------------------------------------------------------------------------
       
   327 // CUpnpConnManagerSession::AddressChangeCompleteL
       
   328 // Notify client about address change event
       
   329 // -----------------------------------------------------------------------------
       
   330 //
       
   331 void CUpnpConnManagerSession::AddressChangeCompleteL()
       
   332     {
       
   333     TPtr8 ptr( reinterpret_cast<TUint8*>( &iLastEvent ),
       
   334                sizeof( TUpnpConnectionManagerNetworkEvent ),
       
   335                sizeof( TUpnpConnectionManagerNetworkEvent ) );
       
   336            
       
   337     iSubscriberMessage.WriteL( KNetworkEventSlot, ptr );
       
   338     iSubscriberMessage.Complete( KErrNone );
       
   339     iLastEvent.SetType( EUnknownEvent );
       
   340     }
       
   341 
       
   342 // -----------------------------------------------------------------------------
       
   343 // CUpnpConnManagerSession::SessionUseConnection
       
   344 // -----------------------------------------------------------------------------
       
   345 //
       
   346 TBool CUpnpConnManagerSession::SessionUseConnection()
       
   347     {
       
   348     return iSessionUseConnection;
       
   349     }
       
   350 
       
   351 // -----------------------------------------------------------------------------
       
   352 // CUpnpConnManagerSession::ConnectionClosedL
       
   353 // Ends subscription with connection close code
       
   354 // -----------------------------------------------------------------------------
       
   355 //
       
   356 void CUpnpConnManagerSession::ConnectionClosedL()
       
   357     {
       
   358     if ( iLastEvent.Type() != EConnectionClosedEvent )
       
   359         {
       
   360         iLastEvent.SetType( EConnectionClosedEvent );
       
   361         
       
   362         if ( !iSubscriberMessage.IsNull() )
       
   363             {
       
   364             ConnectionClosedCompleteL();
       
   365             }    
       
   366         }
       
   367     }
       
   368 
       
   369 // -----------------------------------------------------------------------------
       
   370 // CUpnpConnManagerSession::ConnectionClosedCompleteL
       
   371 // Notify client about connection close event
       
   372 // -----------------------------------------------------------------------------
       
   373 //
       
   374 void CUpnpConnManagerSession::ConnectionClosedCompleteL()
       
   375     {
       
   376     TPtr8 ptr( reinterpret_cast<TUint8*>( &iLastEvent ),
       
   377                sizeof( TUpnpConnectionManagerNetworkEvent ),
       
   378                sizeof( TUpnpConnectionManagerNetworkEvent ) );
       
   379                
       
   380     iSubscriberMessage.WriteL( KNetworkEventSlot, ptr );
       
   381     iSubscriberMessage.Complete( KErrNone );
       
   382     }
       
   383 
       
   384 // End of File