omadrm/drmengine/server/src/DRMXOma.cpp
changeset 0 95b198f216e5
equal deleted inserted replaced
-1:000000000000 0:95b198f216e5
       
     1 /*
       
     2 * Copyright (c) 2004 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:  Datatype for the X-Oma header data
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 
       
    20 // INCLUDE FILES
       
    21 #include <s32strm.h>
       
    22 #include "DRMXOma.h"
       
    23 
       
    24 // EXTERNAL DATA STRUCTURES
       
    25 
       
    26 // EXTERNAL FUNCTION PROTOTYPES  
       
    27 
       
    28 // CONSTANTS
       
    29 
       
    30 // MACROS
       
    31 
       
    32 // LOCAL CONSTANTS AND MACROS
       
    33 
       
    34 // MODULE DATA STRUCTURES
       
    35 
       
    36 // LOCAL FUNCTION PROTOTYPES
       
    37 
       
    38 // FORWARD DECLARATIONS
       
    39 
       
    40 // ============================= LOCAL FUNCTIONS ===============================
       
    41 // ============================ MEMBER FUNCTIONS ===============================
       
    42 
       
    43 // -----------------------------------------------------------------------------
       
    44 // CDRMXOma::NewLC
       
    45 // Two-phased constructor.
       
    46 // -----------------------------------------------------------------------------
       
    47 //
       
    48 CDRMXOma* CDRMXOma::NewLC( const TDesC8& aContentID,
       
    49                            const TTime& aTimeStamp,
       
    50                            const TTimeIntervalSeconds& aWaitTime )
       
    51     {
       
    52     CDRMXOma* self = new( ELeave ) CDRMXOma( aTimeStamp, aWaitTime );
       
    53     CleanupStack::PushL( self );
       
    54     self->ConstructL( aContentID );
       
    55     
       
    56     return self;    
       
    57     };
       
    58 
       
    59 
       
    60 // -----------------------------------------------------------------------------
       
    61 // CDRMXOma::NewL
       
    62 // Two-phased constructor.
       
    63 // -----------------------------------------------------------------------------
       
    64 //
       
    65 CDRMXOma* CDRMXOma::NewL( const TDesC8& aContentID,
       
    66                           const TTime& aTimeStamp,
       
    67                           const TTimeIntervalSeconds& aWaitTime )
       
    68     {
       
    69     CDRMXOma* self = NewLC( aContentID, 
       
    70                             aTimeStamp, aWaitTime );
       
    71     CleanupStack::Pop();
       
    72     
       
    73     return self;
       
    74     };        
       
    75 
       
    76 // -----------------------------------------------------------------------------
       
    77 // CDRMXOma::NewLC
       
    78 // Two-phased constructor.
       
    79 // -----------------------------------------------------------------------------
       
    80 //
       
    81 CDRMXOma* CDRMXOma::NewLC()
       
    82     {
       
    83     CDRMXOma* self = new( ELeave ) CDRMXOma();
       
    84     CleanupStack::PushL( self );
       
    85     
       
    86     return self;    
       
    87     };
       
    88 
       
    89 
       
    90 // -----------------------------------------------------------------------------
       
    91 // CDRMXOma::NewL
       
    92 // Two-phased constructor.
       
    93 // -----------------------------------------------------------------------------
       
    94 //
       
    95 CDRMXOma* CDRMXOma::NewL()
       
    96     {
       
    97     CDRMXOma* self = NewLC();
       
    98     CleanupStack::Pop();
       
    99     
       
   100     return self;
       
   101     };          
       
   102 
       
   103 // -----------------------------------------------------------------------------
       
   104 // Default Constructor - First phase.
       
   105 // -----------------------------------------------------------------------------
       
   106 //
       
   107 CDRMXOma::CDRMXOma( const TTime& aTimeStamp, 
       
   108                    const TTimeIntervalSeconds& aWaitTime ) :
       
   109     iTimeStamp( aTimeStamp ),
       
   110     iWaitTime( aWaitTime )
       
   111     {
       
   112     
       
   113     }; 
       
   114 
       
   115 // -----------------------------------------------------------------------------
       
   116 // Default Constructor - First phase.
       
   117 // -----------------------------------------------------------------------------
       
   118 //
       
   119 CDRMXOma::CDRMXOma()
       
   120     {
       
   121     
       
   122     }; 
       
   123 
       
   124 // -----------------------------------------------------------------------------
       
   125 // Destructor
       
   126 // -----------------------------------------------------------------------------
       
   127 //
       
   128 CDRMXOma::~CDRMXOma()
       
   129     {
       
   130     if( iContentID )
       
   131         {
       
   132         delete iContentID;
       
   133         iContentID = NULL;
       
   134         }        
       
   135     };
       
   136         
       
   137         
       
   138 // -----------------------------------------------------------------------------
       
   139 // CDRMXOma::ContentID
       
   140 // -----------------------------------------------------------------------------
       
   141 //        
       
   142 const TDesC8& CDRMXOma::ContentID() const
       
   143     {
       
   144     return *iContentID;
       
   145     };
       
   146 
       
   147 // -----------------------------------------------------------------------------
       
   148 // CDRMXOma::TimeStamp
       
   149 // -----------------------------------------------------------------------------
       
   150 //    
       
   151 const TTime& CDRMXOma::TimeStamp() const
       
   152     {
       
   153     return iTimeStamp;
       
   154     };
       
   155 
       
   156 // -----------------------------------------------------------------------------
       
   157 // CDRMXOma::WaitTime
       
   158 // -----------------------------------------------------------------------------
       
   159 //    
       
   160 const TTimeIntervalSeconds& CDRMXOma::WaitTime() const
       
   161     {
       
   162     return iWaitTime;
       
   163     };
       
   164 
       
   165 // -----------------------------------------------------------------------------
       
   166 // CDRMXOma::SetContentIDL
       
   167 // -----------------------------------------------------------------------------
       
   168 //         
       
   169 void CDRMXOma::SetContentIDL( const TDesC8& aContentID )
       
   170     {
       
   171     HBufC8* newContentID = aContentID.AllocL();
       
   172     
       
   173     if( iContentID )
       
   174         {
       
   175         delete iContentID;
       
   176         iContentID = NULL;
       
   177         }
       
   178     iContentID = newContentID;    
       
   179     };
       
   180     
       
   181 // -----------------------------------------------------------------------------
       
   182 // CDRMXOma::SetTimeStampL
       
   183 // -----------------------------------------------------------------------------
       
   184 //         
       
   185 void CDRMXOma::SetTimeStampL( const TTime& aTimeStamp )
       
   186     {
       
   187     iTimeStamp = aTimeStamp;    
       
   188     };    
       
   189 
       
   190 // -----------------------------------------------------------------------------
       
   191 // CDRMXOma::SetWaitTimeL
       
   192 // -----------------------------------------------------------------------------
       
   193 //         
       
   194 void CDRMXOma::SetWaitTimeL( const TTimeIntervalSeconds& aWaitTime )
       
   195     {
       
   196     iWaitTime = aWaitTime;    
       
   197     }; 
       
   198 
       
   199 // -----------------------------------------------------------------------------
       
   200 // CDRMXOma::ExternalizeL
       
   201 // -----------------------------------------------------------------------------
       
   202 // 
       
   203 void CDRMXOma::ExternalizeL( RWriteStream& aStream ) const
       
   204     {
       
   205     TInt dataLength = 0;
       
   206     
       
   207     // Write the ContentID
       
   208     dataLength = 0;
       
   209     if( iContentID )
       
   210         {
       
   211         dataLength = iContentID->Length();
       
   212         }
       
   213     aStream.WriteInt32L( dataLength );
       
   214     
       
   215     if( dataLength )
       
   216         {
       
   217         aStream.WriteL( iContentID->Des() );        
       
   218         }
       
   219     
       
   220     // Write the time stamp
       
   221     WriteInt64L( iTimeStamp.Int64(), aStream );
       
   222     
       
   223     // write the wait time
       
   224     aStream.WriteInt32L( iWaitTime.Int() );
       
   225     };
       
   226 
       
   227 // -----------------------------------------------------------------------------
       
   228 // CDRMXOma::InternalizeL
       
   229 // -----------------------------------------------------------------------------
       
   230 // 
       
   231 void CDRMXOma::InternalizeL( RReadStream& aStream )
       
   232     {
       
   233     TInt64 timeData = 0;    
       
   234     TInt dataLength = 0;
       
   235     HBufC8* dataPart = 0;
       
   236     TPtr8 dataBuffer(NULL,0,0);
       
   237     TPtr16 dataBuffer2(NULL,0,0);
       
   238     
       
   239     // Read the ContentID
       
   240     dataLength = aStream.ReadInt32L();
       
   241     
       
   242     if( dataLength )
       
   243         {
       
   244         // Reserve a new buffer:
       
   245         dataPart = HBufC8::NewMaxLC( dataLength );
       
   246         
       
   247         // Set the read buffer:
       
   248         dataBuffer.Set(const_cast<TUint8*>(dataPart->Ptr()), 0, dataLength);
       
   249         
       
   250         // Read the data:
       
   251         aStream.ReadL( dataBuffer );
       
   252         
       
   253         // Pop the buffer 
       
   254         CleanupStack::Pop(); // dataPart
       
   255                 
       
   256         // If an old content identifier exists delete it        
       
   257         if( iContentID )
       
   258             {
       
   259             delete iContentID;
       
   260             iContentID = NULL;
       
   261             }
       
   262         
       
   263         // assign the new content id
       
   264         iContentID = dataPart;    
       
   265         }
       
   266     else
       
   267         {
       
   268         // If an old content identifier exists delete it 
       
   269         if( iContentID )
       
   270             {
       
   271             delete iContentID;
       
   272             iContentID = NULL;
       
   273             }        
       
   274         }           
       
   275         
       
   276     // The Time stamp
       
   277     ReadInt64L( timeData, aStream );
       
   278     iTimeStamp = timeData;    
       
   279                    
       
   280     // The time interval                
       
   281     iWaitTime =  aStream.ReadInt32L();               
       
   282     };   
       
   283 
       
   284 // -----------------------------------------------------------------------------
       
   285 // CDRMXOma::Size
       
   286 // -----------------------------------------------------------------------------
       
   287 // 
       
   288 TInt CDRMXOma::Size() const
       
   289     {
       
   290     TInt size = 0;
       
   291     
       
   292     // Content identifier of the content
       
   293     size += sizeof(TInt32);
       
   294     
       
   295     if( iContentID )
       
   296         {
       
   297         size += iContentID->Size();
       
   298         }
       
   299         
       
   300     // Issuer of the rights
       
   301     size += sizeof(TTime);
       
   302         
       
   303     // Content name
       
   304     size += sizeof(TTimeIntervalSeconds);
       
   305     
       
   306     return size;
       
   307     };    
       
   308  
       
   309 // -----------------------------------------------------------------------------
       
   310 // CDRMXOma::ConstructL
       
   311 // Second phase constructor
       
   312 // -----------------------------------------------------------------------------
       
   313 // 
       
   314 void CDRMXOma::ConstructL( const TDesC8& aContentID )
       
   315     {
       
   316     iContentID = aContentID.AllocL();
       
   317     };                
       
   318 
       
   319 
       
   320 // -----------------------------------------------------------------------------
       
   321 // CDRMXOma::WriteInt64L
       
   322 // -----------------------------------------------------------------------------
       
   323 //
       
   324 void CDRMXOma::WriteInt64L( const TInt64& aWrite, RWriteStream& aStream ) const
       
   325     {
       
   326     TPtr8 output( reinterpret_cast<TUint8*>(const_cast<TInt64*>(&aWrite)), 
       
   327                   sizeof(TInt64), sizeof(TInt64) );
       
   328         
       
   329     aStream.WriteL( output, sizeof(TInt64) );
       
   330     }
       
   331 
       
   332 // -----------------------------------------------------------------------------
       
   333 // CCDRMXOma::ReadInt64L
       
   334 // -----------------------------------------------------------------------------
       
   335 //
       
   336 void CDRMXOma::ReadInt64L( TInt64& aRead, RReadStream& aStream )
       
   337     {
       
   338     TPtr8 input( reinterpret_cast<TUint8*>(&aRead), 0, sizeof(TInt64) );
       
   339     
       
   340     aStream.ReadL( input, sizeof(TInt64) );    
       
   341     };
       
   342             
       
   343 // End of File