|
1 /* |
|
2 * Copyright (c) 2005-2006 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 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 * Nokia Corporation - initial contribution. |
|
11 * |
|
12 * Contributors: |
|
13 * |
|
14 * Description: |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 |
|
20 |
|
21 |
|
22 // INCLUDE FILES |
|
23 #include "IptvDebug.h" |
|
24 |
|
25 #include "CIptvServices.h" |
|
26 #include "CIptvService.h" |
|
27 |
|
28 // EXTERNAL DATA STRUCTURES |
|
29 |
|
30 // EXTERNAL FUNCTION PROTOTYPES |
|
31 |
|
32 // CONSTANTS |
|
33 |
|
34 // MACROS |
|
35 |
|
36 // LOCAL CONSTANTS AND MACROS |
|
37 |
|
38 // MODULE DATA STRUCTURES |
|
39 |
|
40 // LOCAL FUNCTION PROTOTYPES |
|
41 |
|
42 // FORWARD DECLARATIONS |
|
43 |
|
44 // ============================= LOCAL FUNCTIONS =============================== |
|
45 |
|
46 // ============================ MEMBER FUNCTIONS =============================== |
|
47 |
|
48 // ----------------------------------------------------------------------------- |
|
49 // CIptvServices::CIptvServices |
|
50 // C++ default constructor can NOT contain any code, that |
|
51 // might leave. |
|
52 // ----------------------------------------------------------------------------- |
|
53 // |
|
54 CIptvServices::CIptvServices() |
|
55 { |
|
56 } |
|
57 |
|
58 // ----------------------------------------------------------------------------- |
|
59 // CIptvServices::ConstructL |
|
60 // Symbian 2nd phase constructor can leave. |
|
61 // ----------------------------------------------------------------------------- |
|
62 // |
|
63 void CIptvServices::ConstructL() |
|
64 { |
|
65 iServices.Reset(); |
|
66 iService = CIptvService::NewL(); |
|
67 } |
|
68 |
|
69 // ----------------------------------------------------------------------------- |
|
70 // CIptvServices::NewL |
|
71 // Two-phased constructor. |
|
72 // ----------------------------------------------------------------------------- |
|
73 // |
|
74 EXPORT_C CIptvServices* CIptvServices::NewL() |
|
75 { |
|
76 CIptvServices* self = new( ELeave ) CIptvServices; |
|
77 |
|
78 CleanupStack::PushL( self ); |
|
79 self->ConstructL(); |
|
80 CleanupStack::Pop(self); |
|
81 |
|
82 return self; |
|
83 } |
|
84 |
|
85 |
|
86 // Destructor |
|
87 EXPORT_C CIptvServices::~CIptvServices() |
|
88 { |
|
89 TInt i; |
|
90 for ( i = iServices.Count() -1; i >= 0; i-- ) |
|
91 { |
|
92 delete iServices[i]; |
|
93 } |
|
94 iServices.Close(); |
|
95 delete iService; |
|
96 } |
|
97 |
|
98 |
|
99 // ----------------------------------------------------------------------------- |
|
100 // CIptvServices::GetServiceL |
|
101 // ----------------------------------------------------------------------------- |
|
102 // |
|
103 EXPORT_C CIptvService* CIptvServices::GetServiceL(TUint32 aIndex) |
|
104 { |
|
105 if(aIndex > iServices.Count()) |
|
106 { |
|
107 return NULL; |
|
108 } |
|
109 CIptvService* service = CIptvService::NewL(); |
|
110 CleanupStack::PushL(service); //1-> |
|
111 service->SetL(iServices[aIndex]->Des()); |
|
112 CleanupStack::Pop(service); //<-1 |
|
113 return service; |
|
114 } |
|
115 |
|
116 // ----------------------------------------------------------------------------- |
|
117 // CIptvServices::GetServiceRefL |
|
118 // ----------------------------------------------------------------------------- |
|
119 // |
|
120 EXPORT_C CIptvService& CIptvServices::GetServiceRefL(TUint32 aIndex) |
|
121 { |
|
122 if(aIndex > iServices.Count()) |
|
123 { |
|
124 IPTVLOGSTRING_HIGH_LEVEL("CIptvServices::GetServiceL leaving, index out of bounds."); |
|
125 User::Leave(KErrNotFound); |
|
126 } |
|
127 iService->SetL(iServices[aIndex]->Des()); |
|
128 return *iService; |
|
129 } |
|
130 |
|
131 // ----------------------------------------------------------------------------- |
|
132 // CIptvServices::Service |
|
133 // ----------------------------------------------------------------------------- |
|
134 // |
|
135 EXPORT_C CIptvService& CIptvServices::Service( TUint32 aIndex, TInt& aError ) |
|
136 { |
|
137 if ( aIndex > iServices.Count() ) |
|
138 { |
|
139 IPTVLOGSTRING_HIGH_LEVEL( "CIptvServices::Service index out of bounds." ); |
|
140 aError = KErrNotFound; |
|
141 return *iService; |
|
142 } |
|
143 |
|
144 TRAP( aError, iService->SetL( iServices[aIndex]->Des() ) ); |
|
145 return *iService; |
|
146 } |
|
147 |
|
148 // ----------------------------------------------------------------------------- |
|
149 // CIptvServices::AddServiceL |
|
150 // ----------------------------------------------------------------------------- |
|
151 // |
|
152 EXPORT_C TInt CIptvServices::AddL(CIptvService& aService) |
|
153 { |
|
154 HBufC8* serviceBin = aService.GetL(); |
|
155 TInt err = iServices.Append(serviceBin); |
|
156 if(err != KErrNone) |
|
157 { |
|
158 delete serviceBin; |
|
159 } |
|
160 return err; |
|
161 } |
|
162 |
|
163 // ----------------------------------------------------------------------------- |
|
164 // CIptvServices::Count |
|
165 // ----------------------------------------------------------------------------- |
|
166 // |
|
167 EXPORT_C TInt CIptvServices::Count() |
|
168 { |
|
169 return iServices.Count(); |
|
170 } |
|
171 |
|
172 // ----------------------------------------------------------------------------- |
|
173 // CIptvServices::ExternalizeL |
|
174 // ----------------------------------------------------------------------------- |
|
175 // |
|
176 EXPORT_C void CIptvServices::ExternalizeL(RDesWriteStream& aStream) const |
|
177 { |
|
178 TUint32 serviceCount = iServices.Count(); |
|
179 aStream.WriteUint32L(serviceCount); |
|
180 TInt i; |
|
181 CIptvService* service = CIptvService::NewL(); |
|
182 CleanupStack::PushL(service); // 1-> |
|
183 for(i = 0; i < serviceCount; i++) |
|
184 { |
|
185 service->SetL(iServices[i]->Des()); |
|
186 service->ExternalizeL(aStream); |
|
187 } |
|
188 CleanupStack::PopAndDestroy(service); // <-1 |
|
189 } |
|
190 |
|
191 // ----------------------------------------------------------------------------- |
|
192 // CIptvServices::InternalizeL |
|
193 // ----------------------------------------------------------------------------- |
|
194 // |
|
195 EXPORT_C void CIptvServices::InternalizeL(RDesReadStream& aStream) |
|
196 { |
|
197 TUint32 serviceCount = aStream.ReadUint32L(); |
|
198 TInt i, err; |
|
199 CIptvService* service = CIptvService::NewL(); |
|
200 CleanupStack::PushL(service); // 1-> |
|
201 for(i = 0; i < serviceCount; i++) |
|
202 { |
|
203 service->InternalizeL(aStream); |
|
204 HBufC8* serviceBin = service->GetL(); |
|
205 err = iServices.Append(serviceBin); |
|
206 if(err != KErrNone) |
|
207 { |
|
208 delete serviceBin; |
|
209 } |
|
210 } |
|
211 CleanupStack::PopAndDestroy(service); // <-1 |
|
212 } |
|
213 |
|
214 // ----------------------------------------------------------------------------- |
|
215 // CIptvServices::CountExternalizeSize |
|
216 // ----------------------------------------------------------------------------- |
|
217 // |
|
218 EXPORT_C TUint32 CIptvServices::CountExternalizeSize() |
|
219 { |
|
220 TUint32 extSize = 4; //count field |
|
221 TInt i; |
|
222 for(i = 0; i < iServices.Count(); i++) |
|
223 { |
|
224 extSize += iServices[i]->Des().Length(); |
|
225 } |
|
226 return extSize; |
|
227 } |
|
228 |
|
229 // ========================== OTHER EXPORTED FUNCTIONS ========================= |
|
230 |
|
231 // End of File |