First public contribution.
2 * Copyright (c) 2003-2009 Nokia Corporation and/or its subsidiary(-ies).
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".
9 * Initial Contributors:
10 * Nokia Corporation - initial contribution.
19 #include <ecom/ecom.h>
20 #include "agentinfo.h"
21 #include <caf/agent.h>
22 #include <caf/agentfactory.h>
23 #include <caf/agentinterface.h>
25 using namespace ContentAccess;
27 // Default buffer size of zero
28 const TInt KCafApparcBufferSize = 0;
30 CAgentInfo* CAgentInfo::NewLC(const CImplementationInformation& aImplInfo)
32 CAgentInfo* self = new (ELeave) CAgentInfo;
33 CleanupStack::PushL(self);
34 self->ConstructL(aImplInfo);
38 CAgentInfo::CAgentInfo()
42 CAgentInfo::~CAgentInfo()
44 iSupplierMimeTypes.ResetAndDestroy();
45 iSupplierMimeTypes.Close();
46 iConsumerMimeTypes.ResetAndDestroy();
47 iConsumerMimeTypes.Close();
49 // Delete the agent manager and agent factory, this may unload the agent DLL
55 void CAgentInfo::ConstructL(const CImplementationInformation& aImplInfo)
57 // Set up the agent member with the name and Uid of the agent
58 iAgent.SetValue(aImplInfo.DisplayName(), aImplInfo.ImplementationUid());
60 // get the name of the agents private directory
61 TInt length = aImplInfo.OpaqueData().Length();
62 if(length > KMaxSIDLength)
64 User::Leave(KErrCorrupt);
68 iPrivateDirectoryName.Copy(aImplInfo.OpaqueData().Left(KMaxSIDLength));
71 // Extract from the data field from the info.
72 // The data field should be of the form:
73 // "<bufferlength>|<supplier1>,<supplier2>,....,<suppliern>:<consumer1>,<consumer2>"
74 // bufferlength is the desired length of the buffer passed from apparc to DoRecognize
75 TPtrC8 data(aImplInfo.DataType());
76 TPtrC8 supplier(KNullDesC8());
77 TPtrC8 consumer(KNullDesC8());
79 // Search for the "|" field to delimit buffersize and supplier mime types
80 TInt index = data.LocateF('|');
83 // No default buffersize, ie. corrupt
84 User::Leave(KErrCorrupt);
88 TPtrC8 buffersize(data.Left(index));
89 TLex8 bufferLex(buffersize);
90 bufferLex.Val(iPreferredBufferSize);
92 // Make sure a buffer size was actually specified before the | character
93 if(iPreferredBufferSize == 0)
95 iPreferredBufferSize = KCafApparcBufferSize;
98 // Make sure '|' is not the last character
99 if (index + 1 < data.Length())
101 data.Set(aImplInfo.DataType().Mid(index + 1));
105 User::Leave(KErrCorrupt);
110 // Search for the ":" field to delimit supplier and consumer
111 index = data.LocateF(':');
113 // If the colon was present, then set the pointers appropriately
116 // Set supplier pointer
117 supplier.Set(data.Left(index));
119 // Check that ':' is not the last character before setting consumer pointer
120 if (index + 1 < data.Length())
122 consumer.Set(data.Mid(index + 1));
127 User::Leave(KErrCorrupt);
130 // Now parse the supplier mime types
131 ParseMimeTypesL(supplier, iSupplierMimeTypes);
133 // Do the same for the consumer mime types
134 ParseMimeTypesL(consumer, iConsumerMimeTypes);
137 CAgentFactory& CAgentInfo::AgentFactoryL()
139 // Create the agent factory if it hasn't been done already
142 iAgentFactory = CAgentFactory::NewL(iAgent.ImplementationUid());
144 return *iAgentFactory;
147 CAgentManager& CAgentInfo::AgentManagerL()
149 // Create the agent manager
152 iAgentManager = AgentFactoryL().CreateManagerL();
154 return *iAgentManager;
157 TBool CAgentInfo::IsSupportedSupplier(const TDesC8& aSupplierMime) const
159 for (TInt i = 0; i < iSupplierMimeTypes.Count(); ++i)
161 if (aSupplierMime == *iSupplierMimeTypes[i])
169 TBool CAgentInfo::IsSupportedConsumer(const TDesC8& aConsumerMime) const
172 for (TInt i = 0; i < iConsumerMimeTypes.Count(); ++i)
174 if (aConsumerMime == *iConsumerMimeTypes[i])
182 const RPointerArray<HBufC8>& CAgentInfo::SupplierMimeTypes() const
184 return iSupplierMimeTypes;
187 const RPointerArray<HBufC8>& CAgentInfo::ConsumerMimeTypes() const
189 return iConsumerMimeTypes;
192 void CAgentInfo::AddToArrayL(const TDesC8& aElement,
193 RPointerArray<HBufC8>& aArray)
195 // Don't bother adding empty elements
196 if (aElement.Length())
198 HBufC8* newElem = aElement.AllocLC();
199 TPtr8 lowerCasePtr = newElem->Des();
200 lowerCasePtr.LowerCase();
201 User::LeaveIfError(aArray.Append(newElem));
202 CleanupStack::Pop(newElem);
206 void CAgentInfo::ParseMimeTypesL(const TDesC8& aBuf,
207 RPointerArray<HBufC8>& aMimeTypes)
211 while ((pos = ptr.LocateF(',')) >= 0)
213 // Take into account possibility of ,,
216 AddToArrayL(ptr.Left(pos), aMimeTypes);
219 // Now, move the pointer to the position after the ','. BUT if the
220 // ',' is the last position, then we are done, so return (a bit
221 // dirty, but makes things easier
222 if (pos + 1 < ptr.Length())
224 ptr.Set(ptr.Mid(pos + 1));
228 // The ',' is the last character, so quit
233 // Now extract the last mime type.
234 AddToArrayL(ptr, aMimeTypes);
237 TInt CAgentInfo::PreferredBufferSize() const
239 return iPreferredBufferSize;
242 const TDesC& CAgentInfo::PrivateDirectoryName() const
244 return iPrivateDirectoryName;
247 TAgent& CAgentInfo::Agent()