|
1 /* |
|
2 * Copyright (c) 2007 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: CS Server main class. Co-ordinates server startup, |
|
15 * shutdown and receives client requests. |
|
16 * |
|
17 */ |
|
18 |
|
19 // INCLUDE FILES |
|
20 #include <e32base.h> |
|
21 #include <ccsdefs.h> |
|
22 #include <ccsconversationentry.h> |
|
23 |
|
24 // USER INCLUDES |
|
25 #include "ccsdebug.h" |
|
26 #include "ccsserver.h" |
|
27 #include "ccssession.h" |
|
28 #include "ccsplugininterface.h" |
|
29 #include "ccsconversationevent.h" |
|
30 #include "ccsconversationcache.h" |
|
31 #include "ccscontactsmanager.h" |
|
32 |
|
33 //Costant Declaration |
|
34 |
|
35 // ============================== MEMBER FUNCTIONS ============================ |
|
36 |
|
37 // ---------------------------------------------------------------------------- |
|
38 // CCsServer::NewL |
|
39 // Two Phase Construction |
|
40 // ---------------------------------------------------------------------------- |
|
41 CCsServer* CCsServer::NewL() |
|
42 { |
|
43 //TODO check the print macro for warning |
|
44 //TODO handle all error conditions |
|
45 |
|
46 PRINT ( _L("Enter CCsServer::NewL") ); |
|
47 |
|
48 CCsServer* self = new (ELeave) CCsServer; |
|
49 CleanupStack::PushL(self); |
|
50 self->ConstructL(); |
|
51 self->StartL(KCsServerName); |
|
52 CleanupStack::Pop(self); |
|
53 |
|
54 PRINT ( _L("End CCsServer::NewL") ); |
|
55 |
|
56 return self; |
|
57 } |
|
58 |
|
59 // ---------------------------------------------------------------------------- |
|
60 // CCsServer::CCsServer |
|
61 // Constructor |
|
62 // ---------------------------------------------------------------------------- |
|
63 CCsServer::CCsServer() : |
|
64 CServer2(EPriorityLow) |
|
65 { |
|
66 } |
|
67 |
|
68 // ---------------------------------------------------------------------------- |
|
69 // CCsServer::ConstructL |
|
70 // Second phase constructor |
|
71 // ---------------------------------------------------------------------------- |
|
72 void CCsServer::ConstructL() |
|
73 { |
|
74 PRINT ( _L("Enter CCsServer::ConstructL") ); |
|
75 |
|
76 // Create contacts manager and resgiter for events |
|
77 iContactsManager = new CCsContactsManager(); |
|
78 |
|
79 iConversationPlugin = CCsPluginInterface::NewL(); |
|
80 |
|
81 // Create the plugin for the required entries |
|
82 iConversationPlugin->InstantiatePluginL(this); |
|
83 |
|
84 //fetch all initial set of messages |
|
85 iConversationPlugin->GetConversationsL(); |
|
86 |
|
87 // create cache |
|
88 iConversationCache = CCsConversationCache::NewL(iContactsManager, this); |
|
89 |
|
90 iCsCachingStatus = KCachingStatusUnknown; |
|
91 |
|
92 PRINT ( _L("End CCsServer::ConstructL") ); |
|
93 } |
|
94 |
|
95 // ---------------------------------------------------------------------------- |
|
96 // CCsServer::~CCsServer |
|
97 // Destructor |
|
98 // ---------------------------------------------------------------------------- |
|
99 CCsServer::~CCsServer() |
|
100 { |
|
101 PRINT ( _L("Enter CCsServer::~CCsServer") ); |
|
102 |
|
103 // delete cache |
|
104 if (iConversationCache) |
|
105 { |
|
106 delete iConversationCache; |
|
107 iConversationCache = NULL; |
|
108 } |
|
109 |
|
110 // delete the plugin interface object |
|
111 if (iConversationPlugin) |
|
112 { |
|
113 delete iConversationPlugin; |
|
114 iConversationPlugin = NULL; |
|
115 } |
|
116 |
|
117 // Delete the contact manager |
|
118 if (iContactsManager) |
|
119 { |
|
120 delete iContactsManager; |
|
121 iContactsManager = NULL; |
|
122 } |
|
123 |
|
124 REComSession::FinalClose(); |
|
125 |
|
126 PRINT ( _L("End CCsServer::~CCsServer") ); |
|
127 } |
|
128 |
|
129 // ---------------------------------------------------------------------------- |
|
130 // CCsServer::NewSessionL |
|
131 // Constructor |
|
132 // ---------------------------------------------------------------------------- |
|
133 CSession2* CCsServer::NewSessionL(const TVersion& aVersion, const RMessage2& /*aMessage*/) const |
|
134 { |
|
135 TVersion serverVersion(1, 0, 0); |
|
136 if (!User::QueryVersionSupported(serverVersion, aVersion)) |
|
137 User::Leave(KErrNotSupported); |
|
138 |
|
139 CCsSession* session = CCsSession::NewL(const_cast<CCsServer*> (this)); |
|
140 |
|
141 PRINT ( _L("CCsServer::NewSessionL - New Session Created") ); |
|
142 |
|
143 return session; |
|
144 } |
|
145 |
|
146 // ---------------------------------------------------------------------------- |
|
147 // CCsServer::ConversationCacheInterface |
|
148 // Get the cache interface |
|
149 // ---------------------------------------------------------------------------- |
|
150 CCsConversationCache* CCsServer::ConversationCacheInterface() |
|
151 { |
|
152 return iConversationCache; |
|
153 } |
|
154 |
|
155 // ---------------------------------------------------------------------------- |
|
156 // CCsServer::AddConversations |
|
157 // This is to handle the new conversation event callback from plugin dll |
|
158 // The idea is to add entries to the cache and at the same time |
|
159 // update the client UI |
|
160 // ---------------------------------------------------------------------------- |
|
161 void CCsServer::AddConversations( |
|
162 const RPointerArray<CCsConversationEntry>& aConversationEntryLists) |
|
163 { |
|
164 PRINT ( _L("Enter CCsServer::AddConversations") ); |
|
165 |
|
166 iConversationCache->HandleConversations(aConversationEntryLists, |
|
167 KConversationEventNew); |
|
168 |
|
169 PRINT ( _L("End CCsServer::AddConversations") ); |
|
170 } |
|
171 |
|
172 // ---------------------------------------------------------------------------- |
|
173 // CCsServer::ModifyConversations |
|
174 // This is to handle the modify conversation event callback from plugin dll |
|
175 // The idea is to update entries to the cache and at the same time update |
|
176 // the client UI |
|
177 // ---------------------------------------------------------------------------- |
|
178 void CCsServer::ModifyConversations( |
|
179 const RPointerArray<CCsConversationEntry>& aConversationEntryLists) |
|
180 { |
|
181 PRINT ( _L("Enter CCsServer::ModifyConversations") ); |
|
182 |
|
183 iConversationCache->HandleConversations(aConversationEntryLists, |
|
184 KConversationEventUpdate); |
|
185 |
|
186 PRINT ( _L("End CCsServer::ModifyConversations") ); |
|
187 } |
|
188 |
|
189 // ---------------------------------------------------------------------------- |
|
190 // CCsServer::DeleteConversations |
|
191 // This is to handle the delete event callback from plugin dll |
|
192 // The idea is to delete entries to the cache and at the same time update the client UI |
|
193 // ---------------------------------------------------------------------------- |
|
194 void CCsServer::DeleteConversations( |
|
195 const RPointerArray<CCsConversationEntry>& aConversationEntryLists) |
|
196 { |
|
197 PRINT ( _L("Enter CCsServer::DeleteConversations") ); |
|
198 |
|
199 iConversationCache->HandleConversations(aConversationEntryLists, |
|
200 KConversationEventDelete); |
|
201 |
|
202 PRINT ( _L("End CCsServer::DeleteConversations") ); |
|
203 } |
|
204 |
|
205 // ---------------------------------------------------------------------------- |
|
206 // CCsServer::NotifySessions |
|
207 // Callback for on-the-fly data changes |
|
208 // ---------------------------------------------------------------------------- |
|
209 void CCsServer::NotifySessions(CCsClientConversation* aConversation, |
|
210 TUint32 aEvent) |
|
211 { |
|
212 iSessionIter.SetToFirst(); |
|
213 CCsSession* session; |
|
214 while ( (session = (CCsSession*) iSessionIter++) != NULL) |
|
215 { |
|
216 TRAPD(error, session->HandleChangeEventL( aConversation, aEvent )); |
|
217 if (error != KErrNone) |
|
218 { |
|
219 PRINT1 ( _L("CCsServer::NotifySessions - Error:%d"), error ); |
|
220 } |
|
221 } |
|
222 } |
|
223 |
|
224 // ---------------------------------------------------------------------------- |
|
225 // CCsServer::CachingCompleted |
|
226 // This is to get caching complete event from plugins |
|
227 // ---------------------------------------------------------------------------- |
|
228 void CCsServer::CachingCompleted() |
|
229 { |
|
230 // NOTE:- NO CHECK DONE NOW ON NUMBER OF PLUGINS TO KEEP IT SIMPLE. |
|
231 // NOT EXPECTED TO BE MORE THAN 1 PLUGIN FOR TB 9.2. |
|
232 iCsCachingStatus = KCachingStatusCompleted; |
|
233 } |
|
234 |
|
235 // ---------------------------------------------------------------------------- |
|
236 // CCsServer::RefreshConversations |
|
237 // Refresh conversations. |
|
238 // ---------------------------------------------------------------------------- |
|
239 void CCsServer::RefreshConversations() |
|
240 { |
|
241 // NOTE:- NO CHECK DONE NOW ON NUMBER OF PLUGINS TO KEEP IT SIMPLE. |
|
242 // NOT EXPECTED TO BE MORE THAN 1 PLUGIN FOR TB 9.2. |
|
243 |
|
244 // Delete and recreate cache. |
|
245 if (iConversationCache) |
|
246 { |
|
247 delete iConversationCache; |
|
248 iConversationCache = NULL; |
|
249 |
|
250 iCsCachingStatus = KCachingStatusUnknown; |
|
251 TRAPD(error, iConversationCache = CCsConversationCache:: |
|
252 NewL(iContactsManager, this)); |
|
253 if (error != KErrNone) |
|
254 { |
|
255 PRINT1 ( _L("CCsServer::RefreshConversations - Error:%d"), error ); |
|
256 } |
|
257 } |
|
258 |
|
259 // Notify client to refresh |
|
260 NotifySessions(NULL, KConversationEventRefresh); |
|
261 NotifySessions(NULL, KConversationEventListRefresh); |
|
262 // Read again. |
|
263 TRAPD(error, iConversationPlugin->GetConversationsL()); |
|
264 if (error != KErrNone) |
|
265 { |
|
266 PRINT1 ( _L("CCsServer::RefreshConversations - Error:%d"), error ); |
|
267 } |
|
268 } |
|
269 |
|
270 // end of file |