omadrm/drmengine/notifier/src/DRMEventAddRemove.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:  Notification Event object base class
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 
       
    20 // INCLUDE FILES
       
    21 #include    "DRMEventAddRemove.h"
       
    22 
       
    23 // EXTERNAL DATA STRUCTURES
       
    24 // EXTERNAL FUNCTION PROTOTYPES  
       
    25 // CONSTANTS
       
    26 // MACROS
       
    27 // LOCAL CONSTANTS AND MACROS
       
    28 // MODULE DATA STRUCTURES
       
    29 // LOCAL FUNCTION PROTOTYPES
       
    30 // FORWARD DECLARATIONS
       
    31 
       
    32 // ============================ MEMBER FUNCTIONS ===============================
       
    33 
       
    34 
       
    35 
       
    36 // -----------------------------------------------------------------------------
       
    37 // CDRMEventAddRemove::NewLC
       
    38 // two phased constructor
       
    39 // -----------------------------------------------------------------------------
       
    40 //
       
    41 EXPORT_C CDRMEventAddRemove* CDRMEventAddRemove::NewLC( TAddRemoveEventStatus aStatus )
       
    42     {
       
    43     CDRMEventAddRemove* self = new (ELeave) CDRMEventAddRemove( aStatus );
       
    44     CleanupStack::PushL( self );
       
    45     return self; 
       
    46     };
       
    47 
       
    48 // -----------------------------------------------------------------------------
       
    49 // CDRMEventAddRemove::NewL
       
    50 // two phased constructor
       
    51 // -----------------------------------------------------------------------------
       
    52 //
       
    53 EXPORT_C CDRMEventAddRemove* CDRMEventAddRemove::NewL( TAddRemoveEventStatus aStatus )
       
    54     {
       
    55     CDRMEventAddRemove* self = NewLC( aStatus );
       
    56     CleanupStack::Pop();
       
    57     return self;
       
    58     };
       
    59 
       
    60 
       
    61 
       
    62 
       
    63 
       
    64 // -----------------------------------------------------------------------------
       
    65 // CDRMEventAddRemove::CDRMEventAddRemove
       
    66 // C++ default constructor can NOT contain any code, that
       
    67 // might leave.
       
    68 // -----------------------------------------------------------------------------
       
    69 //
       
    70 CDRMEventAddRemove::CDRMEventAddRemove(
       
    71     TAddRemoveEventStatus aStatus ) : MDRMEvent( KEventAddRemove ), 
       
    72                                       iContentID( NULL ),
       
    73                                       iStatus( aStatus )
       
    74     {
       
    75     };
       
    76 
       
    77 // Destructor
       
    78 EXPORT_C CDRMEventAddRemove::~CDRMEventAddRemove()
       
    79     {
       
    80     if( iContentID )
       
    81         {
       
    82         delete iContentID;
       
    83         }
       
    84     };
       
    85 
       
    86 
       
    87 
       
    88 // -----------------------------------------------------------------------------
       
    89 // CDRMEventAddRemove::SetContentIDL
       
    90 // Reserves memory for a copy of the content id and releases the old memory
       
    91 // from the object if it already exists
       
    92 // (other items were commented in a header).
       
    93 // -----------------------------------------------------------------------------
       
    94 //
       
    95 EXPORT_C void CDRMEventAddRemove::SetContentIDL( const TDesC8& aContentID )
       
    96     {
       
    97     if( iContentID )
       
    98         {
       
    99         delete iContentID;
       
   100         iContentID = NULL;
       
   101         }
       
   102     iContentID = aContentID.AllocL();
       
   103     };
       
   104 
       
   105 
       
   106 // -----------------------------------------------------------------------------
       
   107 // CDRMEventAddRemove::Status
       
   108 // Returns the status of the object
       
   109 // (other items were commented in a header).
       
   110 // -----------------------------------------------------------------------------
       
   111 //
       
   112 EXPORT_C TAddRemoveEventStatus CDRMEventAddRemove::Status() const
       
   113     {
       
   114     return iStatus;
       
   115     };
       
   116 
       
   117 // -----------------------------------------------------------------------------
       
   118 // CDRMEventAddRemove::GetContentIDL
       
   119 // reserves memory and returns a pointer to this new object
       
   120 // (other items were commented in a header).
       
   121 // -----------------------------------------------------------------------------
       
   122 //
       
   123 EXPORT_C HBufC8* CDRMEventAddRemove::GetContentIDL() const 
       
   124     {
       
   125     return iContentID->AllocL();
       
   126     };
       
   127     
       
   128 // -----------------------------------------------------------------------------
       
   129 // CDRMEventAddRemove::ExternalizeL
       
   130 // Writes the data of the object into the given stream
       
   131 // (other items were commented in a header).
       
   132 // -----------------------------------------------------------------------------
       
   133 //
       
   134 EXPORT_C void CDRMEventAddRemove::ExternalizeL(
       
   135     RWriteStream& aOutput)
       
   136     {
       
   137     TInt outputLength = 0;
       
   138 
       
   139     MDRMEvent::ExternalizeL(aOutput);
       
   140 
       
   141     // get the output length of the HBufC8*
       
   142     outputLength = iContentID->Size();
       
   143     aOutput.WriteInt32L(outputLength);
       
   144 
       
   145     // write out the HBufC8*
       
   146     aOutput.WriteL(*iContentID);
       
   147 
       
   148     // this implementation may need to be changed if the size of the enum changes
       
   149     aOutput.WriteInt8L(iStatus);
       
   150     };
       
   151 
       
   152 
       
   153 // -----------------------------------------------------------------------------
       
   154 // CDRMEventAddRemove::Internalize
       
   155 // Reads the data of the object from the given stream
       
   156 // (other items were commented in a header).
       
   157 // -----------------------------------------------------------------------------
       
   158 //
       
   159 EXPORT_C void CDRMEventAddRemove::InternalizeL(
       
   160     RReadStream& aInput) 
       
   161     {
       
   162     TInt inputLength = 0;
       
   163 
       
   164     MDRMEvent::InternalizeL(aInput);
       
   165 
       
   166     // Read the length of the HBufC8*
       
   167     inputLength = aInput.ReadInt32L();
       
   168 
       
   169     // Reserve the HBufC8*
       
   170     if( !iContentID )
       
   171         {
       
   172         iContentID = HBufC8::NewL(inputLength);
       
   173         }
       
   174     else
       
   175         {
       
   176         iContentID->ReAllocL(inputLength);
       
   177         }
       
   178 
       
   179     TPtr8 inRead(iContentID->Des());
       
   180 
       
   181     // Read the HBufC8*
       
   182     aInput.ReadL(inRead, inputLength); 
       
   183 
       
   184     // this implementation may need to be changed if the size of the enum changes
       
   185     iStatus = static_cast<TAddRemoveEventStatus>(aInput.ReadInt8L());
       
   186     };
       
   187 
       
   188 // End of File