|
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 RCbsTopicMessages class |
|
15 member functions. |
|
16 * |
|
17 */ |
|
18 |
|
19 |
|
20 |
|
21 // INCLUDE FILES |
|
22 |
|
23 #include "CbsServerConstants.h" |
|
24 #include "RCbs.h" |
|
25 #include "RCbsTopicMessages.h" |
|
26 |
|
27 |
|
28 // ================= MEMBER FUNCTIONS ======================= |
|
29 |
|
30 // ----------------------------------------------------------------------------- |
|
31 // RCbsTopicMessages::RCbsTopicMessages |
|
32 // C++ default constructor can NOT contain any code, that |
|
33 // might leave. |
|
34 // ----------------------------------------------------------------------------- |
|
35 // |
|
36 RCbsTopicMessages::RCbsTopicMessages() |
|
37 { |
|
38 } |
|
39 |
|
40 // ----------------------------------------------------------------------------- |
|
41 // RCbsTopicMessages::Open |
|
42 // Creates a subsession to the server. |
|
43 // (other items were commented in a header). |
|
44 // ----------------------------------------------------------------------------- |
|
45 // |
|
46 TInt RCbsTopicMessages::Open( |
|
47 RCbs& aServer ) |
|
48 { |
|
49 const TIpcArgs args( TIpcArgs::ENothing ); |
|
50 return CreateSubSession( aServer, ECbsCreateTopicMessagesSubsession, args ); |
|
51 } |
|
52 |
|
53 // ----------------------------------------------------------------------------- |
|
54 // RCbsTopicMessages::Close |
|
55 // Closes the subsession. |
|
56 // (other items were commented in a header). |
|
57 // ----------------------------------------------------------------------------- |
|
58 // |
|
59 TInt RCbsTopicMessages::Close() |
|
60 { |
|
61 // Release locked message, if any |
|
62 TCbsMessageHandle handle( 0 ); |
|
63 LockMessage( handle ); |
|
64 |
|
65 // Close the subsession. |
|
66 RSubSessionBase::CloseSubSession( ECbsCloseTopicMessagesSubsession ); |
|
67 return KErrNone; |
|
68 } |
|
69 |
|
70 // ----------------------------------------------------------------------------- |
|
71 // RCbsTopicMessages::GetMessageCount |
|
72 // Returns the total amount of messages the topic contains. |
|
73 // (other items were commented in a header). |
|
74 // ----------------------------------------------------------------------------- |
|
75 // |
|
76 TInt RCbsTopicMessages::GetMessageCount( |
|
77 TCbsTopicNumber aNumber, |
|
78 TInt& aCount ) |
|
79 { |
|
80 // Send request to get the total amount of messages |
|
81 aCount = 0; |
|
82 TPckgBuf< TInt > pckgCount( aCount ); |
|
83 const TIpcArgs args( aNumber, &pckgCount ); |
|
84 |
|
85 TInt result = SendReceive( ECbsGetMessageCount, args ); |
|
86 |
|
87 // If everything went fine, give the result to the client. |
|
88 if ( result == KErrNone ) |
|
89 { |
|
90 aCount = pckgCount(); |
|
91 } |
|
92 return result; |
|
93 } |
|
94 |
|
95 // ----------------------------------------------------------------------------- |
|
96 // RCbsTopicMessages::GetMessage |
|
97 // Returns message information. |
|
98 // (other items were commented in a header). |
|
99 // ----------------------------------------------------------------------------- |
|
100 // |
|
101 TInt RCbsTopicMessages::GetMessage( |
|
102 TCbsTopicNumber aNumber, |
|
103 TInt aIndex, |
|
104 TCbsMessage& aMessage ) |
|
105 { |
|
106 // Send request to get the message from server |
|
107 TPckgBuf< TCbsMessage > pckgMessage; |
|
108 const TIpcArgs args( aNumber, aIndex, &pckgMessage ); |
|
109 |
|
110 TInt result = SendReceive( ECbsGetMessage, args ); |
|
111 |
|
112 if ( result == KErrNone ) |
|
113 { |
|
114 aMessage = pckgMessage(); |
|
115 } |
|
116 else |
|
117 { |
|
118 aMessage.iHandle = 0; |
|
119 } |
|
120 |
|
121 return result; |
|
122 |
|
123 } |
|
124 |
|
125 // ----------------------------------------------------------------------------- |
|
126 // RCbsTopicMessages::FindMessageByHandle |
|
127 // Finds a message by given handle. |
|
128 // (other items were commented in a header). |
|
129 // ----------------------------------------------------------------------------- |
|
130 // |
|
131 TInt RCbsTopicMessages::FindMessageByHandle( |
|
132 const TCbsMessageHandle& aHandle, |
|
133 TCbsMessage& aMessage ) |
|
134 { |
|
135 // Send request to the server to find a message by handle |
|
136 TPckgBuf< TCbsMessageHandle > pckgHandle( aHandle ); |
|
137 TPckgBuf< TCbsMessage > pckgMessage; |
|
138 const TIpcArgs args( &pckgHandle, &pckgMessage ); |
|
139 |
|
140 TInt result = SendReceive( ECbsFindMessageByHandle, args ); |
|
141 |
|
142 // If everything went fine, update the message |
|
143 if ( result == KErrNone ) |
|
144 { |
|
145 aMessage = pckgMessage(); |
|
146 } |
|
147 else |
|
148 { |
|
149 aMessage.iHandle = 0; |
|
150 } |
|
151 |
|
152 return result; |
|
153 |
|
154 } |
|
155 |
|
156 // ----------------------------------------------------------------------------- |
|
157 // RCbsTopicMessages::GetMessageIndexByHandle |
|
158 // Returns the index of a message with given handle in topic. |
|
159 // (other items were commented in a header). |
|
160 // ----------------------------------------------------------------------------- |
|
161 // |
|
162 TInt RCbsTopicMessages::GetMessageIndexByHandle( |
|
163 const TCbsMessageHandle& aHandle, |
|
164 TInt& aIndex ) |
|
165 { |
|
166 TPckgBuf< TCbsMessageHandle > pckgHandle( aHandle ); |
|
167 TPckgBuf< TInt > pckgIndex( 0 ); |
|
168 const TIpcArgs args( &pckgHandle, &pckgIndex ); |
|
169 |
|
170 TInt result( SendReceive( ECbsGetMessageIndexByHandle, args ) ); |
|
171 |
|
172 if ( result == KErrNone ) |
|
173 { |
|
174 aIndex = pckgIndex(); |
|
175 } |
|
176 return result; |
|
177 } |
|
178 |
|
179 // ----------------------------------------------------------------------------- |
|
180 // RCbsTopicMessages::DeleteMessage |
|
181 // Deletes an existing message. |
|
182 // (other items were commented in a header). |
|
183 // ----------------------------------------------------------------------------- |
|
184 // |
|
185 TInt RCbsTopicMessages::DeleteMessage( |
|
186 const TCbsMessageHandle& aHandle ) |
|
187 { |
|
188 // Send request to delete a message by handle |
|
189 TPckgBuf< TCbsMessageHandle > pckgHandle( aHandle ); |
|
190 const TIpcArgs args( &pckgHandle ); |
|
191 return SendReceive( ECbsDeleteMessage, args ); |
|
192 } |
|
193 |
|
194 // ----------------------------------------------------------------------------- |
|
195 // RCbsTopicMessages::SaveMessage |
|
196 // Saves a message (i.e., the saved message won't be deleted to make |
|
197 // room for new messages). |
|
198 // (other items were commented in a header). |
|
199 // ----------------------------------------------------------------------------- |
|
200 // |
|
201 TInt RCbsTopicMessages::SaveMessage( |
|
202 const TCbsMessageHandle& aHandle ) |
|
203 { |
|
204 // Send request to save a message by handle |
|
205 TPckgBuf< TCbsMessageHandle > pckgHandle( aHandle ); |
|
206 const TIpcArgs args( &pckgHandle ); |
|
207 return SendReceive( ECbsSaveMessage, args ); |
|
208 } |
|
209 |
|
210 // ----------------------------------------------------------------------------- |
|
211 // RCbsTopicMessages::LockMessage |
|
212 // Locks the message. |
|
213 // (other items were commented in a header). |
|
214 // ----------------------------------------------------------------------------- |
|
215 // |
|
216 TInt RCbsTopicMessages::LockMessage( |
|
217 const TCbsMessageHandle& aHandle ) |
|
218 { |
|
219 TPckgBuf< TCbsMessageHandle > pckgHandle( aHandle ); |
|
220 const TIpcArgs args( &pckgHandle ); |
|
221 return SendReceive( ECbsLockMessage, args ); |
|
222 } |
|
223 |
|
224 // ----------------------------------------------------------------------------- |
|
225 // RCbsTopicMessages::ReadMessage |
|
226 // Sets the message as read. |
|
227 // (other items were commented in a header). |
|
228 // ----------------------------------------------------------------------------- |
|
229 // |
|
230 TInt RCbsTopicMessages::ReadMessage( |
|
231 const TCbsMessageHandle& aHandle ) |
|
232 { |
|
233 // Send request to set message read by handle |
|
234 TPckgBuf< TCbsMessageHandle > pckgHandle( aHandle ); |
|
235 const TIpcArgs args( &pckgHandle ); |
|
236 return SendReceive( ECbsReadMessage, args ); |
|
237 } |
|
238 |
|
239 // ----------------------------------------------------------------------------- |
|
240 // RCbsTopicMessages::GetMessageContents |
|
241 // Returns the message contents. |
|
242 // (other items were commented in a header). |
|
243 // ----------------------------------------------------------------------------- |
|
244 // |
|
245 TInt RCbsTopicMessages::GetMessageContents( |
|
246 const TCbsMessageHandle& aHandle, |
|
247 TDes& aBuffer ) |
|
248 { |
|
249 // Send request to get the message contents |
|
250 TPckgBuf< TCbsMessageHandle > pckgHandle( aHandle ); |
|
251 TInt length = aBuffer.MaxLength(); |
|
252 const TIpcArgs args( &pckgHandle, length, &aBuffer ); |
|
253 |
|
254 TInt result( SendReceive( ECbsGetMessageContents, args ) ); |
|
255 if ( result != KErrNone ) |
|
256 { |
|
257 aBuffer.Zero(); |
|
258 } |
|
259 return result; |
|
260 } |
|
261 |
|
262 // ----------------------------------------------------------------------------- |
|
263 // RCbsTopicMessages::GetNextAndPrevMessageHandle |
|
264 // Returns the handles of messages that precede and succeed the |
|
265 // given message in server-side list of topic messages. |
|
266 // (other items were commented in a header). |
|
267 // ----------------------------------------------------------------------------- |
|
268 // |
|
269 TInt RCbsTopicMessages::GetNextAndPrevMessageHandle( |
|
270 const TCbsMessageHandle& aCurrentMsgHandle, |
|
271 TCbsMessageHandle& aPrevMsgHandle, |
|
272 TCbsMessageHandle& aNextMsgHandle, |
|
273 TInt& aPosition ) |
|
274 { |
|
275 TPckgBuf< TCbsMessageHandle > pckgCurrentMsg( aCurrentMsgHandle ); |
|
276 TPckgBuf< TCbsNextPrevMsgAndPosition > pckgResults; |
|
277 const TIpcArgs args( &pckgCurrentMsg, &pckgResults ); |
|
278 |
|
279 TInt result( SendReceive( ECbsGetNextAndPrevMsgHandle, args ) ); |
|
280 if ( result == KErrNone ) |
|
281 { |
|
282 aPrevMsgHandle = pckgResults().iPrevMsg; |
|
283 aNextMsgHandle = pckgResults().iNextMsg; |
|
284 aPosition = pckgResults().iPosition; |
|
285 } |
|
286 return result; |
|
287 } |
|
288 |
|
289 // ================= OTHER EXPORTED FUNCTIONS ============== |
|
290 |
|
291 // End of File |