First public contribution.
2 * Copyright (c) 2003-2009 Nokia Corporation and/or its subsidiary(-ies).
4 * This component and the accompanying materials are made available
5 * under the terms of the License "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".
9 * Initial Contributors:
10 * Nokia Corporation - initial contribution.
19 #include <caf/content.h>
22 #include <caf/agentfactory.h>
23 #include "agentinfo.h"
24 #include <caf/agentinterface.h>
25 #include <caf/attributeset.h>
26 #include <caf/agent.h>
27 #include <caf/virtualpath.h>
28 #include <caf/agentfactory.h>
29 #include <caf/caferr.h>
32 #include <caf/attribute.h>
33 #include <caf/bitset.h>
36 using namespace ContentAccess;
38 EXPORT_C CContent* CContent::NewLC(const TDesC& aURI)
40 return CContent::NewLC(aURI, EContentShareReadOnly);
43 EXPORT_C CContent* CContent::NewL(const TDesC& aURI)
45 return CContent::NewL(aURI, EContentShareReadOnly);
48 EXPORT_C CContent* CContent::NewLC(const TDesC& aURI, TContentShareMode aShareMode)
50 CContent* self = new(ELeave) CContent();
51 CleanupStack::PushL(self);
52 self->ConstructL(aURI, aShareMode);
56 EXPORT_C CContent* CContent::NewL(const TDesC& aURI, TContentShareMode aShareMode)
58 CContent* self=CContent::NewLC(aURI, aShareMode);
59 CleanupStack::Pop(self);
63 EXPORT_C CContent* CContent::NewLC(RFile& aFile)
65 CContent* self = new(ELeave) CContent();
66 CleanupStack::PushL(self);
67 self->ConstructL(aFile);
71 EXPORT_C CContent* CContent::NewL(RFile& aFile)
73 CContent* self=CContent::NewLC(aFile);
74 CleanupStack::Pop(self);
78 #ifdef SYMBIAN_ENABLE_SDP_WMDRM_SUPPORT
80 EXPORT_C CContent* CContent::NewLC(const TDesC8& aHeaderData)
82 CContent* self = new(ELeave) CContent();
83 CleanupStack::PushL(self);
84 self->ConstructL(aHeaderData);
88 EXPORT_C CContent* CContent::NewL(const TDesC8& aHeaderData)
90 CContent* self=CContent::NewLC(aHeaderData);
91 CleanupStack::Pop(self);
95 #endif //#ifdef SYMBIAN_ENABLE_SDP_WMDRM_SUPPORT
97 CContent::CContent() : iDefaultVirtualPath(KNullDesC(), KDefaultContentObject())
101 CContent::~CContent()
103 delete iAgentContent;
111 #ifdef SYMBIAN_ENABLE_SDP_WMDRM_SUPPORT
113 #endif //#ifdef SYMBIAN_ENABLE_SDP_WMDRM_SUPPORT
115 // Finished with agent, this closes ECOM handle
116 delete iAgentFactory;
117 REComSession::FinalClose();
121 void CContent::ConstructL(RFile &aFile)
123 // Make our own copy of the file handle
124 User::LeaveIfError(iFile.Duplicate(aFile));
126 // Rewind the file pointer
127 #ifdef SYMBIAN_ENABLE_64_BIT_FILE_SERVER_API
131 #endif //SYMBIAN_ENABLE_64_BIT_FILE_SERVER_API
133 iFile.Seek(ESeekStart, pos);
135 // For case where CAF is built with an RFile
136 CAgentResolver* resolver = CAgentResolver::NewLC(EFalse);
138 // Find the agent who handles the file
139 CAgentInfo& agentInfo = resolver->ResolveFileL(iFile);
141 // copy the agent name and Uid
142 iAgent = agentInfo.Agent();
144 // Construct the agent factory (ECOM handle)
145 iAgentFactory = CAgentFactory::NewL(iAgent.ImplementationUid());
147 // Construct the CAgentContent object
148 iAgentContent = iAgentFactory->CreateContentBrowserL(iFile);
150 // Finished with resolver (and the agentInfo object it owns)
151 CleanupStack::PopAndDestroy(resolver);
154 void CContent::ConstructL(const TDesC& aURI, TContentShareMode aShareMode)
156 iShareMode = aShareMode;
158 // Create the agent resolver which will contains a reference to
159 // the agent responsible for this piece of content
160 CAgentResolver* resolver = CAgentResolver::NewLC(EFalse);
162 // Create a temporary buffer used to store the translated version of the URI
163 HBufC* actualUri = HBufC::NewLC(aURI.Length() + KMaxSIDLength);
164 TPtr uri = actualUri->Des();
166 // Set the TVirtualPathPtr to point to the URI supplied,
167 // this will decode any combined URI into the actual URI and uniqueId
168 // for use in subsequent functions
169 TVirtualPathPtr contentVirtualPath = aURI;
171 // Find the agent who handles the file and translate the URI if it is pointing to a private directory
172 CAgentInfo& agentInfo = resolver->ResolveFileL(contentVirtualPath.URI(), uri, iShareMode);
174 // Set the iVirtualPath to point to the translated URI and the uniqueId
175 iVirtualPath = CVirtualPath::NewL(*actualUri, contentVirtualPath.UniqueId());
177 iDefaultVirtualPath = *iVirtualPath;
179 // Copy the agent name and Uid
180 iAgent = agentInfo.Agent();
182 // Construct the agent factory (ECOM handle)
183 iAgentFactory = CAgentFactory::NewL(iAgent.ImplementationUid());
185 // Construct the agent content browser
186 iAgentContent = iAgentFactory->CreateContentBrowserL(uri, iShareMode);
188 // Finished with resolver and the CAgentInfo object it owns
189 CleanupStack::PopAndDestroy(2, resolver); // actualUri
192 #ifdef SYMBIAN_ENABLE_SDP_WMDRM_SUPPORT
194 void CContent::ConstructL(const TDesC8& aHeaderData)
196 if(aHeaderData.Length() <= 0)
198 User::Leave(KErrMissingWmdrmHeaderData);
201 iHeaderData = aHeaderData.AllocL();
203 CAgentResolver* resolver = CAgentResolver::NewLC(EFalse);
205 // Find the agent who handles the file
206 CAgentInfo& agentInfo = resolver->ResolveFileL(aHeaderData);
208 // copy the agent name and Uid
209 iAgent = agentInfo.Agent();
211 // Construct the agent factory (ECOM handle)
212 iAgentFactory = CAgentFactory::NewL(iAgent.ImplementationUid());
213 // Construct the CAgentContent object
214 iAgentContent = iAgentFactory->CreateContentBrowserL(aHeaderData);
216 // Finished with resolver (and the agentInfo object it owns)
217 CleanupStack::PopAndDestroy(resolver);
220 #endif //#ifdef SYMBIAN_ENABLE_SDP_WMDRM_SUPPORT
222 EXPORT_C TInt CContent::OpenContainer(const TDesC &aUniqueId)
224 return iAgentContent->OpenContainer(aUniqueId);
227 EXPORT_C TInt CContent::CloseContainer ()
229 return iAgentContent->CloseContainer();
232 EXPORT_C void CContent::GetEmbeddedObjectsL (RStreamablePtrArray<CEmbeddedObject>& aArray) const
234 iAgentContent->GetEmbeddedObjectsL(aArray);
237 EXPORT_C void CContent::GetEmbeddedObjectsL (RStreamablePtrArray<CEmbeddedObject>& aArray, TEmbeddedType aType) const
239 iAgentContent->GetEmbeddedObjectsL(aArray, aType);
242 EXPORT_C TInt CContent::Search (RStreamablePtrArray<CEmbeddedObject>& aArray, const TDesC8 &aMimeType, TBool aRecursive)
244 return iAgentContent->Search(aArray, aMimeType, aRecursive);
247 EXPORT_C TInt CContent::GetAttribute (TInt aAttribute, TInt &aValue) const
249 return GetAttribute(aAttribute, aValue, iDefaultVirtualPath.UniqueId());
252 EXPORT_C TInt CContent::GetAttribute (TInt aAttribute, TInt& aValue, const TDesC &aUniqueId) const
254 return iAgentContent->GetAttribute(aAttribute, aValue, aUniqueId);
257 EXPORT_C TInt CContent::GetAttributeSet(RAttributeSet& aAttributeSet) const
259 return GetAttributeSet(aAttributeSet, iDefaultVirtualPath.UniqueId());
262 EXPORT_C TInt CContent::GetAttributeSet(RAttributeSet& aAttributeSet, const TDesC& aUniqueId) const
264 return iAgentContent->GetAttributeSet(aAttributeSet, aUniqueId);
267 EXPORT_C TInt CContent::GetStringAttribute (TInt aAttribute, TDes &aValue) const
269 return GetStringAttribute(aAttribute, aValue, iDefaultVirtualPath.UniqueId());
272 EXPORT_C TInt CContent::GetStringAttribute (TInt aAttribute, TDes &aValue, const TDesC &aUniqueId) const
274 return iAgentContent->GetStringAttribute(aAttribute, aValue, aUniqueId);
277 EXPORT_C TInt CContent::GetStringAttributeSet(RStringAttributeSet& aStringAttributeSet) const
279 return GetStringAttributeSet(aStringAttributeSet, iDefaultVirtualPath.UniqueId());
282 EXPORT_C TInt CContent::GetStringAttributeSet(RStringAttributeSet& aStringAttributeSet, const TDesC& aUniqueId) const
284 return iAgentContent->GetStringAttributeSet(aStringAttributeSet, aUniqueId);
287 EXPORT_C TInt CContent::AgentSpecificCommand (TInt aCommand, const TDesC8 &aInputBuffer, TDes8 &aOutputBuffer)
289 return iAgentContent->AgentSpecificCommand(aCommand, aInputBuffer, aOutputBuffer);
292 EXPORT_C void CContent::AgentSpecificCommand (TInt aCommand, const TDesC8 &aInputBuffer, TDes8 &aOutputBuffer, TRequestStatus &aStatus)
294 iAgentContent->AgentSpecificCommand(aCommand, aInputBuffer, aOutputBuffer, aStatus);
297 EXPORT_C void CContent::NotifyStatusChange(TEventMask aMask, TRequestStatus &aStatus)
299 NotifyStatusChange(aMask, aStatus, iDefaultVirtualPath.UniqueId());
302 EXPORT_C void CContent::NotifyStatusChange(TEventMask aMask, TRequestStatus &aStatus, const TDesC &aUniqueId)
304 iAgentContent->NotifyStatusChange(aMask, aStatus, aUniqueId);
307 EXPORT_C TInt CContent::CancelNotifyStatusChange(TRequestStatus &aStatus)
309 return CancelNotifyStatusChange(aStatus, iDefaultVirtualPath.UniqueId());
312 EXPORT_C TInt CContent::CancelNotifyStatusChange(TRequestStatus &aStatus, const TDesC &aUniqueId)
314 return iAgentContent->CancelNotifyStatusChange(aStatus, aUniqueId);
317 EXPORT_C void CContent::RequestRights(TRequestStatus &aStatus)
319 RequestRights(aStatus, iDefaultVirtualPath.UniqueId());
322 EXPORT_C void CContent::RequestRights(TRequestStatus &aStatus, const TDesC &aUniqueId)
324 iAgentContent->RequestRights(aStatus, aUniqueId);
327 EXPORT_C TInt CContent::CancelRequestRights(TRequestStatus &aStatus)
329 return CancelRequestRights(aStatus, iDefaultVirtualPath.UniqueId());
332 EXPORT_C TInt CContent::CancelRequestRights(TRequestStatus &aStatus, const TDesC& aUniqueId)
334 return iAgentContent->CancelRequestRights(aStatus, aUniqueId);
337 EXPORT_C void CContent::DisplayInfoL(TDisplayInfo aInfo) const
339 DisplayInfoL(aInfo, iDefaultVirtualPath.UniqueId());
342 EXPORT_C void CContent::DisplayInfoL(TDisplayInfo aInfo, const TDesC& aUniqueId) const
344 iAgentContent->DisplayInfoL(aInfo, aUniqueId);
347 EXPORT_C TInt CContent::SetProperty(TAgentProperty aProperty, TInt aValue)
349 return iAgentContent->SetProperty(aProperty, aValue);
352 EXPORT_C CData* CContent::OpenContentL(TIntent aIntent)
354 #ifdef SYMBIAN_ENABLE_SDP_WMDRM_SUPPORT
355 if(iHeaderData != NULL)
356 return OpenContentL(aIntent, *iHeaderData);
358 return OpenContentL(aIntent, iDefaultVirtualPath.UniqueId());
360 return OpenContentL(aIntent, iDefaultVirtualPath.UniqueId());
361 #endif //#ifdef SYMBIAN_ENABLE_SDP_WMDRM_SUPPORT
364 EXPORT_C CData* CContent::OpenContentLC(TIntent aIntent)
366 #ifdef SYMBIAN_ENABLE_SDP_WMDRM_SUPPORT
367 if(iHeaderData != NULL)
368 return OpenContentLC(aIntent, *iHeaderData);
370 return OpenContentLC(aIntent, iDefaultVirtualPath.UniqueId());
372 return OpenContentLC(aIntent, iDefaultVirtualPath.UniqueId());
373 #endif //#ifdef SYMBIAN_ENABLE_SDP_WMDRM_SUPPORT
376 EXPORT_C CData* CContent::OpenContentL(TIntent aIntent, const TDesC &aUniqueId)
378 CData* data = OpenContentLC(aIntent, aUniqueId);
379 CleanupStack::Pop(data);
383 EXPORT_C CData* CContent::OpenContentLC(TIntent aIntent, const TDesC &aUniqueId)
385 // Open the content object specified by the Unique Id
388 // create a CData based upon the URI supplied when this CContent was created
389 return CData::NewLC(iAgent.ImplementationUid(), TVirtualPathPtr(iDefaultVirtualPath.URI(), aUniqueId), aIntent, iShareMode);
393 // create a CData based upon the file handle supplied when this CContent was created
394 return CData::NewLC(iAgent.ImplementationUid(), iFile, aUniqueId, aIntent);
398 #ifdef SYMBIAN_ENABLE_SDP_WMDRM_SUPPORT
400 CData* CContent::OpenContentL(TIntent aIntent, const TDesC8& aHeaderData)
402 CData* data = OpenContentLC(aIntent, aHeaderData);
403 CleanupStack::Pop(data);
407 CData* CContent::OpenContentLC(TIntent aIntent, const TDesC8& aHeaderData)
409 return CData::NewLC(iAgent.ImplementationUid(), aHeaderData, aIntent);
412 #endif //#ifdef SYMBIAN_ENABLE_SDP_WMDRM_SUPPORT
414 EXPORT_C const TAgent& CContent::Agent() const
416 // The agent handling this content
421 // Deprecated functions
423 EXPORT_C CData* CContent::OpenContentL(TIntent aIntent, TContentShareMode aShareMode)
426 // Open the content object specified by the Unique Id
429 // create a CData based upon the URI supplied when this CContent was created
430 data = CData::NewLC(iAgent.ImplementationUid(), iDefaultVirtualPath, aIntent, aShareMode);
434 // create a CData based upon the file handle supplied when this CContent was created
435 data = CData::NewLC(iAgent.ImplementationUid(), iFile, iDefaultVirtualPath.UniqueId(), aIntent);
437 CleanupStack::Pop(data);
441 EXPORT_C CAttribute* CContent::NewAttributeL(TBool aPreloaded)
443 return NewAttributeL(aPreloaded, EContentShareReadOnly);
446 #ifdef SYMBIAN_ENABLE_SDP_WMDRM_SUPPORT
447 EXPORT_C CAttribute* CContent::NewAttributeL(TBool aPreloaded, TContentShareMode aShareMode)
449 CAttribute* attr = NULL;
453 // if we were opened with a file name
454 attr = CAttribute::NewLC(iAgent.ImplementationUid(), iDefaultVirtualPath.URI(), aShareMode);
458 attr = CAttribute::NewLC(iAgent.ImplementationUid(), *iHeaderData);
462 // if we were opened with a file handle
463 attr = CAttribute::NewLC(iAgent.ImplementationUid(), iFile);
466 // If aPreloaded is set, query the agent immediately for all the attributes
469 attr->QuerySet().SetAll();
473 CleanupStack::Pop(attr);
479 EXPORT_C CAttribute* CContent::NewAttributeL(TBool aPreloaded, TContentShareMode aShareMode)
481 CAttribute* attr = NULL;
485 // if we were opened with a file name
486 attr = CAttribute::NewLC(iAgent.ImplementationUid(), iDefaultVirtualPath.URI(), aShareMode);
490 // if we were opened with a file handle
491 attr = CAttribute::NewLC(iAgent.ImplementationUid(), iFile);
494 // If aPreloaded is set, query the agent immediately for all the attributes
497 attr->QuerySet().SetAll();
501 CleanupStack::Pop(attr);
505 #endif //SYMBIAN_ENABLE_SDP_WMDRM_SUPPORT
507 #endif // REMOVE_CAF1
509 // DLL entry point - only for EKA1