upnp/upnpstack/dlnawebserver/src/upnphttpserverruntime.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:  CUpnpHttpServerRuntime is a single runtime.
       
    15 *
       
    16 */
       
    17 
       
    18 #include "upnphttpserverruntime.h"
       
    19 #include "upnpconnectionmanagerproxy.h"
       
    20 #include "upnphttpserver.h"
       
    21 #include "upnpsettings.h"
       
    22 
       
    23 static const TUint KSocketServerConnectionSlots = 60;
       
    24 
       
    25 // -----------------------------------------------------------------------------
       
    26 // CUpnpHttpServerRuntime::CUpnpHttpServerRuntime
       
    27 // -----------------------------------------------------------------------------
       
    28 //
       
    29 CUpnpHttpServerRuntime::CUpnpHttpServerRuntime( TUint /*aUnusedIapId*/,
       
    30                                                 MUpnpHttpServerObserver& aObserver ):
       
    31     iObserver( aObserver )                                               
       
    32     {
       
    33     // No implementation required
       
    34     }
       
    35 
       
    36 // -----------------------------------------------------------------------------
       
    37 // CUpnpHttpServerRuntime::~CUpnpHttpServerRuntime
       
    38 // -----------------------------------------------------------------------------
       
    39 //
       
    40 CUpnpHttpServerRuntime::~CUpnpHttpServerRuntime()
       
    41     {
       
    42     delete iHttpServer;
       
    43     CloseSocketServer();
       
    44     }
       
    45 
       
    46 // -----------------------------------------------------------------------------
       
    47 // CUpnpHttpServerRuntime::NewLC
       
    48 // -----------------------------------------------------------------------------
       
    49 //
       
    50 CUpnpHttpServerRuntime* CUpnpHttpServerRuntime::NewLC( 
       
    51     TUint aUnusedIapId, MUpnpHttpServerObserver& aObserver )
       
    52     {
       
    53     CUpnpHttpServerRuntime* self = new (ELeave) CUpnpHttpServerRuntime( aUnusedIapId, aObserver );
       
    54     CleanupStack::PushL( self );
       
    55     self->ConstructL();
       
    56     return self;
       
    57     }
       
    58 
       
    59 // -----------------------------------------------------------------------------
       
    60 // CUpnpHttpServerRuntime::NewL
       
    61 // -----------------------------------------------------------------------------
       
    62 //
       
    63 CUpnpHttpServerRuntime* CUpnpHttpServerRuntime::NewL( 
       
    64     TUint aUnusedIapId, MUpnpHttpServerObserver& aObserver )
       
    65     {
       
    66     CUpnpHttpServerRuntime* self = CUpnpHttpServerRuntime::NewLC( aUnusedIapId, aObserver );
       
    67     CleanupStack::Pop( self );
       
    68     return self;
       
    69     }
       
    70 
       
    71 // -----------------------------------------------------------------------------
       
    72 // CUpnpHttpServerRuntime::ConstructL
       
    73 // -----------------------------------------------------------------------------
       
    74 //
       
    75 void CUpnpHttpServerRuntime::ConstructL()
       
    76     {    
       
    77     // connecting to needed servers
       
    78     OpenSocketServerL();
       
    79     GetIapAndStartServerL();
       
    80     }
       
    81 
       
    82 // -----------------------------------------------------------------------------
       
    83 // CUpnpHttpServerRuntime::GetIapAndStartServer
       
    84 // -----------------------------------------------------------------------------
       
    85 //    
       
    86 void CUpnpHttpServerRuntime::GetIapAndStartServerL()
       
    87     {       
       
    88     // Gets IAP
       
    89     CUpnpConnectionManagerProxy *proxy = CUpnpConnectionManagerProxy::NewLC( iSocketServ );
       
    90     User::LeaveIfError( proxy->EnsureStart() );
       
    91     TInt iap = proxy->ActiveIap();    
       
    92     
       
    93     TInt bufferSize = CUpnpSettings::GetFileBufferSizeL();
       
    94     // creating Http server
       
    95     iHttpServer = CUpnpHttpServer::NewL( &iObserver, &iSocketServ, iap );
       
    96     iHttpServer->SetFileReadBufferSize( bufferSize );
       
    97     iHttpServer->SetFileWriteBufferSize( bufferSize );
       
    98     
       
    99     CleanupStack::PopAndDestroy( proxy );
       
   100     }
       
   101     
       
   102 // -----------------------------------------------------------------------------
       
   103 // CUpnpHttpServerRuntime::SetCreator
       
   104 // -----------------------------------------------------------------------------
       
   105 //
       
   106 EXPORT_C void CUpnpHttpServerRuntime::SetCreator( MUpnpHttpServerTransactionCreator& aCreator )
       
   107     {
       
   108     iTransactionCreator = &aCreator;
       
   109     iHttpServer->SetTransactionCreator( &aCreator );
       
   110     }
       
   111 
       
   112 // -----------------------------------------------------------------------------
       
   113 // CUpnpHttpServerRuntime::HttpServer
       
   114 // -----------------------------------------------------------------------------
       
   115 //
       
   116 CUpnpHttpServer& CUpnpHttpServerRuntime::HttpServer()
       
   117     {
       
   118     return *iHttpServer; 
       
   119     }
       
   120 
       
   121 // -----------------------------------------------------------------------------
       
   122 // CUpnpHttpServerRuntime::DeleteServer
       
   123 // -----------------------------------------------------------------------------
       
   124 //
       
   125 void CUpnpHttpServerRuntime::DeleteServer()
       
   126     {
       
   127     if ( iHttpServer )
       
   128         {
       
   129         // server should be stopped to notify failed transfers
       
   130         iHttpServer->Stop();
       
   131         delete iHttpServer;
       
   132         iHttpServer = NULL;   
       
   133         CloseSocketServer();
       
   134         }    
       
   135     }
       
   136     
       
   137 // -----------------------------------------------------------------------------
       
   138 // CUpnpHttpServerRuntime::StartServerL
       
   139 // -----------------------------------------------------------------------------
       
   140 //
       
   141 void CUpnpHttpServerRuntime::StartServerL(  const TInt aPort )
       
   142     {
       
   143     OpenSocketServerL();  
       
   144     if ( !iHttpServer )
       
   145         {
       
   146         GetIapAndStartServerL();
       
   147         }
       
   148     iHttpServer->SetTransactionCreator( iTransactionCreator );  
       
   149     iHttpServer->StartL( aPort );
       
   150     }
       
   151     
       
   152 // -----------------------------------------------------------------------------
       
   153 // CUpnpHttpServerRuntime::OpenSocketServerL
       
   154 // -----------------------------------------------------------------------------
       
   155 //
       
   156 void CUpnpHttpServerRuntime::OpenSocketServerL()
       
   157     {
       
   158     if ( !iIsSocketOpened )
       
   159         {
       
   160         User::LeaveIfError( iSocketServ.Connect( KSocketServerConnectionSlots ) );
       
   161         iIsSocketOpened = ETrue;
       
   162         }
       
   163     }
       
   164     
       
   165 // -----------------------------------------------------------------------------
       
   166 // CUpnpHttpServerRuntime::CloseSocketServer
       
   167 // -----------------------------------------------------------------------------
       
   168 //
       
   169 void CUpnpHttpServerRuntime::CloseSocketServer()
       
   170     {
       
   171     iSocketServ.Close();
       
   172     iIsSocketOpened = EFalse;
       
   173     }
       
   174