|
1 /* |
|
2 * Copyright (c) 2002-2009 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: Synchronous wrapper for ROAP protocol suite |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 #include <RoapEng.h> |
|
20 #include "RoapSyncWrapper.h" |
|
21 #include <RoapDef.h> |
|
22 |
|
23 using namespace Roap; |
|
24 |
|
25 // ============================ LOCAL FUNCTIONS =============================== |
|
26 // ----------------------------------------------------------------------------- |
|
27 // UpdateUrlL |
|
28 // ----------------------------------------------------------------------------- |
|
29 // |
|
30 LOCAL_C void UpdateUrlL( HBufC8*& aTargetUrl, const TDesC8& aSourceUrl ) |
|
31 { |
|
32 if ( aTargetUrl ) |
|
33 { |
|
34 delete aTargetUrl; |
|
35 aTargetUrl = NULL; |
|
36 } |
|
37 if ( aSourceUrl.Length() ) |
|
38 { |
|
39 aTargetUrl = aSourceUrl.AllocL(); |
|
40 } |
|
41 } |
|
42 |
|
43 |
|
44 // ---------------------------------------------------------------------------- |
|
45 // DoResetAndDestroy |
|
46 // Does RPointerArray< >->ResetAndDestroy() for the given array aPtr. |
|
47 // ---------------------------------------------------------------------------- |
|
48 // |
|
49 LOCAL_C void DoResetAndDestroy( TAny* aPtr ) |
|
50 { |
|
51 ( reinterpret_cast< RPointerArray< HBufC8 >* >( aPtr ) )-> |
|
52 ResetAndDestroy(); |
|
53 } |
|
54 |
|
55 |
|
56 |
|
57 // ============================ MEMBER FUNCTIONS =============================== |
|
58 |
|
59 CRoapSyncWrapper::CRoapSyncWrapper() : CActive( EPriorityStandard ) |
|
60 { |
|
61 CActiveScheduler::Add( this ); |
|
62 } |
|
63 |
|
64 void CRoapSyncWrapper::ConstructL() |
|
65 { |
|
66 } |
|
67 |
|
68 EXPORT_C CRoapSyncWrapper* CRoapSyncWrapper::NewL() |
|
69 { |
|
70 CRoapSyncWrapper* self = new ( ELeave ) CRoapSyncWrapper; |
|
71 |
|
72 CleanupStack::PushL( self ); |
|
73 self->ConstructL(); |
|
74 CleanupStack::Pop( self ); |
|
75 |
|
76 return self; |
|
77 } |
|
78 |
|
79 EXPORT_C CRoapSyncWrapper::~CRoapSyncWrapper() |
|
80 { |
|
81 Cancel(); |
|
82 delete iErrorUrl; |
|
83 delete iPostResponseUrl; |
|
84 } |
|
85 |
|
86 EXPORT_C void CRoapSyncWrapper::HandleTriggerL( const TDesC8& aTrigger ) |
|
87 { |
|
88 TTriggerType triggerType; |
|
89 TRiContextStatus contextStatus; |
|
90 TDomainOperation domainOperation; |
|
91 RPointerArray<HBufC8> contentIds; |
|
92 CRoapEng* roapEng = CRoapEng::NewL(); |
|
93 |
|
94 CleanupStack::PushL( roapEng ); |
|
95 roapEng->SetTriggerL( aTrigger, NULL, triggerType, contextStatus, |
|
96 domainOperation, contentIds ); |
|
97 contentIds.ResetAndDestroy(); |
|
98 roapEng->AcceptL( this, &iStatus ); |
|
99 SetActive(); |
|
100 iWait.Start(); |
|
101 CleanupStack::PopAndDestroy( roapEng ); |
|
102 User::LeaveIfError( iStatus.Int() ); |
|
103 } |
|
104 |
|
105 EXPORT_C TBool CRoapSyncWrapper::HandleTriggerSilentlyL( const TDesC8& aTrigger ) |
|
106 { |
|
107 TTriggerType triggerType; |
|
108 TRiContextStatus contextStatus; |
|
109 TDomainOperation domainOperation; |
|
110 RPointerArray<HBufC8> contentIds; |
|
111 CRoapEng* roapEng = CRoapEng::NewL(); |
|
112 TBool r = EFalse; |
|
113 |
|
114 TCleanupItem item( DoResetAndDestroy, &contentIds ); |
|
115 CleanupStack::PushL( item ); |
|
116 CleanupStack::PushL( roapEng ); |
|
117 roapEng->SetTriggerL( aTrigger, NULL, triggerType, contextStatus, |
|
118 domainOperation, contentIds ); |
|
119 |
|
120 // if we have a valid RI context, or if there is no user confirmation needed, do the ROAP |
|
121 if ( contextStatus != EInvalidContext ) |
|
122 { |
|
123 roapEng->AcceptL( this, &iStatus ); |
|
124 SetActive(); |
|
125 iWait.Start(); |
|
126 User::LeaveIfError( iStatus.Int() ); |
|
127 r = ETrue; |
|
128 } |
|
129 CleanupStack::PopAndDestroy( roapEng ); |
|
130 CleanupStack::PopAndDestroy( &contentIds ); |
|
131 return r; |
|
132 } |
|
133 |
|
134 EXPORT_C HBufC8* CRoapSyncWrapper::GetErrorUrlL( const TInt aError, TInt& aErrorType ) |
|
135 { |
|
136 |
|
137 // ROAP ERROR CODES |
|
138 switch ( aError ) |
|
139 { |
|
140 case KErrRoapUnsupported: |
|
141 case KErrRoapServerFatal: |
|
142 case KErrRoapDevice: |
|
143 case KErrRoapInvalidDomain: |
|
144 { |
|
145 aErrorType = KErrRoapPermanent; |
|
146 break; |
|
147 } |
|
148 case KErrRoapGeneral: |
|
149 case KErrRoapServer: |
|
150 case KErrRoapDomainFull: |
|
151 case KErrRoapNotRegistered: |
|
152 { |
|
153 aErrorType = KErrRoapTemporary; |
|
154 break; |
|
155 } |
|
156 } |
|
157 |
|
158 if( iErrorUrl ) |
|
159 { |
|
160 return iErrorUrl->AllocL(); |
|
161 } |
|
162 return NULL; |
|
163 } |
|
164 |
|
165 void CRoapSyncWrapper::ErrorUrlL( const TDesC8& aErrorUrl ) |
|
166 { |
|
167 UpdateUrlL( iErrorUrl, aErrorUrl ); |
|
168 } |
|
169 |
|
170 void CRoapSyncWrapper::DoCancel() |
|
171 { |
|
172 if (iWait.IsStarted()) |
|
173 { |
|
174 iWait.AsyncStop(); |
|
175 } |
|
176 } |
|
177 |
|
178 void CRoapSyncWrapper::RunL() |
|
179 { |
|
180 iWait.AsyncStop(); |
|
181 } |
|
182 |
|
183 TBool CRoapSyncWrapper::ConnectionConfL() |
|
184 { |
|
185 return ETrue; |
|
186 } |
|
187 |
|
188 TBool CRoapSyncWrapper::ContactRiConfL() |
|
189 { |
|
190 return ETrue; |
|
191 } |
|
192 |
|
193 TBool CRoapSyncWrapper::TransIdConfL() |
|
194 { |
|
195 return EFalse; |
|
196 } |
|
197 |
|
198 void CRoapSyncWrapper::RightsObjectDetailsL( |
|
199 const RPointerArray<CDRMRights>& /*aRightsList*/ ) |
|
200 { |
|
201 // do nothing |
|
202 } |
|
203 |
|
204 void CRoapSyncWrapper::ContentDownloadInfoL( TPath& /*aTempFolder*/, |
|
205 TFileName& /*aContentName*/, |
|
206 TInt& aMaxSize ) |
|
207 { |
|
208 aMaxSize = -1; |
|
209 } |
|
210 |
|
211 void CRoapSyncWrapper::ContentDetailsL( const TDesC& /*aPath*/, |
|
212 const TDesC8& /*aType*/, |
|
213 const TUid& /*aAppUid*/ ) |
|
214 { |
|
215 } |
|
216 |
|
217 |
|
218 void CRoapSyncWrapper::RoapProgressInfoL( const TInt /*aProgressInfo*/ ) |
|
219 { |
|
220 // do nothing |
|
221 } |
|
222 |
|
223 void CRoapSyncWrapper::PostResponseUrlL( const TDesC8& aPostResponseUrl ) |
|
224 { |
|
225 UpdateUrlL( iPostResponseUrl, aPostResponseUrl ); |
|
226 } |
|
227 |
|
228 EXPORT_C HBufC8* CRoapSyncWrapper::GetPostResponseUrlL() |
|
229 { |
|
230 if ( iPostResponseUrl ) |
|
231 { |
|
232 return iPostResponseUrl->AllocL(); |
|
233 } |
|
234 return NULL; |
|
235 } |
|
236 // End of File |