os/security/contentmgmt/cafstreamingsupport/source/streamagentresolver.cpp
changeset 0 bde4ae8d615e
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/os/security/contentmgmt/cafstreamingsupport/source/streamagentresolver.cpp	Fri Jun 15 03:10:57 2012 +0200
     1.3 @@ -0,0 +1,133 @@
     1.4 +// Copyright (c) 2007-2009 Nokia Corporation and/or its subsidiary(-ies).
     1.5 +// All rights reserved.
     1.6 +// This component and the accompanying materials are made available
     1.7 +// under the terms of the License "Eclipse Public License v1.0"
     1.8 +// which accompanies this distribution, and is available
     1.9 +// at the URL "http://www.eclipse.org/legal/epl-v10.html".
    1.10 +//
    1.11 +// Initial Contributors:
    1.12 +// Nokia Corporation - initial contribution.
    1.13 +//
    1.14 +// Contributors:
    1.15 +//
    1.16 +// Description:
    1.17 +//
    1.18 +
    1.19 +#include "streamagentresolver.h"
    1.20 +#include "streamagentinfo.h"
    1.21 +#include <caf/streaming/streamagentfactory.h>
    1.22 +#include <caf/patchdata.h>
    1.23 +#include "scaflog.h"
    1.24 +
    1.25 +#include <caf/caferr.h>
    1.26 +
    1.27 +using namespace StreamAccess;
    1.28 +
    1.29 +CStreamAgentResolver* CStreamAgentResolver::NewLC()
    1.30 +	{
    1.31 +	CStreamAgentResolver* self = new(ELeave) CStreamAgentResolver();
    1.32 +	CleanupStack::PushL(self);
    1.33 +	self->ConstructL();
    1.34 +	return self;
    1.35 +	}
    1.36 +
    1.37 +CStreamAgentResolver::CStreamAgentResolver()
    1.38 +	{
    1.39 +	}
    1.40 +
    1.41 +CStreamAgentResolver::~CStreamAgentResolver()
    1.42 +	{
    1.43 +	// Reset and Destroy the stream agent information array 
    1.44 +	iStreamAgentInfoArray.ResetAndDestroy();
    1.45 +	}
    1.46 +
    1.47 +void CStreamAgentResolver::ConstructL()
    1.48 +	{
    1.49 +	// Construct a list of the available stream agent interface implementations
    1.50 +	BuildStreamAgentListL();
    1.51 +	}
    1.52 +
    1.53 +void CStreamAgentResolver::BuildStreamAgentListL()
    1.54 +	{
    1.55 +	/* Construct a new implementation information array that is used in conjunction with the ECOM
    1.56 +	 * framework in order to retrieve resource data about the available stream agent plug-ins
    1.57 +	 */
    1.58 +	RImplInfoPtrArray agentImplArray;
    1.59 +	CleanupStack::PushL(TCleanupItem(CleanAgentImplArray, &agentImplArray));
    1.60 +	REComSession::ListImplementationsL(KUidStreamAgentFactoryInterface, agentImplArray);
    1.61 +	
    1.62 +	TInt streamAgentCount = agentImplArray.Count();
    1.63 +	
    1.64 +	DEBUG_PRINTF2(_L("Number of streaming agents found on the device: %d"),streamAgentCount);
    1.65 +	
    1.66 +	for (TInt i = 0; i < streamAgentCount; ++i)
    1.67 +		{
    1.68 +		/* In order to load stream agents from sources other than ROM, the patch 
    1.69 +		 * data KCafLoadPostProductionAgents must be set to True (non-zero).
    1.70 +		 * Default SymbianOS behavior is to only load file and streaming agents from ROM
    1.71 +		 */
    1.72 +		if ((KCafLoadPostProductionAgents == 0) &&
    1.73 +            !agentImplArray[i]->RomBased())
    1.74 +			{
    1.75 +			/* If the stream agent is not in ROM, don't load it because it might
    1.76 +			 * be a security risk.
    1.77 +			 */
    1.78 +			continue;
    1.79 +			}
    1.80 +		
    1.81 +		/* Construct a seperate element in the CStreamAgentInfo array for each of the 
    1.82 +		 * identified stream agent implementations 
    1.83 +		 */
    1.84 +		AddStreamAgentL(*agentImplArray[i]);
    1.85 +		}
    1.86 +	
    1.87 +	CleanupStack::PopAndDestroy(&agentImplArray);
    1.88 +	}
    1.89 +
    1.90 +void CStreamAgentResolver::CleanAgentImplArray(TAny* aArray)
    1.91 +	{
    1.92 +	// Performs the cleanup on the implementation information array
    1.93 +	static_cast<RImplInfoPtrArray*>(aArray)->ResetAndDestroy();
    1.94 +	}
    1.95 +
    1.96 +void CStreamAgentResolver::AddStreamAgentL(const CImplementationInformation& aAgentInfo)
    1.97 +	{
    1.98 +	// Create a new CStreamAgentInfo instance to add to the stream agent list
    1.99 +	CStreamAgentInfo* agentInformation = CStreamAgentInfo::NewLC(aAgentInfo);
   1.100 +	
   1.101 +	TUid agentUid(agentInformation->ImplementationUid());
   1.102 +	TPtrC agentName(agentInformation->Name());
   1.103 +	
   1.104 +	DEBUG_PRINTF3(_L("Stream Agent Identified: 0x%08x (%S)"),agentUid,&agentName);
   1.105 +	
   1.106 +	// Append the CStreamAgentInfo object to the stream agent information array
   1.107 +	User::LeaveIfError(iStreamAgentInfoArray.Append(agentInformation));
   1.108 +	CleanupStack::Pop(agentInformation);
   1.109 +	}
   1.110 +
   1.111 +CStreamAgentInfo& CStreamAgentResolver::ResolveSdpKeyStreamL(const CSdpMediaField& aSdpKeyStream) const
   1.112 +	{
   1.113 +	TInt streamAgentInfoCount = iStreamAgentInfoArray.Count();
   1.114 +	
   1.115 +	/* Loop through each of the identified stream agents to determine which (if any) supports 
   1.116 +	 * the SDP key management description
   1.117 +	 */
   1.118 +	for(TInt i=0; i < streamAgentInfoCount; ++i)
   1.119 +		{
   1.120 +		if(iStreamAgentInfoArray[i]->IsKeyStreamSupportedL(aSdpKeyStream))
   1.121 +			{
   1.122 +			TUid agentUid(iStreamAgentInfoArray[i]->ImplementationUid());
   1.123 +			TPtrC agentName (iStreamAgentInfoArray[i]->Name());
   1.124 +			DEBUG_PRINTF3(_L("Key stream is supported by the agent: 0x%08x (%S)"),agentUid,&agentName);
   1.125 +			return *iStreamAgentInfoArray[i];
   1.126 +			}
   1.127 +		}
   1.128 +	
   1.129 +	// If a stream agent capable of decoding the key stream can not be found, leave with KErrCANoAgent
   1.130 +	DEBUG_PRINTF(_L("A stream agent capable of decoding the key stream can not be found!"));
   1.131 +	User::Leave(KErrCANoAgent);
   1.132 +	
   1.133 +	// Return NULL reference to avoid warnings (should never get here)
   1.134 +	CStreamAgentInfo* retVal=NULL;
   1.135 +	return *retVal;
   1.136 +	}