|
1 /* |
|
2 * Copyright (c) 2010 Kanrikogaku Kenkyusho, Ltd. |
|
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 * Kanrikogaku Kenkyusho, Ltd. - Initial contribution |
|
11 * |
|
12 * Contributors: |
|
13 * |
|
14 * Description: Contains the CDirectPrintProtocolsLoader class definition. |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 #include <ecom/ecom.h> |
|
20 |
|
21 #include "directprintprotocolsloader.h" |
|
22 #include "mprotprintingdevice.h" |
|
23 #include "clog.h" |
|
24 #include "imageprint.h" |
|
25 |
|
26 namespace |
|
27 { |
|
28 const TUid KDirectPrintEcomUid = { 0x10208A1E }; |
|
29 } |
|
30 |
|
31 CDirectPrintProtocolsLoader* CDirectPrintProtocolsLoader::NewL() |
|
32 { |
|
33 LOG("[CDirectPrintProtocolsLoader::NewL]\t Begin"); |
|
34 CDirectPrintProtocolsLoader* self = new (ELeave) CDirectPrintProtocolsLoader(); |
|
35 CleanupStack::PushL(self); |
|
36 self->ConstructL(); |
|
37 CleanupStack::Pop(self); |
|
38 LOG("[CDirectPrintProtocolsLoader::NewL]\t End"); |
|
39 return self; |
|
40 } |
|
41 |
|
42 |
|
43 CDirectPrintProtocolsLoader::~CDirectPrintProtocolsLoader() |
|
44 { |
|
45 LOG("[CDirectPrintProtocolsLoader::~CDirectPrintProtocolsLoader]\t Begin"); |
|
46 iProtocols.ResetAndDestroy(); |
|
47 iProtocolInfos.ResetAndDestroy(); |
|
48 LOG("[CDirectPrintProtocolsLoader::~CDirectPrintProtocolsLoader]\t End"); |
|
49 } |
|
50 |
|
51 |
|
52 TInt CDirectPrintProtocolsLoader::GetNumberOfProtocolsAvailable() const |
|
53 { |
|
54 LOG("[CDirectPrintProtocolsLoader::GetNumberOfProtocolsAvailable]\t Begin"); |
|
55 LOG1("[CDirectPrintProtocolsLoader::GetNumberOfProtocolsAvailable]\t return: %d", iAvailableProtocols); |
|
56 LOG("[CDirectPrintProtocolsLoader::GetNumberOfProtocolsAvailable]\t End"); |
|
57 return iAvailableProtocols; |
|
58 } |
|
59 |
|
60 |
|
61 MProtPrintingDevice* CDirectPrintProtocolsLoader::GetNextProtocol() |
|
62 { |
|
63 LOG("[CDirectPrintProtocolsLoader::GetNextProtocol]\t Begin"); |
|
64 if (iAvailableProtocols <= 0) |
|
65 return NULL; |
|
66 |
|
67 if (iProtIndex == iAvailableProtocols) |
|
68 iProtIndex = 0; |
|
69 |
|
70 MProtPrintingDevice* temp = iProtocols[iProtIndex]; |
|
71 iProtIndex++; |
|
72 LOG("[CDirectPrintProtocolsLoader::GetNextProtocol]\t End"); |
|
73 return temp; |
|
74 } |
|
75 |
|
76 |
|
77 MProtPrintingDevice* CDirectPrintProtocolsLoader::GetProtocolAt(TInt aIndex) |
|
78 { |
|
79 LOG("[CDirectPrintProtocolsLoader::GetProtocolAt]\t Begin"); |
|
80 if( iAvailableProtocols <= 0 ) return NULL; |
|
81 |
|
82 MProtPrintingDevice* temp = NULL; |
|
83 |
|
84 if (aIndex < 0) |
|
85 temp = (MProtPrintingDevice*) iProtocols[0]; |
|
86 else |
|
87 if (aIndex >= iAvailableProtocols) |
|
88 temp = (MProtPrintingDevice*) iProtocols[iAvailableProtocols - 1]; |
|
89 else |
|
90 temp = (MProtPrintingDevice*) iProtocols[aIndex]; |
|
91 |
|
92 LOG("[CDirectPrintProtocolsLoader::GetProtocolAt]\t End"); |
|
93 return temp; |
|
94 |
|
95 } |
|
96 |
|
97 |
|
98 void CDirectPrintProtocolsLoader::Reset() |
|
99 { |
|
100 LOG("[CDirectPrintProtocolsLoader::Reset]\t Begin"); |
|
101 iProtIndex = 0; |
|
102 LOG("[CDirectPrintProtocolsLoader::Reset]\t End"); |
|
103 } |
|
104 |
|
105 |
|
106 TInt CDirectPrintProtocolsLoader::GetProtocolIndex() const |
|
107 { |
|
108 LOG("[CDirectPrintProtocolsLoader::GetProtocolIndex]\t Begin"); |
|
109 |
|
110 TInt retVal = iProtIndex - 1; |
|
111 // The next check is probably unnecessary since GetNextProtocol() should only leave iProtIndex with |
|
112 // a value between 1 and iAvailableProtocols |
|
113 if (retVal < 0) |
|
114 { |
|
115 retVal = iProtocols.Count() - 1; |
|
116 } |
|
117 LOG1("[CDirectPrintProtocolsLoader::GetProtocolIndex] return: %d", retVal); |
|
118 LOG("[CDirectPrintProtocolsLoader::GetProtocolIndex]\t End"); |
|
119 return retVal; |
|
120 } |
|
121 |
|
122 |
|
123 TUint CDirectPrintProtocolsLoader::SupportedProtocols() const |
|
124 { |
|
125 LOG("[CDirectPrintProtocolsLoader::SupportedProtocols]\t Begin"); |
|
126 LOG1("[CDirectPrintProtocolsLoader::SupportedProtocols] return: %d", iSupportedProtocols); |
|
127 LOG("[CDirectPrintProtocolsLoader::SupportedProtocols]\t End"); |
|
128 return iSupportedProtocols; |
|
129 } |
|
130 |
|
131 |
|
132 TInt CDirectPrintProtocolsLoader::GetProtocolName(TInt aIndex, TDes& aName, TInt& aUid) |
|
133 { |
|
134 TInt retVal = KErrNone; |
|
135 |
|
136 if( iAvailableProtocols <= 0 ) |
|
137 { |
|
138 retVal = KErrNotFound; |
|
139 } |
|
140 else |
|
141 { |
|
142 CDirectPrintProtocolInfo* info = NULL; |
|
143 |
|
144 if (aIndex < 0) |
|
145 { |
|
146 info = iProtocolInfos[0]; |
|
147 } |
|
148 else |
|
149 { |
|
150 if (aIndex >= iAvailableProtocols) |
|
151 { |
|
152 info = iProtocolInfos[iAvailableProtocols - 1]; |
|
153 } |
|
154 else |
|
155 { |
|
156 info = iProtocolInfos[aIndex]; |
|
157 } |
|
158 } |
|
159 |
|
160 if (info) |
|
161 { |
|
162 aName.Copy(info->DisplayName()); |
|
163 aUid = info->ImplementationUid().iUid; |
|
164 } |
|
165 } |
|
166 |
|
167 return retVal; |
|
168 } |
|
169 |
|
170 |
|
171 CDirectPrintProtocolsLoader::CDirectPrintProtocolsLoader() |
|
172 { |
|
173 LOG("[CDirectPrintProtocolsLoader::CDirectPrintProtocolsLoader]\t Begin"); |
|
174 iAvailableProtocols = 0; |
|
175 iProtIndex = 0; |
|
176 iSupportedProtocols = 0; |
|
177 LOG("[CDirectPrintProtocolsLoader::CDirectPrintProtocolsLoader]\t End"); |
|
178 } |
|
179 |
|
180 void CDirectPrintProtocolsLoader::ConstructL() |
|
181 { |
|
182 LOG("[CDirectPrintProtocolsLoader::ConstructL]\t Begin"); |
|
183 LoadL(); |
|
184 LOG("[CDirectPrintProtocolsLoader::ConstructL]\t End"); |
|
185 } |
|
186 |
|
187 void CDirectPrintProtocolsLoader::LoadL() |
|
188 { |
|
189 LOG("[CDirectPrintProtocolsLoader::LoadL]\t Begin"); |
|
190 RImplInfoPtrArray infoArray; |
|
191 REComSession::ListImplementationsL( KDirectPrintEcomUid, infoArray ); |
|
192 CleanupClosePushL( infoArray ); |
|
193 MProtPrintingDevice* device = NULL; |
|
194 LOG1("CDirectPrintProtocolsLoader::LoadL infoArray.Count(): %d", infoArray.Count()); |
|
195 for( TInt i = 0; i < infoArray.Count(); i++ ) |
|
196 { |
|
197 LOG1("CDirectPrintProtocolsLoader::LoadL i: %d", i); |
|
198 CImplementationInformation* info = infoArray[i]; |
|
199 if (info->Version() == 2) |
|
200 { |
|
201 CDirectPrintProtocolInfo* protocolInfo = CDirectPrintProtocolInfo::NewLC(*info); |
|
202 iProtocolInfos.AppendL( protocolInfo ); |
|
203 CleanupStack::Pop( protocolInfo ); |
|
204 |
|
205 TPtrC8 dataType = info->DataType(); |
|
206 TEComResolverParams resolverParams; |
|
207 resolverParams.SetDataType( dataType ); |
|
208 resolverParams.SetWildcardMatch( ETrue ); |
|
209 TAny* prot = REComSession::CreateImplementationL( KDirectPrintEcomUid, |
|
210 _FOFF( MProtPrintingDevice, iDtor_ID_Key ), NULL, resolverParams ); |
|
211 device = reinterpret_cast<MProtPrintingDevice*>(prot); |
|
212 //device->ConstructL( KNullDesC ); |
|
213 //device = reinterpret_cast<MProtPrintingDevice*>(prot); |
|
214 |
|
215 TCleanupItem clItem( CleanupProt, device ); |
|
216 CleanupStack::PushL( clItem ); |
|
217 device->ConstructL( KNullDesC ); |
|
218 LOG1("CDirectPrintProtocolsLoader::LoadL device->SupportedProtocols(): %d", device->SupportedProtocols()); |
|
219 iProtocols.AppendL( device ); |
|
220 iSupportedProtocols |= device->SupportedProtocols(); |
|
221 CleanupStack::Pop(); // device |
|
222 device = NULL; |
|
223 } |
|
224 } |
|
225 |
|
226 infoArray.ResetAndDestroy(); |
|
227 CleanupStack::PopAndDestroy(); // infoArray |
|
228 |
|
229 iAvailableProtocols = iProtocols.Count(); |
|
230 LOG("[CDirectPrintProtocolsLoader::LoadL]\t End"); |
|
231 } |
|
232 |
|
233 void CDirectPrintProtocolsLoader::CleanupProt( TAny* aData ) |
|
234 { |
|
235 LOG("[CDirectPrintProtocolsLoader::CleanupProt]\t Begin"); |
|
236 MProtPrintingDevice* prot = (MProtPrintingDevice*)aData; |
|
237 delete prot; |
|
238 LOG("[CDirectPrintProtocolsLoader::CleanupProt]\t End"); |
|
239 } |
|
240 |
|
241 // End of File |