|
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: Session class to connect SatServer. |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 #include <RSatSession.h> |
|
20 #include "SatSOpcodes.h" |
|
21 #include "SatServerFactory.h" |
|
22 #include "SatLog.h" |
|
23 |
|
24 _LIT( KSatSessionMtx, "SATSESSIONMTX" ); |
|
25 |
|
26 // ============================ MEMBER FUNCTIONS =============================== |
|
27 |
|
28 // ----------------------------------------------------------------------------- |
|
29 // RSatSession::RSatSession |
|
30 // C++ default constructor can NOT contain any code, that |
|
31 // might leave. |
|
32 // ----------------------------------------------------------------------------- |
|
33 // |
|
34 EXPORT_C RSatSession::RSatSession() : |
|
35 RSessionBase() |
|
36 { |
|
37 LOG( SIMPLE, "SATCLIENT: RSatSession::RSatSession calling-exiting" ) |
|
38 } |
|
39 |
|
40 // ----------------------------------------------------------------------------- |
|
41 // RSatSession::ConnectL |
|
42 // Connects to SatServer. |
|
43 // ----------------------------------------------------------------------------- |
|
44 // |
|
45 EXPORT_C void RSatSession::ConnectL() |
|
46 { |
|
47 LOG( SIMPLE, "SATCLIENT: RSatSession::ConnectL calling" ) |
|
48 |
|
49 #ifdef ENABLE_SAT_LOGGING |
|
50 RProcess test; |
|
51 LOG2( SIMPLE, |
|
52 "SATCLIENT: RSatSession::ConnectL UID of calling process: 0x%x", |
|
53 test.SecureId().iId ) |
|
54 test.Close(); |
|
55 #endif |
|
56 |
|
57 RMutex sessionStartMutex; |
|
58 TInt createErr( sessionStartMutex.CreateGlobal( KSatSessionMtx ) ); |
|
59 if ( createErr ) |
|
60 { |
|
61 TInt openErr( sessionStartMutex.OpenGlobal( KSatSessionMtx ) ); |
|
62 User::LeaveIfError( openErr ); |
|
63 LOG( SIMPLE, "SATCLIENT: Opened SATSESSIONMTX" ) |
|
64 } |
|
65 |
|
66 LOG( SIMPLE, "SATCLIENT: Asking ownership of SATSESSIONMTX" ) |
|
67 sessionStartMutex.Wait(); |
|
68 LOG( SIMPLE, "SATCLIENT: Got ownership of SATSESSIONMTX" ) |
|
69 |
|
70 // Create new session for SatServer. |
|
71 TInt error( CreateSession( KSatServerName, Version(), KSatMessageSlots ) ); |
|
72 |
|
73 // Server may not be fully started, so let's retry after synchronization. |
|
74 if ( KErrNone != error ) |
|
75 { |
|
76 LOG2( SIMPLE, |
|
77 "SATCLIENT: RSatSession::ConnectL CreateSession %d", error ) |
|
78 |
|
79 // Starts a new process, loading SAT Server. |
|
80 TBuf<1> arguments; |
|
81 RProcess satProcess; |
|
82 |
|
83 if ( KErrNone == satProcess.Create( KSatServerNameAndPath, arguments ) ) |
|
84 { |
|
85 TRequestStatus rendezvousStatus; |
|
86 |
|
87 satProcess.Rendezvous( rendezvousStatus ); |
|
88 satProcess.Resume(); |
|
89 User::WaitForRequest( rendezvousStatus ); |
|
90 LOG2( SIMPLE, |
|
91 "SATCLIENT: RSatSession::ConnectL Rendezvous %d", |
|
92 rendezvousStatus.Int() ) |
|
93 satProcess.Close(); |
|
94 } |
|
95 |
|
96 // Retry session creation. |
|
97 error = CreateSession( KSatServerName, |
|
98 Version(), KSatMessageSlots ); |
|
99 LOG2( DETAILED, |
|
100 "SATCLIENT: RSatSession::ConnectL CreateSession %d", |
|
101 error ) |
|
102 } |
|
103 |
|
104 LOG( SIMPLE, "SATCLIENT: Releasing ownership of SATSESSIONMTX" ) |
|
105 sessionStartMutex.Signal(); |
|
106 sessionStartMutex.Close(); |
|
107 User::LeaveIfError( error ); |
|
108 |
|
109 LOG( SIMPLE, "SATCLIENT: RSatSession::ConnectL exiting" ) |
|
110 } |
|
111 |
|
112 // ----------------------------------------------------------------------------- |
|
113 // RSatSession::Version |
|
114 // Returns the version of this API. |
|
115 // ----------------------------------------------------------------------------- |
|
116 // |
|
117 EXPORT_C TVersion RSatSession::Version() const |
|
118 { |
|
119 LOG( SIMPLE, "SATCLIENT: RSatSession::Version calling-exiting" ) |
|
120 |
|
121 #ifdef ENABLE_SAT_LOGGING |
|
122 RProcess test; |
|
123 LOG2( SIMPLE, |
|
124 "SATCLIENT: RSatSession::Version UID of calling process: 0x%x", |
|
125 test.SecureId().iId ) |
|
126 test.Close(); |
|
127 #endif |
|
128 |
|
129 return TVersion( |
|
130 KSatServerMajorVersionNumber, |
|
131 KSatServerMinorVersionNumber, |
|
132 KSatServerBuildVersionNumber ); |
|
133 } |