1 /* |
|
2 * Copyright (c) 2002-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: RCntParserServer implementation. |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 // needed for client interface |
|
20 #include "clientserver.h" |
|
21 #include "cntparserserver.h" |
|
22 #include "cntparserclient.h" |
|
23 |
|
24 #include "debug.h" |
|
25 |
|
26 const TUint KDefaultMessageSlots=4; |
|
27 |
|
28 |
|
29 //------------------------------------------------------------ |
|
30 // RCntParserServer::RCntParserServer() |
|
31 //------------------------------------------------------------ |
|
32 EXPORT_C RCntParserServer::RCntParserServer():iConnected(ECntParserNotConnected) |
|
33 { |
|
34 } |
|
35 //------------------------------------------------------------ |
|
36 // RCntParserServer::Connect() |
|
37 //------------------------------------------------------------ |
|
38 EXPORT_C TInt RCntParserServer::Connect() |
|
39 { |
|
40 LOGGER_ENTERFN( "RCntParserServer::Connect()" ); |
|
41 |
|
42 TInt r = KErrNone; |
|
43 |
|
44 if( iConnected == ECntParserNotConnected ) |
|
45 { |
|
46 r = CreateSession( KCntParserName, Version(), KDefaultMessageSlots ); |
|
47 if(r==KErrNone) |
|
48 { |
|
49 iConnected=ECntParserConnected; |
|
50 } |
|
51 else |
|
52 { |
|
53 RProcess p; |
|
54 TInt err = p.Create(KTxtServer, KNullDesC); |
|
55 if ( err != KErrNone ) |
|
56 { |
|
57 // Loading failed. |
|
58 return err; |
|
59 } |
|
60 TRequestStatus status; |
|
61 p.Rendezvous( status ); |
|
62 if( status != KRequestPending ) |
|
63 { |
|
64 p.Kill(0); // abort startup |
|
65 p.Close(); |
|
66 return KErrGeneral; // status can be KErrNone: don't return status.Int() |
|
67 } |
|
68 else |
|
69 { |
|
70 p.Resume(); // logon OK - start the server |
|
71 } |
|
72 |
|
73 User::WaitForRequest( status ); |
|
74 |
|
75 if( status != KErrNone ) |
|
76 { |
|
77 p.Close(); |
|
78 return status.Int(); |
|
79 } |
|
80 |
|
81 r = CreateSession( KCntParserName, Version() ); |
|
82 if( r == KErrNone ) |
|
83 { |
|
84 iConnected = ECntParserConnected; |
|
85 } |
|
86 p.Close(); |
|
87 } |
|
88 } |
|
89 else |
|
90 { |
|
91 r = KErrCouldNotConnect; |
|
92 } |
|
93 LOGGER_WRITE_1( "RCntParserServer::Connect() : return %d", r ); |
|
94 return r; |
|
95 } |
|
96 //------------------------------------------------------------ |
|
97 // RCntParserServer::Disconnect() |
|
98 //------------------------------------------------------------ |
|
99 EXPORT_C TInt RCntParserServer::Disconnect() |
|
100 { |
|
101 LOGGER_ENTERFN( "RCntParserServer::Disconnect()" ); |
|
102 |
|
103 TInt res = KErrNone; |
|
104 if(iConnected==ECntParserConnected) |
|
105 { |
|
106 res = SendReceive( ECntParserServerDisconnect, TIpcArgs(NULL) ); |
|
107 if( res == KErrNone ) |
|
108 { |
|
109 iConnected = ECntParserNotConnected; |
|
110 RSessionBase::Close(); |
|
111 } |
|
112 } |
|
113 else |
|
114 { |
|
115 res = KErrCouldNotDisconnect; |
|
116 } |
|
117 LOGGER_WRITE_1( "RCntParserServer::CreateIrMCL2PhoneBook() : return %d", res ); |
|
118 return res; |
|
119 } |
|
120 //------------------------------------------------------------ |
|
121 // RCntParserServer::Version(void) const |
|
122 //------------------------------------------------------------ |
|
123 EXPORT_C TVersion RCntParserServer::Version(void) const |
|
124 { |
|
125 return(TVersion(KCntParserMajorVersionNumber,KCntParserMinorVersionNumber,KCntParserBuildVersionNumber)); |
|
126 } |
|
127 //------------------------------------------------------------ |
|
128 // RCntParserServer::CreateIrMCL2PhoneBook(TInt aMaxNumberOfContacts, TBool aForced) |
|
129 //------------------------------------------------------------ |
|
130 EXPORT_C int RCntParserServer::CreateIrMCL2PhoneBook(TInt aMaxNumberOfContacts, TBool aForced) |
|
131 { |
|
132 LOGGER_ENTERFN( "RCntParserServer::CreateIrMCL2PhoneBook()" ); |
|
133 TInt res(KErrNone); |
|
134 if( iConnected == ECntParserConnected ) |
|
135 { |
|
136 res = SendReceive(ECntParserServerCreateIrMCL2,TIpcArgs(aMaxNumberOfContacts,aForced)); |
|
137 } |
|
138 else |
|
139 { |
|
140 res = KErrNotReady; |
|
141 } |
|
142 LOGGER_WRITE_1( "RCntParserServer::CreateIrMCL2PhoneBook() : return %d", res ); |
|
143 return res; |
|
144 } |
|
145 //------------------------------------------------------------ |
|
146 // RCntParserServer::ContactsParsed() |
|
147 //------------------------------------------------------------ |
|
148 EXPORT_C TInt RCntParserServer::ContactsParsed() |
|
149 { |
|
150 LOGGER_ENTERFN( "RCntParserServer::ContactsParsed()" ); |
|
151 |
|
152 TInt res=KErrNone; |
|
153 if( iConnected == ECntParserConnected ) |
|
154 { |
|
155 TPckgBuf<TInt> pckg; |
|
156 res = SendReceive(ECntParserServerCntParsed,TIpcArgs(&pckg)); |
|
157 if( res == KErrNone ) |
|
158 { |
|
159 res = pckg(); |
|
160 } |
|
161 } |
|
162 else |
|
163 { |
|
164 res = KErrNotReady; |
|
165 } |
|
166 LOGGER_WRITE_1( "RCntParserServer::ContactsParsed() : return %d", res ); |
|
167 return res; |
|
168 } |
|
169 //------------------------------------------------------------ |
|
170 // RCntParserServer::TotalNumberOfContacts() |
|
171 //------------------------------------------------------------ |
|
172 EXPORT_C TInt RCntParserServer::TotalNumberOfContacts() |
|
173 { |
|
174 LOGGER_ENTERFN( "RCntParserServer::TotalNumberOfContacts()" ); |
|
175 |
|
176 TInt res = KErrNone; |
|
177 if( iConnected == ECntParserConnected ) |
|
178 { |
|
179 TPckgBuf<TInt> pckg; |
|
180 res = SendReceive(ECntParserServerTotalNumOfContacts,TIpcArgs(&pckg)); |
|
181 if( res == KErrNone) |
|
182 { |
|
183 res = pckg(); |
|
184 } |
|
185 } |
|
186 else |
|
187 { |
|
188 res = KErrNotReady; |
|
189 } |
|
190 LOGGER_WRITE_1( "RCntParserServer::TotalNumberOfContacts() : return %d", res ); |
|
191 return res; |
|
192 } |
|
193 //------------------------------------------------------------ |
|
194 // RCntParserServer::Cancel() |
|
195 //------------------------------------------------------------ |
|
196 EXPORT_C TInt RCntParserServer::Cancel() |
|
197 { |
|
198 LOGGER_ENTERFN( "RCntParserServer::Cancel()" ); |
|
199 |
|
200 TInt res = KErrNone; |
|
201 if( iConnected == ECntParserConnected ) |
|
202 { |
|
203 res = SendReceive(ECntParserServerCancel,TIpcArgs(NULL)); |
|
204 } |
|
205 else |
|
206 { |
|
207 res = KErrCancel; |
|
208 } |
|
209 LOGGER_WRITE_1( "RCntParserServer::Cancel() : return %d", res ); |
|
210 return res; |
|
211 } |
|
212 //------------------------------------------------------------ |
|
213 // RCntParserServer::CancelAll() |
|
214 //------------------------------------------------------------ |
|
215 EXPORT_C TInt RCntParserServer::CancelAll() |
|
216 { |
|
217 LOGGER_ENTERFN( "RCntParserServer::CancelAll()" ); |
|
218 |
|
219 TInt res = KErrNone; |
|
220 if(iConnected==ECntParserConnected) |
|
221 { |
|
222 res = SendReceive(ECntParserServerCancelAll,TIpcArgs(NULL)); |
|
223 } |
|
224 else |
|
225 { |
|
226 res = KErrCancel; |
|
227 } |
|
228 LOGGER_WRITE_1( "RCntParserServer::CancelAll() : return %d", res ); |
|
229 return res; |
|
230 } |
|
231 //------------------------------------------------------------ |
|
232 // RCntParserServer::ContactsSaved() |
|
233 //------------------------------------------------------------ |
|
234 EXPORT_C TInt RCntParserServer::ContactsSaved() |
|
235 { |
|
236 LOGGER_ENTERFN( "RCntParserServer::ContactsSaved()" ); |
|
237 |
|
238 TInt res = KErrNone; |
|
239 if( iConnected == ECntParserConnected ) |
|
240 { |
|
241 TPckgBuf<TInt> pckg; |
|
242 SendReceive(ECntParserServerCntSaved,TIpcArgs(&pckg)); |
|
243 res = pckg(); |
|
244 } |
|
245 else |
|
246 { |
|
247 res = KErrNotReady; |
|
248 } |
|
249 LOGGER_WRITE_1( "RCntParserServer::ContactsSaved() : return %d", res ); |
|
250 return res; |
|
251 } |
|
252 |
|