upnpsharing/upnpdlnaprofiler/src/upnpresparameters.cpp
changeset 0 7f85d04be362
equal deleted inserted replaced
-1:000000000000 0:7f85d04be362
       
     1 /*
       
     2 * Copyright (c) 2006-2007 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:      Implementation file of CUpnpResParameters class. 
       
    15 *                CUpnpResParameters is created to encapsulate information  
       
    16 *                that is needed in a contentdirectory res element.
       
    17 *
       
    18 */
       
    19 
       
    20 
       
    21 
       
    22 
       
    23 
       
    24 
       
    25 // system includes
       
    26 
       
    27 // user includes
       
    28 #include "upnpresparameters.h"
       
    29 #include "upnpdlnaprofiler.h"
       
    30 
       
    31 _LIT( KComponentLogfile, "dlnaprofiler.txt");
       
    32 #include "upnplog.h"
       
    33 
       
    34 
       
    35 // constants
       
    36 const TInt KMaxTintLength = 20; // max. TInt string representation length.
       
    37 const TInt KMinutesInHour = 60;
       
    38 const TInt KSecondsInMinute = 60;
       
    39 const TInt KSecondsInHour = KMinutesInHour * KSecondsInMinute;
       
    40 
       
    41 const TInt KHourMaxLength = 5;
       
    42 const TInt KMinutesLength = 2;
       
    43 const TInt KSecondsLength = 2;
       
    44 
       
    45 _LIT( KResolutionDivider, "x" );
       
    46 _LIT( KTimeDivider, ":" );
       
    47 _LIT( KZero, "0" );
       
    48 
       
    49     
       
    50 // ======== LOCAL FUNCTIONS ========
       
    51 // NONE
       
    52 
       
    53 // ======== MEMBER FUNCTIONS ========
       
    54 
       
    55 // --------------------------------------------------------------------------
       
    56 // CUpnpResParameters C++ constructor
       
    57 // --------------------------------------------------------------------------
       
    58 //
       
    59 CUpnpResParameters::CUpnpResParameters()
       
    60     {
       
    61     __LOG( "[UPnPDlnaProfiler] CUpnpResParameters constructor" );
       
    62     }
       
    63 
       
    64 
       
    65 // --------------------------------------------------------------------------
       
    66 // CUpnpResParameters::ConstructL
       
    67 // --------------------------------------------------------------------------
       
    68 //
       
    69 void CUpnpResParameters::ConstructL()
       
    70     {
       
    71     __LOG( "[UPnPDlnaProfiler] CUpnpResParameters::ConstructL" );
       
    72     }
       
    73 
       
    74 
       
    75 // --------------------------------------------------------------------------
       
    76 // CUpnpResParameters::NewL
       
    77 // --------------------------------------------------------------------------
       
    78 //
       
    79 EXPORT_C CUpnpResParameters* CUpnpResParameters::NewL()
       
    80     {
       
    81     __LOG( "[UPnPDlnaProfiler] CUpnpResParameters::NewL" );
       
    82     CUpnpResParameters* self = CUpnpResParameters::NewLC();
       
    83     CleanupStack::Pop( self );
       
    84     return self;
       
    85     }
       
    86 
       
    87 
       
    88 // --------------------------------------------------------------------------
       
    89 // CUpnpResParameters::NewLC
       
    90 // --------------------------------------------------------------------------
       
    91 //
       
    92 EXPORT_C CUpnpResParameters* CUpnpResParameters::NewLC()
       
    93     {
       
    94     __LOG( "[UPnPDlnaProfiler] CUpnpResParameters::NewLC" );
       
    95     CUpnpResParameters* self = new( ELeave ) CUpnpResParameters;
       
    96     CleanupStack::PushL( self );
       
    97     self->ConstructL();
       
    98     return self;
       
    99     }
       
   100 
       
   101 
       
   102 // --------------------------------------------------------------------------
       
   103 // CUpnpResParameters destructor
       
   104 // --------------------------------------------------------------------------
       
   105 //
       
   106 CUpnpResParameters::~CUpnpResParameters()
       
   107     {
       
   108     __LOG( "[UPnPDlnaProfiler] CUpnpResParameters destructor" );
       
   109     delete iProtocolInfo;
       
   110     delete iMimetype;
       
   111     }
       
   112 
       
   113 // --------------------------------------------------------------------------
       
   114 // CUpnpResParameters::ProtocolInfo
       
   115 // --------------------------------------------------------------------------
       
   116 //
       
   117 EXPORT_C const TDesC8& CUpnpResParameters::ProtocolInfo() const
       
   118     {
       
   119     __LOG( "[UPnPDlnaProfiler] CUpnpResParameters::ProtocolInfo" );
       
   120 
       
   121     if ( iProtocolInfo ) 
       
   122         {
       
   123         return *iProtocolInfo;
       
   124         }
       
   125 
       
   126     return KNullDesC8();
       
   127     }
       
   128 
       
   129 // --------------------------------------------------------------------------
       
   130 // CUpnpResParameters::FileSizeL
       
   131 // --------------------------------------------------------------------------
       
   132 //
       
   133 EXPORT_C HBufC8* CUpnpResParameters::FileSizeL() const
       
   134     {
       
   135     __LOG( "[UPnPDlnaProfiler] CUpnpResParameters::FileSizeL" );
       
   136     HBufC8* retval = NULL;
       
   137     
       
   138     TBuf<KMaxTintLength> sizeOfFile;
       
   139     sizeOfFile.Num( iFileSize );
       
   140     
       
   141     retval = HBufC8::NewL( sizeOfFile.Length() );
       
   142     retval->Des().Append( sizeOfFile );
       
   143     
       
   144     return retval;
       
   145     }
       
   146 
       
   147 // --------------------------------------------------------------------------
       
   148 // CUpnpResParameters::DurationL
       
   149 //
       
   150 //   Requirement [7.3.22.1]: The syntax of the res@duration must be 
       
   151 //   compliant to the following definition:
       
   152 //     duration = hours ":" minutes ":" seconds
       
   153 //     hours = 1*5 DIGIT; 0-99999
       
   154 //     minutes = 2 DIGIT ; 00-59
       
   155 //     seconds = 2 DIGIT ["." 3 DIGIT] ; 00-59 (.000-.999) 
       
   156 // --------------------------------------------------------------------------
       
   157 //
       
   158 EXPORT_C HBufC8* CUpnpResParameters::DurationL() const
       
   159     {
       
   160     __LOG( "[UPnPDlnaProfiler] CUpnpResParameters::DurationL" );
       
   161     HBufC8* retval = NULL;
       
   162 
       
   163     // Leave if the duration has invalid value
       
   164     if( iDurationInSeconds < 0 )
       
   165         {
       
   166         User::Leave( KErrArgument );
       
   167         }
       
   168 
       
   169     TInt hour = iDurationInSeconds / KSecondsInHour;
       
   170     TInt min = (iDurationInSeconds % KSecondsInHour) / KSecondsInMinute;
       
   171     TInt sec = (iDurationInSeconds % KSecondsInHour) % KSecondsInMinute;
       
   172 
       
   173     // Leave if the duration is longer than allowed (99999h 99min 99sec)
       
   174     if( hour >= 100000 )
       
   175         {
       
   176         User::Leave( KErrArgument );
       
   177         }
       
   178 
       
   179     // Convert TInt to TBuf
       
   180     TBuf<KHourMaxLength> hours;
       
   181     hours.Num( hour );
       
   182     hours.Trim();
       
   183 
       
   184     TBuf<2> minutes;
       
   185     minutes.Num( min );
       
   186 
       
   187     TBuf<2> seconds;
       
   188     seconds.Num( sec );
       
   189 
       
   190     retval = HBufC8::NewL( hours.Length() + 
       
   191                            KTimeDivider().Length() + 
       
   192                            KMinutesLength +
       
   193                            KTimeDivider().Length() + 
       
   194                            KSecondsLength );
       
   195 
       
   196     retval->Des().Append( hours );
       
   197     retval->Des().Append( KTimeDivider() );
       
   198     if( min < 10 )
       
   199         {
       
   200         retval->Des().Append( KZero() );
       
   201         }
       
   202     retval->Des().Append( minutes );
       
   203     retval->Des().Append( KTimeDivider() );
       
   204     if( sec < 10 )
       
   205         {
       
   206         retval->Des().Append( KZero() );
       
   207         }
       
   208     retval->Des().Append( seconds );
       
   209 
       
   210     return retval;
       
   211     }
       
   212 
       
   213 // --------------------------------------------------------------------------
       
   214 // CUpnpResParameters::ResolutionL
       
   215 // --------------------------------------------------------------------------
       
   216 //
       
   217 EXPORT_C HBufC8* CUpnpResParameters::ResolutionL() const
       
   218     {
       
   219     __LOG( "[UPnPDlnaProfiler] CUpnpResParameters::ResolutionL" );
       
   220     HBufC8* retval = NULL;
       
   221     
       
   222     TBuf<KMaxTintLength> width;
       
   223     width.Num( iResolution.iWidth );
       
   224 
       
   225     TBuf<KMaxTintLength> height;
       
   226     height.Num( iResolution.iHeight );
       
   227 
       
   228     retval = HBufC8::NewL( width.Length() + 
       
   229                           KResolutionDivider().Length() + 
       
   230                           height.Length() );
       
   231                           
       
   232     retval->Des().Append( width );
       
   233     retval->Des().Append( KResolutionDivider() );
       
   234     retval->Des().Append( height );
       
   235     
       
   236     return retval;
       
   237     }
       
   238 
       
   239 // --------------------------------------------------------------------------
       
   240 // CUpnpResParameters::IsImageFile
       
   241 // --------------------------------------------------------------------------
       
   242 //
       
   243 EXPORT_C TBool CUpnpResParameters::IsImageFile() const
       
   244     {
       
   245     __LOG( "[UPnPDlnaProfiler] CUpnpResParameters::IsImageFile" );
       
   246     TBool retval = EFalse;
       
   247 
       
   248     if ( iMimetype->Left( KMimeStartLength ).Compare( KImage() ) == 0 ) 
       
   249         {
       
   250         retval = ETrue;
       
   251         }
       
   252 
       
   253     return retval;
       
   254     }
       
   255 
       
   256 // --------------------------------------------------------------------------
       
   257 // CUpnpResParameters::IsAudioOrVideoFile
       
   258 // --------------------------------------------------------------------------
       
   259 //
       
   260 EXPORT_C TBool CUpnpResParameters::IsAudioOrVideoFile() const
       
   261     {
       
   262     __LOG( "[UPnPDlnaProfiler] CUpnpResParameters::IsAudioOrVideoFile" );
       
   263     TBool retval = EFalse;
       
   264 
       
   265     if ( iMimetype->Left( KMimeStartLength ).Compare( KVideo() ) == 0 ||
       
   266          iMimetype->Left( KMimeStartLength ).Compare( KAudio() ) == 0 ) 
       
   267         {
       
   268         retval = ETrue;
       
   269         }
       
   270 
       
   271     return retval;
       
   272     }
       
   273 
       
   274 // --------------------------------------------------------------------------
       
   275 // CUpnpResParameters::SetProtocolInfoL
       
   276 // --------------------------------------------------------------------------
       
   277 //
       
   278 void CUpnpResParameters::SetProtocolInfoL( const TDesC8& aProtocolInfo ) 
       
   279     {
       
   280     __LOG( "[UPnPDlnaProfiler] CUpnpResParameters::SetProtocolInfoL" );
       
   281     iProtocolInfo = aProtocolInfo.AllocL();    
       
   282     }
       
   283 
       
   284 // --------------------------------------------------------------------------
       
   285 // CUpnpResParameters::SetMimetypeL
       
   286 // --------------------------------------------------------------------------
       
   287 //  
       
   288 void CUpnpResParameters::SetMimetypeL( const TDesC8& aMimetype )
       
   289     {
       
   290     __LOG( "[UPnPDlnaProfiler] CUpnpResParameters::SetMimetypeL" );
       
   291     iMimetype = aMimetype.AllocL();
       
   292     }
       
   293 
       
   294 // --------------------------------------------------------------------------
       
   295 // CUpnpResParameters::SetFileSize
       
   296 // --------------------------------------------------------------------------
       
   297 //
       
   298 void CUpnpResParameters::SetFileSize( TInt aFileSize )
       
   299     {
       
   300     __LOG( "[UPnPDlnaProfiler] CUpnpResParameters::SetFileSize" );
       
   301     iFileSize = aFileSize;
       
   302     }
       
   303 // --------------------------------------------------------------------------
       
   304 // CUpnpResParameters::SetResolution
       
   305 // --------------------------------------------------------------------------
       
   306 //
       
   307 void CUpnpResParameters::SetResolution( TSize aResolution ) 
       
   308     {
       
   309     __LOG( "[UPnPDlnaProfiler] CUpnpResParameters::SetResolution" );
       
   310     iResolution = aResolution;
       
   311     }
       
   312 
       
   313 // --------------------------------------------------------------------------
       
   314 // CUpnpResParameters::SetDurationInSeconds
       
   315 // --------------------------------------------------------------------------
       
   316 //
       
   317 void CUpnpResParameters::SetDurationInSeconds( TInt64 aDuration ) 
       
   318     {
       
   319     __LOG( "[UPnPDlnaProfiler] CUpnpResParameters::\
       
   320 SetDurationInSeconds" );
       
   321     iDurationInSeconds = aDuration;
       
   322     }
       
   323 
       
   324 // --------------------------------------------------------------------------
       
   325 // CUpnpResParameters::MimeType
       
   326 // --------------------------------------------------------------------------
       
   327 //    
       
   328 const TDesC8& CUpnpResParameters::MimeType() 
       
   329     {
       
   330     if ( iMimetype ) 
       
   331         {
       
   332         return *iMimetype;
       
   333         }
       
   334     
       
   335     return KNullDesC8();
       
   336     }
       
   337 // end of file