upnp/upnpstack/serviceframework/src/upnpdeviceimplementation.cpp
changeset 0 f5a58ecadc66
child 9 5c72fd91570d
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 CUpnpDeviceImplementation class
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 // INCLUDE FILES
       
    20 
       
    21 #include <e32math.h>
       
    22 #include <xmlengdom.h> 
       
    23 
       
    24 #include <upnpdevicedescriptionstore.h>
       
    25 #include "upnpfileutils.h"
       
    26 #include "upnpcustomlog.h"
       
    27 #include "upnpdeviceimplementation.h"
       
    28 #include "upnpdispatcher.h"
       
    29 #include "upnpcontenthandlerscontroller.h"
       
    30 #include "upnpdevicedescriptionprovider.h"
       
    31 
       
    32 
       
    33 static const TInt KMaxDeviceDescriptionLenght(20480);
       
    34 // ============================= LOCAL FUNCTIONS ===============================
       
    35 
       
    36 // -----------------------------------------------------------------------------
       
    37 // CUpnpDeviceImplementation::NewL
       
    38 // -----------------------------------------------------------------------------
       
    39 //
       
    40 EXPORT_C CUpnpDeviceImplementation* CUpnpDeviceImplementation::NewL( 
       
    41         const TDesC8& aUri, 
       
    42         CUpnpDeviceDescriptionStore& aDescriptionStore,
       
    43         MUpnpDeviceDescriptionProvider& aProvider )
       
    44     {
       
    45     LOGS("CUpnpDevice:: CUpnpDevice::NewL( const TDesC& aFilename, TInt aIapId, TInt aHandle )" );
       
    46 
       
    47     HBufC8* descr = UpnpFileUtil::ReadFileL( aDescriptionStore.DescriptionFile() );
       
    48     if ( descr->Length()> KMaxDeviceDescriptionLenght )
       
    49         {
       
    50         delete descr;
       
    51         User::Leave( KErrTooBig );
       
    52         }
       
    53     CleanupStack::PushL( descr );
       
    54 
       
    55     CUpnpContentHandlersController* controller = CUpnpContentHandlersController::NewLC();
       
    56 
       
    57     CUpnpDeviceImplementation* deviceImpl = controller->ParseDeviceImplL( *descr );
       
    58     CleanupStack::PushL( deviceImpl );
       
    59     deviceImpl->ConstructL( aUri, aDescriptionStore, aProvider );
       
    60     CleanupStack::Pop( deviceImpl );
       
    61 
       
    62     CleanupStack::PopAndDestroy( controller );
       
    63     CleanupStack::PopAndDestroy( descr );
       
    64 
       
    65     return deviceImpl;
       
    66     }
       
    67            
       
    68 CUpnpDeviceImplementation::CUpnpDeviceImplementation()
       
    69     {
       
    70     }
       
    71 
       
    72 EXPORT_C CUpnpDeviceImplementation::~CUpnpDeviceImplementation()
       
    73     {
       
    74     }
       
    75 
       
    76 // -----------------------------------------------------------------------------
       
    77 // CUpnpDeviceImplementation::ConstructL
       
    78 // -----------------------------------------------------------------------------
       
    79 //
       
    80 void CUpnpDeviceImplementation::ConstructL( const TDesC8& aDeviceDescriptioUri,
       
    81                                         CUpnpDeviceDescriptionStore& aDescriptionStore,
       
    82                                         MUpnpDeviceDescriptionProvider& aProvider )
       
    83     {
       
    84     BaseConstructL( aDeviceDescriptioUri, aDescriptionStore, aProvider  );
       
    85     }
       
    86 
       
    87 // -----------------------------------------------------------------------------
       
    88 // CUpnpDeviceImplementation::StartL
       
    89 // -----------------------------------------------------------------------------
       
    90 //
       
    91 EXPORT_C void CUpnpDeviceImplementation::StartL( const TInt aPort )
       
    92     {   
       
    93     StartHttpServerL( aPort );
       
    94     AddLocalDeviceL();
       
    95     }
       
    96     
       
    97 // -----------------------------------------------------------------------------
       
    98 // CUpnpDeviceImplementation::StopL
       
    99 // -----------------------------------------------------------------------------
       
   100 //
       
   101 EXPORT_C void CUpnpDeviceImplementation::StopL()
       
   102     {
       
   103     StopL( EStopNormal );
       
   104     }
       
   105 
       
   106 // -----------------------------------------------------------------------------
       
   107 // CUpnpDeviceImplementation::StopL
       
   108 // -----------------------------------------------------------------------------
       
   109 //
       
   110 EXPORT_C void CUpnpDeviceImplementation::StopL( TStopMode aMode )
       
   111     {
       
   112     if ( ( aMode == EStopNormal  ) || ( aMode == EStopSilent ) )
       
   113         {
       
   114         StopDeviceL( aMode );
       
   115         }
       
   116     }
       
   117     
       
   118 // -----------------------------------------------------------------------------
       
   119 // CUpnpDeviceImplementation::StopDeviceL
       
   120 // -----------------------------------------------------------------------------
       
   121 //
       
   122 void CUpnpDeviceImplementation::StopDeviceL( TStopMode aMode )
       
   123     {
       
   124     SaveDescriptionStoreL();
       
   125     
       
   126     if( aMode == EStopSilent )
       
   127         {
       
   128         RemoveLocalDeviceL( Uuid(), ETrue );    
       
   129         }
       
   130     else 
       
   131         {
       
   132         RemoveLocalDeviceL( Uuid(), EFalse );    
       
   133         }
       
   134     StopHttpServer();
       
   135     }
       
   136 
       
   137 // -----------------------------------------------------------------------------
       
   138 // CUpnpDeviceImplementation::AddLocalDeviceL
       
   139 // -----------------------------------------------------------------------------
       
   140 //
       
   141 void CUpnpDeviceImplementation::AddLocalDeviceL()
       
   142     {
       
   143     GenerateUdnsL(this);
       
   144     SaveDescriptionStoreL();
       
   145     
       
   146     const TPtrC8 uuid = Uuid();
       
   147     const TPtrC8 device = DeviceType();
       
   148     const TDesC8& url = DescriptionUrl();
       
   149 
       
   150     iDispatcher->AddLocalDeviceL( uuid, device, url, ServiceTypesL(), iIsRootDevice );
       
   151 
       
   152     delete iPath;
       
   153     iPath = NULL;
       
   154     iPath = DescriptionUrl().AllocL();
       
   155     }
       
   156 
       
   157 // -----------------------------------------------------------------------------
       
   158 // CUpnpDeviceImplementation::RemoveLocalDeviceL
       
   159 // -----------------------------------------------------------------------------
       
   160 //
       
   161 void CUpnpDeviceImplementation::RemoveLocalDeviceL( const TDesC8& aUuid, TBool aSilent )
       
   162     {
       
   163     iDispatcher->RemoveLocalDeviceL( aUuid, aSilent );
       
   164     }
       
   165 
       
   166 // End of File
       
   167 
       
   168 
       
   169