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 CCbsTopicCollection class
|
|
15 |
* member functions.
|
|
16 |
*
|
|
17 |
*
|
|
18 |
*/
|
|
19 |
|
|
20 |
|
|
21 |
// INCLUDE FILES
|
|
22 |
|
|
23 |
#include "CbsCommon.h"
|
|
24 |
#include "CCbsSession.h"
|
|
25 |
#include "CCbsTopicCollection.h"
|
|
26 |
#include "CCbsDbImpTopicCollection.h"
|
|
27 |
#include "CCbsDbImpTopicList.h"
|
|
28 |
#include "CbsServerConstants.h"
|
|
29 |
#include "CCbsServer.h"
|
|
30 |
#include "CbsLogger.h"
|
|
31 |
|
|
32 |
// ================= MEMBER FUNCTIONS =======================
|
|
33 |
|
|
34 |
// -----------------------------------------------------------------------------
|
|
35 |
// CCbsTopicCollection::CCbsTopicCollection
|
|
36 |
// C++ default constructor can NOT contain any code, that
|
|
37 |
// might leave.
|
|
38 |
// -----------------------------------------------------------------------------
|
|
39 |
//
|
|
40 |
CCbsTopicCollection::CCbsTopicCollection(
|
|
41 |
CCbsSession& aSession,
|
|
42 |
CCbsDbImpTopicCollection& aCollection,
|
|
43 |
CCbsDbImpTopicList& aList )
|
|
44 |
: CCbsObject( aSession ),
|
|
45 |
iCollection( aCollection ),
|
|
46 |
iTopicList ( aList )
|
|
47 |
{
|
|
48 |
}
|
|
49 |
|
|
50 |
// -----------------------------------------------------------------------------
|
|
51 |
// CCbsTopicCollection::ConstructL
|
|
52 |
// Symbian 2nd phase constructor can leave.
|
|
53 |
// -----------------------------------------------------------------------------
|
|
54 |
//
|
|
55 |
void CCbsTopicCollection::ConstructL()
|
|
56 |
{
|
|
57 |
iCollection.AddObserverL( this );
|
|
58 |
}
|
|
59 |
|
|
60 |
// -----------------------------------------------------------------------------
|
|
61 |
// CCbsTopicCollection::NewL
|
|
62 |
// Two-phased constructor.
|
|
63 |
// -----------------------------------------------------------------------------
|
|
64 |
//
|
|
65 |
CCbsTopicCollection* CCbsTopicCollection::NewL(
|
|
66 |
CCbsSession& aSession,
|
|
67 |
CCbsDbImpTopicCollection& aCollection,
|
|
68 |
CCbsDbImpTopicList& aList )
|
|
69 |
{
|
|
70 |
// Normal two phase construction.
|
|
71 |
CCbsTopicCollection* self =
|
|
72 |
new ( ELeave ) CCbsTopicCollection( aSession, aCollection, aList );
|
|
73 |
CleanupStack::PushL( self );
|
|
74 |
self->ConstructL();
|
|
75 |
CleanupStack::Pop();
|
|
76 |
return self;
|
|
77 |
}
|
|
78 |
|
|
79 |
// Destructor
|
|
80 |
CCbsTopicCollection::~CCbsTopicCollection()
|
|
81 |
{
|
|
82 |
CBSLOGSTRING("CBSSERVER: >>> CCbsTopicCollection::~CCbsTopicCollection()");
|
|
83 |
// Remove from the observers.
|
|
84 |
iCollection.RemoveObserver( this );
|
|
85 |
CBSLOGSTRING("CBSSERVER: <<< CCbsTopicCollection::~CCbsTopicCollection()");
|
|
86 |
}
|
|
87 |
|
|
88 |
// -----------------------------------------------------------------------------
|
|
89 |
// CCbsTopicCollection::HandleRequestsL
|
|
90 |
// Passes the requests to proper functions.
|
|
91 |
// (other items were commented in a header).
|
|
92 |
// -----------------------------------------------------------------------------
|
|
93 |
//
|
|
94 |
TBool CCbsTopicCollection::HandleRequestsL(
|
|
95 |
const RMessage2& aMessage )
|
|
96 |
{
|
|
97 |
CBSLOGSTRING("CBSSERVER: >>> CCbsTopicCollection::HandleRequestsL()");
|
|
98 |
|
|
99 |
TBool requestHandled( ETrue );
|
|
100 |
|
|
101 |
// Handle the requests.
|
|
102 |
switch ( aMessage.Function() )
|
|
103 |
{
|
|
104 |
case ECbsCloseTopicCollectionSubsession:
|
|
105 |
CloseCollection();
|
|
106 |
aMessage.Complete( KErrNone );
|
|
107 |
break;
|
|
108 |
|
|
109 |
case ECbsGetTopicInfoCount:
|
|
110 |
GetTopicCountL();
|
|
111 |
break;
|
|
112 |
|
|
113 |
case ECbsGetTopicInfo:
|
|
114 |
GetTopicInfoL();
|
|
115 |
break;
|
|
116 |
|
|
117 |
case ECbsTopicInList:
|
|
118 |
TopicInListL();
|
|
119 |
break;
|
|
120 |
|
|
121 |
case ECbsNotifyOnChange:
|
|
122 |
NotifyOnChange();
|
|
123 |
break;
|
|
124 |
|
|
125 |
case ECbsNotifyOnChangeCancel:
|
|
126 |
NotifyOnChangeCancel();
|
|
127 |
break;
|
|
128 |
|
|
129 |
default:
|
|
130 |
requestHandled = EFalse;
|
|
131 |
break;
|
|
132 |
}
|
|
133 |
|
|
134 |
CBSLOGSTRING2("CBSSERVER: <<< CCbsTopicCollection::HandleRequestsL(), returning requestHandled: %d", requestHandled );
|
|
135 |
return requestHandled;
|
|
136 |
}
|
|
137 |
|
|
138 |
// -----------------------------------------------------------------------------
|
|
139 |
// CCbsTopicCollection::TopicCollectionContentsChangedInd
|
|
140 |
// Called whenever topic collection contents are changed
|
|
141 |
// (other items were commented in a header).
|
|
142 |
// -----------------------------------------------------------------------------
|
|
143 |
//
|
|
144 |
void CCbsTopicCollection::TopicCollectionContentsChangedInd()
|
|
145 |
{
|
|
146 |
// Notify if necessary.
|
|
147 |
Notify();
|
|
148 |
}
|
|
149 |
|
|
150 |
// -----------------------------------------------------------------------------
|
|
151 |
// CCbsTopicCollection::CloseCollection
|
|
152 |
// Closes the subsession.
|
|
153 |
// (other items were commented in a header).
|
|
154 |
// -----------------------------------------------------------------------------
|
|
155 |
//
|
|
156 |
void CCbsTopicCollection::CloseCollection()
|
|
157 |
{
|
|
158 |
// Removes the object.
|
|
159 |
Session().Server().DeleteObjectByHandle( Message().Int3() );
|
|
160 |
}
|
|
161 |
|
|
162 |
// -----------------------------------------------------------------------------
|
|
163 |
// CCbsTopicCollection::GetTopicCountL
|
|
164 |
// Writes the number of topics in the topic collection to the client.
|
|
165 |
// (other items were commented in a header).
|
|
166 |
// -----------------------------------------------------------------------------
|
|
167 |
//
|
|
168 |
void CCbsTopicCollection::GetTopicCountL()
|
|
169 |
{
|
|
170 |
TInt count;
|
|
171 |
iCollection.GetTopicIdentityCount( count );
|
|
172 |
// Write the count to the client side.
|
|
173 |
TPckgBuf< TInt > pckg( count );
|
|
174 |
Message().WriteL( 0, pckg );
|
|
175 |
|
|
176 |
// Complete the request.
|
|
177 |
Message().Complete( KErrNone );
|
|
178 |
}
|
|
179 |
|
|
180 |
// -----------------------------------------------------------------------------
|
|
181 |
// CCbsTopicCollection::GetTopicInfoL
|
|
182 |
// Writes the topic identity requested by the client to the client side.
|
|
183 |
// (other items were commented in a header).
|
|
184 |
// -----------------------------------------------------------------------------
|
|
185 |
//
|
|
186 |
void CCbsTopicCollection::GetTopicInfoL()
|
|
187 |
{
|
|
188 |
// Get the index from the client
|
|
189 |
TInt index( 0 );
|
|
190 |
index = Message().Int0();
|
|
191 |
|
|
192 |
TCbsTopicInfo info;
|
|
193 |
iCollection.GetTopicIdentityL( index, info );
|
|
194 |
|
|
195 |
// Write the count to the client side.
|
|
196 |
TPckgBuf< TCbsTopicInfo > pckg( info );
|
|
197 |
Message().WriteL( 1, pckg );
|
|
198 |
|
|
199 |
// Complete the request.
|
|
200 |
Message().Complete( KErrNone );
|
|
201 |
|
|
202 |
}
|
|
203 |
|
|
204 |
// -----------------------------------------------------------------------------
|
|
205 |
// CCbsTopicCollection::TopicInListL
|
|
206 |
// Writes a truth value to the client determining the existence
|
|
207 |
// of a topic in the current topic list.
|
|
208 |
// (other items were commented in a header).
|
|
209 |
// -----------------------------------------------------------------------------
|
|
210 |
//
|
|
211 |
void CCbsTopicCollection::TopicInListL()
|
|
212 |
{
|
|
213 |
// Get the topic index from the client
|
|
214 |
TInt index( 0 );
|
|
215 |
index = Message().Int0();
|
|
216 |
|
|
217 |
// Check if this topic exists in the topic list.
|
|
218 |
TCbsTopicInfo topicInfo;
|
|
219 |
iCollection.GetTopicIdentityL( index, topicInfo );
|
|
220 |
|
|
221 |
TBool inList( iTopicList.TopicIndexInList( topicInfo.iNumber ) >= 0 );
|
|
222 |
|
|
223 |
// Write the result back to the client.
|
|
224 |
TPckgBuf< TBool > pckg( inList );
|
|
225 |
Message().WriteL( 1, pckg );
|
|
226 |
|
|
227 |
// Complete the request.
|
|
228 |
Message().Complete( KErrNone );
|
|
229 |
|
|
230 |
}
|
|
231 |
|
|
232 |
// -----------------------------------------------------------------------------
|
|
233 |
// CCbsTopicCollection::NotifyOnChange
|
|
234 |
// Sets up a notification so that the client will be notified when the
|
|
235 |
// collecton is changed.
|
|
236 |
// (other items were commented in a header).
|
|
237 |
// -----------------------------------------------------------------------------
|
|
238 |
//
|
|
239 |
void CCbsTopicCollection::NotifyOnChange()
|
|
240 |
{
|
|
241 |
// Just create a pending request.
|
|
242 |
if ( iIsMessage )
|
|
243 |
{
|
|
244 |
NotifyOnChangeCancel();
|
|
245 |
}
|
|
246 |
|
|
247 |
iIsMessage = ETrue;
|
|
248 |
iMessage = Message();
|
|
249 |
}
|
|
250 |
|
|
251 |
// -----------------------------------------------------------------------------
|
|
252 |
// CCbsTopicCollection::NotifyOnChangeCancel
|
|
253 |
// Cancels the pending request.
|
|
254 |
// (other items were commented in a header).
|
|
255 |
// -----------------------------------------------------------------------------
|
|
256 |
//
|
|
257 |
void CCbsTopicCollection::NotifyOnChangeCancel()
|
|
258 |
{
|
|
259 |
// Cancel the notification.
|
|
260 |
if ( iIsMessage )
|
|
261 |
{
|
|
262 |
iMessage.Complete( KErrCancel );
|
|
263 |
}
|
|
264 |
|
|
265 |
iIsMessage = EFalse;
|
|
266 |
Message().Complete( KErrNone );
|
|
267 |
}
|
|
268 |
|
|
269 |
// -----------------------------------------------------------------------------
|
|
270 |
// CCbsTopicCollection::Notify
|
|
271 |
// Notifies the client.
|
|
272 |
// (other items were commented in a header).
|
|
273 |
// -----------------------------------------------------------------------------
|
|
274 |
//
|
|
275 |
void CCbsTopicCollection::Notify()
|
|
276 |
{
|
|
277 |
// Notify, if necessary
|
|
278 |
if ( iIsMessage )
|
|
279 |
{
|
|
280 |
iMessage.Complete( KErrNone );
|
|
281 |
}
|
|
282 |
}
|
|
283 |
|
|
284 |
// ================= OTHER EXPORTED FUNCTIONS ==============
|
|
285 |
|
|
286 |
// End of File
|