sl@0: /* sl@0: * Copyright (c) 2003-2009 Nokia Corporation and/or its subsidiary(-ies). sl@0: * All rights reserved. sl@0: * This component and the accompanying materials are made available sl@0: * under the terms of the License "Eclipse Public License v1.0" sl@0: * which accompanies this distribution, and is available sl@0: * at the URL "http://www.eclipse.org/legal/epl-v10.html". sl@0: * sl@0: * Initial Contributors: sl@0: * Nokia Corporation - initial contribution. sl@0: * sl@0: * Contributors: sl@0: * sl@0: * Description: sl@0: * sl@0: */ sl@0: sl@0: sl@0: #include sl@0: #include "agentinfo.h" sl@0: #include sl@0: #include sl@0: #include sl@0: sl@0: using namespace ContentAccess; sl@0: sl@0: // Default buffer size of zero sl@0: const TInt KCafApparcBufferSize = 0; sl@0: sl@0: CAgentInfo* CAgentInfo::NewLC(const CImplementationInformation& aImplInfo) sl@0: { sl@0: CAgentInfo* self = new (ELeave) CAgentInfo; sl@0: CleanupStack::PushL(self); sl@0: self->ConstructL(aImplInfo); sl@0: return self; sl@0: } sl@0: sl@0: CAgentInfo::CAgentInfo() sl@0: { sl@0: } sl@0: sl@0: CAgentInfo::~CAgentInfo() sl@0: { sl@0: iSupplierMimeTypes.ResetAndDestroy(); sl@0: iSupplierMimeTypes.Close(); sl@0: iConsumerMimeTypes.ResetAndDestroy(); sl@0: iConsumerMimeTypes.Close(); sl@0: sl@0: // Delete the agent manager and agent factory, this may unload the agent DLL sl@0: delete iAgentManager; sl@0: delete iAgentFactory; sl@0: } sl@0: sl@0: sl@0: void CAgentInfo::ConstructL(const CImplementationInformation& aImplInfo) sl@0: { sl@0: // Set up the agent member with the name and Uid of the agent sl@0: iAgent.SetValue(aImplInfo.DisplayName(), aImplInfo.ImplementationUid()); sl@0: sl@0: // get the name of the agents private directory sl@0: TInt length = aImplInfo.OpaqueData().Length(); sl@0: if(length > KMaxSIDLength) sl@0: { sl@0: User::Leave(KErrCorrupt); sl@0: } sl@0: else sl@0: { sl@0: iPrivateDirectoryName.Copy(aImplInfo.OpaqueData().Left(KMaxSIDLength)); sl@0: } sl@0: sl@0: // Extract from the data field from the info. sl@0: // The data field should be of the form: sl@0: // "|,,....,:," sl@0: // bufferlength is the desired length of the buffer passed from apparc to DoRecognize sl@0: TPtrC8 data(aImplInfo.DataType()); sl@0: TPtrC8 supplier(KNullDesC8()); sl@0: TPtrC8 consumer(KNullDesC8()); sl@0: sl@0: // Search for the "|" field to delimit buffersize and supplier mime types sl@0: TInt index = data.LocateF('|'); sl@0: if(index < 0) sl@0: { sl@0: // No default buffersize, ie. corrupt sl@0: User::Leave(KErrCorrupt); sl@0: } sl@0: else sl@0: { sl@0: TPtrC8 buffersize(data.Left(index)); sl@0: TLex8 bufferLex(buffersize); sl@0: bufferLex.Val(iPreferredBufferSize); sl@0: sl@0: // Make sure a buffer size was actually specified before the | character sl@0: if(iPreferredBufferSize == 0) sl@0: { sl@0: iPreferredBufferSize = KCafApparcBufferSize; sl@0: } sl@0: sl@0: // Make sure '|' is not the last character sl@0: if (index + 1 < data.Length()) sl@0: { sl@0: data.Set(aImplInfo.DataType().Mid(index + 1)); sl@0: } sl@0: else sl@0: { sl@0: User::Leave(KErrCorrupt); sl@0: } sl@0: } sl@0: sl@0: sl@0: // Search for the ":" field to delimit supplier and consumer sl@0: index = data.LocateF(':'); sl@0: sl@0: // If the colon was present, then set the pointers appropriately sl@0: if (index >= 0) sl@0: { sl@0: // Set supplier pointer sl@0: supplier.Set(data.Left(index)); sl@0: sl@0: // Check that ':' is not the last character before setting consumer pointer sl@0: if (index + 1 < data.Length()) sl@0: { sl@0: consumer.Set(data.Mid(index + 1)); sl@0: } sl@0: } sl@0: else sl@0: { sl@0: User::Leave(KErrCorrupt); sl@0: } sl@0: sl@0: // Now parse the supplier mime types sl@0: ParseMimeTypesL(supplier, iSupplierMimeTypes); sl@0: sl@0: // Do the same for the consumer mime types sl@0: ParseMimeTypesL(consumer, iConsumerMimeTypes); sl@0: } sl@0: sl@0: CAgentFactory& CAgentInfo::AgentFactoryL() sl@0: { sl@0: // Create the agent factory if it hasn't been done already sl@0: if (!iAgentFactory) sl@0: { sl@0: iAgentFactory = CAgentFactory::NewL(iAgent.ImplementationUid()); sl@0: } sl@0: return *iAgentFactory; sl@0: } sl@0: sl@0: CAgentManager& CAgentInfo::AgentManagerL() sl@0: { sl@0: // Create the agent manager sl@0: if (!iAgentManager) sl@0: { sl@0: iAgentManager = AgentFactoryL().CreateManagerL(); sl@0: } sl@0: return *iAgentManager; sl@0: } sl@0: sl@0: TBool CAgentInfo::IsSupportedSupplier(const TDesC8& aSupplierMime) const sl@0: { sl@0: for (TInt i = 0; i < iSupplierMimeTypes.Count(); ++i) sl@0: { sl@0: if (aSupplierMime == *iSupplierMimeTypes[i]) sl@0: { sl@0: return ETrue; sl@0: } sl@0: } sl@0: return EFalse; sl@0: } sl@0: sl@0: TBool CAgentInfo::IsSupportedConsumer(const TDesC8& aConsumerMime) const sl@0: { sl@0: sl@0: for (TInt i = 0; i < iConsumerMimeTypes.Count(); ++i) sl@0: { sl@0: if (aConsumerMime == *iConsumerMimeTypes[i]) sl@0: { sl@0: return ETrue; sl@0: } sl@0: } sl@0: return EFalse; sl@0: } sl@0: sl@0: const RPointerArray& CAgentInfo::SupplierMimeTypes() const sl@0: { sl@0: return iSupplierMimeTypes; sl@0: } sl@0: sl@0: const RPointerArray& CAgentInfo::ConsumerMimeTypes() const sl@0: { sl@0: return iConsumerMimeTypes; sl@0: } sl@0: sl@0: void CAgentInfo::AddToArrayL(const TDesC8& aElement, sl@0: RPointerArray& aArray) sl@0: { sl@0: // Don't bother adding empty elements sl@0: if (aElement.Length()) sl@0: { sl@0: HBufC8* newElem = aElement.AllocLC(); sl@0: TPtr8 lowerCasePtr = newElem->Des(); sl@0: lowerCasePtr.LowerCase(); sl@0: User::LeaveIfError(aArray.Append(newElem)); sl@0: CleanupStack::Pop(newElem); sl@0: } sl@0: } sl@0: sl@0: void CAgentInfo::ParseMimeTypesL(const TDesC8& aBuf, sl@0: RPointerArray& aMimeTypes) sl@0: { sl@0: TPtrC8 ptr(aBuf); sl@0: TInt pos = 0; sl@0: while ((pos = ptr.LocateF(',')) >= 0) sl@0: { sl@0: // Take into account possibility of ,, sl@0: if (pos > 0) sl@0: { sl@0: AddToArrayL(ptr.Left(pos), aMimeTypes); sl@0: } sl@0: sl@0: // Now, move the pointer to the position after the ','. BUT if the sl@0: // ',' is the last position, then we are done, so return (a bit sl@0: // dirty, but makes things easier sl@0: if (pos + 1 < ptr.Length()) sl@0: { sl@0: ptr.Set(ptr.Mid(pos + 1)); sl@0: } sl@0: else sl@0: { sl@0: // The ',' is the last character, so quit sl@0: return; sl@0: } sl@0: } sl@0: sl@0: // Now extract the last mime type. sl@0: AddToArrayL(ptr, aMimeTypes); sl@0: } sl@0: sl@0: TInt CAgentInfo::PreferredBufferSize() const sl@0: { sl@0: return iPreferredBufferSize; sl@0: } sl@0: sl@0: const TDesC& CAgentInfo::PrivateDirectoryName() const sl@0: { sl@0: return iPrivateDirectoryName; sl@0: } sl@0: sl@0: TAgent& CAgentInfo::Agent() sl@0: { sl@0: return iAgent; sl@0: }