|
1 /* |
|
2 * Copyright (c) 2004-2008 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 #include <e32base.h> |
|
22 #include "IptvDebug.h" |
|
23 #include "CIptvUtil.h" |
|
24 #include <bautils.h> |
|
25 #include "CIptvProvisioningProcessor.h" |
|
26 #include "CIptvPPContentHandler.h" |
|
27 |
|
28 #include "CIptvServices.h" |
|
29 |
|
30 _LIT8( KMimeType, "text/xml" ); |
|
31 |
|
32 // ======== MEMBER FUNCTIONS ======== |
|
33 |
|
34 // -------------------------------------------------------------------------- |
|
35 // Symbian 2nd phase constructor can leave. |
|
36 // -------------------------------------------------------------------------- |
|
37 // |
|
38 void CIptvProvisioningProcessor::ConstructL() |
|
39 { |
|
40 IPTVLOGSTRING_LOW_LEVEL( "CIptvProvisioningProcessor::ConstructL" ); |
|
41 |
|
42 User::LeaveIfError( iFs.Connect() ); |
|
43 iHandler = CIptvPPContentHandler::NewL( *this, iFs ); |
|
44 iParser = CParser::NewL( KMimeType, *iHandler ); |
|
45 } |
|
46 |
|
47 // -------------------------------------------------------------------------- |
|
48 // Two-phased constructor. |
|
49 // Create instance of concrete interface implementation. |
|
50 // -------------------------------------------------------------------------- |
|
51 // |
|
52 EXPORT_C CIptvProvisioningProcessor* CIptvProvisioningProcessor::NewL() |
|
53 { |
|
54 IPTVLOGSTRING_LOW_LEVEL( "CIptvProvisioningProcessor::NewL" ); |
|
55 |
|
56 CIptvProvisioningProcessor* self = |
|
57 new( ELeave ) CIptvProvisioningProcessor(); |
|
58 CleanupStack::PushL( self ); |
|
59 |
|
60 self->ConstructL(); |
|
61 |
|
62 CleanupStack::Pop( self ); |
|
63 |
|
64 return self; |
|
65 } |
|
66 |
|
67 // -------------------------------------------------------------------------- |
|
68 // Destructor. |
|
69 // -------------------------------------------------------------------------- |
|
70 // |
|
71 CIptvProvisioningProcessor::~CIptvProvisioningProcessor() |
|
72 { |
|
73 IPTVLOGSTRING_LOW_LEVEL( |
|
74 "CIptvProvisioningProcessor::~CIptvProvisioningProcessor" ); |
|
75 |
|
76 delete iParser; |
|
77 delete iHandler; |
|
78 delete iXmlFileContent; |
|
79 iXmlFileContent = NULL; |
|
80 iFs.Close(); |
|
81 } |
|
82 |
|
83 // -------------------------------------------------------------------------- |
|
84 // C++ default constructor. |
|
85 // -------------------------------------------------------------------------- |
|
86 // |
|
87 CIptvProvisioningProcessor::CIptvProvisioningProcessor() : |
|
88 iHandler( NULL ), |
|
89 iParser( NULL ), |
|
90 iXmlFileContent( NULL ), |
|
91 iLocal( ETrue ) |
|
92 { |
|
93 IPTVLOGSTRING_LOW_LEVEL( |
|
94 "CIptvProvisioningProcessor::CIptvProvisioningProcessor" ); |
|
95 } |
|
96 |
|
97 // -------------------------------------------------------------------------- |
|
98 // CIptvProvisioningProcessor::StopParsing |
|
99 // -------------------------------------------------------------------------- |
|
100 // |
|
101 void CIptvProvisioningProcessor::StopParsing() |
|
102 { |
|
103 IPTVLOGSTRING_LOW_LEVEL( "CIptvProvisioningProcessor::StopParsing" ); |
|
104 |
|
105 TRAPD( error, iParser->ParseEndL() ); |
|
106 if ( KErrNone != error ) |
|
107 { |
|
108 IPTVLOGSTRING2_LOW_LEVEL( |
|
109 "CIptvProvisioningProcessor::StopParsing --- ParseEndL leaved %d", error ); |
|
110 } |
|
111 } |
|
112 |
|
113 // -------------------------------------------------------------------------- |
|
114 // CIptvProvisioningProcessor::ExternalProvisionL |
|
115 // -------------------------------------------------------------------------- |
|
116 // |
|
117 EXPORT_C CIptvServices* CIptvProvisioningProcessor::ExternalProvisionL( |
|
118 RFile& aFile, |
|
119 TInt& aError ) |
|
120 { |
|
121 IPTVLOGSTRING_LOW_LEVEL( "CIptvProvisioningProcessor::ExternalProvisionL" ); |
|
122 |
|
123 iLocal = EFalse; |
|
124 iHandler->Reset(); |
|
125 iHandler->SetMode( iLocal ); |
|
126 |
|
127 CIptvServices* services = CIptvServices::NewL(); |
|
128 CleanupStack::PushL( services ); |
|
129 iHandler->SetServicesArray( services ); |
|
130 |
|
131 TInt size = 0; |
|
132 User::LeaveIfError( aFile.Size( size ) ); |
|
133 delete iXmlFileContent; |
|
134 iXmlFileContent = NULL; |
|
135 iXmlFileContent = HBufC8::NewL( size ); |
|
136 TPtr8 fileContentPtr = iXmlFileContent->Des(); |
|
137 User::LeaveIfError( aFile.Read( fileContentPtr ) ); |
|
138 TInt pos( 0 ); |
|
139 aFile.Seek( ESeekStart, pos ); |
|
140 |
|
141 if ( iXmlFileContent->Length() > 0 ) |
|
142 { |
|
143 iParser->ParseBeginL(); |
|
144 iParser->ParseL( iXmlFileContent->Des() ); |
|
145 iParser->ParseEndL(); |
|
146 } |
|
147 |
|
148 aError = iHandler->GetError(); |
|
149 |
|
150 delete iXmlFileContent; |
|
151 iXmlFileContent = NULL; |
|
152 |
|
153 CleanupStack::Pop( services ); |
|
154 return services; |
|
155 } |
|
156 |
|
157 // -------------------------------------------------------------------------- |
|
158 // CIptvProvisioningProcessor::LocalProvisionL |
|
159 // -------------------------------------------------------------------------- |
|
160 // |
|
161 EXPORT_C CIptvServices* CIptvProvisioningProcessor::LocalProvisionL( |
|
162 const TDesC& aFileName, |
|
163 TInt& aError ) |
|
164 { |
|
165 IPTVLOGSTRING2_LOW_LEVEL( |
|
166 "CIptvProvisioningProcessor::LocalProvisionL -- Provision file: %S", |
|
167 &aFileName ); |
|
168 |
|
169 if ( !BaflUtils::FileExists( iFs, aFileName ) ) |
|
170 { |
|
171 IPTVLOGSTRING2_LOW_LEVEL( |
|
172 "CIptvProvisioningProcessor::File not found: %S", &aFileName ); |
|
173 aError = KErrNotFound; |
|
174 return NULL; |
|
175 } |
|
176 |
|
177 iLocal = ETrue; |
|
178 iHandler->Reset(); |
|
179 iHandler->SetMode( iLocal ); |
|
180 |
|
181 CIptvServices* services = CIptvServices::NewL(); |
|
182 CleanupStack::PushL( services ); |
|
183 iHandler->SetServicesArray( services ); |
|
184 |
|
185 RFile phile; |
|
186 TInt error( phile.Open( iFs, aFileName, EFileRead ) ); |
|
187 |
|
188 if ( KErrNone != error ) |
|
189 { |
|
190 IPTVLOGSTRING2_LOW_LEVEL( |
|
191 "CIptvProvisioningProcessor::Provision file.Open error %d", error ); |
|
192 aError = error; |
|
193 iHandler->Reset(); |
|
194 iHandler->SetServicesArray( NULL ); |
|
195 CleanupStack::PopAndDestroy( services ); |
|
196 return NULL; |
|
197 } |
|
198 CleanupClosePushL( phile ); |
|
199 TInt size = 0; |
|
200 User::LeaveIfError( phile.Size( size ) ); |
|
201 delete iXmlFileContent; |
|
202 iXmlFileContent = NULL; |
|
203 iXmlFileContent = HBufC8::NewL( size ); |
|
204 TPtr8 fileContentPtr = iXmlFileContent->Des(); |
|
205 User::LeaveIfError( phile.Read( fileContentPtr ) ); |
|
206 CleanupStack::PopAndDestroy( &phile ); // closes file |
|
207 |
|
208 if ( iXmlFileContent->Length() > 0 ) |
|
209 { |
|
210 iParser->ParseBeginL(); |
|
211 iParser->ParseL( iXmlFileContent->Des() ); |
|
212 iParser->ParseEndL(); |
|
213 } |
|
214 |
|
215 aError = iHandler->GetError(); |
|
216 |
|
217 delete iXmlFileContent; |
|
218 iXmlFileContent = NULL; |
|
219 |
|
220 CleanupStack::Pop( services ); |
|
221 |
|
222 return services; |
|
223 } |
|
224 |
|
225 // -------------------------------------------------------------------------- |
|
226 // DLL entry point. |
|
227 // -------------------------------------------------------------------------- |
|
228 // |
|
229 #ifndef EKA2 |
|
230 |
|
231 GLDEF_C TInt E32Dll( TDllReason /* aReason */ ) |
|
232 { |
|
233 return( KErrNone ); |
|
234 } |
|
235 |
|
236 #endif |