33
|
1 |
/*
|
|
2 |
* Copyright (c) 2003 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: This module contains the implementation of CCbsTopicMessages class
|
|
15 |
* member functions.
|
|
16 |
*
|
|
17 |
*
|
|
18 |
*/
|
|
19 |
|
|
20 |
|
|
21 |
// INCLUDE FILES
|
|
22 |
|
|
23 |
#include <e32svr.h>
|
|
24 |
#include "CbsCommon.h"
|
|
25 |
#include "CbsServerPanic.h"
|
|
26 |
#include "CCbsTopicMessages.h"
|
|
27 |
#include "CCbsSession.h"
|
|
28 |
#include "CbsServerConstants.h"
|
|
29 |
#include "CCbsDbImpTopicMessages.h"
|
|
30 |
#include "CCbsServer.h"
|
|
31 |
#include "CbsLogger.h"
|
|
32 |
|
|
33 |
// ================= MEMBER FUNCTIONS =======================
|
|
34 |
|
|
35 |
// -----------------------------------------------------------------------------
|
|
36 |
// CCbsTopicMessages::CCbsTopicMessages
|
|
37 |
// C++ default constructor can NOT contain any code, that
|
|
38 |
// might leave.
|
|
39 |
// -----------------------------------------------------------------------------
|
|
40 |
//
|
|
41 |
CCbsTopicMessages::CCbsTopicMessages(
|
|
42 |
CCbsSession& aSession,
|
|
43 |
CCbsDbImpTopicMessages& aMessages,
|
|
44 |
CCbsRecEtel& aReceiver )
|
|
45 |
: CCbsObject( aSession ),
|
|
46 |
iMessages( aMessages ),
|
|
47 |
iLocked( 0 ),
|
|
48 |
iReceiver( aReceiver )
|
|
49 |
{
|
|
50 |
}
|
|
51 |
|
|
52 |
|
|
53 |
// -----------------------------------------------------------------------------
|
|
54 |
// CCbsTopicMessages::NewL
|
|
55 |
// Two-phased constructor.
|
|
56 |
// -----------------------------------------------------------------------------
|
|
57 |
//
|
|
58 |
CCbsTopicMessages* CCbsTopicMessages::NewL(
|
|
59 |
CCbsSession& aSession,
|
|
60 |
CCbsDbImpTopicMessages& aMessages,
|
|
61 |
CCbsRecEtel& aReceiver )
|
|
62 |
{
|
|
63 |
// Normal two phase construction
|
|
64 |
CCbsTopicMessages* self =
|
|
65 |
new ( ELeave ) CCbsTopicMessages( aSession, aMessages, aReceiver );
|
|
66 |
return self;
|
|
67 |
}
|
|
68 |
|
|
69 |
|
|
70 |
// Destructor
|
|
71 |
CCbsTopicMessages::~CCbsTopicMessages()
|
|
72 |
{
|
|
73 |
CBSLOGSTRING("CBSSERVER: >>> CCbsTopicMessages::~CCbsTopicMessages()");
|
|
74 |
CBSLOGSTRING("CBSSERVER: <<< CCbsTopicMessages::~CCbsTopicMessages()");
|
|
75 |
}
|
|
76 |
|
|
77 |
// -----------------------------------------------------------------------------
|
|
78 |
// CCbsTopicMessages::HandleRequestsL
|
|
79 |
// Handle the requests for the object.
|
|
80 |
// Passes requests to proper functions
|
|
81 |
// (other items were commented in a header).
|
|
82 |
// -----------------------------------------------------------------------------
|
|
83 |
//
|
|
84 |
TBool CCbsTopicMessages::HandleRequestsL(
|
|
85 |
const RMessage2& aMessage )
|
|
86 |
{
|
|
87 |
CBSLOGSTRING("CBSSERVER: >>> CCbsTopicMessages::HandleRequestsL()");
|
|
88 |
TBool requestHandled ( ETrue );
|
|
89 |
// Handle the requests that are for the subsession.
|
|
90 |
switch ( aMessage.Function() )
|
|
91 |
{
|
|
92 |
case ECbsCloseTopicMessagesSubsession:
|
|
93 |
CloseTopicMessages();
|
|
94 |
aMessage.Complete( KErrNone );
|
|
95 |
break;
|
|
96 |
|
|
97 |
case ECbsGetMessageCount:
|
|
98 |
GetMessageCountL();
|
|
99 |
break;
|
|
100 |
|
|
101 |
case ECbsGetMessage:
|
|
102 |
GetMessageL();
|
|
103 |
break;
|
|
104 |
|
|
105 |
case ECbsFindMessageByHandle:
|
|
106 |
FindMessageByHandleL();
|
|
107 |
break;
|
|
108 |
|
|
109 |
case ECbsGetMessageIndexByHandle:
|
|
110 |
GetMessageIndexByHandleL();
|
|
111 |
break;
|
|
112 |
|
|
113 |
case ECbsGetNextAndPrevMsgHandle:
|
|
114 |
GetNextAndPrevMsgHandleL();
|
|
115 |
break;
|
|
116 |
|
|
117 |
case ECbsDeleteMessage:
|
|
118 |
DeleteMessageL( iReceiver );
|
|
119 |
break;
|
|
120 |
|
|
121 |
case ECbsSaveMessage:
|
|
122 |
SaveMessageL( iReceiver );
|
|
123 |
break;
|
|
124 |
|
|
125 |
case ECbsLockMessage:
|
|
126 |
LockMessageL();
|
|
127 |
break;
|
|
128 |
|
|
129 |
case ECbsReadMessage:
|
|
130 |
ReadMessageL( iReceiver );
|
|
131 |
break;
|
|
132 |
|
|
133 |
case ECbsGetMessageContents:
|
|
134 |
GetMessageContentsL();
|
|
135 |
break;
|
|
136 |
|
|
137 |
default:
|
|
138 |
requestHandled = EFalse;
|
|
139 |
break;
|
|
140 |
}
|
|
141 |
CBSLOGSTRING2("CBSSERVER: <<< CCbsTopicMessages::HandleRequestsL(), returning requestHandled: %d", requestHandled );
|
|
142 |
return requestHandled;
|
|
143 |
}
|
|
144 |
|
|
145 |
// -----------------------------------------------------------------------------
|
|
146 |
// CCbsTopicMessages::CloseTopicMessages
|
|
147 |
// Closes the subsession.
|
|
148 |
// (other items were commented in a header).
|
|
149 |
// -----------------------------------------------------------------------------
|
|
150 |
//
|
|
151 |
void CCbsTopicMessages::CloseTopicMessages()
|
|
152 |
{
|
|
153 |
// Removes the object.
|
|
154 |
Session().Server().DeleteObjectByHandle( Message().Int3() );
|
|
155 |
}
|
|
156 |
|
|
157 |
// -----------------------------------------------------------------------------
|
|
158 |
// CCbsTopicMessages::GetMessageCountL
|
|
159 |
// Returns the total amount of messages to the client.
|
|
160 |
// (other items were commented in a header).
|
|
161 |
// -----------------------------------------------------------------------------
|
|
162 |
//
|
|
163 |
void CCbsTopicMessages::GetMessageCountL()
|
|
164 |
{
|
|
165 |
// First, get the handle from the client
|
|
166 |
TInt topicNumber( 0 );
|
|
167 |
topicNumber = Message().Int0();
|
|
168 |
|
|
169 |
// Then, get the message count from the database.
|
|
170 |
TInt count( 0 );
|
|
171 |
iMessages.GetMessageCountL( static_cast<TUint16> ( topicNumber ), count );
|
|
172 |
|
|
173 |
// Write the message count to the client side.
|
|
174 |
TPckgBuf< TInt > pckgCount( count );
|
|
175 |
Message().WriteL( 1, pckgCount );
|
|
176 |
|
|
177 |
// Complete the request.
|
|
178 |
Message().Complete( KErrNone );
|
|
179 |
|
|
180 |
}
|
|
181 |
|
|
182 |
// -----------------------------------------------------------------------------
|
|
183 |
// CCbsTopicMessages::GetMessageL
|
|
184 |
// Returns the requested message to the client.
|
|
185 |
// (other items were commented in a header).
|
|
186 |
// -----------------------------------------------------------------------------
|
|
187 |
//
|
|
188 |
void CCbsTopicMessages::GetMessageL()
|
|
189 |
{
|
|
190 |
// Read the parameters from the client side
|
|
191 |
TInt topicNumber( 0 );
|
|
192 |
TInt index( 0 );
|
|
193 |
topicNumber = Message().Int0();
|
|
194 |
index = Message().Int1();
|
|
195 |
|
|
196 |
// Then get the message from database.
|
|
197 |
TPckgBuf< TCbsDbMessage > pckgMessage;
|
|
198 |
iMessages.GetMessageL( static_cast<TUint16> ( topicNumber ), index, pckgMessage() );
|
|
199 |
|
|
200 |
// And finally write the message information to the client side
|
|
201 |
Message().WriteL( 2, pckgMessage );
|
|
202 |
|
|
203 |
// And complete the request.
|
|
204 |
Message().Complete( KErrNone );
|
|
205 |
}
|
|
206 |
|
|
207 |
// -----------------------------------------------------------------------------
|
|
208 |
// CCbsTopicMessages::FindMessageByHandleL
|
|
209 |
// Finds a message by its handle.
|
|
210 |
// (other items were commented in a header).
|
|
211 |
// -----------------------------------------------------------------------------
|
|
212 |
//
|
|
213 |
void CCbsTopicMessages::FindMessageByHandleL()
|
|
214 |
{
|
|
215 |
// Read the parameters from the client side.
|
|
216 |
TPckgBuf< TCbsMessageHandle > pckgHandle( 0 );
|
|
217 |
Message().ReadL( 0, pckgHandle );
|
|
218 |
|
|
219 |
// Find the message.
|
|
220 |
TPckgBuf< TCbsMessage > pckgMessage;
|
|
221 |
iMessages.FindMessageByHandleL( pckgHandle(), pckgMessage() );
|
|
222 |
|
|
223 |
// Write the result to the client side.
|
|
224 |
Message().WriteL( 1, pckgMessage );
|
|
225 |
|
|
226 |
// Complete the request.
|
|
227 |
Message().Complete( KErrNone );
|
|
228 |
}
|
|
229 |
|
|
230 |
// -----------------------------------------------------------------------------
|
|
231 |
// CCbsTopicMessages::GetMessageIndexByHandleL
|
|
232 |
// Returns message index in topic by message handle.
|
|
233 |
// (other items were commented in a header).
|
|
234 |
// -----------------------------------------------------------------------------
|
|
235 |
//
|
|
236 |
void CCbsTopicMessages::GetMessageIndexByHandleL()
|
|
237 |
{
|
|
238 |
TPckgBuf< TCbsMessageHandle > pckgHandle( 0 );
|
|
239 |
Message().ReadL( 0, pckgHandle );
|
|
240 |
|
|
241 |
TInt index( iMessages.FindMessagePositionByHandleL( pckgHandle() ) );
|
|
242 |
|
|
243 |
TPckgBuf< TInt > pckgIndex( index );
|
|
244 |
Message().WriteL( 1, pckgIndex );
|
|
245 |
|
|
246 |
Message().Complete( KErrNone );
|
|
247 |
}
|
|
248 |
|
|
249 |
// -----------------------------------------------------------------------------
|
|
250 |
// CCbsTopicMessages::DeleteMessageL
|
|
251 |
// Deletes a message.
|
|
252 |
// (other items were commented in a header).
|
|
253 |
// -----------------------------------------------------------------------------
|
|
254 |
//
|
|
255 |
void CCbsTopicMessages::DeleteMessageL( const CCbsRecEtel& aReceiver )
|
|
256 |
{
|
|
257 |
// Read the handle from the client side.
|
|
258 |
TPckgBuf< TCbsMessageHandle > pckgHandle( 0 );
|
|
259 |
Message().ReadL( 0, pckgHandle );
|
|
260 |
|
|
261 |
// And then try to delete the message.
|
|
262 |
iMessages.DeleteMessageL( pckgHandle(), aReceiver );
|
|
263 |
|
|
264 |
// Finally, complete the request.
|
|
265 |
Message().Complete( KErrNone );
|
|
266 |
}
|
|
267 |
|
|
268 |
// -----------------------------------------------------------------------------
|
|
269 |
// CCbsTopicMessages::SaveMessageL
|
|
270 |
// Saves a message.
|
|
271 |
// (other items were commented in a header).
|
|
272 |
// -----------------------------------------------------------------------------
|
|
273 |
//
|
|
274 |
void CCbsTopicMessages::SaveMessageL( const CCbsRecEtel& aReceiver )
|
|
275 |
{
|
|
276 |
// Read the parameter from the client side.
|
|
277 |
TPckgBuf< TCbsMessageHandle > pckgHandle( 0 );
|
|
278 |
Message().ReadL( 0, pckgHandle );
|
|
279 |
|
|
280 |
// Save the message.
|
|
281 |
iMessages.SaveMessageL( pckgHandle(), aReceiver );
|
|
282 |
|
|
283 |
// Complete the request.
|
|
284 |
Message().Complete( KErrNone );
|
|
285 |
}
|
|
286 |
|
|
287 |
// -----------------------------------------------------------------------------
|
|
288 |
// CCbsTopicMessages::LockMessageL
|
|
289 |
// Locks a message.
|
|
290 |
// (other items were commented in a header).
|
|
291 |
// -----------------------------------------------------------------------------
|
|
292 |
//
|
|
293 |
void CCbsTopicMessages::LockMessageL()
|
|
294 |
{
|
|
295 |
// Read the parameter from the client side.
|
|
296 |
TPckgBuf< TCbsMessageHandle > pckgHandle( 0 );
|
|
297 |
Message().ReadL( 0, pckgHandle );
|
|
298 |
|
|
299 |
TCbsDbMessageHandle handle( pckgHandle() );
|
|
300 |
|
|
301 |
if ( handle != iLocked )
|
|
302 |
{
|
|
303 |
iMessages.LockMessageL( iLocked, handle );
|
|
304 |
iLocked = handle;
|
|
305 |
}
|
|
306 |
|
|
307 |
// Complete the request.
|
|
308 |
Message().Complete( KErrNone );
|
|
309 |
}
|
|
310 |
|
|
311 |
// -----------------------------------------------------------------------------
|
|
312 |
// CCbsTopicMessages::ReadMessageL
|
|
313 |
// Reads a message.
|
|
314 |
// (other items were commented in a header).
|
|
315 |
// -----------------------------------------------------------------------------
|
|
316 |
//
|
|
317 |
void CCbsTopicMessages::ReadMessageL( const CCbsRecEtel& aReceiver )
|
|
318 |
{
|
|
319 |
// Read parameter from the client side.
|
|
320 |
TPckgBuf< TCbsMessageHandle > pckgHandle( 0 );
|
|
321 |
Message().ReadL( 0, pckgHandle );
|
|
322 |
|
|
323 |
// Perform the operation.
|
|
324 |
iMessages.ReadMessageL( pckgHandle(), aReceiver );
|
|
325 |
|
|
326 |
// Complete the request.
|
|
327 |
Message().Complete( KErrNone );
|
|
328 |
}
|
|
329 |
|
|
330 |
// -----------------------------------------------------------------------------
|
|
331 |
// CCbsTopicMessages::GetMessageContentsL
|
|
332 |
// Returns the content of the message to the client.
|
|
333 |
// (other items were commented in a header).
|
|
334 |
// -----------------------------------------------------------------------------
|
|
335 |
//
|
|
336 |
void CCbsTopicMessages::GetMessageContentsL()
|
|
337 |
{
|
|
338 |
// Read the parameters from the client side.
|
|
339 |
TPckgBuf< TCbsMessageHandle > pckgHandle( 0 );
|
|
340 |
Message().ReadL( 0, pckgHandle );
|
|
341 |
|
|
342 |
TInt bufSize( 0 );
|
|
343 |
bufSize = Message().Int1();
|
|
344 |
|
|
345 |
TCbsDbMessage message;
|
|
346 |
iMessages.FindMessageByHandleL( pckgHandle(), message );
|
|
347 |
|
|
348 |
if ( message.iLength != 0 )
|
|
349 |
{
|
|
350 |
// Message is not empty.
|
|
351 |
// First allocate memory and then get the contents.
|
|
352 |
// Finally write data to client side.
|
|
353 |
TInt size ( ( message.iLength < bufSize ) ?
|
|
354 |
message.iLength : bufSize );
|
|
355 |
|
|
356 |
// guaranteed to allocate n bytes, n >= size
|
|
357 |
HBufC* buffer = HBufC::NewLC( size ); // on CS
|
|
358 |
|
|
359 |
TPtr16 pointer( buffer->Des() );
|
|
360 |
pointer.Zero();
|
|
361 |
|
|
362 |
// Note: parameter 'size' required, since MaxLength
|
|
363 |
// may be > bufSize
|
|
364 |
iMessages.GetMessageContentsL( pckgHandle(), pointer, size );
|
|
365 |
|
|
366 |
#ifndef _DEBUG
|
|
367 |
Message().WriteL( 2, pointer );
|
|
368 |
#else
|
|
369 |
TRAPD( result, Message().WriteL( 2, pointer ) );
|
|
370 |
if ( result != KErrNone )
|
|
371 |
{
|
|
372 |
RDebug::Print(_L("Server buffer length: %d, max: %d"),
|
|
373 |
pointer.Length(), pointer.MaxLength());
|
|
374 |
__DEBUGGER();
|
|
375 |
User::Leave( result );
|
|
376 |
}
|
|
377 |
|
|
378 |
#endif
|
|
379 |
CleanupStack::PopAndDestroy(); // buffer
|
|
380 |
}
|
|
381 |
|
|
382 |
// Complete the request.
|
|
383 |
Message().Complete( KErrNone );
|
|
384 |
}
|
|
385 |
|
|
386 |
// -----------------------------------------------------------------------------
|
|
387 |
// CCbsTopicMessages::GetNextAndPrevMsgHandleL
|
|
388 |
// Retrieves and returns the handles of messages that
|
|
389 |
// precede and succeed the given message in topic.
|
|
390 |
// Also returns two flags indicating whether the
|
|
391 |
// given message is the first and/or the last message in topic.
|
|
392 |
// (other items were commented in a header).
|
|
393 |
// -----------------------------------------------------------------------------
|
|
394 |
//
|
|
395 |
void CCbsTopicMessages::GetNextAndPrevMsgHandleL()
|
|
396 |
{
|
|
397 |
// Retrieve the requested topic number
|
|
398 |
TPckgBuf< TCbsMessageHandle > pckgCurrentMsg( 0 );
|
|
399 |
Message().ReadL( 0, pckgCurrentMsg );
|
|
400 |
|
|
401 |
// Determine requested information
|
|
402 |
TCbsMessageHandle nextMsg(0);
|
|
403 |
TCbsMessageHandle prevMsg(0);
|
|
404 |
TInt position(0);
|
|
405 |
iMessages.GetNextAndPrevMsgHandleL(
|
|
406 |
pckgCurrentMsg(), nextMsg, prevMsg, position);
|
|
407 |
|
|
408 |
// Write results back
|
|
409 |
TPckgBuf< TCbsNextPrevMsgAndPosition > pckgResults;
|
|
410 |
pckgResults().iPrevMsg = prevMsg;
|
|
411 |
pckgResults().iNextMsg = nextMsg;
|
|
412 |
pckgResults().iPosition = position;
|
|
413 |
|
|
414 |
Message().WriteL( 1, pckgResults );
|
|
415 |
|
|
416 |
// Complete request
|
|
417 |
Message().Complete( KErrNone );
|
|
418 |
|
|
419 |
}
|
|
420 |
|
|
421 |
// ========================== OTHER EXPORTED FUNCTIONS =========================
|
|
422 |
// End of File
|