wmdrm/wmdrmengine/wmdrmagent/src/wmdrmagentcontent.cpp
changeset 0 95b198f216e5
equal deleted inserted replaced
-1:000000000000 0:95b198f216e5
       
     1 /*
       
     2 * Copyright (c) 2009 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: 
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 
       
    20 // INCLUDE FILES
       
    21 #include <caf.h>
       
    22 #include <bitset.h>
       
    23 #include <attribute.h>
       
    24 #include <caf/attributeset.h>
       
    25 #include <caf/stringattributeset.h>
       
    26 #include <e32test.h>
       
    27 #include <utf.h>
       
    28 #include "wmdrmagentcontent.h"
       
    29 #include "wmdrmagentattributes.h"
       
    30 #include "asf.h"
       
    31 #include "logfn.h"
       
    32 
       
    33 using namespace ContentAccess;
       
    34 
       
    35 // LOCAL FUNCTION PROTOTYPES
       
    36 LOCAL_C TInt MapContentShareMode(TContentShareMode aMode);
       
    37 template<class S>
       
    38 LOCAL_C void PointerArrayResetDestroyAndClose(TAny* aPtr);
       
    39 
       
    40 // ============================= LOCAL FUNCTIONS ===============================
       
    41 
       
    42 // -----------------------------------------------------------------------------
       
    43 // MapContentShareMode
       
    44 // Maps the CAF specific file share mode to the RFs/RFile sharing mode
       
    45 // -----------------------------------------------------------------------------
       
    46 //
       
    47 TInt MapContentShareMode(TContentShareMode aMode)
       
    48     {
       
    49     TInt r = EFileRead | EFileShareAny;
       
    50 
       
    51     switch (aMode)
       
    52         {
       
    53         case EContentShareReadOnly:
       
    54             r = EFileRead | EFileShareReadersOnly;
       
    55             break;
       
    56         case EContentShareReadWrite:
       
    57             r = EFileRead | EFileShareReadersOrWriters;
       
    58             break;
       
    59         case EContentShareExclusive:
       
    60             r = EFileRead | EFileShareExclusive;
       
    61             break;
       
    62         }
       
    63     return r;
       
    64     }
       
    65 
       
    66 // -----------------------------------------------------------------------------
       
    67 // PointerArrayResetDestroyAndClose
       
    68 // Template method used to push RPointerArrays to the cleanup stack. Takes
       
    69 // care of deleting all pointers in the array.
       
    70 // -----------------------------------------------------------------------------
       
    71 //
       
    72 template<class S>
       
    73 void PointerArrayResetDestroyAndClose(TAny* aPtr)
       
    74     {
       
    75     (reinterpret_cast<RPointerArray<S>*>(aPtr))->ResetAndDestroy();
       
    76     (reinterpret_cast<RPointerArray<S>*>(aPtr))->Close();
       
    77     }
       
    78 
       
    79 // ============================ MEMBER FUNCTIONS ===============================
       
    80 
       
    81 // -----------------------------------------------------------------------------
       
    82 // CWmDrmAgentContent::CWmDrmAgentContent
       
    83 // Reset all member variables
       
    84 // -----------------------------------------------------------------------------
       
    85 //
       
    86 CWmDrmAgentContent::CWmDrmAgentContent():
       
    87     iURI(NULL),
       
    88     iAsf(NULL)
       
    89     {
       
    90     LOGFN( "CWmDrmAgentContent::CWmDrmAgentContent" );
       
    91     }
       
    92 
       
    93 // -----------------------------------------------------------------------------
       
    94 // CWmDrmAgentContent::NewL
       
    95 // Two-phased constructors
       
    96 // -----------------------------------------------------------------------------
       
    97 //
       
    98 CWmDrmAgentContent* CWmDrmAgentContent::NewL(const TDesC& aURI, TContentShareMode aShareMode)
       
    99     {
       
   100     LOGFN( "CWmDrmAgentContent::NewL" );
       
   101     CWmDrmAgentContent* self = new (ELeave) CWmDrmAgentContent();
       
   102     CleanupStack::PushL(self);
       
   103     self->ConstructL(aURI, aShareMode);
       
   104     CleanupStack::Pop(self);
       
   105     return self;
       
   106     }
       
   107 
       
   108 // -----------------------------------------------------------------------------
       
   109 // CWmDrmAgentContent::NewLC
       
   110 // Two-phased constructors
       
   111 // -----------------------------------------------------------------------------
       
   112 //
       
   113 CWmDrmAgentContent* CWmDrmAgentContent::NewLC(
       
   114     const TDesC& aUri,
       
   115     TContentShareMode aShareMode)
       
   116     {
       
   117     LOGFN( "CWmDrmAgentContent::NewLC" );
       
   118     CWmDrmAgentContent* self = new (ELeave) CWmDrmAgentContent();
       
   119     CleanupStack::PushL(self);
       
   120     self->ConstructL(aUri, aShareMode);
       
   121     return self;
       
   122     }
       
   123 
       
   124 
       
   125 // -----------------------------------------------------------------------------
       
   126 // CWmDrmAgentContent::NewL
       
   127 // Two-phased constructors
       
   128 // -----------------------------------------------------------------------------
       
   129 //
       
   130 //
       
   131 
       
   132 CWmDrmAgentContent* CWmDrmAgentContent::NewL(RFile& aFile)
       
   133     {
       
   134     LOGFN( "CWmDrmAgentContent::NewL (2)" );
       
   135     CWmDrmAgentContent* self = new (ELeave) CWmDrmAgentContent();
       
   136     CleanupStack::PushL(self);
       
   137     self->ConstructL(aFile);
       
   138     CleanupStack::Pop(self);
       
   139     return self;
       
   140     }
       
   141 
       
   142 // -----------------------------------------------------------------------------
       
   143 // CWmDrmAgentContent::NewLC
       
   144 // Two-phased constructors
       
   145 // -----------------------------------------------------------------------------
       
   146 //
       
   147 //
       
   148 
       
   149 CWmDrmAgentContent* CWmDrmAgentContent::NewLC(RFile& aFile)
       
   150     {
       
   151     LOGFN( "CWmDrmAgentContent::NewLC (2)" );
       
   152     CWmDrmAgentContent* self = new (ELeave) CWmDrmAgentContent();
       
   153     CleanupStack::PushL(self);
       
   154     self->ConstructL(aFile);
       
   155     return self;
       
   156     }
       
   157 
       
   158 
       
   159 
       
   160 // -----------------------------------------------------------------------------
       
   161 // CWmDrmAgentContent::~CWmDrmAgentContent
       
   162 // -----------------------------------------------------------------------------
       
   163 //
       
   164 CWmDrmAgentContent::~CWmDrmAgentContent()
       
   165     {
       
   166     LOGFN( "CWmDrmAgentContent::~CWmDrmAgentContent" );
       
   167     iFile.Close();
       
   168     iFs.Close();
       
   169     delete iURI;
       
   170     delete iAsf;
       
   171     }
       
   172 
       
   173 // -----------------------------------------------------------------------------
       
   174 // CWmDrmAgentContent::ConstructL
       
   175 // Initialize the agent from a URI (file name) and file mode, opens the
       
   176 // the file and takes membership of the handle
       
   177 // -----------------------------------------------------------------------------
       
   178 //
       
   179 void CWmDrmAgentContent::ConstructL(const TDesC& aUri, TContentShareMode aShareMode)
       
   180     {
       
   181     LOGFN( "CWmDrmAgentContent::ConstructL" );
       
   182     iURI = aUri.AllocL();
       
   183     User::LeaveIfError(iFs.Connect());
       
   184     User::LeaveIfError(iFile.Open(iFs, aUri, MapContentShareMode(aShareMode)));
       
   185     iAsf = CAsf::NewL(iFile);
       
   186     }
       
   187 
       
   188 // -----------------------------------------------------------------------------
       
   189 // CWmDrmAgentContent::ConstructL
       
   190 // Initialize the agent from a file handle, duplicates the handle
       
   191 // -----------------------------------------------------------------------------
       
   192 //
       
   193 void CWmDrmAgentContent::ConstructL(RFile& aFile)
       
   194     {
       
   195     TFileName name;
       
   196 
       
   197     LOGFN( "CWmDrmAgentContent::ConstructL (2)" );
       
   198     User::LeaveIfError(iFile.Duplicate(aFile));
       
   199     User::LeaveIfError(iFs.Connect());
       
   200     iFile.Name(name);
       
   201     iURI = name.AllocL();
       
   202     iAsf = CAsf::NewL(iFile);
       
   203     }
       
   204 
       
   205 // -----------------------------------------------------------------------------
       
   206 // CWmDrmAgentContent::OpenContainer
       
   207 // -----------------------------------------------------------------------------
       
   208 //
       
   209 
       
   210 TInt CWmDrmAgentContent::OpenContainer(const TDesC&)
       
   211     {
       
   212     LOGFN( "CWmDrmAgentContent::OpenContainer" );
       
   213     return KErrNotFound;
       
   214     }
       
   215 
       
   216 // -----------------------------------------------------------------------------
       
   217 // CWmDrmAgentContent::CloseContainer
       
   218 // -----------------------------------------------------------------------------
       
   219 //
       
   220 
       
   221 TInt CWmDrmAgentContent::CloseContainer()
       
   222     {
       
   223     LOGFN( "CWmDrmAgentContent::CloseContainer" );
       
   224     return KErrNotFound;
       
   225     }
       
   226 
       
   227 // -----------------------------------------------------------------------------
       
   228 // CWmDrmAgentContent::GetEmbeddedObjectsL
       
   229 // -----------------------------------------------------------------------------
       
   230 //
       
   231 
       
   232 void CWmDrmAgentContent::GetEmbeddedObjectsL(RStreamablePtrArray<CEmbeddedObject>& /*aArray*/)
       
   233     {
       
   234     LOGFN( "CWmDrmAgentContent::GetEmbeddedObjectsL" );
       
   235     User::Leave(KErrNotSupported);
       
   236     }
       
   237 
       
   238 // -----------------------------------------------------------------------------
       
   239 // CWmDrmAgentContent::GetEmbeddedObjectsL
       
   240 // -----------------------------------------------------------------------------
       
   241 //
       
   242 
       
   243 void CWmDrmAgentContent::GetEmbeddedObjectsL(RStreamablePtrArray<CEmbeddedObject>& aArray, TEmbeddedType aType)
       
   244     {
       
   245     LOGFN( "CWmDrmAgentContent::GetEmbeddedObjectsL" );
       
   246     // the only embedded object is the file itself
       
   247     if(aType == EContentObject)
       
   248         {
       
   249         // just get the default object since there is only one content object
       
   250         GetEmbeddedObjectsL(aArray);
       
   251         }
       
   252     }
       
   253 
       
   254 // -----------------------------------------------------------------------------
       
   255 // CWmDrmAgentContent::Search
       
   256 // -----------------------------------------------------------------------------
       
   257 //
       
   258 
       
   259 TInt CWmDrmAgentContent::Search(RStreamablePtrArray<CEmbeddedObject>& /*aArray*/, const TDesC8& /*aMimeType*/, TBool )
       
   260     {
       
   261     LOGFN( "CWmDrmAgentContent::Search" );
       
   262     return KErrNotSupported;
       
   263     }
       
   264 
       
   265 // -----------------------------------------------------------------------------
       
   266 // CWmDrmAgentContent::GetAttribute
       
   267 // -----------------------------------------------------------------------------
       
   268 //
       
   269 
       
   270 TInt CWmDrmAgentContent::GetAttribute(TInt aAttribute, TInt& aValue, const TDesC& aUniqueId)
       
   271     {
       
   272     TInt r = KErrNone;
       
   273     TInt err = KErrNone;
       
   274 
       
   275     LOGFN( "CWmDrmAgentContent::GetAttribute" );
       
   276     TRAP(err, r = TWmDrmAgentAttributes::GetAttributeL(
       
   277               iAsf, aAttribute, aValue, TVirtualPathPtr(*iURI, aUniqueId)));
       
   278     if (err != KErrNone)
       
   279         {
       
   280         r = err;
       
   281         }
       
   282     return r;
       
   283     }
       
   284 
       
   285 // -----------------------------------------------------------------------------
       
   286 // CWmDrmAgentContent::GetAttributeSet
       
   287 // -----------------------------------------------------------------------------
       
   288 //
       
   289 
       
   290 TInt CWmDrmAgentContent::GetAttributeSet(RAttributeSet& aAttributeSet, const TDesC& aUniqueId)
       
   291     {
       
   292     TInt r = KErrNone;
       
   293     TInt err = KErrNone;
       
   294 
       
   295     LOGFN( "CWmDrmAgentContent::GetAttributeSet" );
       
   296     TRAP(err,r = TWmDrmAgentAttributes::GetAttributeSetL(iAsf, aAttributeSet,
       
   297         TVirtualPathPtr(*iURI, aUniqueId)));
       
   298     if (err != KErrNone)
       
   299         {
       
   300         r = err;
       
   301         }
       
   302     return r;
       
   303     }
       
   304 
       
   305 
       
   306 // -----------------------------------------------------------------------------
       
   307 // CWmDrmAgentContent::GetStringAttribute
       
   308 // -----------------------------------------------------------------------------
       
   309 //
       
   310 
       
   311 TInt CWmDrmAgentContent::GetStringAttribute(TInt aAttribute, TDes& aValue, const TDesC& aUniqueId)
       
   312     {
       
   313 
       
   314     TInt r = KErrNone;
       
   315     TInt err = KErrNone;
       
   316 
       
   317     LOGFN( "CWmDrmAgentContent::GetStringAttribute" );
       
   318     TRAP(err, r = TWmDrmAgentAttributes::GetStringAttributeL(iAsf, aAttribute,
       
   319         aValue, TVirtualPathPtr(*iURI, aUniqueId)));
       
   320     if (err != KErrNone)
       
   321         {
       
   322         r = err;
       
   323         }
       
   324     return r;
       
   325 
       
   326     }
       
   327 
       
   328 // -----------------------------------------------------------------------------
       
   329 // CWmDrmAgentContent::GetStringAttributeSet
       
   330 // -----------------------------------------------------------------------------
       
   331 //
       
   332 
       
   333 TInt CWmDrmAgentContent::GetStringAttributeSet(RStringAttributeSet& aStringAttributeSet, const TDesC& aUniqueId)
       
   334     {
       
   335     TInt r = KErrNone;
       
   336     TInt err = KErrNone;
       
   337 
       
   338     LOGFN( "CWmDrmAgentContent::GetStringAttributeSet" );
       
   339     TRAP(err,r = TWmDrmAgentAttributes::GetStringAttributeSetL(
       
   340         iAsf, aStringAttributeSet,
       
   341         TVirtualPathPtr(*iURI, aUniqueId)));
       
   342     if (err != KErrNone)
       
   343         {
       
   344         r = err;
       
   345         }
       
   346     return r;
       
   347 
       
   348     }
       
   349 
       
   350 // -----------------------------------------------------------------------------
       
   351 // CWmDrmAgentContent::AgentSpecificCommand
       
   352 // -----------------------------------------------------------------------------
       
   353 //
       
   354 TInt CWmDrmAgentContent::AgentSpecificCommand(
       
   355     TInt /*aCommand*/,
       
   356     const TDesC8& /*aInputBuffer*/,
       
   357     TDes8& /*aOutputBuffer*/)
       
   358     {
       
   359     LOGFN( "CWmDrmAgentContent::AgentSpecificCommand" );
       
   360     return KErrCANotSupported;
       
   361     }
       
   362 
       
   363 // -----------------------------------------------------------------------------
       
   364 // CWmDrmAgentContent::AgentSpecificCommand
       
   365 // -----------------------------------------------------------------------------
       
   366 //
       
   367 void CWmDrmAgentContent::AgentSpecificCommand(
       
   368     TInt aCommand,
       
   369     const TDesC8& aInputBuffer,
       
   370     TDes8& aOutputBuffer,
       
   371     TRequestStatus& aStatus)
       
   372     {
       
   373     LOGFN( "CWmDrmAgentContent::AgentSpecificCommand (2)" );
       
   374     TRequestStatus *ptr = &aStatus;
       
   375     User::RequestComplete(ptr, AgentSpecificCommand(aCommand, aInputBuffer,
       
   376         aOutputBuffer));
       
   377     }
       
   378 
       
   379 // -----------------------------------------------------------------------------
       
   380 // CWmDrmAgentContent::NotifyStatusChange
       
   381 // -----------------------------------------------------------------------------
       
   382 //
       
   383 void CWmDrmAgentContent::NotifyStatusChange(TEventMask , TRequestStatus& aStatus, const TDesC& )
       
   384     {
       
   385     LOGFN( "CWmDrmAgentContent::NotifyStatusChange" );
       
   386     TRequestStatus* ptr = &aStatus;
       
   387     User::RequestComplete(ptr, KErrCANotSupported);
       
   388     }
       
   389 
       
   390 // -----------------------------------------------------------------------------
       
   391 // CWmDrmAgentContent::CancelNotifyStatusChange
       
   392 // -----------------------------------------------------------------------------
       
   393 //
       
   394 TInt CWmDrmAgentContent::CancelNotifyStatusChange(
       
   395     TRequestStatus& /*aStatus*/,
       
   396     const TDesC& /*aUniqueId*/)
       
   397     {
       
   398     LOGFN( "CWmDrmAgentContent::CancelNotifyStatusChange" );
       
   399     return KErrCANotSupported;
       
   400     }
       
   401 
       
   402 // -----------------------------------------------------------------------------
       
   403 // CWmDrmAgentContent::RequestRights
       
   404 // -----------------------------------------------------------------------------
       
   405 //
       
   406 void CWmDrmAgentContent::RequestRights(TRequestStatus& aStatus, const TDesC& )
       
   407     {
       
   408     LOGFN( "CWmDrmAgentContent::RequestRights" );
       
   409     TRequestStatus* ptr = &aStatus;
       
   410     User::RequestComplete(ptr, KErrCANotSupported);
       
   411     }
       
   412 
       
   413 // -----------------------------------------------------------------------------
       
   414 // CWmDrmAgentContent::CancelRequestRights
       
   415 // -----------------------------------------------------------------------------
       
   416 //
       
   417 TInt CWmDrmAgentContent::CancelRequestRights(
       
   418     TRequestStatus& aStatus,
       
   419     const TDesC& /*aUniqueId*/)
       
   420     {
       
   421     LOGFN( "CWmDrmAgentContent::CancelRequestRights" );
       
   422     TRequestStatus *ptr = &aStatus;
       
   423     User::RequestComplete(ptr, KErrCANotSupported);
       
   424     return KErrCANotSupported;
       
   425     }
       
   426 
       
   427 // -----------------------------------------------------------------------------
       
   428 // CWmDrmAgentContent::DisplayInfoL
       
   429 // -----------------------------------------------------------------------------
       
   430 //
       
   431 void CWmDrmAgentContent::DisplayInfoL(
       
   432     TDisplayInfo /*aDisplayInfo*/,
       
   433     const TDesC& /*aUniqueId*/)
       
   434     {
       
   435     LOGFN( "CWmDrmAgentContent::DisplayInfoL" );
       
   436     User::Leave(KErrCANotSupported);
       
   437     }
       
   438 
       
   439 
       
   440 // -----------------------------------------------------------------------------
       
   441 // CWmDrmAgentContent::SetProperty
       
   442 // Reset all member variables
       
   443 // -----------------------------------------------------------------------------
       
   444 //
       
   445 TInt CWmDrmAgentContent::SetProperty(
       
   446     TAgentProperty /*aProperty*/,
       
   447     TInt /*aValue*/)
       
   448     {
       
   449     LOGFN( "CWmDrmAgentContent::SetProperty" );
       
   450     return KErrCANotSupported;
       
   451     }
       
   452 
       
   453