os/security/contentmgmt/cafstreamingsupport/source/streamagentresolver.cpp
author sl
Tue, 10 Jun 2014 14:32:02 +0200
changeset 1 260cb5ec6c19
permissions -rw-r--r--
Update contrib.
     1 // Copyright (c) 2007-2009 Nokia Corporation and/or its subsidiary(-ies).
     2 // All rights reserved.
     3 // This component and the accompanying materials are made available
     4 // under the terms of the License "Eclipse Public License v1.0"
     5 // which accompanies this distribution, and is available
     6 // at the URL "http://www.eclipse.org/legal/epl-v10.html".
     7 //
     8 // Initial Contributors:
     9 // Nokia Corporation - initial contribution.
    10 //
    11 // Contributors:
    12 //
    13 // Description:
    14 //
    15 
    16 #include "streamagentresolver.h"
    17 #include "streamagentinfo.h"
    18 #include <caf/streaming/streamagentfactory.h>
    19 #include <caf/patchdata.h>
    20 #include "scaflog.h"
    21 
    22 #include <caf/caferr.h>
    23 
    24 using namespace StreamAccess;
    25 
    26 CStreamAgentResolver* CStreamAgentResolver::NewLC()
    27 	{
    28 	CStreamAgentResolver* self = new(ELeave) CStreamAgentResolver();
    29 	CleanupStack::PushL(self);
    30 	self->ConstructL();
    31 	return self;
    32 	}
    33 
    34 CStreamAgentResolver::CStreamAgentResolver()
    35 	{
    36 	}
    37 
    38 CStreamAgentResolver::~CStreamAgentResolver()
    39 	{
    40 	// Reset and Destroy the stream agent information array 
    41 	iStreamAgentInfoArray.ResetAndDestroy();
    42 	}
    43 
    44 void CStreamAgentResolver::ConstructL()
    45 	{
    46 	// Construct a list of the available stream agent interface implementations
    47 	BuildStreamAgentListL();
    48 	}
    49 
    50 void CStreamAgentResolver::BuildStreamAgentListL()
    51 	{
    52 	/* Construct a new implementation information array that is used in conjunction with the ECOM
    53 	 * framework in order to retrieve resource data about the available stream agent plug-ins
    54 	 */
    55 	RImplInfoPtrArray agentImplArray;
    56 	CleanupStack::PushL(TCleanupItem(CleanAgentImplArray, &agentImplArray));
    57 	REComSession::ListImplementationsL(KUidStreamAgentFactoryInterface, agentImplArray);
    58 	
    59 	TInt streamAgentCount = agentImplArray.Count();
    60 	
    61 	DEBUG_PRINTF2(_L("Number of streaming agents found on the device: %d"),streamAgentCount);
    62 	
    63 	for (TInt i = 0; i < streamAgentCount; ++i)
    64 		{
    65 		/* In order to load stream agents from sources other than ROM, the patch 
    66 		 * data KCafLoadPostProductionAgents must be set to True (non-zero).
    67 		 * Default SymbianOS behavior is to only load file and streaming agents from ROM
    68 		 */
    69 		if ((KCafLoadPostProductionAgents == 0) &&
    70             !agentImplArray[i]->RomBased())
    71 			{
    72 			/* If the stream agent is not in ROM, don't load it because it might
    73 			 * be a security risk.
    74 			 */
    75 			continue;
    76 			}
    77 		
    78 		/* Construct a seperate element in the CStreamAgentInfo array for each of the 
    79 		 * identified stream agent implementations 
    80 		 */
    81 		AddStreamAgentL(*agentImplArray[i]);
    82 		}
    83 	
    84 	CleanupStack::PopAndDestroy(&agentImplArray);
    85 	}
    86 
    87 void CStreamAgentResolver::CleanAgentImplArray(TAny* aArray)
    88 	{
    89 	// Performs the cleanup on the implementation information array
    90 	static_cast<RImplInfoPtrArray*>(aArray)->ResetAndDestroy();
    91 	}
    92 
    93 void CStreamAgentResolver::AddStreamAgentL(const CImplementationInformation& aAgentInfo)
    94 	{
    95 	// Create a new CStreamAgentInfo instance to add to the stream agent list
    96 	CStreamAgentInfo* agentInformation = CStreamAgentInfo::NewLC(aAgentInfo);
    97 	
    98 	TUid agentUid(agentInformation->ImplementationUid());
    99 	TPtrC agentName(agentInformation->Name());
   100 	
   101 	DEBUG_PRINTF3(_L("Stream Agent Identified: 0x%08x (%S)"),agentUid,&agentName);
   102 	
   103 	// Append the CStreamAgentInfo object to the stream agent information array
   104 	User::LeaveIfError(iStreamAgentInfoArray.Append(agentInformation));
   105 	CleanupStack::Pop(agentInformation);
   106 	}
   107 
   108 CStreamAgentInfo& CStreamAgentResolver::ResolveSdpKeyStreamL(const CSdpMediaField& aSdpKeyStream) const
   109 	{
   110 	TInt streamAgentInfoCount = iStreamAgentInfoArray.Count();
   111 	
   112 	/* Loop through each of the identified stream agents to determine which (if any) supports 
   113 	 * the SDP key management description
   114 	 */
   115 	for(TInt i=0; i < streamAgentInfoCount; ++i)
   116 		{
   117 		if(iStreamAgentInfoArray[i]->IsKeyStreamSupportedL(aSdpKeyStream))
   118 			{
   119 			TUid agentUid(iStreamAgentInfoArray[i]->ImplementationUid());
   120 			TPtrC agentName (iStreamAgentInfoArray[i]->Name());
   121 			DEBUG_PRINTF3(_L("Key stream is supported by the agent: 0x%08x (%S)"),agentUid,&agentName);
   122 			return *iStreamAgentInfoArray[i];
   123 			}
   124 		}
   125 	
   126 	// If a stream agent capable of decoding the key stream can not be found, leave with KErrCANoAgent
   127 	DEBUG_PRINTF(_L("A stream agent capable of decoding the key stream can not be found!"));
   128 	User::Leave(KErrCANoAgent);
   129 	
   130 	// Return NULL reference to avoid warnings (should never get here)
   131 	CStreamAgentInfo* retVal=NULL;
   132 	return *retVal;
   133 	}