|
1 // Copyright (c) 2004-2009 Nokia Corporation and/or its subsidiary(-ies). |
|
2 // All rights reserved. |
|
3 // This component and the accompanying materials are made available |
|
4 // under the terms of "Eclipse Public License v1.0" |
|
5 // which accompanies this distribution, and is available |
|
6 // at the URL "http://www.eclipse.org/legal/epl-v10.html". |
|
7 // |
|
8 // Initial Contributors: |
|
9 // Nokia Corporation - initial contribution. |
|
10 // |
|
11 // Contributors: |
|
12 // |
|
13 // Description: |
|
14 // |
|
15 |
|
16 #include <rsendas.h> |
|
17 |
|
18 #include <s32mem.h> |
|
19 |
|
20 #include "sendasservername.h" |
|
21 #include "sendasserverdefs.h" |
|
22 #include <csendasmessagetypes.h> |
|
23 #include <csendasaccounts.h> |
|
24 #include <tsendasmessagetypefilter.h> |
|
25 |
|
26 const TUid KSendAsServerExeUid = {0x10204286}; |
|
27 const TInt KSendAsRetryTimeout = 100000; |
|
28 const TInt KSendAsRetryCount = 10; |
|
29 |
|
30 static TInt StartServer() |
|
31 { |
|
32 const TUidType serverUid(KNullUid, KNullUid, KSendAsServerExeUid); |
|
33 RProcess server; |
|
34 TInt r = server.Create(KSendAsServerExe, KNullDesC, serverUid); |
|
35 |
|
36 if( r != KErrNone ) |
|
37 { |
|
38 return r; |
|
39 } |
|
40 |
|
41 TRequestStatus status; |
|
42 server.Rendezvous(status); |
|
43 if( status != KRequestPending ) |
|
44 { |
|
45 server.Kill(0); // abort start-up |
|
46 } |
|
47 else |
|
48 { |
|
49 server.Resume(); // wait for server start-up. |
|
50 } |
|
51 User::WaitForRequest(status); |
|
52 |
|
53 // If the server panics on start-up, then exit reason may still be zero, |
|
54 // which is not distinguishable from KErrNone. |
|
55 r = (server.ExitType() == EExitPanic ) ? KErrGeneral : status.Int(); |
|
56 server.Close(); |
|
57 return r; |
|
58 } |
|
59 |
|
60 /** |
|
61 Establishes a connection to the SendAs Server. |
|
62 |
|
63 @return |
|
64 KErrNone on success, a system wide error code otherwise. |
|
65 */ |
|
66 EXPORT_C TInt RSendAs::Connect() |
|
67 { |
|
68 return Connect(KSendAsDefaultMessageSlots); |
|
69 } |
|
70 |
|
71 |
|
72 /** |
|
73 Establishes a connection to the SendAs Server. |
|
74 |
|
75 |
|
76 @param aMessageSlots |
|
77 The number of message slots available to this session. This determines the |
|
78 number of outstanding requests the client may have with the server at any one |
|
79 time. The maximum number of slots is 255. If aMessageSlots==-1 then this |
|
80 indicates that the RSendAs connection should use messages from the global free |
|
81 pool of messages. |
|
82 |
|
83 @return |
|
84 KErrNone on success, a system wide error code otherwise. |
|
85 */ |
|
86 EXPORT_C TInt RSendAs::Connect(TInt aMessageSlots) |
|
87 { |
|
88 TInt retry = KSendAsRetryCount; |
|
89 TVersion version(KSendAsServerVersionMajor, KSendAsServerVersionMinor, KSendAsServerVersionBuild); |
|
90 FOREVER |
|
91 { |
|
92 TInt r = CreateSession(KSendAsServerName, version, aMessageSlots); |
|
93 if( r != KErrNotFound && r != KErrServerTerminated && r != KErrServerBusy ) |
|
94 { |
|
95 return r; |
|
96 } |
|
97 if( --retry == 0 ) |
|
98 { |
|
99 return r; |
|
100 } |
|
101 if( r == KErrServerBusy ) |
|
102 { |
|
103 User::After(KSendAsRetryTimeout); |
|
104 } |
|
105 r = StartServer(); |
|
106 if( r != KErrNone && r != KErrAlreadyExists ) |
|
107 { |
|
108 return r; |
|
109 } |
|
110 } |
|
111 } |
|
112 |
|
113 /** |
|
114 Retrieves the connected session's available message types from the SendAs Server. |
|
115 This will filter all MTMs that can send messages. This list can be refined |
|
116 by applying filters using FilterAgainstCapability. |
|
117 |
|
118 |
|
119 @param aMessageTypeInfo |
|
120 This is the CSendAsMessageType into which the session's MTM list information |
|
121 will be stored. |
|
122 |
|
123 @see CSendAsMessageTypes |
|
124 */ |
|
125 EXPORT_C void RSendAs::FilteredMessageTypesL(CSendAsMessageTypes& aMessageTypeInfo) |
|
126 { |
|
127 TPckgBuf<TInt> desLen(0); |
|
128 |
|
129 // request needed buffer size for the UID/name list |
|
130 User::LeaveIfError(SendReceive(ESASGetMessageTypeListLength, TIpcArgs(&desLen))); |
|
131 if (desLen() > 0) |
|
132 { |
|
133 HBufC8* clientBuf = HBufC8::NewLC(desLen()); |
|
134 TPtr8 ptr(clientBuf->Des()); |
|
135 |
|
136 // request server populate list |
|
137 User::LeaveIfError(SendReceive(ESASGetMessageTypes, TIpcArgs(&ptr))); |
|
138 |
|
139 RDesReadStream readStream; |
|
140 readStream.Open(*clientBuf); |
|
141 CleanupClosePushL(readStream); |
|
142 |
|
143 aMessageTypeInfo.InternalizeL(readStream); |
|
144 CleanupStack::PopAndDestroy(2, clientBuf); // clientBuf, readStream. |
|
145 } |
|
146 } |
|
147 |
|
148 /** |
|
149 Refines the connected session's available message types. Applying a filter will |
|
150 remove all mtms which do not support the supplied capability |
|
151 |
|
152 |
|
153 @param aMessageCapability |
|
154 This defines the capability describing which of the available MTMs held by the |
|
155 SendAs session should remain. |
|
156 |
|
157 @return |
|
158 KErrNone on success, a system wide error code otherwise. |
|
159 */ |
|
160 EXPORT_C TInt RSendAs::FilterAgainstCapability(TUid aMessageCapability) |
|
161 { |
|
162 TSendAsMessageTypeFilter filter(aMessageCapability); |
|
163 TPckg<TSendAsMessageTypeFilter> buf(filter); |
|
164 |
|
165 return SendReceive(ESASSetFilter,TIpcArgs((TDes8*)&buf)); |
|
166 } |
|
167 |
|
168 /** |
|
169 Refines the connected session's available message types. Applying a filter will |
|
170 remove all mtms which do not satisfy the supplied condition. |
|
171 |
|
172 |
|
173 @param aMessageCapability |
|
174 This defines the capability describing which MTMs held by the SendAs session |
|
175 should be filtered. Other mtms will be removed. |
|
176 |
|
177 @param aValue |
|
178 The value to be applied to the available MTMs in combination with the filter |
|
179 condition. MTMs which satify the condition will not be removed from the |
|
180 available MTM list. |
|
181 |
|
182 @param aConditionType |
|
183 The condition which to apply to the list of MTMs. |
|
184 |
|
185 @return |
|
186 KErrNone on success, a system wide error code otherwise. |
|
187 |
|
188 @see TSendAsConditionType |
|
189 */ |
|
190 EXPORT_C TInt RSendAs::FilterAgainstCapability(TUid aMessageCapability, TInt aValue, TSendAsConditionType aConditionType) |
|
191 { |
|
192 TSendAsMessageTypeFilter filter(aMessageCapability, aValue, aConditionType); |
|
193 TPckg<TSendAsMessageTypeFilter> buf(filter); |
|
194 |
|
195 return SendReceive(ESASSetFilter,TIpcArgs((TDes8*)&buf)); |
|
196 } |
|
197 |
|
198 /** |
|
199 Refreshes the connected session's available message types to all MTMs which can |
|
200 send messages. |
|
201 |
|
202 |
|
203 @return |
|
204 KErrNone on success, a system wide error code otherwise. |
|
205 */ |
|
206 EXPORT_C TInt RSendAs::ResetMessageFilter() |
|
207 { |
|
208 return SendReceive(ESASClearFilter, TIpcArgs()); |
|
209 } |
|
210 |
|
211 |
|
212 /** |
|
213 Returns the connected session's available accounts for message types. |
|
214 |
|
215 |
|
216 @param aMessageType |
|
217 The message type UID which the accounts should support. |
|
218 |
|
219 @param aAccounts |
|
220 On success this will be populated with the available accounts which support the |
|
221 supplied message type. |
|
222 */ |
|
223 EXPORT_C void RSendAs::AvailableAccountsL(TUid aMessageType, CSendAsAccounts& aAccounts) |
|
224 { |
|
225 TPckgBuf<TInt> desLen(0); |
|
226 TPckgBuf<TUid> sendUid(aMessageType); |
|
227 |
|
228 // request needed buffer size for the UID/name list |
|
229 User::LeaveIfError(SendReceive(ESASGetAccountListLength, TIpcArgs(&desLen, &sendUid))); |
|
230 if(desLen() > 0) |
|
231 { |
|
232 HBufC8* clientBuf = HBufC8::NewLC(desLen()); |
|
233 TPtr8 ptr(clientBuf->Des()); |
|
234 |
|
235 // request server populate list |
|
236 User::LeaveIfError(SendReceive(ESASGetAccountList,TIpcArgs(&ptr, &sendUid))); |
|
237 |
|
238 RDesReadStream readStream; |
|
239 readStream.Open(*clientBuf); |
|
240 CleanupClosePushL(readStream); |
|
241 |
|
242 aAccounts.InternalizeL(readStream); |
|
243 CleanupStack::PopAndDestroy(2, clientBuf); // clientBuf, readStream. |
|
244 } |
|
245 } |
|
246 |