os/security/contentmgmt/contentaccessfwfordrm/source/caf/manager.cpp
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
/*
sl@0
     2
* Copyright (c) 2003-2009 Nokia Corporation and/or its subsidiary(-ies).
sl@0
     3
* All rights reserved.
sl@0
     4
* This component and the accompanying materials are made available
sl@0
     5
* under the terms of the License "Eclipse Public License v1.0"
sl@0
     6
* which accompanies this distribution, and is available
sl@0
     7
* at the URL "http://www.eclipse.org/legal/epl-v10.html".
sl@0
     8
*
sl@0
     9
* Initial Contributors:
sl@0
    10
* Nokia Corporation - initial contribution.
sl@0
    11
*
sl@0
    12
* Contributors:
sl@0
    13
*
sl@0
    14
* Description: 
sl@0
    15
*
sl@0
    16
*/
sl@0
    17
sl@0
    18
sl@0
    19
#include <caf/manager.h>
sl@0
    20
#include <caf/agentinterface.h>
sl@0
    21
#include <caf/agent.h>
sl@0
    22
#include "agentinfo.h"
sl@0
    23
#include <caf/agentfactory.h>
sl@0
    24
#include <caf/attributeset.h>
sl@0
    25
#include <caf/caftypes.h>
sl@0
    26
#include <caf/caferr.h>
sl@0
    27
#include <caf/virtualpath.h>
sl@0
    28
#include <caf/dirstreamable.h>
sl@0
    29
#include <caf/rightsmanager.h>
sl@0
    30
#include <caf/cafpanic.h>
sl@0
    31
#include "resolver.h"
sl@0
    32
sl@0
    33
using namespace ContentAccess;
sl@0
    34
sl@0
    35
EXPORT_C CManager* CManager::NewL()
sl@0
    36
	{
sl@0
    37
	CManager* self = CManager::NewLC();
sl@0
    38
	CleanupStack::Pop(self);
sl@0
    39
	return self;
sl@0
    40
	}
sl@0
    41
	
sl@0
    42
EXPORT_C CManager* CManager::NewLC()
sl@0
    43
	{
sl@0
    44
	CManager* self = new (ELeave) CManager;
sl@0
    45
	CleanupStack::PushL(self);
sl@0
    46
	self->ConstructL();
sl@0
    47
	return self;
sl@0
    48
	}
sl@0
    49
sl@0
    50
CManager::CManager()
sl@0
    51
	{
sl@0
    52
	}
sl@0
    53
sl@0
    54
CManager::~CManager()
sl@0
    55
	{
sl@0
    56
	delete iResolver;
sl@0
    57
	}
sl@0
    58
sl@0
    59
void CManager::ConstructL()
sl@0
    60
	{
sl@0
    61
	iResolver = CAgentResolver::NewL(EFalse);
sl@0
    62
	}
sl@0
    63
sl@0
    64
EXPORT_C TInt CManager::DeleteFile(const TDesC &aFileName) const
sl@0
    65
	{
sl@0
    66
	TRAPD(err, DoDeleteFileL(aFileName));
sl@0
    67
	return err;
sl@0
    68
	}
sl@0
    69
	
sl@0
    70
void CManager::DoDeleteFileL(const TDesC &aFileName) const
sl@0
    71
	{
sl@0
    72
	TFileName actualFileName;
sl@0
    73
	
sl@0
    74
	// initalise a pointer to the relevant CAgentManager object
sl@0
    75
	// iResolver retains ownership of the pointer
sl@0
    76
	CAgentInfo& agentInfo = iResolver->ResolveFileL(aFileName, actualFileName, EContentShareReadOnly);
sl@0
    77
sl@0
    78
	User::LeaveIfError(agentInfo.AgentManagerL().DeleteFile(actualFileName));
sl@0
    79
	}
sl@0
    80
sl@0
    81
EXPORT_C TInt CManager::CopyFile(RFile& aSourceFile, const TDesC &aDestination) const
sl@0
    82
	{
sl@0
    83
	TRAPD(err, DoCopyFileL(aSourceFile, aDestination));
sl@0
    84
	return err;
sl@0
    85
	}
sl@0
    86
sl@0
    87
void CManager::DoCopyFileL(RFile& aSourceFile, const TDesC &aDestination) const
sl@0
    88
	{
sl@0
    89
	TFileName actualDestination;
sl@0
    90
	TBool thePrivateDir = EFalse;
sl@0
    91
	TUid agentUid = KNullUid;
sl@0
    92
sl@0
    93
	// Find out which agent owns the directory where the destination file lives
sl@0
    94
	TUid destinationAgentUid = iResolver->ResolveDirectory(aDestination, actualDestination, thePrivateDir);
sl@0
    95
	
sl@0
    96
	if(destinationAgentUid != iResolver->DefaultAgentUid())
sl@0
    97
		{
sl@0
    98
		// Destination file is in an agent private directory
sl@0
    99
		// Use destination agent to copy
sl@0
   100
		agentUid = destinationAgentUid;
sl@0
   101
		}
sl@0
   102
	else
sl@0
   103
		{
sl@0
   104
		// Use RFile version of ResolveFileL to find the Agent Uid
sl@0
   105
		agentUid = iResolver->ResolveFileL(aSourceFile).Agent().ImplementationUid();
sl@0
   106
		}
sl@0
   107
		
sl@0
   108
	// If creating the appropriate CAgentManager succeeded ask the agent to copy the file
sl@0
   109
	User::LeaveIfError(iResolver->AgentInfoL(agentUid).AgentManagerL().CopyFile(aSourceFile, actualDestination));
sl@0
   110
	}
sl@0
   111
sl@0
   112
EXPORT_C TInt CManager::CopyFile(const TDesC &aSource, const TDesC &aDestination) const
sl@0
   113
	{
sl@0
   114
	TRAPD(err, DoCopyFileL(aSource, aDestination));
sl@0
   115
	return err;
sl@0
   116
	}
sl@0
   117
sl@0
   118
void CManager::DoCopyFileL(const TDesC &aSource, const TDesC &aDestination) const
sl@0
   119
	{
sl@0
   120
	TFileName actualSource;
sl@0
   121
	TFileName actualDestination;
sl@0
   122
	TBool thePrivateDir = EFalse;
sl@0
   123
	TUid agentUid = KNullUid;
sl@0
   124
	
sl@0
   125
	// Find out which agent owns the directory where the source file lives
sl@0
   126
	TUid sourceAgentUid = iResolver->ResolveDirectory(aSource, actualSource, thePrivateDir);
sl@0
   127
sl@0
   128
	// Find out which agent owns the directory where the destination file lives
sl@0
   129
	TUid destinationAgentUid = iResolver->ResolveDirectory(aDestination, actualDestination, thePrivateDir);
sl@0
   130
	
sl@0
   131
	if(sourceAgentUid != iResolver->DefaultAgentUid())
sl@0
   132
		{
sl@0
   133
		// Source file is in an agent private directory
sl@0
   134
		// Use source agent to copy
sl@0
   135
		agentUid = sourceAgentUid;
sl@0
   136
		}
sl@0
   137
	else if(destinationAgentUid != iResolver->DefaultAgentUid())
sl@0
   138
		{
sl@0
   139
		// Destination file is in an agent private directory
sl@0
   140
		// Use destination agent to copy
sl@0
   141
		agentUid = destinationAgentUid;
sl@0
   142
		}
sl@0
   143
	else
sl@0
   144
		{
sl@0
   145
		// Source and destination are in publicly accessable directories
sl@0
   146
		agentUid = iResolver->ResolveFileL(aSource, actualSource, EContentShareReadOnly).Agent().ImplementationUid();
sl@0
   147
		}
sl@0
   148
		
sl@0
   149
	// If creating the appropriate CAgentManager succeeded ask the agent to copy the file
sl@0
   150
	User::LeaveIfError(iResolver->AgentInfoL(agentUid).AgentManagerL().CopyFile(actualSource, actualDestination));
sl@0
   151
	}
sl@0
   152
sl@0
   153
EXPORT_C TInt CManager::RenameFile(const TDesC& aSource, const TDesC& aDestination) const
sl@0
   154
	{
sl@0
   155
	TRAPD(err, DoRenameFileL(aSource, aDestination));
sl@0
   156
	return err;
sl@0
   157
	}
sl@0
   158
sl@0
   159
void CManager::DoRenameFileL(const TDesC& aSource, const TDesC& aDestination) const
sl@0
   160
	{
sl@0
   161
	TFileName actualSource;
sl@0
   162
	TFileName actualDestination;
sl@0
   163
	TBool thePrivateDir = EFalse;
sl@0
   164
	TUid agentUid = KNullUid;
sl@0
   165
sl@0
   166
	// Find out which agent owns the directory where the source file lives
sl@0
   167
	TUid sourceAgentUid = iResolver->ResolveDirectory(aSource, actualSource, thePrivateDir);
sl@0
   168
sl@0
   169
	// Find out which agent owns the directory where the destination file lives
sl@0
   170
	TUid destinationAgentUid = iResolver->ResolveDirectory(aDestination, actualDestination, thePrivateDir);
sl@0
   171
	
sl@0
   172
	if(sourceAgentUid != iResolver->DefaultAgentUid())
sl@0
   173
		{
sl@0
   174
		// Source file is in an agent private directory
sl@0
   175
		// Use source agent to copy
sl@0
   176
		agentUid = sourceAgentUid;
sl@0
   177
		}
sl@0
   178
	else if(destinationAgentUid != iResolver->DefaultAgentUid())
sl@0
   179
		{
sl@0
   180
		// Destination file is in an agent private directory
sl@0
   181
		// Use destination agent to copy
sl@0
   182
		agentUid = destinationAgentUid;
sl@0
   183
		}
sl@0
   184
	else
sl@0
   185
		{
sl@0
   186
		// Source and destination are in publicly accessable directories
sl@0
   187
		agentUid = iResolver->ResolveFileL(aSource, actualSource, EContentShareReadOnly).Agent().ImplementationUid();
sl@0
   188
		}
sl@0
   189
		
sl@0
   190
	// Ask the agent to move or rename the file
sl@0
   191
	User::LeaveIfError(iResolver->AgentInfoL(agentUid).AgentManagerL().RenameFile(actualSource, actualDestination));
sl@0
   192
	}
sl@0
   193
sl@0
   194
EXPORT_C TInt CManager::MkDir(const TDesC &aPath) const
sl@0
   195
	{
sl@0
   196
	TRAPD(err, DoMkDirL(aPath));
sl@0
   197
		
sl@0
   198
	return err;	
sl@0
   199
	}
sl@0
   200
sl@0
   201
void CManager::DoMkDirL(const TDesC &aPath) const
sl@0
   202
	{
sl@0
   203
	TBool isThePrivateDir = EFalse;
sl@0
   204
	TFileName actualPath;
sl@0
   205
	
sl@0
   206
	// Figure out which agent handles the directory
sl@0
   207
	TUid uid = iResolver->ResolveDirectory(aPath, actualPath, isThePrivateDir);
sl@0
   208
sl@0
   209
	User::LeaveIfError(iResolver->AgentInfoL(uid).AgentManagerL().MkDir(actualPath));
sl@0
   210
	}
sl@0
   211
sl@0
   212
EXPORT_C TInt CManager::MkDirAll (const TDesC &aPath) const
sl@0
   213
	{
sl@0
   214
	TRAPD(err, DoMkDirAllL(aPath));
sl@0
   215
	return err;	
sl@0
   216
	}
sl@0
   217
sl@0
   218
void CManager::DoMkDirAllL(const TDesC &aPath) const
sl@0
   219
	{
sl@0
   220
	TBool isThePrivateDir = EFalse;
sl@0
   221
	TFileName actualPath;
sl@0
   222
	
sl@0
   223
	// Figure out which agent handles the directory
sl@0
   224
	TUid uid = iResolver->ResolveDirectory(aPath, actualPath, isThePrivateDir);
sl@0
   225
	
sl@0
   226
	User::LeaveIfError(iResolver->AgentInfoL(uid).AgentManagerL().MkDirAll(actualPath));
sl@0
   227
	}
sl@0
   228
sl@0
   229
EXPORT_C TInt CManager::RmDir(const TDesC &aPath) const
sl@0
   230
	{
sl@0
   231
	TRAPD(err, DoRmDirL(aPath));
sl@0
   232
	return err;	
sl@0
   233
	}
sl@0
   234
sl@0
   235
void CManager::DoRmDirL(const TDesC &aPath) const
sl@0
   236
	{
sl@0
   237
	TBool isThePrivateDir = EFalse;
sl@0
   238
	TFileName actualPath;
sl@0
   239
	
sl@0
   240
	// Figure out which agent handles the directory
sl@0
   241
	TUid uid = iResolver->ResolveDirectory(aPath, actualPath, isThePrivateDir);
sl@0
   242
sl@0
   243
	if(isThePrivateDir)
sl@0
   244
		{
sl@0
   245
		User::Leave(KErrAccessDenied);	
sl@0
   246
		}
sl@0
   247
	else
sl@0
   248
		{
sl@0
   249
		User::LeaveIfError(iResolver->AgentInfoL(uid).AgentManagerL().RmDir(actualPath));
sl@0
   250
		}
sl@0
   251
	}
sl@0
   252
sl@0
   253
EXPORT_C TInt CManager::RenameDir(const TDesC& aOldName, const TDesC& aNewName) const
sl@0
   254
		{
sl@0
   255
		TRAPD(err, DoRenameDirL(aOldName, aNewName));
sl@0
   256
		return err;
sl@0
   257
		}
sl@0
   258
sl@0
   259
void CManager::DoRenameDirL(const TDesC &aOldName, const TDesC& aNewName) const
sl@0
   260
	{
sl@0
   261
	TPath actualSource;
sl@0
   262
	TPath actualDestination;
sl@0
   263
	TBool thePrivateDir = EFalse;
sl@0
   264
	TUid agentUid = iResolver->DefaultAgentUid();
sl@0
   265
sl@0
   266
	// Find out which agent owns the directory where the source file lives
sl@0
   267
	TUid sourceAgentUid = iResolver->ResolveDirectory(aOldName, actualSource, thePrivateDir);
sl@0
   268
sl@0
   269
	// Find out which agent owns the directory where the destination file lives
sl@0
   270
	TUid destinationAgentUid = iResolver->ResolveDirectory(aNewName, actualDestination, thePrivateDir);
sl@0
   271
	
sl@0
   272
	if(sourceAgentUid != iResolver->DefaultAgentUid())
sl@0
   273
		{
sl@0
   274
		// Source file is in an agent private directory
sl@0
   275
		// Use source agent to copy
sl@0
   276
		agentUid = sourceAgentUid;
sl@0
   277
		}
sl@0
   278
	else if(destinationAgentUid != iResolver->DefaultAgentUid())
sl@0
   279
		{
sl@0
   280
		// Destination file is in an agent private directory
sl@0
   281
		// Use destination agent to copy
sl@0
   282
		agentUid = destinationAgentUid;
sl@0
   283
		}
sl@0
   284
		
sl@0
   285
	// Ask the agent to move or rename the file
sl@0
   286
	User::LeaveIfError(iResolver->AgentInfoL(agentUid).AgentManagerL().RenameDir(actualSource, actualDestination));
sl@0
   287
	}
sl@0
   288
sl@0
   289
sl@0
   290
EXPORT_C TInt CManager::GetDir(const TDesC &aName, TUint aEntryAttMask, TUint aEntrySortKey, CDir *&aEntryList) const 
sl@0
   291
	{
sl@0
   292
	TRAPD(err, DoGetDirL(aName, aEntryAttMask, aEntrySortKey, aEntryList));
sl@0
   293
	return err;
sl@0
   294
	}
sl@0
   295
	
sl@0
   296
void CManager::DoGetDirL(const TDesC &aName, TUint aEntryAttMask, TUint aEntrySortKey, CDir *&aEntryList) const 	
sl@0
   297
	{
sl@0
   298
	TBool isThePrivateDir = EFalse;
sl@0
   299
	TFileName actualPath;
sl@0
   300
	
sl@0
   301
	// Figure out which agent handles the directory
sl@0
   302
	TUid uid = iResolver->ResolveDirectory(aName, actualPath, isThePrivateDir);
sl@0
   303
sl@0
   304
	if(isThePrivateDir)
sl@0
   305
		{
sl@0
   306
		// If we are doing GetDir of C:\\private\\ just create an empty CDirStreamable
sl@0
   307
		aEntryList = CDirStreamable::NewL();
sl@0
   308
		}
sl@0
   309
	else
sl@0
   310
		{
sl@0
   311
		User::LeaveIfError(iResolver->AgentInfoL(uid).AgentManagerL().GetDir(actualPath, aEntryAttMask, aEntrySortKey, aEntryList));
sl@0
   312
		}
sl@0
   313
	}
sl@0
   314
sl@0
   315
EXPORT_C TInt CManager::GetDir(const TDesC &aName, TUint aEntryAttMask, TUint aEntrySortKey, CDir *&aEntryList, CDir *&aDirList) const 
sl@0
   316
	{
sl@0
   317
	TRAPD(err, DoGetDirL(aName, aEntryAttMask, aEntrySortKey, aEntryList, aDirList));
sl@0
   318
	return err;
sl@0
   319
	}
sl@0
   320
sl@0
   321
void CManager::DoGetDirL(const TDesC &aName, TUint aEntryAttMask, TUint aEntrySortKey, CDir *&aEntryList, CDir *&aDirList) const 
sl@0
   322
	{
sl@0
   323
	TBool isThePrivateDir = EFalse;
sl@0
   324
	TFileName actualPath;
sl@0
   325
	CDir* emptyDirList;
sl@0
   326
	
sl@0
   327
	// Figure out which agent handles the directory
sl@0
   328
	TUid uid = iResolver->ResolveDirectory(aName, actualPath, isThePrivateDir);
sl@0
   329
sl@0
   330
	if(isThePrivateDir)
sl@0
   331
		{
sl@0
   332
		// If we are doing GetDir of C:\\private\\ just create an empty entryList
sl@0
   333
		emptyDirList = CDirStreamable::NewL();
sl@0
   334
		CleanupStack::PushL(emptyDirList);
sl@0
   335
sl@0
   336
		GetListOfAgentPrivateDirectoriesL(aDirList);
sl@0
   337
sl@0
   338
		CleanupStack::Pop(emptyDirList);
sl@0
   339
		aEntryList = emptyDirList;		
sl@0
   340
		}
sl@0
   341
	else
sl@0
   342
		{
sl@0
   343
		User::LeaveIfError(iResolver->AgentInfoL(uid).AgentManagerL().GetDir(actualPath, aEntryAttMask, aEntrySortKey, aEntryList, aDirList));
sl@0
   344
		}
sl@0
   345
	}
sl@0
   346
sl@0
   347
EXPORT_C TInt CManager::GetDir(const TDesC &aName, const TUidType &aEntryUid, TUint aEntrySortKey, CDir *&aFileList) const 
sl@0
   348
	{
sl@0
   349
	TRAPD(err, DoGetDirL(aName, aEntryUid, aEntrySortKey, aFileList));
sl@0
   350
	return err;
sl@0
   351
	}
sl@0
   352
sl@0
   353
void CManager::DoGetDirL(const TDesC &aName, const TUidType &aEntryUid, TUint aEntrySortKey, CDir *&aFileList) const 
sl@0
   354
	{
sl@0
   355
	TBool isThePrivateDir = EFalse;
sl@0
   356
	TFileName actualPath;
sl@0
   357
	
sl@0
   358
	// Figure out which agent handles the directory
sl@0
   359
	TUid uid = iResolver->ResolveDirectory(aName, actualPath, isThePrivateDir);
sl@0
   360
sl@0
   361
	if(isThePrivateDir)
sl@0
   362
		{
sl@0
   363
		// We've been asked to look at C:\\private\\ just return an empty CDirStreamable
sl@0
   364
		aFileList = CDirStreamable::NewL();
sl@0
   365
		}
sl@0
   366
	else
sl@0
   367
		{
sl@0
   368
		User::LeaveIfError(iResolver->AgentInfoL(uid).AgentManagerL().GetDir(actualPath, aEntryUid, aEntrySortKey, aFileList));
sl@0
   369
		}
sl@0
   370
	}
sl@0
   371
sl@0
   372
EXPORT_C TInt CManager::GetAttribute(TInt aAttribute, TInt& aValue, const TVirtualPathPtr& aVirtualPath) const
sl@0
   373
	{
sl@0
   374
	TRAPD(err, DoGetAttributeL(aAttribute, aValue, aVirtualPath));
sl@0
   375
	return err;
sl@0
   376
	}
sl@0
   377
sl@0
   378
void CManager::DoGetAttributeL(TInt aAttribute, TInt& aValue, const TVirtualPathPtr& aVirtualPath) const
sl@0
   379
	{
sl@0
   380
	HBufC* uriBuffer = HBufC::NewLC(aVirtualPath.URI().Length() + KMaxSIDLength);
sl@0
   381
	TPtr uri = uriBuffer->Des();
sl@0
   382
sl@0
   383
	// Find the agent who handles the file 
sl@0
   384
	CAgentInfo& agentInfo = iResolver->ResolveFileL(aVirtualPath.URI(),uri, EContentShareReadOnly);
sl@0
   385
	User::LeaveIfError(agentInfo.AgentManagerL().GetAttribute(aAttribute, aValue, TVirtualPathPtr(uri, aVirtualPath.UniqueId())));
sl@0
   386
	CleanupStack::PopAndDestroy(uriBuffer);
sl@0
   387
	}
sl@0
   388
	
sl@0
   389
EXPORT_C TInt CManager::GetAttribute(TInt aAttribute, TInt& aValue, RFile& aFile, const TDesC& aUniqueId) 
sl@0
   390
	{
sl@0
   391
	TRAPD(err, DoGetAttributeL(aAttribute, aValue, aFile, aUniqueId));
sl@0
   392
	return err;
sl@0
   393
	}
sl@0
   394
sl@0
   395
void CManager::DoGetAttributeL(TInt aAttribute, TInt& aValue, RFile& aFile, const TDesC& aUniqueId) const
sl@0
   396
	{
sl@0
   397
	// Find the agent who handles the file 
sl@0
   398
	CAgentInfo& agentInfo = iResolver->ResolveFileL(aFile);
sl@0
   399
	User::LeaveIfError(agentInfo.AgentManagerL().GetAttribute(aAttribute, aValue, aFile, aUniqueId));
sl@0
   400
	}
sl@0
   401
	
sl@0
   402
sl@0
   403
EXPORT_C TInt CManager::GetStringAttribute(TInt aAttribute, TDes& aValue, const TVirtualPathPtr& aVirtualPath) const
sl@0
   404
	{
sl@0
   405
	TRAPD(err, DoGetStringAttributeL(aAttribute, aValue, aVirtualPath));
sl@0
   406
	return err;
sl@0
   407
	}
sl@0
   408
	
sl@0
   409
void CManager::DoGetStringAttributeL(TInt aAttribute, TDes& aValue, const TVirtualPathPtr& aVirtualPath) const
sl@0
   410
	{
sl@0
   411
	HBufC* uriBuffer = HBufC::NewLC(aVirtualPath.URI().Length() + KMaxSIDLength);
sl@0
   412
	TPtr uri = uriBuffer->Des();
sl@0
   413
sl@0
   414
sl@0
   415
	// Find the agent who handles the file 
sl@0
   416
	CAgentInfo& agentInfo = iResolver->ResolveFileL(aVirtualPath.URI(), uri, EContentShareReadOnly);
sl@0
   417
	
sl@0
   418
	// find out the attribute
sl@0
   419
	User::LeaveIfError(agentInfo.AgentManagerL().GetStringAttribute(aAttribute, aValue, TVirtualPathPtr(uri,aVirtualPath.UniqueId())));
sl@0
   420
	CleanupStack::PopAndDestroy(uriBuffer);
sl@0
   421
	}
sl@0
   422
	
sl@0
   423
EXPORT_C TInt CManager::GetStringAttribute (TInt aAttribute, TDes& aValue, RFile& aFile, const TDesC& aUniqueId)	
sl@0
   424
	{
sl@0
   425
	TRAPD(err, DoGetStringAttributeL(aAttribute, aValue, aFile, aUniqueId));
sl@0
   426
	return err;
sl@0
   427
	}
sl@0
   428
	
sl@0
   429
void CManager::DoGetStringAttributeL(TInt aAttribute, TDes& aValue, RFile& aFile, const TDesC& aUniqueId) const
sl@0
   430
	{
sl@0
   431
	// Find the agent who handles the file 
sl@0
   432
	CAgentInfo& agentInfo = iResolver->ResolveFileL(aFile);	
sl@0
   433
	// find out the attribute
sl@0
   434
	User::LeaveIfError(agentInfo.AgentManagerL().GetStringAttribute(aAttribute, aValue, aFile, aUniqueId));
sl@0
   435
	}
sl@0
   436
sl@0
   437
EXPORT_C TInt CManager::GetAttributeSet(RAttributeSet& aAttributeSet, const TVirtualPathPtr& aVirtualPath) const
sl@0
   438
	{
sl@0
   439
	TRAPD(err, DoGetAttributeSetL(aAttributeSet, aVirtualPath));
sl@0
   440
	return err;
sl@0
   441
	}
sl@0
   442
sl@0
   443
void CManager::DoGetAttributeSetL(RAttributeSet& aAttributeSet, const TVirtualPathPtr& aVirtualPath) const	
sl@0
   444
	{
sl@0
   445
	HBufC* uriBuffer = HBufC::NewLC(aVirtualPath.URI().Length() + KMaxSIDLength);
sl@0
   446
	TPtr uri = uriBuffer->Des();
sl@0
   447
	
sl@0
   448
	// Find the agent who handles the file 
sl@0
   449
	CAgentInfo& agentInfo = iResolver->ResolveFileL(aVirtualPath.URI(), uri, EContentShareReadOnly);
sl@0
   450
	
sl@0
   451
	User::LeaveIfError(agentInfo.AgentManagerL().GetAttributeSet(aAttributeSet, TVirtualPathPtr(uri, aVirtualPath.UniqueId())));
sl@0
   452
	CleanupStack::PopAndDestroy(uriBuffer);
sl@0
   453
	}
sl@0
   454
sl@0
   455
EXPORT_C TInt CManager::GetAttributeSet (RAttributeSet& aAttributeSet, RFile& aFile, const TDesC& aUniqueId)
sl@0
   456
	{
sl@0
   457
	TRAPD(err, DoGetAttributeSetL(aAttributeSet, aFile, aUniqueId));
sl@0
   458
	return err;
sl@0
   459
	}
sl@0
   460
sl@0
   461
void CManager::DoGetAttributeSetL(RAttributeSet& aAttributeSet, RFile& aFile, const TDesC& aUniqueId) const	
sl@0
   462
	{
sl@0
   463
	// Find the agent who handles the file 
sl@0
   464
	CAgentInfo& agentInfo = iResolver->ResolveFileL(aFile);
sl@0
   465
	User::LeaveIfError(agentInfo.AgentManagerL().GetAttributeSet(aAttributeSet, aFile, aUniqueId));
sl@0
   466
	}	
sl@0
   467
sl@0
   468
EXPORT_C TInt CManager::GetStringAttributeSet(RStringAttributeSet& aStringAttributeSet, const TVirtualPathPtr& aVirtualPath) const
sl@0
   469
	{
sl@0
   470
	TRAPD(err, DoGetStringAttributeSetL(aStringAttributeSet, aVirtualPath));
sl@0
   471
	return err;
sl@0
   472
	}
sl@0
   473
sl@0
   474
void CManager::DoGetStringAttributeSetL(RStringAttributeSet& aStringAttributeSet, const TVirtualPathPtr& aVirtualPath) const
sl@0
   475
	{
sl@0
   476
	HBufC* uriBuffer = HBufC::NewLC(aVirtualPath.URI().Length() + KMaxSIDLength);
sl@0
   477
	TPtr uri = uriBuffer->Des();
sl@0
   478
	
sl@0
   479
	// Find the agent who handles the file 
sl@0
   480
	CAgentInfo& agentInfo = iResolver->ResolveFileL(aVirtualPath.URI(),uri, EContentShareReadOnly);
sl@0
   481
sl@0
   482
	// find out the array of attributes
sl@0
   483
	User::LeaveIfError(agentInfo.AgentManagerL().GetStringAttributeSet(aStringAttributeSet, TVirtualPathPtr(uri, aVirtualPath.UniqueId())));
sl@0
   484
	CleanupStack::PopAndDestroy(uriBuffer);
sl@0
   485
	}
sl@0
   486
sl@0
   487
EXPORT_C TInt CManager::GetStringAttributeSet(RStringAttributeSet& aStringAttributeSet, RFile& aFile, const TDesC& aUniqueId)
sl@0
   488
	{
sl@0
   489
	TRAPD(err, DoGetStringAttributeSetL(aStringAttributeSet, aFile, aUniqueId));
sl@0
   490
	return err;
sl@0
   491
	}
sl@0
   492
sl@0
   493
void CManager::DoGetStringAttributeSetL(RStringAttributeSet& aStringAttributeSet, RFile& aFile, const TDesC& aUniqueId) const
sl@0
   494
	{
sl@0
   495
	// Find the agent who handles the file 
sl@0
   496
	CAgentInfo& agentInfo = iResolver->ResolveFileL(aFile);
sl@0
   497
	// find out the array of attributes
sl@0
   498
	User::LeaveIfError(agentInfo.AgentManagerL().GetStringAttributeSet(aStringAttributeSet, aFile, aUniqueId));
sl@0
   499
	}
sl@0
   500
sl@0
   501
EXPORT_C void CManager::NotifyStatusChange(const TDesC &aURI, TEventMask aMask, TRequestStatus &aStatus) 
sl@0
   502
	{
sl@0
   503
	TRAPD(err, DoNotifyStatusChangeL(aURI, aMask, aStatus));
sl@0
   504
	if(err != KErrNone)
sl@0
   505
		{
sl@0
   506
		// Must have failed before asking the agent for status
sl@0
   507
		TRequestStatus* status = &aStatus;
sl@0
   508
		User::RequestComplete(status, err);
sl@0
   509
		}
sl@0
   510
	}
sl@0
   511
sl@0
   512
void CManager::DoNotifyStatusChangeL(const TDesC &aURI, TEventMask aMask, TRequestStatus &aStatus) 
sl@0
   513
	{
sl@0
   514
	HBufC* uriBuffer = HBufC::NewLC(aURI.Length() + KMaxSIDLength);
sl@0
   515
	TPtr uri = uriBuffer->Des();
sl@0
   516
	
sl@0
   517
	// Find the agent who handles the file 
sl@0
   518
	CAgentInfo& agentInfo = iResolver->ResolveFileL(aURI, uri, EContentShareReadOnly);
sl@0
   519
	
sl@0
   520
	// Ask the agent to notifiy the client when the status of the given file changes
sl@0
   521
	agentInfo.AgentManagerL().NotifyStatusChange(uri, aMask, aStatus);
sl@0
   522
	CleanupStack::PopAndDestroy(uriBuffer);
sl@0
   523
	}
sl@0
   524
sl@0
   525
EXPORT_C TInt CManager::CancelNotifyStatusChange (const TDesC &aURI, TRequestStatus &aStatus) 
sl@0
   526
	{
sl@0
   527
	TRAPD(err, DoCancelNotifyStatusChangeL(aURI, aStatus));
sl@0
   528
	return err;
sl@0
   529
	}
sl@0
   530
sl@0
   531
void CManager::DoCancelNotifyStatusChangeL(const TDesC &aURI, TRequestStatus &aStatus) 
sl@0
   532
	{
sl@0
   533
	HBufC* uriBuffer = HBufC::NewLC(aURI.Length() + KMaxSIDLength);
sl@0
   534
	TPtr uri = uriBuffer->Des();
sl@0
   535
	
sl@0
   536
	// Find the agent who handles the file 
sl@0
   537
	CAgentInfo& agentInfo = iResolver->ResolveFileL(aURI, uri, EContentShareReadOnly);
sl@0
   538
	
sl@0
   539
	// cancel the notification request
sl@0
   540
	User::LeaveIfError(agentInfo.AgentManagerL().CancelNotifyStatusChange(uri, aStatus));
sl@0
   541
	CleanupStack::PopAndDestroy(uriBuffer);
sl@0
   542
	}
sl@0
   543
sl@0
   544
EXPORT_C TInt CManager::SetProperty(TAgentProperty aProperty, TInt aValue)
sl@0
   545
	{
sl@0
   546
	TRAPD(err, DoSetPropertyL(aProperty, aValue));
sl@0
   547
	return err;
sl@0
   548
	}
sl@0
   549
sl@0
   550
void CManager::DoSetPropertyL(TAgentProperty aProperty, TInt aValue)
sl@0
   551
	{
sl@0
   552
	TInt err = KErrNone;
sl@0
   553
	TInt rVal = KErrNone;
sl@0
   554
	TInt i = 0;
sl@0
   555
	TInt count = iResolver->AgentInfoCount();
sl@0
   556
	
sl@0
   557
	CAgentInfo &defaultAgentInfo = iResolver->AgentInfoL(iResolver->DefaultAgentUid());
sl@0
   558
	err = defaultAgentInfo.AgentManagerL().SetProperty(aProperty, aValue);
sl@0
   559
	if(err == KErrNoMemory)
sl@0
   560
		{
sl@0
   561
		User::Leave(KErrNoMemory);
sl@0
   562
		}
sl@0
   563
	
sl@0
   564
	// Ignore F32 agent return code unless it's KErrNoMemory
sl@0
   565
	err= KErrNone;
sl@0
   566
	
sl@0
   567
	// Set the property in all the other agents
sl@0
   568
	for( i = 0; i < count; i++)
sl@0
   569
		{
sl@0
   570
		CAgentInfo& agentInfo = iResolver->AgentInfo(i);
sl@0
   571
		err = agentInfo.AgentManagerL().SetProperty(aProperty, aValue);
sl@0
   572
		if(err == KErrNoMemory)
sl@0
   573
			{
sl@0
   574
			User::Leave(KErrNoMemory);
sl@0
   575
			}
sl@0
   576
			
sl@0
   577
		// If an error occurred and no previous error has occured
sl@0
   578
		if(err != KErrNone && rVal == KErrNone)
sl@0
   579
			{
sl@0
   580
			rVal = err;
sl@0
   581
			}
sl@0
   582
		}
sl@0
   583
	
sl@0
   584
	// leave if an error occurred in any agent
sl@0
   585
	User::LeaveIfError(rVal);
sl@0
   586
	}
sl@0
   587
sl@0
   588
EXPORT_C void CManager::DisplayInfoL(TDisplayInfo aInfo, const TVirtualPathPtr& aVirtualPath)
sl@0
   589
	{
sl@0
   590
	HBufC* uriBuffer = HBufC::NewLC(aVirtualPath.URI().Length() + KMaxSIDLength);
sl@0
   591
	TPtr uri = uriBuffer->Des();
sl@0
   592
sl@0
   593
	// Find the agent who handles the file 
sl@0
   594
	CAgentInfo& agentInfo = iResolver->ResolveFileL(aVirtualPath.URI(), uri, EContentShareReadOnly);
sl@0
   595
	
sl@0
   596
	// find out the attribute
sl@0
   597
	agentInfo.AgentManagerL().DisplayInfoL(aInfo, TVirtualPathPtr(uri, aVirtualPath.UniqueId()));
sl@0
   598
	CleanupStack::PopAndDestroy(uriBuffer);
sl@0
   599
	}
sl@0
   600
sl@0
   601
EXPORT_C void CManager::DisplayInfoL(TDisplayInfo aInfo, RFile& aFile, const TDesC& aUniqueId) 
sl@0
   602
	{
sl@0
   603
	// Find the agent who handles the file 
sl@0
   604
	CAgentInfo& agentInfo = iResolver->ResolveFileL(aFile);
sl@0
   605
	// find out the attribute
sl@0
   606
	agentInfo.AgentManagerL().DisplayInfoL(aInfo, aFile, aUniqueId);
sl@0
   607
	}
sl@0
   608
sl@0
   609
EXPORT_C void CManager::ListAgentsL (RArray <TAgent>& aAgents) 
sl@0
   610
	{
sl@0
   611
	TInt i = 0;
sl@0
   612
	TBuf <KMaxAgentNameLength> agentName;
sl@0
   613
	TInt count = iResolver->AgentInfoCount();
sl@0
   614
	
sl@0
   615
	// build the array of pointers from CAgentResolver
sl@0
   616
	for(i = 0; i < count; i++)
sl@0
   617
		{
sl@0
   618
		TAgent agent = iResolver->AgentInfo(i).Agent();
sl@0
   619
		User::LeaveIfError(aAgents.Append(agent));
sl@0
   620
		}
sl@0
   621
	}
sl@0
   622
sl@0
   623
EXPORT_C TInt CManager::AgentSpecificCommand (TAgent &aAgent, TInt aCommand, const TDesC8 &aInputBuffer, TDes8 &aOutputBuffer) 
sl@0
   624
	{
sl@0
   625
	CAgentManager* manager = NULL;
sl@0
   626
	TInt err = KErrNone;
sl@0
   627
	TRAP(err, manager = &iResolver->AgentInfoL(aAgent.ImplementationUid()).AgentManagerL());
sl@0
   628
	if(err == KErrNone)
sl@0
   629
		{
sl@0
   630
		err = manager->AgentSpecificCommand (aCommand, aInputBuffer, aOutputBuffer);
sl@0
   631
		}
sl@0
   632
	return err;
sl@0
   633
	}
sl@0
   634
sl@0
   635
EXPORT_C void CManager::AgentSpecificCommand (TAgent &aAgent, TInt aCommand, const TDesC8 &aInputBuffer, TDes8 &aOutputBuffer, TRequestStatus &aStatus) 
sl@0
   636
	{
sl@0
   637
	CAgentManager* manager = NULL;
sl@0
   638
	
sl@0
   639
	TRAPD(err, manager = &iResolver->AgentInfoL(aAgent.ImplementationUid()).AgentManagerL());
sl@0
   640
	if(err == KErrNone)
sl@0
   641
		{
sl@0
   642
		manager->AgentSpecificCommand (aCommand, aInputBuffer, aOutputBuffer, aStatus);
sl@0
   643
		}
sl@0
   644
	else
sl@0
   645
		{
sl@0
   646
		TRequestStatus* status = &aStatus;
sl@0
   647
		User::RequestComplete(status, err);
sl@0
   648
		}
sl@0
   649
	}
sl@0
   650
sl@0
   651
EXPORT_C void CManager::DisplayManagementInfoL(TAgent& aAgent)
sl@0
   652
	{
sl@0
   653
	CAgentInfo& agentInfo = iResolver->AgentInfoL(aAgent.ImplementationUid());
sl@0
   654
sl@0
   655
	// Ask agent to display management info
sl@0
   656
	agentInfo.AgentManagerL().DisplayManagementInfoL();
sl@0
   657
	}
sl@0
   658
sl@0
   659
EXPORT_C CRightsManager* CManager::CreateRightsManagerL(TAgent& aAgent) const
sl@0
   660
	{
sl@0
   661
	// Create a rights manager
sl@0
   662
	return CRightsManager::NewL(aAgent.ImplementationUid());
sl@0
   663
	}
sl@0
   664
sl@0
   665
void CManager::GetListOfAgentPrivateDirectoriesL(CDir *&aDir) const
sl@0
   666
	{
sl@0
   667
	CDirStreamable *ptr = NULL;
sl@0
   668
	// fill in the agent directories under the \\private\\ directory 
sl@0
   669
	TInt i = 0;
sl@0
   670
	TInt count = iResolver->AgentInfoCount();
sl@0
   671
	
sl@0
   672
	TBuf <KMaxAgentNameLength> agentName;
sl@0
   673
	TPath privateDirectory;
sl@0
   674
	
sl@0
   675
	// Create CDirStreamable object
sl@0
   676
	ptr = CDirStreamable::NewL();
sl@0
   677
	CleanupStack::PushL(ptr);
sl@0
   678
	
sl@0
   679
	// set aDir to point to the CDirStreamable we just created
sl@0
   680
	for(i = 0; i < count; i++)
sl@0
   681
		{
sl@0
   682
		// only fill in the agents that have a private directory that is not blank
sl@0
   683
		if(iResolver->AgentInfo(i).PrivateDirectoryName().Length() != 0)
sl@0
   684
			{
sl@0
   685
			TEntry aEntry;
sl@0
   686
			aEntry.iName = iResolver->AgentInfo(i).Agent().Name();
sl@0
   687
			aEntry.iAtt = KEntryAttDir;
sl@0
   688
			aEntry.iType = TUidType();
sl@0
   689
			aEntry.iSize = 0;
sl@0
   690
			ptr->AddL(aEntry);
sl@0
   691
			}
sl@0
   692
		}
sl@0
   693
	CleanupStack::Pop(ptr);
sl@0
   694
	aDir = ptr;
sl@0
   695
	}
sl@0
   696
sl@0
   697
#ifndef REMOVE_CAF1
sl@0
   698
EXPORT_C void CManager::DeleteFileL(const TDesC &aFileName)
sl@0
   699
	{
sl@0
   700
	CManager *m = CManager::NewLC();
sl@0
   701
	User::LeaveIfError(m->DeleteFile(aFileName));
sl@0
   702
	CleanupStack::PopAndDestroy(m);
sl@0
   703
	}
sl@0
   704
#endif // REMOVE_CAF1
sl@0
   705
sl@0
   706
#ifdef SYMBIAN_ENABLE_SDP_WMDRM_SUPPORT
sl@0
   707
sl@0
   708
EXPORT_C TInt CManager::GetAttribute(const TDesC8& aHeaderData, TInt aAttribute, TInt& aValue) const
sl@0
   709
	{
sl@0
   710
	TRAPD(err, DoGetAttributeL(aHeaderData, aAttribute, aValue));
sl@0
   711
	return err;
sl@0
   712
	}
sl@0
   713
sl@0
   714
void CManager::DoGetAttributeL(const TDesC8& aHeaderData, TInt aAttribute, TInt& aValue) const
sl@0
   715
	{
sl@0
   716
	// Find the agent who handles the file 
sl@0
   717
	CAgentInfo& agentInfo = iResolver->ResolveFileL(aHeaderData);
sl@0
   718
	User::LeaveIfError(agentInfo.AgentManagerL().GetAttribute(aHeaderData, aAttribute, aValue));
sl@0
   719
	}
sl@0
   720
	
sl@0
   721
EXPORT_C TInt CManager::GetAttributeSet(const TDesC8& aHeaderData, RAttributeSet& aAttributeSet) const
sl@0
   722
	{
sl@0
   723
	TRAPD(err, DoGetAttributeSetL(aHeaderData, aAttributeSet));
sl@0
   724
	return err;
sl@0
   725
	}
sl@0
   726
sl@0
   727
void CManager::DoGetAttributeSetL(const TDesC8& aHeaderData, RAttributeSet& aAttributeSet) const	
sl@0
   728
	{
sl@0
   729
	// Find the agent who handles the file 
sl@0
   730
	CAgentInfo& agentInfo = iResolver->ResolveFileL(aHeaderData);
sl@0
   731
	
sl@0
   732
	User::LeaveIfError(agentInfo.AgentManagerL().GetAttributeSet(aHeaderData, aAttributeSet));
sl@0
   733
	}
sl@0
   734
	
sl@0
   735
EXPORT_C TInt CManager::GetStringAttribute(const TDesC8& aHeaderData, TInt aAttribute, TDes& aValue) const
sl@0
   736
	{
sl@0
   737
	TRAPD(err, DoGetStringAttributeL(aHeaderData, aAttribute, aValue));
sl@0
   738
	return err;
sl@0
   739
	}
sl@0
   740
	
sl@0
   741
void CManager::DoGetStringAttributeL(const TDesC8& aHeaderData, TInt aAttribute, TDes& aValue) const
sl@0
   742
	{
sl@0
   743
	// Find the agent who handles the file 
sl@0
   744
	CAgentInfo& agentInfo = iResolver->ResolveFileL(aHeaderData);
sl@0
   745
	
sl@0
   746
	// find out the attribute
sl@0
   747
	User::LeaveIfError(agentInfo.AgentManagerL().GetStringAttribute(aHeaderData, aAttribute, aValue));
sl@0
   748
	}
sl@0
   749
	
sl@0
   750
EXPORT_C TInt CManager::GetStringAttributeSet(const TDesC8& aHeaderData, RStringAttributeSet& aStringAttributeSet) const
sl@0
   751
	{
sl@0
   752
	TRAPD(err, DoGetStringAttributeSetL(aHeaderData, aStringAttributeSet));
sl@0
   753
	return err;
sl@0
   754
	}
sl@0
   755
sl@0
   756
void CManager::DoGetStringAttributeSetL(const TDesC8& aHeaderData, RStringAttributeSet& aStringAttributeSet) const
sl@0
   757
	{
sl@0
   758
	// Find the agent who handles the file 
sl@0
   759
	CAgentInfo& agentInfo = iResolver->ResolveFileL(aHeaderData);
sl@0
   760
sl@0
   761
	// find out the array of attributes
sl@0
   762
	User::LeaveIfError(agentInfo.AgentManagerL().GetStringAttributeSet(aHeaderData, aStringAttributeSet));
sl@0
   763
	}
sl@0
   764
	
sl@0
   765
#endif //SYMBIAN_ENABLE_SDP_WMDRM_SUPPORT