|
1 /** |
|
2 * Copyright (c) 2010 Sasken Communication Technologies Ltd. |
|
3 * All rights reserved. |
|
4 * This component and the accompanying materials are made available |
|
5 * under the terms of the "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 * Pritam Roy Biswas, Sasken Communication Technologies Ltd - Initial contribution |
|
11 * |
|
12 * Description: |
|
13 * Client-side handle to a session with a server. Derives from RSessionBase to |
|
14 * create a communicating channel with the server. |
|
15 * |
|
16 */ |
|
17 |
|
18 #include "smfcredmgrclientsession.h" |
|
19 |
|
20 // The number of connection attempts. |
|
21 const TInt KConnectAttempts = 2; |
|
22 |
|
23 // Global Functions |
|
24 static TInt StartServer() |
|
25 { |
|
26 |
|
27 RProcess server; |
|
28 TInt r = server.Create(KCredMgrServerName, KNullDesC); |
|
29 if (r != KErrNone) |
|
30 { |
|
31 return r; |
|
32 } |
|
33 TRequestStatus stat = KRequestPending; |
|
34 server.Rendezvous(stat); |
|
35 if (stat != KRequestPending) |
|
36 server.Kill(0); |
|
37 else |
|
38 server.Resume(); |
|
39 |
|
40 User::WaitForRequest(stat); |
|
41 TExitType et = server.ExitType(); |
|
42 TInt code = stat.Int(); |
|
43 r = (et == EExitPanic) ? KErrGeneral : code; |
|
44 server.Close(); |
|
45 |
|
46 return KErrNone; |
|
47 } |
|
48 |
|
49 RSmfCredMgrClientSession::RSmfCredMgrClientSession() |
|
50 { |
|
51 |
|
52 } |
|
53 |
|
54 TInt RSmfCredMgrClientSession::connectToServer() |
|
55 { |
|
56 TInt retry = KConnectAttempts; |
|
57 TInt r = 0; |
|
58 for (;;) |
|
59 { |
|
60 r = CreateSession(KCredMgrServerName, Version(), 1); |
|
61 if (r == KErrNone) |
|
62 { |
|
63 break; |
|
64 } |
|
65 else if (r != KErrNotFound && r != KErrServerTerminated) |
|
66 { |
|
67 return r; |
|
68 } |
|
69 |
|
70 if (--retry == 0) |
|
71 { |
|
72 return r; |
|
73 } |
|
74 |
|
75 r = StartServer(); |
|
76 if (r != KErrNone && r != KErrAlreadyExists) |
|
77 { |
|
78 return r; |
|
79 //error |
|
80 } |
|
81 } |
|
82 |
|
83 return r; |
|
84 |
|
85 } |
|
86 |
|
87 TVersion RSmfCredMgrClientSession::Version() const |
|
88 { |
|
89 return (TVersion(KSecureServMajorVersionNumber, |
|
90 KSecureServMinorVersionNumber, KSecureServBuildVersionNumber)); |
|
91 } |
|
92 |
|
93 void RSmfCredMgrClientSession::Close() |
|
94 { |
|
95 RSessionBase::Close(); |
|
96 } |
|
97 |
|
98 void RSmfCredMgrClientSession::RequestAsyncService( |
|
99 TCredentialServerRequestID aRequestType, TRequestStatus& aStatus) |
|
100 { |
|
101 SendReceive(aRequestType, aStatus); |
|
102 } |
|
103 |
|
104 void RSmfCredMgrClientSession::RequestService( |
|
105 TCredentialServerRequestID aRequestType, const TIpcArgs &aArgs) |
|
106 { |
|
107 TInt err = SendReceive(aRequestType, aArgs); |
|
108 |
|
109 } |
|
110 |