|
1 /* |
|
2 * Copyright (c) 2004-2007 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 "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: Contains the CProtocolsLoader class definition. |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 #include <ecom/ecom.h> |
|
20 |
|
21 #include "cprotocolsloader.h" |
|
22 #include "mprotprintingdevice.h" |
|
23 #include "clog.h" |
|
24 #include "imageprint.h" |
|
25 |
|
26 namespace |
|
27 { |
|
28 const TUid KImagePrintEcomUid = { 0x10208A1E }; |
|
29 } |
|
30 |
|
31 CProtocolsLoader* CProtocolsLoader::NewL() |
|
32 { |
|
33 LOG("[CProtocolsLoader::NewL]\t Begin"); |
|
34 CProtocolsLoader* self = new (ELeave) CProtocolsLoader(); |
|
35 CleanupStack::PushL(self); |
|
36 self->ConstructL(); |
|
37 CleanupStack::Pop(self); |
|
38 LOG("[CProtocolsLoader::NewL]\t End"); |
|
39 return self; |
|
40 } |
|
41 |
|
42 |
|
43 CProtocolsLoader::~CProtocolsLoader() |
|
44 { |
|
45 LOG("[CProtocolsLoader::~CProtocolsLoader]\t Begin"); |
|
46 iProtocols.ResetAndDestroy(); |
|
47 LOG("[CProtocolsLoader::~CProtocolsLoader]\t End"); |
|
48 } |
|
49 |
|
50 |
|
51 TInt CProtocolsLoader::GetNumberOfProtocolsAvailable() const |
|
52 { |
|
53 LOG("[CProtocolsLoader::GetNumberOfProtocolsAvailable]\t Begin"); |
|
54 LOG1("[CProtocolsLoader::GetNumberOfProtocolsAvailable]\t return: %d", iAvailableProtocols); |
|
55 LOG("[CProtocolsLoader::GetNumberOfProtocolsAvailable]\t End"); |
|
56 return iAvailableProtocols; |
|
57 } |
|
58 |
|
59 |
|
60 MProtPrintingDevice* CProtocolsLoader::GetNextProtocol() |
|
61 { |
|
62 LOG("[CProtocolsLoader::GetNextProtocol]\t Begin"); |
|
63 if (iAvailableProtocols <= 0) |
|
64 return NULL; |
|
65 |
|
66 if (iProtIndex == iAvailableProtocols) |
|
67 iProtIndex = 0; |
|
68 |
|
69 MProtPrintingDevice* temp = iProtocols[iProtIndex]; |
|
70 iProtIndex++; |
|
71 LOG("[CProtocolsLoader::GetNextProtocol]\t End"); |
|
72 return temp; |
|
73 } |
|
74 |
|
75 |
|
76 MProtPrintingDevice* CProtocolsLoader::GetProtocolAt(TInt aIndex) |
|
77 { |
|
78 LOG("[CProtocolsLoader::GetProtocolAt]\t Begin"); |
|
79 if( iAvailableProtocols <= 0 ) return NULL; |
|
80 |
|
81 MProtPrintingDevice* temp = NULL; |
|
82 |
|
83 if (aIndex < 0) |
|
84 temp = (MProtPrintingDevice*) iProtocols[0]; |
|
85 else |
|
86 if (aIndex >= iAvailableProtocols) |
|
87 temp = (MProtPrintingDevice*) iProtocols[iAvailableProtocols - 1]; |
|
88 else |
|
89 temp = (MProtPrintingDevice*) iProtocols[aIndex]; |
|
90 |
|
91 LOG("[CProtocolsLoader::GetProtocolAt]\t End"); |
|
92 return temp; |
|
93 |
|
94 } |
|
95 |
|
96 |
|
97 void CProtocolsLoader::Reset() |
|
98 { |
|
99 LOG("[CProtocolsLoader::Reset]\t Begin"); |
|
100 iProtIndex = 0; |
|
101 LOG("[CProtocolsLoader::Reset]\t End"); |
|
102 } |
|
103 |
|
104 |
|
105 TInt CProtocolsLoader::GetProtocolIndex() const |
|
106 { |
|
107 LOG("[CProtocolsLoader::GetProtocolIndex]\t Begin"); |
|
108 |
|
109 TInt retVal = iProtIndex - 1; |
|
110 // The next check is probably unnecessary since GetNextProtocol() should only leave iProtIndex with |
|
111 // a value between 1 and iAvailableProtocols |
|
112 if (retVal < 0) |
|
113 { |
|
114 retVal = iProtocols.Count() - 1; |
|
115 } |
|
116 LOG1("[CProtocolsLoader::GetProtocolIndex] return: %d", retVal); |
|
117 LOG("[CProtocolsLoader::GetProtocolIndex]\t End"); |
|
118 return retVal; |
|
119 } |
|
120 |
|
121 |
|
122 TUint CProtocolsLoader::SupportedProtocols() const |
|
123 { |
|
124 LOG("[CProtocolsLoader::SupportedProtocols]\t Begin"); |
|
125 LOG1("[CProtocolsLoader::SupportedProtocols] return: %d", iSupportedProtocols); |
|
126 LOG("[CProtocolsLoader::SupportedProtocols]\t End"); |
|
127 return iSupportedProtocols; |
|
128 } |
|
129 |
|
130 |
|
131 CProtocolsLoader::CProtocolsLoader() |
|
132 { |
|
133 LOG("[CProtocolsLoader::CProtocolsLoader]\t Begin"); |
|
134 iAvailableProtocols = 0; |
|
135 iProtIndex = 0; |
|
136 iSupportedProtocols = 0; |
|
137 LOG("[CProtocolsLoader::CProtocolsLoader]\t End"); |
|
138 } |
|
139 |
|
140 void CProtocolsLoader::ConstructL() |
|
141 { |
|
142 LOG("[CProtocolsLoader::ConstructL]\t Begin"); |
|
143 LoadL(); |
|
144 LOG("[CProtocolsLoader::ConstructL]\t End"); |
|
145 } |
|
146 |
|
147 void CProtocolsLoader::LoadL() |
|
148 { |
|
149 LOG("[CProtocolsLoader::LoadL]\t Begin"); |
|
150 RImplInfoPtrArray infoArray; |
|
151 REComSession::ListImplementationsL( KImagePrintEcomUid, infoArray ); |
|
152 CleanupClosePushL( infoArray ); |
|
153 MProtPrintingDevice* device = NULL; |
|
154 LOG1("CProtocolsLoader::LoadL infoArray.Count(): %d", infoArray.Count()); |
|
155 for( TInt i = 0; i < infoArray.Count(); i++ ) |
|
156 { |
|
157 LOG1("CProtocolsLoader::LoadL i: %d", i); |
|
158 TPtrC8 dataType = infoArray[i]->DataType(); |
|
159 TEComResolverParams resolverParams; |
|
160 resolverParams.SetDataType( dataType ); |
|
161 resolverParams.SetWildcardMatch( ETrue ); |
|
162 TAny* prot = REComSession::CreateImplementationL( KImagePrintEcomUid, |
|
163 _FOFF( MProtPrintingDevice, iDtor_ID_Key ), NULL, resolverParams ); |
|
164 device = static_cast<MProtPrintingDevice*>(prot); |
|
165 TCleanupItem clItem( CleanupProt, device ); |
|
166 CleanupStack::PushL( clItem ); |
|
167 device->ConstructL( KNullDesC ); |
|
168 LOG1("CProtocolsLoader::LoadL device->SupportedProtocols(): %d", device->SupportedProtocols()); |
|
169 iProtocols.AppendL( device ); |
|
170 iSupportedProtocols |= device->SupportedProtocols(); |
|
171 CleanupStack::Pop(); // device |
|
172 device = NULL; |
|
173 } |
|
174 |
|
175 infoArray.ResetAndDestroy(); |
|
176 CleanupStack::PopAndDestroy(); // infoArray |
|
177 |
|
178 iAvailableProtocols = iProtocols.Count(); |
|
179 LOG("[CProtocolsLoader::LoadL]\t End"); |
|
180 } |
|
181 |
|
182 void CProtocolsLoader::CleanupProt( TAny* aData ) |
|
183 { |
|
184 LOG("[CProtocolsLoader::CleanupProt]\t Begin"); |
|
185 MProtPrintingDevice* prot = (MProtPrintingDevice*)aData; |
|
186 delete prot; |
|
187 LOG("[CProtocolsLoader::CleanupProt]\t End"); |
|
188 } |
|
189 |
|
190 // End of File |