os/security/contentmgmt/contentaccessfwfordrm/source/caf/resolver.h
author sl@SLION-WIN7.fritz.box
Fri, 15 Jun 2012 03:10:57 +0200
changeset 0 bde4ae8d615e
permissions -rw-r--r--
First public contribution.
     1 /*
     2 * Copyright (c) 2003-2009 Nokia Corporation and/or its subsidiary(-ies).
     3 * All rights reserved.
     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".
     8 *
     9 * Initial Contributors:
    10 * Nokia Corporation - initial contribution.
    11 *
    12 * Contributors:
    13 *
    14 * Description: 
    15 *
    16 */
    17 
    18 
    19 /**
    20  @file
    21  @internalComponent
    22  @released
    23 */
    24 
    25 
    26 #ifndef __RESOLVER_H__
    27 #define __RESOLVER_H__
    28 
    29 #include <e32std.h>
    30 #include <ecom/ecom.h>
    31 #include <caf/caftypes.h>
    32 
    33 namespace ContentAccess
    34 	{
    35 	const TUid KF32AgentImplUid = { 0x101FC2CF };
    36 
    37 	class CAgentInfo;
    38 	
    39 	/**
    40 	Used to identify the Content Access Agent who handles a particular file.
    41 	 
    42 	CAgentResolver builds an array of CAgentInfo objects. Each CAgentInfo object
    43 	holds metadata related to a particular agent implementation.
    44 
    45 	This class resolves:
    46 	  - Content to the Agent which manages it
    47 	  - Supplier mime-types to the agent which imports files with that mime type.
    48 
    49 	@internalComponent
    50 	@released
    51 	*/
    52 	class CAgentResolver : public CActive
    53 			{
    54 		public:
    55 			/** Constructs a new CAgentResolver and puts it on the cleanup stack
    56 			* @param aDynamicAgentUpdate ETrue if the CAgentResolver should update its list of agents when new agents appear. A CActiveScheduler must already be running when ETrue is supplied
    57 			* @leave KErrCANoAgent If no F32 agent was found
    58 			*/
    59 			IMPORT_C static CAgentResolver* NewLC(const TBool aDynamicAgentUpdate);
    60 
    61 			/** Constructs a new CAgentResolver
    62 			* @param aDynamicAgentUpdate ETrue if the CAgentResolver should update its list of agents when new agents appear. A CActiveScheduler must already be running when ETrue is supplied
    63 			* @leave KErrCANoAgent If no F32 agent was found
    64 			*/
    65 			IMPORT_C static CAgentResolver* NewL(const TBool aDynamicAgentUpdate);
    66 			virtual ~CAgentResolver();
    67 	
    68 			/** Finds the agent that handles the given supplier MIME type.
    69 			
    70 			@param aMimeType	MIME type from the supplier application.
    71 			@return				The CAgentInfo object associated with the agent that handles files with this MIME type.
    72 			 
    73 			@leave KErrCANoAgent	If no CA agent supports the given MIME type. 
    74 			*/
    75 			CAgentInfo& ResolveSupplierMimeL(const TDesC8& aMimeType) const;
    76 			 
    77 			/** Finds the agent that handles the given consumer MIME type.
    78 				
    79 			@note	Planning to remove this from the CAF API
    80 			
    81 			@param aMimeType	MIME type of the file
    82 			@return			The CAgentInfo object associated with the agent that handles files with this MIME type.
    83  			*/
    84 			CAgentInfo& ResolveConsumerMime(const TDesC8& aMimeType) const;
    85 			
    86 			/** Finds the agent that handles a file.
    87 			
    88 			@param aFile Handle of the file to be resolved.
    89 			@return	The CAgentInfo object associated with the agent that will handle this file.
    90 			*/
    91 			CAgentInfo& ResolveFileL(RFile& aFile) const;			
    92 
    93 #ifdef SYMBIAN_ENABLE_SDP_WMDRM_SUPPORT
    94 			
    95 			/** Finds the agent which handles this piece of content.
    96 			@param aHeaderData	Header data of WMDRM file or stream content.
    97 			@return				CAgentInfo object associated with the agent that will handle WMDRM content.	
    98 			*/
    99 			CAgentInfo& ResolveFileL(const TDesC8& aHeaderData);
   100 			
   101 #endif //#ifdef SYMBIAN_ENABLE_SDP_WMDRM_SUPPORT
   102 						
   103 			/** Finds the agent that handles a file and returns the actual URI of the content.
   104 			
   105 			If the aUri is of the form "c:\\private\\agent_name\\" 
   106 			it will be translated to the form "c:\\private\\SID\\" in
   107 			aActualUri. Otherwise the aUri is just copied to aActualUri
   108 			
   109 			@param aUri	Location of file to be resolved.
   110 			@param aActualUri The actual location of the file
   111 			@param aShareMode The file sharing mode to be used with this file
   112 			@return	The CAgentInfo object associated with the agent that will handle this file.
   113 			*/
   114 			CAgentInfo& ResolveFileL(const TDesC& aUri, TDes& aActualUri, TContentShareMode aShareMode = EContentShareReadOnly) const;
   115 
   116 			/** Find the agent who owns a directory
   117 			
   118 			This function also maps a path from the agent directory name
   119 			to it's actual name in the file system.
   120 			
   121 			ie. For example if an agent "x" has files stored in a private server directory
   122 			"c:\\private\\12345678\\" 
   123 			
   124 			The file appear as "c:\\private\\x\\" to applications using CAF. This function
   125 			converts "c:\\private\\x\\" back to "c:\\private\\12345678\\"
   126 
   127 			@param aPath The path in the form c:\\private\\agent_name\\...
   128 			@param aActualPath The path in the form c:\\private\\SID\\...
   129 			@param aThePrivateDir to ETrue if the directory is just "\\private\\" 
   130 			@return	The Uid of the agent who owns the directory
   131 			*/			
   132 			TUid ResolveDirectory(const TDesC& aPath, TDes& aActualPath, TBool& aThePrivateDir) const;
   133 			
   134 			/** Converts a filename containing the agent SID to the filename containing the agent name.
   135 			@param aFileName The filename in the form "c:\\private\\12345678\\"
   136 			@return A buffer to the new filename in the form "c:\\private\\agent_name\\"
   137 			*/
   138 			HBufC* ConvertAgentFileNameL(const TDesC& aFileName) const;
   139 		
   140 			/** Determines the MIME types of the a file and the mime type of its contents.
   141 
   142 			This function should only be used by the CAF recogizer DLL.
   143 			
   144 			@param aName			The file name/URI to be investigated.
   145 			@param aBuffer			A buffer containing bytes from the start of the file.
   146 			@param aFileMimeType	If the file is recognized this will be populated with 
   147 									the mime type of the file.
   148 			@param aContentMimeType	If the file is recognized this will be populated with the mime type of the content object within the file. 
   149 
   150 			@return					ETrue if the file is recognized by content access agent
   151 			@return					EFalse if the file is not recognized by a content access agent
   152 			*/
   153 			IMPORT_C TBool DoRecognizeL(const TDesC& aName, const TDesC8& aBuffer, TDes8& aFileMimeType, TDes8& aContentMimeType);
   154 	
   155 			/** Gets the preferred buffer size for recognizing files using the RecognizeFile() function.
   156 			
   157 			This function should only be used by the CAF recogizer DLL.  
   158 
   159 			@return	The largest preferred buffer nominated by any agent for recognizing files using the the DoRecognize() function.
   160 			*/
   161 			IMPORT_C TInt PreferredBufferSize();
   162 		
   163 			/** Accessor for the SupplierMimeTypes array.
   164 			*
   165 			* @return	An array of supplier MIME type supported by CAF agents.
   166 			*/
   167 			IMPORT_C const RArray<TPtrC8>& SupplierMimeTypes() const;
   168 
   169 			/** Accessor for the ConsumerMimeTypes array.
   170 			*
   171 			* @note	Planning to remove this from the CAF API
   172 			*
   173 			* @return	An array of consumer MIME types supported by CAF agents.
   174 			*/
   175 			IMPORT_C const RArray<TPtrC8>& ConsumerMimeTypes() const;
   176 
   177 #ifdef SYMBIAN_ENABLE_SDP_WMDRM_SUPPORT			
   178 			/** This function should only be used by the CAF recogizer DLL.
   179 			
   180 			@param aHeader			Header data of WMDRM content.
   181 			@param aFileMimeType	If the content is recognized this will be populated with 
   182 									the mime type of the content.
   183 			@param aContentMimeType	If the content is recognized this will be populated with the mime type of the content. 
   184 
   185 			@return					ETrue if the content is recognized by content access agent
   186 			@return					EFalse if the content is not recognized by a content access agent
   187 			*/
   188 			IMPORT_C TBool DoRecognizeL(const TDesC8& aHeader, TDes8& aFileMimeType, TDes8& aContentMimeType);
   189 #endif //#ifdef SYMBIAN_ENABLE_SDP_WMDRM_SUPPORT	
   190 
   191 			/** Find an agent by it's Uid */
   192 			CAgentInfo& AgentInfoL(const TUid& aUid) const;
   193 			
   194 			/** Find an agent by it's name */
   195 			CAgentInfo& AgentInfoL(const TDesC& aAgentName) const;
   196 			
   197 			/** Reference an agent in the iAgentInfos array by index */
   198 			CAgentInfo& AgentInfo(TInt aIndex) const;
   199 			
   200 			/** The number of agents, excluding the F32Agent */
   201 			 TInt AgentInfoCount() const;
   202 			
   203 			/** The default F32 agent */
   204 			TUid DefaultAgentUid() const;
   205 
   206 		private:
   207 			// From CActive, used for dynamically updating the list of content access agents
   208 			virtual void DoCancel();
   209 			virtual void RunL();
   210 		
   211 		private:
   212 			CAgentResolver(const TBool aDynamicAgentUpdate);
   213 			
   214 			/** Second phase constructor for CAgentResolver
   215 			*/
   216 			void ConstructL();
   217 
   218 
   219 			/** Builds a list of all the Content Access Agents. */
   220 			void BuildListOfAgentsL();
   221 			
   222 			/** Add an agent to the list of agents */
   223 			void AddAgentL(const CImplementationInformation& aImplInfo);
   224 
   225 			/** Resets the list. */
   226 			void DestroyListOfAgents();
   227 
   228 			/** Is this the F32 Agent 
   229 			@param aAgentInfo The agentinfo representing the agent
   230 			@return ETrue if it is the F32Agent, EFalse otherwise
   231 			*/
   232 			TBool IsF32Agent(CAgentInfo& aAgentInfo);
   233 
   234 			// Cleanup item
   235 			static void CleanImplArray(TAny* aArray);
   236 
   237 		private:
   238 			const TBool iDynamicAgentUpdate;
   239 			REComSession* iEcomSession;
   240 
   241 			RArray<TPtrC8> iSupplierMimeTypes;
   242 			RArray<TPtrC8> iConsumerMimeTypes;
   243 	
   244 			// Array of agentInfos (not including F32 agent)
   245 			RPointerArray <CAgentInfo> iAgentInfos;
   246 
   247 			// This points to the agent which handles content if it is not
   248 			// recognised by any other agent (this should be the F32Agent)
   249 			CAgentInfo* iDefaultAgent;
   250 			};
   251 
   252 	} // namespace ContentAccess
   253 #endif /* __RESOLVER_H__ */
   254