os/security/contentmgmt/contentaccessfwfordrm/engineering/dox/HowToContentAPI.dox
author sl@SLION-WIN7.fritz.box
Fri, 15 Jun 2012 03:10:57 +0200
changeset 0 bde4ae8d615e
permissions -rw-r--r--
First public contribution.
sl@0
     1
// Copyright (c) 2006-2009 Nokia Corporation and/or its subsidiary(-ies).
sl@0
     2
// All rights reserved.
sl@0
     3
// This component and the accompanying materials are made available
sl@0
     4
// under the terms of the License "Eclipse Public License v1.0"
sl@0
     5
// which accompanies this distribution, and is available
sl@0
     6
// at the URL "http://www.eclipse.org/legal/epl-v10.html".
sl@0
     7
//
sl@0
     8
// Initial Contributors:
sl@0
     9
// Nokia Corporation - initial contribution.
sl@0
    10
//
sl@0
    11
// Contributors:
sl@0
    12
//
sl@0
    13
// Description:
sl@0
    14
// NOTE: For the purpose of clarity we have ommitted full error checking in the 
sl@0
    15
// <hr>
sl@0
    16
// An example content file is given below. It has a number of content objects
sl@0
    17
// and a number of containers with other containers and content objects inside.
sl@0
    18
// It is likely that each container will have information or meta-data related
sl@0
    19
// to the collection of objects it holds. 
sl@0
    20
// <hr>
sl@0
    21
// The <code>ContentAccess::CContent</code> object encapsulates a single file. It allows an application to look
sl@0
    22
// at the structure of the objects within the file and the attributes of those objects.
sl@0
    23
// There a two ways to create a \c CContent object. The application can specify the URI of the 
sl@0
    24
// content or it can supply an open file handle.
sl@0
    25
// // Create a CContent with a URI
sl@0
    26
// CContent* content = CContent::NewL(uri);
sl@0
    27
// // Create a CContent with an existing file handle
sl@0
    28
// CContent* content = CContent::NewL(aFs, aFile);
sl@0
    29
// Upon creation, \c CContent selects the agent that will handle the file. For 
sl@0
    30
// <hr>
sl@0
    31
// <code>ContentAccess::CContent</code> acts like a cursor, only able to list the contents of one container 
sl@0
    32
// object at any one time. When \c CContent is first opened it views the top level
sl@0
    33
// container within the file. The top level container is actually the file itself. 
sl@0
    34
// This top level container concept applies to all files, regardless of how many 
sl@0
    35
// content or container objects are inside. 
sl@0
    36
// Even a content file such as a JPEG image is a container, it's just that 
sl@0
    37
// the file only has the <code>"DEFAULT"</code> object embedded inside.
sl@0
    38
// So when the example file shown earlier is opened the following objects can be seen
sl@0
    39
// by the \c CContent:
sl@0
    40
// In this top level container there is only one embedded content object visible (the .jpg file) and two
sl@0
    41
// embedded container objects.
sl@0
    42
// // Create an array to store the results of CContent::GetEmbeddedObjectsL()
sl@0
    43
// RStreamablePtrArray<CEmbeddedObject> myArray;
sl@0
    44
// CleanupClosePushL(myArray);
sl@0
    45
// // Get the embedded content objects in the current container
sl@0
    46
// content->GetEmbeddedObjectsL(myArray, EContentObject); 
sl@0
    47
// i = myArray.Count();  // One content object
sl@0
    48
// // clear the contents of the array
sl@0
    49
// myArray.ResetAndDestroy();
sl@0
    50
// // Get the number of container objects in the current container
sl@0
    51
// content->GetEmbeddedObjectsL(myArray, EContainerObject); 
sl@0
    52
// i = myArray.Count(); // Two container objects
sl@0
    53
// // clear the contents of the array
sl@0
    54
// myArray->ResetAndDestroy();
sl@0
    55
// <hr>
sl@0
    56
// To investigate the objects inside a container \c CContent must first open the container. 
sl@0
    57
// This changes <code>CContent</code>'s focus from the current container to the container specified in
sl@0
    58
// the <code>ContentAccess::CContent::OpenContainer()</code> function.
sl@0
    59
// <b> Opening Container 1 from the top level of the file </b>
sl@0
    60
// // Get the container objects in the top level of the file
sl@0
    61
// content->GetEmbeddedObjectsL(myArray, EContainerObject);
sl@0
    62
// // Find the Unique Id of the first container
sl@0
    63
// TPtrC UniqueId = myArray[0]->UniqueId();
sl@0
    64
// // Open the first container
sl@0
    65
// content->OpenContainer(UniqueId);
sl@0
    66
// Now \c CContent can see the contents of Container 1:
sl@0
    67
// At this point, listing the objects that \c CContent can see gives six MP3
sl@0
    68
// files and one container object.
sl@0
    69
// // Get the embedded content objects in the current container
sl@0
    70
// content->GetEmbeddedObjectsL(myArray, EContentObject); 
sl@0
    71
// i = myArray.Count();  // Six content objects
sl@0
    72
// myArray.ResetAndDestroy();
sl@0
    73
// // Get the number of container objects in the current container
sl@0
    74
// content->GetEmbeddedObjectsL(myArray, EContainerObject); 
sl@0
    75
// i = myArray.Count(); // One container object
sl@0
    76
// myArray.ResetAndDestroy();
sl@0
    77
// <b> Opening Container 1.1 from Container 1</b>
sl@0
    78
// The same process can be followed again to see the contents of Container 1.1
sl@0
    79
// // Get the array of container objects in the current container
sl@0
    80
// content->GetEmbeddedObjectsL(myArray, EContainerObject);
sl@0
    81
// // Find the Unique Id of the first container within Container 1
sl@0
    82
// TPtrC UniqueId = myArray[0]->UniqueId();
sl@0
    83
// // Open Container 1.1
sl@0
    84
// content->OpenContainer(UniqueId);
sl@0
    85
// myArray.ResetAndDestroy();
sl@0
    86
// // Can now see two content objects (the MOV file and the TXT file)
sl@0
    87
// content->GetEmbeddedObjectsL(myArray, EContentObject);
sl@0
    88
// i = myArray.Count(); 
sl@0
    89
// myArray.ResetAndDestroy();
sl@0
    90
// // Zero container objects
sl@0
    91
// content->GetEmbeddedObjectsL(myArray, EContentObject);
sl@0
    92
// i = myArray.Count(); 
sl@0
    93
// myArray.ResetAndDestroy();
sl@0
    94
// <hr>
sl@0
    95
// To look once more at the contents of the container that encloses the current container
sl@0
    96
// the <code>ContentAccess::CContent::CloseContainer()</code> function should be used.
sl@0
    97
// Continuing our example, if we close the Container 1.1 we are left viewing
sl@0
    98
// Container 1 again.
sl@0
    99
// // Close Container 1.1
sl@0
   100
// Econtent->CloseContainer();
sl@0
   101
// // Get the embedded content objects in the current container
sl@0
   102
// content->GetEmbeddedObjectsL(myArray, EContentObject); 
sl@0
   103
// i = myArray.Count();  // Six content objects
sl@0
   104
// myArray.ResetAndDestroy();
sl@0
   105
// // Get the number of container objects in the current container
sl@0
   106
// content->GetEmbeddedObjectsL(myArray, EContainerObject); 
sl@0
   107
// i = myArray.Count(); // One container object
sl@0
   108
// myArray.ResetAndDestroy();
sl@0
   109
// <hr>
sl@0
   110
// If an application wants to find all the content with a particular MIME
sl@0
   111
// type within a file it should use <code>ContentAccess::CContent::Search()</code>.
sl@0
   112
// This function will produce a list of all content objects with the specified
sl@0
   113
// MIME type that are stored under the current container.
sl@0
   114
// // Create an array for storing the result of the search
sl@0
   115
// RStreamablePtrArray<CEmbeddedObject> myArray;
sl@0
   116
// CleanupClosePushL(myArray);
sl@0
   117
// // Get all MP3 files in Container 1 
sl@0
   118
// content->Search(myArray, _L("mpeg/audio"), EFalse);
sl@0
   119
// // Do something with results
sl@0
   120
// // Cleanup
sl@0
   121
// CleanupStack::PopAndDestroy(1);
sl@0
   122
// <hr>
sl@0
   123
// The functions described earlier can be used to locate a particular content
sl@0
   124
// object within a file. <code>ContentAccess::CContent::OpenContentL()</code> can be used to 
sl@0
   125
// read the content object. The \c UniqueId parameter can be used to identify
sl@0
   126
// a particular object within the file.
sl@0
   127
// The call to <code>ContentAccess::CContent::OpenContentL()</code> will leave if the intent 
sl@0
   128
// is not permitted. This could occur if the file is DRM protected but no 
sl@0
   129
// rights are present. 
sl@0
   130
// If the file is DRM protected and the call to <code>OpenContentL()</code> succeeds, the rights 
sl@0
   131
// are not consumed at this point. CAF just checks that it is possible to use the 
sl@0
   132
// content.
sl@0
   133
// // Open the content object specified by uniqueId with the EPlay Intent
sl@0
   134
// CData* data = content->OpenContentL(EPlay, uniqueId);
sl@0
   135
// If the application already knows the URI and unique Id of the content object 
sl@0
   136
// it wants to read from, it can create a \c CData object directly. 
sl@0
   137
// CData* data = CData::NewL(TVirtualPathPtr(uri, uniqueId), EPlay, EContentShareReadOnly);
sl@0
   138
// Once the \c CData object has been constructed, it allows the content object to be used
sl@0
   139
// as if it were a standalone unprotected file. The client must call <code>ContentAccess::CData::ExecuteIntent()</code> 
sl@0
   140
// when the rights should be consumed. If the file is not DRM protected, the call 
sl@0
   141
// will be ignored by the agent handling the file.
sl@0
   142
// TBuf8 <256> buf;
sl@0
   143
// data->ExecuteIntent(EPlay);
sl@0
   144
// data->Seek(SomePosition,ESEEK_START);
sl@0
   145
// data->Read(buf);
sl@0
   146
// There are several overloaded versions of the <code>ContentAccess::CData::Read()</code> function. Only one is illustrated
sl@0
   147
// above for example purposes.
sl@0
   148
// <hr>
sl@0
   149
// The \c CContent interface supports notification requests for content objects within files. The
sl@0
   150
// events for which an application can request notification are given by the enumeration <code>ContentAccess::TEventMask</code>.
sl@0
   151
// The following example requests and cancels notification for rights becoming available:
sl@0
   152
// // Request notification when rights become available for a particular content object 
sl@0
   153
// content->NotifyStatusChange(ERightsAvailable, status, uniqueId);
sl@0
   154
// // Cancel notification request 
sl@0
   155
// content->CancelNotifyStatusChange(status, uniqueId);
sl@0
   156
// <hr>
sl@0
   157
// There are two functions available that give the application some control over the rights: 
sl@0
   158
// - <b> Request Rights </b> 
sl@0
   159
// \n\n
sl@0
   160
// <code>ContentAccess::CContent::RequestRights()</code> allows the application to ask the agent to undertake
sl@0
   161
// whatever steps are necessary to obtain rights for the given content object. Some agents
sl@0
   162
// may not support this mechanism, in which case they will return <code>KErrCANotSupported</code>.
sl@0
   163
// \n\n
sl@0
   164
// The request rights call includes an \c TRequestStatus parameter, which allows the application to
sl@0
   165
// be notified of the outcome of the rights request.
sl@0
   166
// content->RequestRights(status, uniqueId);
sl@0
   167
// \n\n
sl@0
   168
// - <b> Display Info </b>
sl@0
   169
// \n\n
sl@0
   170
// <code>ContentAccess::CContent::DisplayInfoL()</code> allows the application to ask the agent to display
sl@0
   171
// the file and/or rights information for the given content object. The call returns when
sl@0
   172
// the display is dismissed.
sl@0
   173
// \n\n
sl@0
   174
// Some agents may not support this mechanism, in which case they will leave with <code>KErrCANotSupported</code>.
sl@0
   175
// \n\n
sl@0
   176
// content->DisplayInfoL(EFileProperties, uniqueId);
sl@0
   177
// <hr>
sl@0
   178
// <hr>
sl@0
   179
// 
sl@0
   180
//
sl@0
   181
sl@0
   182
/**
sl@0
   183
 @page CContentAPI Consumer API (Browsing and reading from content files)
sl@0
   184
 - @ref ExampleFile
sl@0
   185
 - @ref CreatingCContent
sl@0
   186
 - @ref Listing
sl@0
   187
 - @ref OpeningContainer
sl@0
   188
 - @ref ClosingContainer
sl@0
   189
 - @ref Searching
sl@0
   190
 - @ref CAFCData
sl@0
   191
 - @ref ContentNotification
sl@0
   192
 - @ref ContentRights
sl@0
   193
 - @ref AgentResolution 
sl@0
   194
 code examples given below. For examples with error checking see @ref ExampleReadWithErrCheck.
sl@0
   195
 @section ExampleFile An Example Content File
sl@0
   196
 @image html DRMFile1.gif
sl@0
   197
 @section CreatingCContent Creating a CContent Object
sl@0
   198
 @code
sl@0
   199
 @endcode
sl@0
   200
 @code
sl@0
   201
 @endcode
sl@0
   202
 details on how this selection is done see @ref AgentResolution.
sl@0
   203
 @section Listing Listing objects within a container
sl@0
   204
 @image html DRMFile2.gif
sl@0
   205
 @code
sl@0
   206
 @endcode
sl@0
   207
 @section OpeningContainer Opening a container
sl@0
   208
 @code
sl@0
   209
 @endcode
sl@0
   210
 @image html DRMFile3.gif
sl@0
   211
 @code
sl@0
   212
 @endcode
sl@0
   213
 @code
sl@0
   214
 @endcode
sl@0
   215
 @image html DRMFile4.gif
sl@0
   216
 @section ClosingContainer Closing a Container
sl@0
   217
 @code
sl@0
   218
 @endcode
sl@0
   219
 @image html DRMFile3.gif
sl@0
   220
 @section Searching Searching for a MIME type within a file
sl@0
   221
 @code
sl@0
   222
 @endcode
sl@0
   223
 @section CAFCData Reading data from a content object
sl@0
   224
 @code
sl@0
   225
 @endcode
sl@0
   226
 @code
sl@0
   227
 @endcode
sl@0
   228
 @code
sl@0
   229
 @endcode
sl@0
   230
 @section ContentNotification Content Object Notifications
sl@0
   231
 @code
sl@0
   232
 @endcode
sl@0
   233
 @section ContentRights Handling Rights for DRM content
sl@0
   234
 @code
sl@0
   235
 @endcode
sl@0
   236
 @code
sl@0
   237
 @endcode
sl@0
   238
 @section AgentResolution Agent resolution during CContent object creation
sl@0
   239
 @li During the creation of a CContent object an instance of the internal object CAgentResolver is created.
sl@0
   240
 @li CAgentResolver uses ECOM to identifier all the Content Access Agents (CAAs) on the system. An instance of CAgentInfo is created for each CAA found. CAgentInfo contains supplier and consumer MIME types as well as the CAA plug-in details.
sl@0
   241
 @li When a URI is supplied to CContent::NewL() and it contains a path for the private directory of one of the agent's then that CAA is used. For RFile no private directory exists so this check cannot be performed.
sl@0
   242
 @li If a private directory cannot be obtained from the URI or an RFile was supplied to CContent::NewL() each CAA plug-in identified by CAgentResolver is loaded in turn. 
sl@0
   243
 @li CAgentResolver obtains a CAgentManager object from each CAA in turn and calls IsRecognized() allowing the agent implementation to determine if it can support the file.
sl@0
   244
 @li If no CAA responds the default F32 CAA is used in to open the file as it is assumed to be unprotected content.
sl@0
   245
 @li Note: The MIME types loaded into CAgentInfo are not used for Agent Resolution but are utilized in file type recognition under Application Architecture recognizer framework.
sl@0
   246
*/