|
1 /* |
|
2 * Copyright (c) 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 "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: Implementation for presence cache client. |
|
15 * |
|
16 */ |
|
17 |
|
18 #include <e32std.h> |
|
19 |
|
20 #include <prescachereadhandler.h> |
|
21 |
|
22 #include "presencecacheclientnotification.h" |
|
23 #include "presencecachedefs.h" |
|
24 #include "ximpobjecthelpers.h" |
|
25 #include "presenceinfoimp.h" |
|
26 #include "presencebuddyinfoimp.h" |
|
27 #include "personpresenceinfoimp.h" |
|
28 |
|
29 // ============================ MEMBER FUNCTIONS ============================= |
|
30 |
|
31 // --------------------------------------------------------------------------- |
|
32 // CPresenceCacheClientNotification::NewL |
|
33 // --------------------------------------------------------------------------- |
|
34 // |
|
35 CPresenceCacheClientNotification* CPresenceCacheClientNotification::NewL( |
|
36 CPresenceCacheClient& aClient) |
|
37 { |
|
38 CPresenceCacheClientNotification* self = new(ELeave)CPresenceCacheClientNotification(aClient); |
|
39 CleanupStack::PushL( self ); |
|
40 self->ConstructL(); |
|
41 CleanupStack::Pop(); |
|
42 return self; |
|
43 } |
|
44 |
|
45 // --------------------------------------------------------------------------- |
|
46 // CPresenceCacheClientNotification::~CPresenceCacheClientNotification |
|
47 // --------------------------------------------------------------------------- |
|
48 // |
|
49 CPresenceCacheClientNotification::~CPresenceCacheClientNotification() |
|
50 { |
|
51 Cancel(); |
|
52 } |
|
53 |
|
54 // --------------------------------------------------------------------------- |
|
55 // CPresenceCacheClientNotification::CPresenceCacheClientNotification |
|
56 // --------------------------------------------------------------------------- |
|
57 // |
|
58 CPresenceCacheClientNotification::CPresenceCacheClientNotification(CPresenceCacheClient& aClient) |
|
59 : CActive( EPriorityStandard ), iClient( aClient ), iNotificationSubscribed( EFalse ) |
|
60 { |
|
61 } |
|
62 |
|
63 // --------------------------------------------------------------------------- |
|
64 // CPresenceCacheClientNotification::ConstructL |
|
65 // --------------------------------------------------------------------------- |
|
66 // |
|
67 void CPresenceCacheClientNotification::ConstructL() |
|
68 { |
|
69 CActiveScheduler::Add( this ); |
|
70 } |
|
71 |
|
72 // --------------------------------------------------------------------------- |
|
73 // CPresenceCacheClientNotification::RunL |
|
74 // --------------------------------------------------------------------------- |
|
75 // |
|
76 void CPresenceCacheClientNotification::RunL() |
|
77 { |
|
78 TInt origStatus = iStatus.Int(); |
|
79 |
|
80 MPresCacheReadHandler* client = ClientNotifyHandler(); |
|
81 |
|
82 if ( origStatus ) |
|
83 { |
|
84 iNotificationSubscribed = EFalse; |
|
85 TRAP_IGNORE( client->HandlePresenceNotificationL( origStatus, NULL )); |
|
86 } |
|
87 else |
|
88 { |
|
89 StartNotifySubscription(); |
|
90 PreseneceFromServerToClientL( *client, iSizePckg() ); |
|
91 } |
|
92 } |
|
93 // ---------------------------------------------------------- |
|
94 // CPresenceCacheClientNotification::RunError |
|
95 // ---------------------------------------------------------- |
|
96 // |
|
97 TInt CPresenceCacheClientNotification::RunError( TInt aError ) |
|
98 { |
|
99 if ( KErrServerTerminated == aError ) |
|
100 { |
|
101 // When server is terminated we notify the clienrt about that |
|
102 iNotificationSubscribed = EFalse; |
|
103 MPresCacheReadHandler* client = ClientNotifyHandler(); |
|
104 TRAP_IGNORE( client->HandlePresenceNotificationL( aError, NULL )); |
|
105 } |
|
106 else |
|
107 { |
|
108 // StartNotifySubscription is already called. |
|
109 } |
|
110 return KErrNone; |
|
111 } |
|
112 |
|
113 // --------------------------------------------------------------------------- |
|
114 // CPresenceCacheClientNotification::DoCancel |
|
115 // --------------------------------------------------------------------------- |
|
116 // |
|
117 void CPresenceCacheClientNotification::DoCancel() |
|
118 { |
|
119 // TODO: consider when this is safe |
|
120 iClient.SendReceive( NRequest::ECancelWaitingForNotification ); |
|
121 } |
|
122 |
|
123 // --------------------------------------------------------------------------- |
|
124 // CPresenceCacheClientNotification::SubscribePresenceBuddyChangeL |
|
125 // --------------------------------------------------------------------------- |
|
126 // |
|
127 TInt CPresenceCacheClientNotification::SubscribePresenceBuddyChangeL( |
|
128 const MXIMPIdentity& aIdentity) |
|
129 { |
|
130 if ( !iNotificationSubscribed ) |
|
131 { |
|
132 StartNotifySubscription(); |
|
133 } |
|
134 |
|
135 HBufC8* myIdPack = iClient.PackIdentityLC(aIdentity); |
|
136 |
|
137 // Package message arguments before sending to the server |
|
138 TIpcArgs args; |
|
139 args.Set(1, myIdPack); |
|
140 |
|
141 TInt err = iClient.SendReceive( NRequest::ESubscribeBuddyPresenceChange, args ); |
|
142 CleanupStack::PopAndDestroy( myIdPack ); |
|
143 |
|
144 return err; |
|
145 } |
|
146 |
|
147 // --------------------------------------------------------------------------- |
|
148 // CPresenceCacheClientNotification::UnsubscribePresenceBuddyChangeL |
|
149 // --------------------------------------------------------------------------- |
|
150 // |
|
151 void CPresenceCacheClientNotification::UnsubscribePresenceBuddyChangeL( |
|
152 const MXIMPIdentity& aIdentity) |
|
153 { |
|
154 HBufC8* myIdPack = iClient.PackIdentityLC(aIdentity); |
|
155 |
|
156 // Package message arguments before sending to the server |
|
157 TIpcArgs args; |
|
158 args.Set(1, myIdPack); |
|
159 |
|
160 TInt err = iClient.SendReceive( NRequest::EUnSubscribeBuddyPresenceChange, args ); |
|
161 CleanupStack::PopAndDestroy( myIdPack ); |
|
162 User::LeaveIfError( err ); |
|
163 } |
|
164 |
|
165 // --------------------------------------------------------------------------- |
|
166 // CPresenceCacheClientNotification::StartNotifySubscriptionL |
|
167 // --------------------------------------------------------------------------- |
|
168 // |
|
169 void CPresenceCacheClientNotification::StartNotifySubscription() |
|
170 { |
|
171 // Package message arguments before sending to the server |
|
172 SetActive(); |
|
173 TIpcArgs args(&iSizePckg); |
|
174 iClient.SendReceive( NRequest::EWaitingForNotification, args, iStatus ); |
|
175 iNotificationSubscribed = ETrue; |
|
176 } |
|
177 |
|
178 // --------------------------------------------------------------------------- |
|
179 // CPresenceCacheClientNotification::ClientNotifyHandler |
|
180 // --------------------------------------------------------------------------- |
|
181 // |
|
182 MPresCacheReadHandler* CPresenceCacheClientNotification::ClientNotifyHandler() |
|
183 { |
|
184 return iClient.iNotifyClient; |
|
185 } |
|
186 |
|
187 // --------------------------------------------------------------------------- |
|
188 // CPresenceCacheClientNotification::PreseneceFromServerToClientL |
|
189 // --------------------------------------------------------------------------- |
|
190 // |
|
191 void CPresenceCacheClientNotification::PreseneceFromServerToClientL( |
|
192 MPresCacheReadHandler& aClient, TInt aSize ) |
|
193 { |
|
194 CPresenceBuddyInfoImp* buddyInfo(NULL); |
|
195 buddyInfo = CPresenceBuddyInfoImp::NewLC(); |
|
196 HBufC8* presInfoDes = HBufC8::NewLC( aSize ); |
|
197 TPtr8 ptrBuf( presInfoDes->Des() ); |
|
198 TInt err = iClient.SendReceive( NRequest::EGetLastNotifiedtPacket, TIpcArgs( &ptrBuf )); |
|
199 if ( !err ) |
|
200 { |
|
201 TXIMPObjectPacker< CPresenceBuddyInfoImp >::UnPackL( *buddyInfo, *presInfoDes ); |
|
202 CleanupStack::PopAndDestroy( presInfoDes ); |
|
203 aClient.HandlePresenceNotificationL( KErrNone, buddyInfo ); |
|
204 CleanupStack::Pop( buddyInfo ); |
|
205 } |
|
206 else |
|
207 { |
|
208 CleanupStack::PopAndDestroy( presInfoDes ); |
|
209 CleanupStack::PopAndDestroy( buddyInfo ); |
|
210 } |
|
211 } |
|
212 |
|
213 // end of file |