|
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: access right class implemetation |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 // INCLUDE FILES |
|
20 #include "cimcacheaccessor.h" |
|
21 #include <imcachedefs.h> |
|
22 #include <s32mem.h> |
|
23 // logs |
|
24 #include "imcachedebugtrace.h" |
|
25 |
|
26 // ----------------------------------------------------------------------------- |
|
27 // CIMCacheAccessor::NewL() |
|
28 // Two-phased constructor. |
|
29 // ----------------------------------------------------------------------------- |
|
30 // |
|
31 CIMCacheAccessor* CIMCacheAccessor::NewL(TInt aServiceId, |
|
32 const TDesC& aSenderId ) |
|
33 { |
|
34 TRACE( T_LIT("CIMCacheAccessor::NewL begin") ); |
|
35 CIMCacheAccessor* self = new ( ELeave ) CIMCacheAccessor( aServiceId ) ; |
|
36 CleanupStack::PushL( self ); |
|
37 self->ConstructL( aSenderId ); |
|
38 CleanupStack::Pop( self ); //self |
|
39 TRACE( T_LIT("CIMCacheAccessor::NewL end") ); |
|
40 return self; |
|
41 } |
|
42 // ----------------------------------------------------------------------------- |
|
43 // CIMCacheAccessor::ConstructL() |
|
44 // Symbian OS default constructor can leave. |
|
45 // ----------------------------------------------------------------------------- |
|
46 // |
|
47 void CIMCacheAccessor::ConstructL( const TDesC& aSenderId ) |
|
48 { |
|
49 TRACE( T_LIT("CIMCacheAccessor::ConstructL begin") ); |
|
50 iUserId = aSenderId.AllocL(); |
|
51 User::LeaveIfError( iClient.Connect() ); |
|
52 iClient.StartTransactionL( EIMCacheInitAccess, |
|
53 iServiceId, |
|
54 *iUserId |
|
55 ); |
|
56 |
|
57 TRACE( T_LIT("CIMCacheAccessor::ConstructL end") ); |
|
58 } |
|
59 // ----------------------------------------------------------------------------- |
|
60 // CIMCacheAccessor::~CIMCacheAccessor() |
|
61 // Destructor |
|
62 // ----------------------------------------------------------------------------- |
|
63 // |
|
64 CIMCacheAccessor::~CIMCacheAccessor() |
|
65 { |
|
66 TRACE( T_LIT("CIMCacheAccessor::~CIMCacheAccessor begin") ); |
|
67 delete iUserId; |
|
68 //do not close the client session here. since there is also updater class which is closing the session |
|
69 //moved this part of code which is common to both udpater and Accessor i.e, client ~CIMCacheClient() |
|
70 //iClient.Close(); |
|
71 TRACE( T_LIT("CIMCacheAccessor::~CIMCacheAccessor end") ); |
|
72 } |
|
73 // ----------------------------------------------------------------------------- |
|
74 // CIMCacheAccessor::CIMCacheAccessor() |
|
75 // C++ default constructor can NOT contain any code, that |
|
76 // might leave. |
|
77 // ----------------------------------------------------------------------------- |
|
78 // |
|
79 CIMCacheAccessor::CIMCacheAccessor(TInt aServiceId ) |
|
80 :iServiceId( aServiceId ) |
|
81 { |
|
82 TRACE( T_LIT("CIMCacheAccessor::CIMCacheAccessor ") ); |
|
83 } |
|
84 |
|
85 // ----------------------------------------------------------------------------- |
|
86 // CIMCacheAccessor::ServiceId() |
|
87 // ----------------------------------------------------------------------------- |
|
88 // |
|
89 TInt CIMCacheAccessor::ServiceId() const |
|
90 { |
|
91 return iServiceId; |
|
92 } |
|
93 |
|
94 // ----------------------------------------------------------------------------- |
|
95 // CIMCacheAccess::RegisterObserverL() |
|
96 // ----------------------------------------------------------------------------- |
|
97 // |
|
98 void CIMCacheAccessor::RegisterObserverL( MIMCacheEventHandler& aObserver ) |
|
99 { |
|
100 TRACE( T_LIT("CIMCacheAccess::RegisterObserverL begin") ); |
|
101 // update case ETrue says CV is active |
|
102 // cch need not to register |
|
103 iClient.RegisterAccessObserverL( aObserver ); |
|
104 TRACE( T_LIT("CIMCacheAccess::RegisterObserverL end") ); |
|
105 } |
|
106 |
|
107 // ----------------------------------------------------------------------------- |
|
108 // CIMCacheAccess::UnRegisterObserverL() |
|
109 // ----------------------------------------------------------------------------- |
|
110 // |
|
111 void CIMCacheAccessor::UnRegisterObserver( MIMCacheEventHandler& aObserver ) |
|
112 { |
|
113 TRACE( T_LIT("CIMCacheAccess::UnRegisterObserverL begin") ); |
|
114 iClient.UnRegisterAccessObserver( aObserver ); |
|
115 TRACE( T_LIT("CIMCacheAccess::UnRegisterObserverL end") ); |
|
116 } |
|
117 // ----------------------------------------------------------------------------- |
|
118 // CIMCacheAccess::GetUnreadMessageCountL() |
|
119 // ----------------------------------------------------------------------------- |
|
120 // |
|
121 TInt CIMCacheAccessor::GetUnreadMessageCountL(const TDesC& aBuddyId) |
|
122 { |
|
123 TRACE( T_LIT("CIMCacheAccess::GetUnreadMessageCount") ); |
|
124 if( !aBuddyId.Length() ) |
|
125 { |
|
126 User::Leave( KErrArgument ) ; |
|
127 } |
|
128 return iClient.GetInformationL(EIMCacheGetUnreadCount, iServiceId,aBuddyId ); |
|
129 } |
|
130 //----------------------------------------------------------------------------- |
|
131 // CIMCacheAccessor::IsConversationExistL |
|
132 // ( Other items commented in header ) |
|
133 //----------------------------------------------------------------------------- |
|
134 TBool CIMCacheAccessor::IsConversationExistL( const TDesC& aBuddyId ) |
|
135 { |
|
136 TRACE( T_LIT("CIMCacheAccess::IsConversationExistL Start ") ); |
|
137 if( !aBuddyId.Length() ) |
|
138 { |
|
139 User::Leave( KErrArgument ) ; |
|
140 } |
|
141 TBool ret = iClient.GetInformationL(EIMCacheIsConversationExist,iServiceId, aBuddyId ); |
|
142 TRACE( T_LIT("CIMCacheAccess::IsConversationExistL End ") ); |
|
143 return ret; |
|
144 } |
|
145 |
|
146 // ----------------------------------------------------------------------------- |
|
147 // CIMCacheAccess::GetAllUnreadMessageCountL() |
|
148 // ----------------------------------------------------------------------------- |
|
149 // |
|
150 TInt CIMCacheAccessor::GetAllUnreadMessageCountL() |
|
151 { |
|
152 TRACE( T_LIT("CIMCacheAccess::GetAllUnreadMessageCountL") ); |
|
153 return iClient.GetInformationL( EIMCacheGetAllUnreadCount,iServiceId ); |
|
154 } |
|
155 |
|
156 |
|
157 // ----------------------------------------------------------------------------- |
|
158 // CIMCacheAccessor::CloseConversationL() |
|
159 // ----------------------------------------------------------------------------- |
|
160 // |
|
161 void CIMCacheAccessor::CloseConversationL( const TDesC& aBuddyId ) |
|
162 { |
|
163 TRACE( T_LIT("CIMCacheAccessor::CloseConversationL begin") ); |
|
164 if( !aBuddyId.Length() ) |
|
165 { |
|
166 User::Leave( KErrArgument ) ; |
|
167 } |
|
168 iClient.StartTransactionL( EIMCacheCloseConversation, |
|
169 iServiceId, |
|
170 aBuddyId |
|
171 ); |
|
172 TRACE( T_LIT("CIMCacheAccessor::CloseConversationL end") ); |
|
173 } |
|
174 |
|
175 // ----------------------------------------------------------------------------- |
|
176 // CIMCacheAccessor::GetChatListL() |
|
177 // ----------------------------------------------------------------------------- |
|
178 // |
|
179 RArray<SIMCacheChatItem> CIMCacheAccessor::GetChatListL( const TInt aServiceId ) |
|
180 { |
|
181 TRACE( T_LIT("CIMCacheUpdater::GetChatListL") ); |
|
182 RArray<SIMCacheChatItem> chatListArray;//array to hold chat item |
|
183 TBool more = EFalse; |
|
184 TPtr8 bufferPtr = iClient.GetChatListL( aServiceId ); |
|
185 InternalizeChatListL( chatListArray, bufferPtr, more ); |
|
186 |
|
187 while( more) |
|
188 { |
|
189 bufferPtr = iClient.GetBufferedDataL( EIMCacheGetBufferedPackets ); |
|
190 InternalizeChatListL( chatListArray, bufferPtr, more ); |
|
191 } |
|
192 return chatListArray; |
|
193 } |
|
194 |
|
195 // ----------------------------------------------------------------------------- |
|
196 // CIMCacheAccessor::InternalizeChatListL |
|
197 // ----------------------------------------------------------------------------- |
|
198 // |
|
199 void CIMCacheAccessor::InternalizeChatListL(RArray<SIMCacheChatItem>& aChatArray, TPtr8 aChatListBuffer ,TBool& aMore ) |
|
200 { |
|
201 TRACE( T_LIT("CIMCacheAccessor::InternalizeChatListL() begin") ); |
|
202 |
|
203 RDesReadStream readAllStream ; |
|
204 RDesReadStream readStream ; |
|
205 |
|
206 readAllStream.Open( aChatListBuffer ); |
|
207 CleanupClosePushL(readAllStream); |
|
208 |
|
209 TInt messageCount = readAllStream.ReadInt16L(); |
|
210 |
|
211 for( TInt i=0; i< messageCount; i++) |
|
212 { |
|
213 SIMCacheChatItem chatItem = |
|
214 { |
|
215 0, |
|
216 }; |
|
217 |
|
218 TInt size = readAllStream.ReadInt16L() ; |
|
219 HBufC8* mBuffer = HBufC8::NewLC( size ); |
|
220 TPtr8 mBufferPtr = mBuffer->Des(); |
|
221 |
|
222 readAllStream.ReadL( mBufferPtr , size ); |
|
223 |
|
224 readStream.Open( *mBuffer ); |
|
225 CleanupClosePushL(readStream) ; |
|
226 |
|
227 chatItem.iServiceId = static_cast<TInt>( readStream.ReadInt16L() ); |
|
228 |
|
229 TInt textSize = readStream.ReadInt16L(); |
|
230 HBufC* buddyId = HBufC::NewLC( textSize ); |
|
231 TPtr buddyIdPtr = buddyId->Des(); |
|
232 readStream.ReadL( buddyIdPtr , textSize); |
|
233 |
|
234 chatItem.iBuddyId = buddyId; |
|
235 CleanupStack::Pop(buddyId); // ownership to structure variable |
|
236 aChatArray.Insert(chatItem, 0); |
|
237 CleanupStack::PopAndDestroy(2);//close read stream, delete mBuffer. |
|
238 |
|
239 } |
|
240 |
|
241 aMore = static_cast<TBool>( readAllStream.ReadInt16L() ); |
|
242 CleanupStack::PopAndDestroy();//readAllStream. |
|
243 TRACE( T_LIT("CIMCacheAccessor::InternalizeChatListL() End") ); |
|
244 } |
|
245 |
|
246 // END OF FILE |
|
247 |
|
248 |