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 |
// The Supplier API allows agents to publicise the MIME types they are
|
sl@0
|
17 |
// interested in. When those files arrive on the device, message handling
|
sl@0
|
18 |
// applications can check these MIME types and import the file
|
sl@0
|
19 |
// into CAF. The agent transforms the file into a different format
|
sl@0
|
20 |
// for use within the device.
|
sl@0
|
21 |
// In most cases this won't be necessary, since the files will arrive in the
|
sl@0
|
22 |
// same format that they will be used in. However, some agents require the device
|
sl@0
|
23 |
// to protect (encrypt) the content at the moment it arrives; the Supplier
|
sl@0
|
24 |
// API fulfills that role.
|
sl@0
|
25 |
// The classes used in the supply operation are:
|
sl@0
|
26 |
// <code>ContentAccess::CSupplier</code> and instances of <code>ContentAccess::CImportFile</code>.
|
sl@0
|
27 |
// <hr>
|
sl@0
|
28 |
// The <code>ContentAccess::CSupplier</code> is designed to allow several unrelated files to be imported
|
sl@0
|
29 |
// into CAF. It uses its <code>ContentAccess::CAgentResolver</code> member to determine
|
sl@0
|
30 |
// which CA agent should be used to import each file. The <code>CAgentResolver</code> builds
|
sl@0
|
31 |
// a list of all agents when it is created and updates the list if new agents
|
sl@0
|
32 |
// are installed.
|
sl@0
|
33 |
// A typical import session will start with the creation of a <code>CSupplier</code>, e.g.,
|
sl@0
|
34 |
// //Create Supplier
|
sl@0
|
35 |
// CSupplier *mySupplier = CSupplier::NewL();
|
sl@0
|
36 |
// Most applications will have a preference for the directory where output files
|
sl@0
|
37 |
// are to be stored. Usually the first thing to do with the new <code>CSupplier</code> instance
|
sl@0
|
38 |
// is to set the output path.
|
sl@0
|
39 |
// //Set output path for DRM protected content
|
sl@0
|
40 |
// _LIT(KPath,"C:\myOutputFiles");
|
sl@0
|
41 |
// mySupplier->SetOutputDirectoryL(KPath());
|
sl@0
|
42 |
// It is not necessary to set the output path if the application
|
sl@0
|
43 |
// provides output file handles to the agent.
|
sl@0
|
44 |
// <hr>
|
sl@0
|
45 |
// <b> Check that the MIME type is supported </b>
|
sl@0
|
46 |
// Before importing a file into the content access framework, an application
|
sl@0
|
47 |
// should check that the MIME type of the file is supported. Each agent publishes a
|
sl@0
|
48 |
// list of the MIME types it supports. The list is configured in the agent's
|
sl@0
|
49 |
// resource file and can be checked using <code>ContentAccess::CSupplier::IsImportSupported()</code>
|
sl@0
|
50 |
// if(!mySupplier->IsImportSupported(myMimeType))
|
sl@0
|
51 |
// return;
|
sl@0
|
52 |
// <b> Create a CMetaDataList object </b>
|
sl@0
|
53 |
// The <code>CMetaDataList</code> object is used to store any information associated with the import file that
|
sl@0
|
54 |
// may be useful for the agent. These values will be passed to the agent.
|
sl@0
|
55 |
// For example OMA DRM 1.0 files sometimes arrive with the HTTP header
|
sl@0
|
56 |
// <code>X-Oma-Drm-Separate-Delivery</code>. This informs the agent how long before rights are expected
|
sl@0
|
57 |
// for the content. If the rights were expected in 12 seconds it would be something like
|
sl@0
|
58 |
// the following:
|
sl@0
|
59 |
// // Create meta-data array
|
sl@0
|
60 |
// CMetaDataArray *metaDataArray = new (ELeave) CMetaDataArray();
|
sl@0
|
61 |
// CleanupStack::PushL(metaDataArray);
|
sl@0
|
62 |
// // Add any useful information we can think of....
|
sl@0
|
63 |
// metaDataArray->AddL(_L("Content Type"), _L("application/vnd.oma.drm.dm"));
|
sl@0
|
64 |
// metaDataArray->AddL(_L("X-Oma-Drm-Separate-Delivery"), _L("12"));
|
sl@0
|
65 |
// The file is 'written' to CAF using a <code>ContentAccess::CImportFile</code> object.
|
sl@0
|
66 |
// <code>ContentAccess::CSupplier::ImportFile()</code> creates an <code>CImportFile</code> object for importing a file.
|
sl@0
|
67 |
// The parameters supplied indicate whether the agent will create the output files or whether
|
sl@0
|
68 |
// the application using CAF will generate output files for the agent on demand.
|
sl@0
|
69 |
// // Create the import object, passing in the metaDataArray created earlier
|
sl@0
|
70 |
// // The application will supply the output files
|
sl@0
|
71 |
// CImportFile *import = mySupplier->ImportFileL(sourceMimeType, *metaDataArray);
|
sl@0
|
72 |
// The application should now transfer the file to CAF using the <code>CImportFile</code> object.
|
sl@0
|
73 |
// Only one file can be transferred by each instance although several output files
|
sl@0
|
74 |
// may be produced. Applications should create new <code>CImportFile</code> objects in order to import more files.
|
sl@0
|
75 |
// <b> Agents Generating the Output files </b>
|
sl@0
|
76 |
// If the application wants the agent to generate the output files, it should supply a suggested
|
sl@0
|
77 |
// file name in the call to <code>CSupplier::ImportFile()</code>. Even if this parameter is a zero length
|
sl@0
|
78 |
// descriptor, it still indicates that the agent is responsible for generating output files.
|
sl@0
|
79 |
// Agents will create the output files in a directory nominated by the application when it called
|
sl@0
|
80 |
// <code>CSupplier::SetOutputDirectoryL()</code> or they may decide to store the output files in their private
|
sl@0
|
81 |
// directory.
|
sl@0
|
82 |
// Applications should check at the end of the import to find out how many output files were created
|
sl@0
|
83 |
// and where they are stored.
|
sl@0
|
84 |
// <b> Application generating the Output files</b>
|
sl@0
|
85 |
// If no suggested file name is passed to the agent, the application will provide output files for
|
sl@0
|
86 |
// the agent to use. This mechanism allows applications to open files in their own private directory and
|
sl@0
|
87 |
// ask the CAF agent to store the output in those files.
|
sl@0
|
88 |
// The way it works is the same as an any other import operation, the difference is that the call
|
sl@0
|
89 |
// to <code>CImportFile::WriteData()</code> or <code>CImportFile::WriteComplete()</code> may return an error code of
|
sl@0
|
90 |
// <code>KErrCANewFileHandleRequired</code>.
|
sl@0
|
91 |
// This error code indicates that the agent needs a new output file handle in order to continue. The
|
sl@0
|
92 |
// application should open a new output file with write access and call <code>CImportFile::ContinueWithNewOutputFile()</code>
|
sl@0
|
93 |
// to supply the new handle to the agent. It is possible that further handles may be needed, if so
|
sl@0
|
94 |
// <code>CImportFile::ContinueWithNewOutputFile()</code> will return <code>KErrCANewFileHandleRequired</code> and the application should
|
sl@0
|
95 |
// repeat the procedure with another file.
|
sl@0
|
96 |
// The agent must cache its state before returning <code>KErrCANewFileHandleRequired</code>. The application MUST NOT resend
|
sl@0
|
97 |
// the same <code>WriteData()</code> or <code>WriteComplete()</code> command.
|
sl@0
|
98 |
// At the end of the import operation the output files will still be listed regardless of whether
|
sl@0
|
99 |
// they were supplied by the application or the agent.
|
sl@0
|
100 |
// <hr>
|
sl@0
|
101 |
// <code>ContentAccess::CImportFile</code> is the class used to write the file data to CAF.
|
sl@0
|
102 |
// It is created by <code>ContentAccess::CSupplier</code> and can only be used to import a single file.
|
sl@0
|
103 |
// An application should call <code>WriteData()</code> to transfer a field in 'chunks' to the Content
|
sl@0
|
104 |
// Access Framework. Usually this would be something like the following:
|
sl@0
|
105 |
// TFileName fileName;
|
sl@0
|
106 |
// TBuf8<128> data;
|
sl@0
|
107 |
// TInt err = KErrNone;
|
sl@0
|
108 |
// // start importing content
|
sl@0
|
109 |
// while( (source still has data) && (err==KErrNone) )
|
sl@0
|
110 |
// source.read(data);
|
sl@0
|
111 |
// err = import->WriteData(data);
|
sl@0
|
112 |
// // need to supply new file to import to ?
|
sl@0
|
113 |
// while (err == KErrCANewFileHandleRequired)
|
sl@0
|
114 |
// // supply new file in order to continue writing
|
sl@0
|
115 |
// RFile newFile;
|
sl@0
|
116 |
// import->GetSuggestedOutputFileName(fileName);
|
sl@0
|
117 |
// newFile.Open(fileName, EFileWrite);
|
sl@0
|
118 |
// err = import->ContinueWithNewOutputFile(newFile, fileName);
|
sl@0
|
119 |
// newFile.Close();
|
sl@0
|
120 |
// <hr>
|
sl@0
|
121 |
// When all the data is written, the application should call <code>ContentAccess::CImportFile::WriteComplete()</code>, this will
|
sl@0
|
122 |
// let the agent know that all the data has been transferred and allow it to perform any final processing.
|
sl@0
|
123 |
// err = import->WriteComplete();
|
sl@0
|
124 |
// // When application supplies file handles it must always check to see if
|
sl@0
|
125 |
// // the agent needs a new file handle
|
sl@0
|
126 |
// while(err == KErrCANewFileHandleRequired)
|
sl@0
|
127 |
// RFile newFile;
|
sl@0
|
128 |
// import->GetSuggestedOutputFileName(fileName);
|
sl@0
|
129 |
// newFile.Open(fileName, EFileWrite);
|
sl@0
|
130 |
// err = import->ContinueWithNewOutputFile(newFile, filename);
|
sl@0
|
131 |
// // It is possible that the agent needs yet another file handle
|
sl@0
|
132 |
// newFile.Close(); // agent makes a copy so we don't need to keep our file handle
|
sl@0
|
133 |
// At this stage all the agent's work is done, the <code>CImportFile</code> object can be deleted.
|
sl@0
|
134 |
// <hr>
|
sl@0
|
135 |
// When the import is finished the application may wish to check if any output files have
|
sl@0
|
136 |
// been produced. The list of output files is accessed using <code>ContentAccess::CImportFile::OutputFileL()</code>.
|
sl@0
|
137 |
// // loop over all the output files produced
|
sl@0
|
138 |
// for(TInt i =0; i < import->OutputFileCountL(); i++)
|
sl@0
|
139 |
// // Can now retrieve filename, type of file (receipt or content) and
|
sl@0
|
140 |
// // MIME type for the file produced
|
sl@0
|
141 |
// TPtr filename = import->OutputFileL(i).FileName();
|
sl@0
|
142 |
// TOutputType type = import->OutputFileL(i).OutputType();
|
sl@0
|
143 |
// TPtr8 mimetype = import->OutputFileL(i).MimeType();
|
sl@0
|
144 |
// The output files can be either content files or receipts for DRM rights. It is possible that no output
|
sl@0
|
145 |
// files will be generated and the file will be "absorbed" into the agent.
|
sl@0
|
146 |
// Also, it is important to remember that the MIME type and most likely the file extension of the output files are
|
sl@0
|
147 |
// almost certainly different to the MIME type and file extension of the imported file.
|
sl@0
|
148 |
// <hr>
|
sl@0
|
149 |
//
|
sl@0
|
150 |
//
|
sl@0
|
151 |
|
sl@0
|
152 |
/**
|
sl@0
|
153 |
@page CSupplierAPI Importing files into the Content Access Framework
|
sl@0
|
154 |
- @ref SupplierAPI
|
sl@0
|
155 |
- @ref ImportSession
|
sl@0
|
156 |
- @ref ImportCAF
|
sl@0
|
157 |
- @ref Importfile
|
sl@0
|
158 |
- @ref ImportComplete
|
sl@0
|
159 |
- @ref ImportOutput
|
sl@0
|
160 |
code examples given below. For examples with error checking see @ref ExampleSupplier2.
|
sl@0
|
161 |
@section SupplierAPI Supplier API
|
sl@0
|
162 |
@section ImportSession Starting a new import session
|
sl@0
|
163 |
@code
|
sl@0
|
164 |
@endcode
|
sl@0
|
165 |
@code
|
sl@0
|
166 |
@endcode
|
sl@0
|
167 |
@section ImportCAF Preparing to import the file
|
sl@0
|
168 |
@code
|
sl@0
|
169 |
@endcode
|
sl@0
|
170 |
@code
|
sl@0
|
171 |
@endcode
|
sl@0
|
172 |
@section ImportFile Creating the CImportFile object
|
sl@0
|
173 |
@code
|
sl@0
|
174 |
@endcode
|
sl@0
|
175 |
@section Importfile Transferring the file to the Content Access Agent
|
sl@0
|
176 |
@code
|
sl@0
|
177 |
@endcode
|
sl@0
|
178 |
@section ImportComplete Completing the Import
|
sl@0
|
179 |
@code
|
sl@0
|
180 |
@endcode
|
sl@0
|
181 |
@section ImportOutput Output files produced
|
sl@0
|
182 |
@code
|
sl@0
|
183 |
@endcode
|
sl@0
|
184 |
*/
|