|
1 // Copyright (c) 2007-2009 Nokia Corporation and/or its subsidiary(-ies). |
|
2 // All rights reserved. |
|
3 // This component and the accompanying materials are made available |
|
4 // under the terms of "Eclipse Public License v1.0" |
|
5 // which accompanies this distribution, and is available |
|
6 // at the URL "http://www.eclipse.org/legal/epl-v10.html". |
|
7 // |
|
8 // Initial Contributors: |
|
9 // Nokia Corporation - initial contribution. |
|
10 // |
|
11 // Contributors: |
|
12 // |
|
13 // Description: |
|
14 // The class provides an implementation of the SUPL Push API SMS or WAP Push channel for |
|
15 // the receiver's part of the interface. |
|
16 // |
|
17 // |
|
18 |
|
19 /** |
|
20 @file |
|
21 @internalComponent |
|
22 @deprecated |
|
23 */ |
|
24 |
|
25 #include <e32base.h> |
|
26 #include <e32property.h> |
|
27 |
|
28 #include <lbs/lbssuplpushreceiver.h> |
|
29 #include "lbsdevloggermacros.h" |
|
30 |
|
31 #include "lbssuplpushprops.h" |
|
32 #include "lbssuplpushreceiverchannel.h" |
|
33 |
|
34 |
|
35 /** |
|
36 Creates the channel and starts listening for incoming SUPL INIT messages. |
|
37 |
|
38 @param aChannel [In] The id of the channel to listen messages on. |
|
39 @param aObserver [In] A reference to an observer waiting for SUPL INIT messages. |
|
40 @param aPropOwnerSecureId [In] The secure id of the process that owns the P&S propertirs used. |
|
41 |
|
42 @return an instance of the channel. The calling class becomes the |
|
43 owner of the returned instance and is responsible its disposal. |
|
44 |
|
45 @leave If a error happens, it leaves with the correspondent error code. |
|
46 |
|
47 @see CLbsSuplPushRecImpl::NewL |
|
48 */ |
|
49 CLbsSuplPushRecChannel* CLbsSuplPushRecChannel::NewL(TLbsSuplPushChannel aChannel, |
|
50 MLbsSuplPushRecObserver& aObserver, TUid aPropOwnerSecureId) |
|
51 { |
|
52 LBSLOG(ELogP1, "CLbsSuplPushRecChannel::NewL() Begin\n"); |
|
53 CLbsSuplPushRecChannel* self = new (ELeave) CLbsSuplPushRecChannel(aChannel, aObserver, aPropOwnerSecureId); |
|
54 CleanupStack::PushL(self); |
|
55 self->ConstructL(); |
|
56 CleanupStack::Pop(self); |
|
57 LBSLOG(ELogP1, "CLbsSuplPushRecChannel::NewL() End\n"); |
|
58 return self; |
|
59 } |
|
60 |
|
61 /** |
|
62 Cancels the subscription for new messages and close the property used. |
|
63 |
|
64 @see CLbsSuplPushRecImpl::~CLbsSuplPushRecImpl |
|
65 */ |
|
66 CLbsSuplPushRecChannel::~CLbsSuplPushRecChannel() |
|
67 { |
|
68 LBSLOG(ELogP1, "CLbsSuplPushRecChannel::~CLbsSuplPushRecChannel() Begin\n"); |
|
69 Cancel(); |
|
70 iInitProperty.Close(); |
|
71 LBSLOG(ELogP1, "CLbsSuplPushRecChannel::~CLbsSuplPushRecChannel() End\n"); |
|
72 } |
|
73 |
|
74 /** |
|
75 Constructor. |
|
76 |
|
77 @param aChannel [In] The id of the channel to listen messages on. |
|
78 @param aObserver [In] A reference to an observer waiting for SUPL INIT messages. |
|
79 @param aPropOwnerSecureId [In] The secure id of the process that owns the P&S propertirs used. |
|
80 |
|
81 @see CLbsSuplPushRecChannel::NewL |
|
82 */ |
|
83 CLbsSuplPushRecChannel::CLbsSuplPushRecChannel(TLbsSuplPushChannel aChannel, MLbsSuplPushRecObserver& aObserver, |
|
84 TUid aPropOwnerSecureId) : CActive(EPriorityStandard), |
|
85 iObserver(aObserver), iChannel(aChannel), iPropOwnerSecureId(aPropOwnerSecureId) |
|
86 { |
|
87 LBSLOG(ELogP1, "CLbsSuplPushRecChannel::CLbsSuplPushRecChannel() Begin\n"); |
|
88 if(aChannel==ELbsSuplPushChannelSMS) |
|
89 { |
|
90 iInitPropKey=KLbsSuplPushSmsInitKey; |
|
91 iAckPropKey=KLbsSuplPushSmsAckKey; |
|
92 } |
|
93 else |
|
94 { |
|
95 iInitPropKey=KLbsSuplPushWapInitKey; |
|
96 iAckPropKey=KLbsSuplPushWapAckKey; |
|
97 } |
|
98 CActiveScheduler::Add(this); |
|
99 LBSLOG(ELogP1, "CLbsSuplPushRecChannel::CLbsSuplPushRecChannel() End\n"); |
|
100 } |
|
101 |
|
102 /** |
|
103 The 2nd phase constructor. Attaches to the property, completes the async request to cause the RunL |
|
104 method to be called for the first time and check if already there is a message set to the INIT property. |
|
105 |
|
106 @leave If a error happens, it leaves with one of the system error codes. |
|
107 |
|
108 @see CLbsSuplPushRecChannel::NewL |
|
109 */ |
|
110 void CLbsSuplPushRecChannel::ConstructL() |
|
111 { |
|
112 LBSLOG(ELogP1, "CLbsSuplPushRecChannel::ConstructL() Begin\n"); |
|
113 User::LeaveIfError(iInitProperty.Attach(iPropOwnerSecureId, iInitPropKey, EOwnerThread)); |
|
114 |
|
115 TRequestStatus* status = &iStatus; |
|
116 User::RequestComplete(status, KErrNone); |
|
117 SetActive(); |
|
118 LBSLOG(ELogP1, "CLbsSuplPushRecChannel::ConstructL() End\n"); |
|
119 } |
|
120 |
|
121 |
|
122 /** |
|
123 Called when the INIT property is changed and once on the construction of the object. Extracts |
|
124 the message from the INIT property, notifies both the observer by calling the |
|
125 MLbsSuplPushRecObserver::OnSuplInit function and the sender by setting the ACK property. |
|
126 Then it resubscribes for the INIT property to listen for next messages. |
|
127 |
|
128 @see CSuplPushImpl |
|
129 @see MLbsSuplPushRecObserver::OnSuplInit |
|
130 @see CActive::RunL |
|
131 */ |
|
132 void CLbsSuplPushRecChannel::RunL() |
|
133 { |
|
134 LBSLOG(ELogP1, "CLbsSuplPushRecChannel::RunL() Begin\n"); |
|
135 if(iStatus==KErrNone) |
|
136 { |
|
137 iInitProperty.Subscribe(iStatus); |
|
138 SetActive(); |
|
139 |
|
140 TPckgBuf<TInt> length; |
|
141 TInt err = RProperty::Get(iPropOwnerSecureId, iInitPropKey, length); |
|
142 |
|
143 //The INIT propery has been defined but not set yet. |
|
144 if(err==KErrNone && length.Length()==0) |
|
145 { |
|
146 LBSLOG(ELogP1, "CLbsSuplPushRecChannel::RunL() - err==KErrNone && length.Length()==0 End\n"); |
|
147 return; |
|
148 } |
|
149 |
|
150 //Can't do anything here, just resubscribe |
|
151 if(err!=KErrOverflow || length()<=0) |
|
152 { |
|
153 //The property must be set in the correct value. |
|
154 __ASSERT_DEBUG(0, User::Invariant()); |
|
155 LBSLOG(ELogP1, "CLbsSuplPushRecChannel::RunL() - err!=KErrOverflow || length()<=0 End\n"); |
|
156 return; |
|
157 } |
|
158 |
|
159 TInt len = length() + 2*sizeof(TInt); |
|
160 |
|
161 HBufC8* msg = HBufC8::New(len); |
|
162 |
|
163 //Not enough memory to handle the message, just resubscribe |
|
164 if(msg==0) |
|
165 { |
|
166 LBSLOG(ELogP1, "CLbsSuplPushRecChannel::RunL() - msg==0 End\n"); |
|
167 return; |
|
168 } |
|
169 |
|
170 TPtr8 ptr = msg->Des(); |
|
171 err = RProperty::Get(iPropOwnerSecureId, iInitPropKey, ptr); |
|
172 if(err!=KErrNone || ptr.Length()!=len) |
|
173 { |
|
174 delete msg; |
|
175 //Unexpected environment error or the length of the message is not equal the length declared in |
|
176 //the header. |
|
177 __ASSERT_DEBUG(0, User::Invariant()); |
|
178 LBSLOG(ELogP1, |
|
179 "CLbsSuplPushRecChannel::RunL() RProperty::Get(iPropOwnerSecureId, iInitPropKey, ptr)|| ptr.Length()!=len End\n"); |
|
180 return; |
|
181 } |
|
182 |
|
183 TPckgBuf<TInt> reqId; |
|
184 reqId.Copy(msg->Mid(sizeof(TInt), sizeof(TInt))); |
|
185 |
|
186 if(reqId()<=0) |
|
187 { |
|
188 delete msg; |
|
189 //Message is corrupted, the reqId must be > 0. |
|
190 __ASSERT_DEBUG(0, User::Invariant()); |
|
191 LBSLOG(ELogP1, "CLbsSuplPushRecChannel::RunL() - reqId()<=0 End\n"); |
|
192 return; |
|
193 } |
|
194 |
|
195 |
|
196 TInt ackId = 0; |
|
197 err = RProperty::Get(iPropOwnerSecureId, iAckPropKey, ackId); |
|
198 |
|
199 if(err!=KErrNone || ackId<0) |
|
200 { |
|
201 delete msg; |
|
202 if(ackId<0) |
|
203 { |
|
204 RProperty::Set(iPropOwnerSecureId, iAckPropKey, 0); |
|
205 } |
|
206 //Unexpected environment error or wrong ackId, it must be > 0. |
|
207 __ASSERT_DEBUG(0, User::Invariant()); |
|
208 LBSLOG(ELogP1, |
|
209 "CLbsSuplPushRecChannel::RunL() - RProperty::Get(iPropOwnerSecureId, iAckPropKey, ackId)!=KErrNone || ackId<0 End\n"); |
|
210 return; |
|
211 } |
|
212 |
|
213 |
|
214 //We notify the observer only if message was not delivered before |
|
215 if(ackId!=reqId()) |
|
216 { |
|
217 TLbsSuplPushRequestId reqIdUnsgn = reqId(); |
|
218 TPtrC8 msgPtr = msg->Right(length()); |
|
219 err = RProperty::Set(iPropOwnerSecureId, iAckPropKey, reqId()); |
|
220 //Unexpected environment error. |
|
221 __ASSERT_DEBUG(err==KErrNone, User::Invariant()); |
|
222 iObserver.OnSuplInit(iChannel, reqIdUnsgn , msgPtr); |
|
223 LBSLOG(ELogP9, "<-S MLbsSuplPushRecObserver::OnSuplInit() SuplPush\n"); |
|
224 LBSLOG2(ELogP9, " > TLbsSuplPushChannel aChannel = %d\n", iChannel); |
|
225 LBSLOG2(ELogP9, " > TLbsSuplPushRequestId aReqId = %d\n", reqIdUnsgn); |
|
226 |
|
227 } |
|
228 |
|
229 delete msg; |
|
230 } |
|
231 else |
|
232 { |
|
233 iInitProperty.Subscribe(iStatus); |
|
234 SetActive(); |
|
235 } |
|
236 LBSLOG(ELogP1, "CLbsSuplPushRecChannel::RunL() End\n"); |
|
237 } |
|
238 /** |
|
239 Cancels the subscription for the INIT property. |
|
240 |
|
241 @see CActive::Cancel |
|
242 @see CLbsSuplPushRecChannel::~CLbsSuplPushRecChannel |
|
243 */ |
|
244 void CLbsSuplPushRecChannel::DoCancel() |
|
245 { |
|
246 LBSLOG(ELogP1, "CLbsSuplPushRecChannel::DoCancel() Begin\n"); |
|
247 iInitProperty.Cancel(); |
|
248 LBSLOG(ELogP1, "CLbsSuplPushRecChannel::DoCancel() End\n"); |
|
249 } |
|
250 |