omadrm/drmhelper/src/ConsumeData.cpp
changeset 0 95b198f216e5
child 18 8a03a285ab14
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/omadrm/drmhelper/src/ConsumeData.cpp	Thu Dec 17 08:52:27 2009 +0200
@@ -0,0 +1,146 @@
+/*
+* Copyright (c) 2004 Nokia Corporation and/or its subsidiary(-ies).
+* All rights reserved.
+* This component and the accompanying materials are made available
+* under the terms of "Eclipse Public License v1.0"
+* which accompanies this distribution, and is available
+* at the URL "http://www.eclipse.org/legal/epl-v10.html".
+*
+* Initial Contributors:
+* Nokia Corporation - initial contribution.
+*
+* Contributors:
+*
+* Description:  Implements consume data encapsulation
+*
+*/
+
+
+// INCLUDE FILES
+#include <e32std.h>
+#include "consumedata.h"
+
+// LOCAL CONSTANTS AND MACROS
+
+// ============================ MEMBER FUNCTIONS ===============================
+
+// -----------------------------------------------------------------------------
+// CConsumeData::ConsumeData
+// C++ default constructor can NOT contain any code, that might leave.
+// -----------------------------------------------------------------------------
+//
+CConsumeData::CConsumeData() : CBase()
+    {
+    }
+    
+// -----------------------------------------------------------------------------
+// CConsumeData::~ConsumeData
+// C++ default destructor
+// -----------------------------------------------------------------------------
+//    
+CConsumeData::~CConsumeData()
+    {
+    // If the connection is still open call finish
+    if( iConnectionStatus && iContentURI8 ) 
+        {
+        iRdb.Consume( ContentAccess::EStop, *iContentURI8 );    
+        }
+    
+    // Close the connection to the server:
+    iRdb.Close();
+    
+    // Reset the connection status
+    iConnectionStatus = EFalse;
+        
+    // Delete the content id
+    if( iContentURI8 )
+        {
+        delete iContentURI8;
+        iContentURI8 = NULL;    
+        }
+    }
+    
+
+// -----------------------------------------------------------------------------
+// CConsumeData::NewLC
+// 2-phase constructor
+// -----------------------------------------------------------------------------
+//
+CConsumeData* CConsumeData::NewLC( const TDesC8& aUri )
+    {
+    CConsumeData* self = new (ELeave) CConsumeData();
+    CleanupStack::PushL( self );
+    self->ConstructL( aUri );
+    return self;
+    }
+    
+// -----------------------------------------------------------------------------
+// CConsumeData::NewL
+// 2-phase constructor
+// -----------------------------------------------------------------------------
+//
+CConsumeData* CConsumeData::NewL( const TDesC8& aUri )
+    {
+    CConsumeData* self = NewLC( aUri );
+    CleanupStack::Pop( self );
+    return self;        
+    }    
+
+// -----------------------------------------------------------------------------
+// CConsumeData::Consume
+// -----------------------------------------------------------------------------
+//
+TInt CConsumeData::Consume( const ContentAccess::TIntent& aIntent )
+    {
+    TInt retVal = KErrNone;
+    
+    if( !iConnectionStatus )
+        {
+        return KErrNotReady;    
+        }
+        
+    retVal = iRdb.Consume( aIntent, *iContentURI8 );
+
+    if( aIntent == ContentAccess::EStop )
+        {
+        iRdb.Close();
+        iConnectionStatus = EFalse;    
+        }
+        
+    return retVal;    
+    }
+// -----------------------------------------------------------------------------
+// CConsumeData::CompareUri
+// -----------------------------------------------------------------------------
+//
+TInt CConsumeData::CompareUri( const TDesC8& aUri ) const
+    {
+    if( !iContentURI8 )
+        {
+        return KErrNotReady;    
+        }
+        
+    return iContentURI8->Des().Compare( aUri );
+    }
+
+// -----------------------------------------------------------------------------
+// CConsumeData::ConstructL
+// 2nd phase constructor
+// -----------------------------------------------------------------------------
+//
+void CConsumeData::ConstructL( const TDesC8& aUri )
+    {
+    // Connect the rights client
+    User::LeaveIfError( iRdb.Connect() );
+
+    // Set the connection status
+    iConnectionStatus = ETrue;
+    
+    // copy the url for internal use
+    iContentURI8 = aUri.AllocL();    
+    }
+
+// ========================== OTHER EXPORTED FUNCTIONS =========================
+
+
+//  End of File