sl@0
|
1 |
/*
|
sl@0
|
2 |
* Copyright (c) 2003-2009 Nokia Corporation and/or its subsidiary(-ies).
|
sl@0
|
3 |
* All rights reserved.
|
sl@0
|
4 |
* This component and the accompanying materials are made available
|
sl@0
|
5 |
* under the terms of the License "Eclipse Public License v1.0"
|
sl@0
|
6 |
* which accompanies this distribution, and is available
|
sl@0
|
7 |
* at the URL "http://www.eclipse.org/legal/epl-v10.html".
|
sl@0
|
8 |
*
|
sl@0
|
9 |
* Initial Contributors:
|
sl@0
|
10 |
* Nokia Corporation - initial contribution.
|
sl@0
|
11 |
*
|
sl@0
|
12 |
* Contributors:
|
sl@0
|
13 |
*
|
sl@0
|
14 |
* Description:
|
sl@0
|
15 |
*
|
sl@0
|
16 |
*/
|
sl@0
|
17 |
|
sl@0
|
18 |
|
sl@0
|
19 |
#include <ecom/ecom.h>
|
sl@0
|
20 |
#include "agentinfo.h"
|
sl@0
|
21 |
#include <caf/agent.h>
|
sl@0
|
22 |
#include <caf/agentfactory.h>
|
sl@0
|
23 |
#include <caf/agentinterface.h>
|
sl@0
|
24 |
|
sl@0
|
25 |
using namespace ContentAccess;
|
sl@0
|
26 |
|
sl@0
|
27 |
// Default buffer size of zero
|
sl@0
|
28 |
const TInt KCafApparcBufferSize = 0;
|
sl@0
|
29 |
|
sl@0
|
30 |
CAgentInfo* CAgentInfo::NewLC(const CImplementationInformation& aImplInfo)
|
sl@0
|
31 |
{
|
sl@0
|
32 |
CAgentInfo* self = new (ELeave) CAgentInfo;
|
sl@0
|
33 |
CleanupStack::PushL(self);
|
sl@0
|
34 |
self->ConstructL(aImplInfo);
|
sl@0
|
35 |
return self;
|
sl@0
|
36 |
}
|
sl@0
|
37 |
|
sl@0
|
38 |
CAgentInfo::CAgentInfo()
|
sl@0
|
39 |
{
|
sl@0
|
40 |
}
|
sl@0
|
41 |
|
sl@0
|
42 |
CAgentInfo::~CAgentInfo()
|
sl@0
|
43 |
{
|
sl@0
|
44 |
iSupplierMimeTypes.ResetAndDestroy();
|
sl@0
|
45 |
iSupplierMimeTypes.Close();
|
sl@0
|
46 |
iConsumerMimeTypes.ResetAndDestroy();
|
sl@0
|
47 |
iConsumerMimeTypes.Close();
|
sl@0
|
48 |
|
sl@0
|
49 |
// Delete the agent manager and agent factory, this may unload the agent DLL
|
sl@0
|
50 |
delete iAgentManager;
|
sl@0
|
51 |
delete iAgentFactory;
|
sl@0
|
52 |
}
|
sl@0
|
53 |
|
sl@0
|
54 |
|
sl@0
|
55 |
void CAgentInfo::ConstructL(const CImplementationInformation& aImplInfo)
|
sl@0
|
56 |
{
|
sl@0
|
57 |
// Set up the agent member with the name and Uid of the agent
|
sl@0
|
58 |
iAgent.SetValue(aImplInfo.DisplayName(), aImplInfo.ImplementationUid());
|
sl@0
|
59 |
|
sl@0
|
60 |
// get the name of the agents private directory
|
sl@0
|
61 |
TInt length = aImplInfo.OpaqueData().Length();
|
sl@0
|
62 |
if(length > KMaxSIDLength)
|
sl@0
|
63 |
{
|
sl@0
|
64 |
User::Leave(KErrCorrupt);
|
sl@0
|
65 |
}
|
sl@0
|
66 |
else
|
sl@0
|
67 |
{
|
sl@0
|
68 |
iPrivateDirectoryName.Copy(aImplInfo.OpaqueData().Left(KMaxSIDLength));
|
sl@0
|
69 |
}
|
sl@0
|
70 |
|
sl@0
|
71 |
// Extract from the data field from the info.
|
sl@0
|
72 |
// The data field should be of the form:
|
sl@0
|
73 |
// "<bufferlength>|<supplier1>,<supplier2>,....,<suppliern>:<consumer1>,<consumer2>"
|
sl@0
|
74 |
// bufferlength is the desired length of the buffer passed from apparc to DoRecognize
|
sl@0
|
75 |
TPtrC8 data(aImplInfo.DataType());
|
sl@0
|
76 |
TPtrC8 supplier(KNullDesC8());
|
sl@0
|
77 |
TPtrC8 consumer(KNullDesC8());
|
sl@0
|
78 |
|
sl@0
|
79 |
// Search for the "|" field to delimit buffersize and supplier mime types
|
sl@0
|
80 |
TInt index = data.LocateF('|');
|
sl@0
|
81 |
if(index < 0)
|
sl@0
|
82 |
{
|
sl@0
|
83 |
// No default buffersize, ie. corrupt
|
sl@0
|
84 |
User::Leave(KErrCorrupt);
|
sl@0
|
85 |
}
|
sl@0
|
86 |
else
|
sl@0
|
87 |
{
|
sl@0
|
88 |
TPtrC8 buffersize(data.Left(index));
|
sl@0
|
89 |
TLex8 bufferLex(buffersize);
|
sl@0
|
90 |
bufferLex.Val(iPreferredBufferSize);
|
sl@0
|
91 |
|
sl@0
|
92 |
// Make sure a buffer size was actually specified before the | character
|
sl@0
|
93 |
if(iPreferredBufferSize == 0)
|
sl@0
|
94 |
{
|
sl@0
|
95 |
iPreferredBufferSize = KCafApparcBufferSize;
|
sl@0
|
96 |
}
|
sl@0
|
97 |
|
sl@0
|
98 |
// Make sure '|' is not the last character
|
sl@0
|
99 |
if (index + 1 < data.Length())
|
sl@0
|
100 |
{
|
sl@0
|
101 |
data.Set(aImplInfo.DataType().Mid(index + 1));
|
sl@0
|
102 |
}
|
sl@0
|
103 |
else
|
sl@0
|
104 |
{
|
sl@0
|
105 |
User::Leave(KErrCorrupt);
|
sl@0
|
106 |
}
|
sl@0
|
107 |
}
|
sl@0
|
108 |
|
sl@0
|
109 |
|
sl@0
|
110 |
// Search for the ":" field to delimit supplier and consumer
|
sl@0
|
111 |
index = data.LocateF(':');
|
sl@0
|
112 |
|
sl@0
|
113 |
// If the colon was present, then set the pointers appropriately
|
sl@0
|
114 |
if (index >= 0)
|
sl@0
|
115 |
{
|
sl@0
|
116 |
// Set supplier pointer
|
sl@0
|
117 |
supplier.Set(data.Left(index));
|
sl@0
|
118 |
|
sl@0
|
119 |
// Check that ':' is not the last character before setting consumer pointer
|
sl@0
|
120 |
if (index + 1 < data.Length())
|
sl@0
|
121 |
{
|
sl@0
|
122 |
consumer.Set(data.Mid(index + 1));
|
sl@0
|
123 |
}
|
sl@0
|
124 |
}
|
sl@0
|
125 |
else
|
sl@0
|
126 |
{
|
sl@0
|
127 |
User::Leave(KErrCorrupt);
|
sl@0
|
128 |
}
|
sl@0
|
129 |
|
sl@0
|
130 |
// Now parse the supplier mime types
|
sl@0
|
131 |
ParseMimeTypesL(supplier, iSupplierMimeTypes);
|
sl@0
|
132 |
|
sl@0
|
133 |
// Do the same for the consumer mime types
|
sl@0
|
134 |
ParseMimeTypesL(consumer, iConsumerMimeTypes);
|
sl@0
|
135 |
}
|
sl@0
|
136 |
|
sl@0
|
137 |
CAgentFactory& CAgentInfo::AgentFactoryL()
|
sl@0
|
138 |
{
|
sl@0
|
139 |
// Create the agent factory if it hasn't been done already
|
sl@0
|
140 |
if (!iAgentFactory)
|
sl@0
|
141 |
{
|
sl@0
|
142 |
iAgentFactory = CAgentFactory::NewL(iAgent.ImplementationUid());
|
sl@0
|
143 |
}
|
sl@0
|
144 |
return *iAgentFactory;
|
sl@0
|
145 |
}
|
sl@0
|
146 |
|
sl@0
|
147 |
CAgentManager& CAgentInfo::AgentManagerL()
|
sl@0
|
148 |
{
|
sl@0
|
149 |
// Create the agent manager
|
sl@0
|
150 |
if (!iAgentManager)
|
sl@0
|
151 |
{
|
sl@0
|
152 |
iAgentManager = AgentFactoryL().CreateManagerL();
|
sl@0
|
153 |
}
|
sl@0
|
154 |
return *iAgentManager;
|
sl@0
|
155 |
}
|
sl@0
|
156 |
|
sl@0
|
157 |
TBool CAgentInfo::IsSupportedSupplier(const TDesC8& aSupplierMime) const
|
sl@0
|
158 |
{
|
sl@0
|
159 |
for (TInt i = 0; i < iSupplierMimeTypes.Count(); ++i)
|
sl@0
|
160 |
{
|
sl@0
|
161 |
if (aSupplierMime == *iSupplierMimeTypes[i])
|
sl@0
|
162 |
{
|
sl@0
|
163 |
return ETrue;
|
sl@0
|
164 |
}
|
sl@0
|
165 |
}
|
sl@0
|
166 |
return EFalse;
|
sl@0
|
167 |
}
|
sl@0
|
168 |
|
sl@0
|
169 |
TBool CAgentInfo::IsSupportedConsumer(const TDesC8& aConsumerMime) const
|
sl@0
|
170 |
{
|
sl@0
|
171 |
|
sl@0
|
172 |
for (TInt i = 0; i < iConsumerMimeTypes.Count(); ++i)
|
sl@0
|
173 |
{
|
sl@0
|
174 |
if (aConsumerMime == *iConsumerMimeTypes[i])
|
sl@0
|
175 |
{
|
sl@0
|
176 |
return ETrue;
|
sl@0
|
177 |
}
|
sl@0
|
178 |
}
|
sl@0
|
179 |
return EFalse;
|
sl@0
|
180 |
}
|
sl@0
|
181 |
|
sl@0
|
182 |
const RPointerArray<HBufC8>& CAgentInfo::SupplierMimeTypes() const
|
sl@0
|
183 |
{
|
sl@0
|
184 |
return iSupplierMimeTypes;
|
sl@0
|
185 |
}
|
sl@0
|
186 |
|
sl@0
|
187 |
const RPointerArray<HBufC8>& CAgentInfo::ConsumerMimeTypes() const
|
sl@0
|
188 |
{
|
sl@0
|
189 |
return iConsumerMimeTypes;
|
sl@0
|
190 |
}
|
sl@0
|
191 |
|
sl@0
|
192 |
void CAgentInfo::AddToArrayL(const TDesC8& aElement,
|
sl@0
|
193 |
RPointerArray<HBufC8>& aArray)
|
sl@0
|
194 |
{
|
sl@0
|
195 |
// Don't bother adding empty elements
|
sl@0
|
196 |
if (aElement.Length())
|
sl@0
|
197 |
{
|
sl@0
|
198 |
HBufC8* newElem = aElement.AllocLC();
|
sl@0
|
199 |
TPtr8 lowerCasePtr = newElem->Des();
|
sl@0
|
200 |
lowerCasePtr.LowerCase();
|
sl@0
|
201 |
User::LeaveIfError(aArray.Append(newElem));
|
sl@0
|
202 |
CleanupStack::Pop(newElem);
|
sl@0
|
203 |
}
|
sl@0
|
204 |
}
|
sl@0
|
205 |
|
sl@0
|
206 |
void CAgentInfo::ParseMimeTypesL(const TDesC8& aBuf,
|
sl@0
|
207 |
RPointerArray<HBufC8>& aMimeTypes)
|
sl@0
|
208 |
{
|
sl@0
|
209 |
TPtrC8 ptr(aBuf);
|
sl@0
|
210 |
TInt pos = 0;
|
sl@0
|
211 |
while ((pos = ptr.LocateF(',')) >= 0)
|
sl@0
|
212 |
{
|
sl@0
|
213 |
// Take into account possibility of ,,
|
sl@0
|
214 |
if (pos > 0)
|
sl@0
|
215 |
{
|
sl@0
|
216 |
AddToArrayL(ptr.Left(pos), aMimeTypes);
|
sl@0
|
217 |
}
|
sl@0
|
218 |
|
sl@0
|
219 |
// Now, move the pointer to the position after the ','. BUT if the
|
sl@0
|
220 |
// ',' is the last position, then we are done, so return (a bit
|
sl@0
|
221 |
// dirty, but makes things easier
|
sl@0
|
222 |
if (pos + 1 < ptr.Length())
|
sl@0
|
223 |
{
|
sl@0
|
224 |
ptr.Set(ptr.Mid(pos + 1));
|
sl@0
|
225 |
}
|
sl@0
|
226 |
else
|
sl@0
|
227 |
{
|
sl@0
|
228 |
// The ',' is the last character, so quit
|
sl@0
|
229 |
return;
|
sl@0
|
230 |
}
|
sl@0
|
231 |
}
|
sl@0
|
232 |
|
sl@0
|
233 |
// Now extract the last mime type.
|
sl@0
|
234 |
AddToArrayL(ptr, aMimeTypes);
|
sl@0
|
235 |
}
|
sl@0
|
236 |
|
sl@0
|
237 |
TInt CAgentInfo::PreferredBufferSize() const
|
sl@0
|
238 |
{
|
sl@0
|
239 |
return iPreferredBufferSize;
|
sl@0
|
240 |
}
|
sl@0
|
241 |
|
sl@0
|
242 |
const TDesC& CAgentInfo::PrivateDirectoryName() const
|
sl@0
|
243 |
{
|
sl@0
|
244 |
return iPrivateDirectoryName;
|
sl@0
|
245 |
}
|
sl@0
|
246 |
|
sl@0
|
247 |
TAgent& CAgentInfo::Agent()
|
sl@0
|
248 |
{
|
sl@0
|
249 |
return iAgent;
|
sl@0
|
250 |
}
|